Exemple #1
0
def addmapifdoesntexist(mapname, maparchivechecksum):
    map = Session.query(Map).filter(Map.map_name == mapname).first()
    if map == None:
        try:
            map = Map(mapname)
            map.map_archivechecksum = maparchivechecksum
            Session.add(map)
            Session.commit()
        except:
            return (False, "error adding to db: " + str(sys.exc_value))

        return (True, "")

    if map.map_archivechecksum == None:
        map.map_archivechecksum = maparchivechecksum
        try:
            Session.commit()
            return (True, "")
        except:
            return (False, "error updating db: " + str(sys.exc_value))

    if map.map_archivechecksum != maparchivechecksum:
        return (False, "map archive checksum doesn't match the one already on the website.")

    return (True, "")
Exemple #2
0
    def add(self):
        botrunnerName = self.form_result["botrunnerName"]
        sharedSecret = self.form_result["sharedSecret"]

        botrunner = BotRunner(botrunnerName, sharedSecret)
        Session.add(botrunner)
        Session.commit()

        c.message = "Added ok"
        return render('genericmessage.html')
Exemple #3
0
def addstaticdata():
    rolerows = Session.query(Role).all()
    for rolename in [ 'accountadmin', 'aiadmin', 'mapadmin', 'modadmin', 'leagueadmin', 'botrunneradmin', 'requestadmin', 'apiclient' ]:
        rolefound = False
        for rolerow in rolerows:
            if rolerow.role_name == rolename:
                rolefound = True
        if not rolefound:
            role = Role(rolename)
            Session.add(role)
            Session.flush()
Exemple #4
0
def setValue(key_name, key_value):
    global defaults

    if not defaults.has_key(key_name):
        raise Exception("confighelper.setvalue, no such key_name: " + key_name)

    configrow = Session.query(Config).filter(Config.config_key == key_name).first()
    if configrow == None:
        config = Config(key_name, key_value)
        Session.add(config)
    else:
        configrow.setValue(key_value)
Exemple #5
0
def logonUserWithAuthenticatedOpenID(openidurl):
    account = None
    # note: this could be optimized a little...
    for thisaccount in Session.query(Account):
        for openid in thisaccount.openids:
            if openid.openid == openidurl:
                account = thisaccount
    if account == None:
        # create new account
        account = Account(openidurl, openidurl)
        account.openids.append(OpenID(openidurl))
        Session.add(account)

    session['username'] = openidurl
Exemple #6
0
    def add(self):
        if not roles.isInRole(roles.modadmin):
            c.message = "You must be logged in as a modadmin"
            return render("genericmessage.html")

        modname = self.form_result["modName"]
        modarchivechecksum = self.form_result["modArchiveChecksum"]
        modurl = self.form_result["modUrl"]

        mod = Mod(modname)
        mod.mod_url = modurl
        mod.mod_archivechecksum = modarchivechecksum
        Session.add(mod)
        Session.commit()

        c.message = "Added ok"
        return render("genericmessage.html")
Exemple #7
0
    def add(self):
        if not roles.isInRole(roles.modadmin):
            c.message = "You must be logged in as a modadmin. Sorry, temporary"
            return render('genericmessage.html')

        enginename = self.form_result["engineName"]
        enginearchivechecksum = self.form_result["engineArchiveChecksum"]
        engineurl = self.form_result["engineUrl"]

        engine = Engine(enginename)
        engine.engine_url = engineurl
        engine.engine_archivechecksum = enginearchivechecksum
        Session.add(engine)
        Session.commit()

        c.message = "Added ok"
        return render('genericmessage.html')
Exemple #8
0
    def add(self):
        if not roles.isInRole(roles.mapadmin):
            c.message = "You must be logged in as a mapadmin"
            return render('genericmessage.html')

        mapname = self.form_result["mapName"]
        maparchivechecksum = self.form_result["mapArchiveChecksum"]
        mapurl = self.form_result["mapUrl"]

        map = Map(mapname)
        map.map_url = mapurl
        map.map_archivechecksum = maparchivechecksum
        Session.add(map)
        Session.commit()

        c.message = "Added ok"
        return render('genericmessage.html')
Exemple #9
0
def validatesharedsecret(lbotrunnername, sharedsecret):
    global botrunnername

    botrunner = getBotRunner(lbotrunnername)

    if botrunner == None:
        # Never seen this botrunner before, just add it
        botrunner = BotRunner(lbotrunnername, sharedsecret)
        Session.add(botrunner)
        Session.commit()

        # if this fails, return true anyway
        return True
    else:
        if botrunner.botrunner_sharedsecret == sharedsecret:
            botrunnername = lbotrunnername
            return True
        return False
Exemple #10
0
    def add(self):
        if not roles.isInRole(roles.accountadmin):
            c.message = "You must be logged in as a accountadmin"
            return render('genericmessage.html')

        username = self.form_result['username']
        userfullname = self.form_result['userfullname']
        email = self.form_result['email']
        password = self.form_result['password']

        account = Account(username, userfullname)
        account.passwordinfo = PasswordInfo(password)
        account.email = email
        Session.add(account)
        Session.commit()

        c.message = "Added ok"
        return render('genericmessage.html')
Exemple #11
0
    def add(self):
        if not roles.isInRole(roles.aiadmin):
            c.message = "You must be logged in as aiadmin"
            return render("genericmessage.html")

        aiName = self.form_result["aiName"]
        aiVersion = self.form_result["aiVersion"]
        downloadUrl = self.form_result["downloadUrl"]
        needsCompiling = self.form_result["needsCompiling"]

        ai = AI(aiName, aiVersion)
        ai.ai_downloadurl = downloadUrl
        ai.ai_needscompiling = needsCompiling
        ai.owneraccount = accounthelper.getAccount(session["user"])
        Session.add(ai)
        Session.commit()

        c.message = "Added ok"
        return render("genericmessage.html")
Exemple #12
0
    def submit(self):
        map = Session.query(Map).filter(Map.map_name == self.form_result['mapname']).first()
        mod = Session.query(Mod).filter(Mod.mod_name == self.form_result['modname']).first()
        ai0 = Session.query(AI).filter(AI.ai_id == self.form_result['ai0']).first()
        ai1 = Session.query(AI).filter(AI.ai_id == self.form_result['ai1']).first()
        ai0side = Session.query(ModSide).filter(ModSide.mod_side_id == self.form_result['ai0side']).first()
        ai1side = Session.query(ModSide).filter(ModSide.mod_side_id == self.form_result['ai1side']).first()

        matchrequest = MatchRequest(ai0 = ai0, ai1 = ai1, map = map, mod = mod,
                                    speed = self.form_result['speed'],
                                    softtimeout = self.form_result['softtimeout'],
                                    hardtimeout = self.form_result['hardtimeout'],
                                    ai0_side=ai0side, ai1_side=ai1side)

        Session.add(matchrequest)

        Session.commit()

        return "Submitted ok."
Exemple #13
0
def addaiifdoesntexist(ainame, aiversion):
    ai = getAI(ainame, aiversion)
    if ai == None:
        ai_base = Session.query(AIBase).filter(AIBase.ai_base_name == 
                                ainame).first()
        if ai_base == None:
            ai_base = AIBase(ainame)
            Session.add(ai_base)
            Session.flush()
        ai_base_id = ai_base.ai_base_id
        try:
            ai = AI(ai_base_id, aiversion)
            Session.add(ai)
            Session.commit()
        except:
            print sys.exc_value
            return(False, "error adding to db: " + str(sys.exc_value))

    return (True,'')
Exemple #14
0
    def add(self):
        if not roles.isInRole(roles.leagueadmin):
            c.message = "You must be logged in as a leagueadmin"
            return render('genericmessage.html')

        leagueName = self.form_result["leagueName"]
        modId = self.form_result["modId"]
        mapId = self.form_result["mapId"]
        speed = self.form_result["speed"]
        softtimeout = self.form_result["softtimeout"]
        hardtimeout = self.form_result["hardtimeout"]
        nummatchesperaipair = self.form_result["nummatchesperaipair"]
        sides = self.form_result["sides"]
        sidemodes = self.form_result["sidemodes"]
        playagainstself = self.form_result["playagainstself"]
        account = Session.query(Account).filter(Account.username == session['user']).first()
        ais = []
        for i in range(Session.query(AI).count()):
            ai_i = 'ai_checkbox_' + str(i)
            if (self.form_result.has_key(ai_i)):
                ais.append(i)

        league = League(leagueName, account, modId, mapId,
                nummatchesperaipair, speed, softtimeout, hardtimeout,
                sides, sidemodes, playagainstself)
        leagueais = [LeagueAI(ai, league) for ai in ais]
        Session.add(league)
        Session.add_all(leagueais)        
        
        matchrequests = Session.query(MatchRequest).filter(MatchRequest.league_id ==\
                league.league_id)         
        matchresults = [req for req in matchrequests if req.matchresult != None] 
        
        matchscheduler.addLeagueMatches(league, matchrequests, matchresults)
        Session.flush()
        Session.commit()
        
        redirect(url(controller='league', action='view', id=league.league_id))
def addmatchrequest(ai0, ai1, mod, map, speed, softtimeout, hardtimeout):
    newmatchrequest = MatchRequest(ai0 = ai0, ai1 = ai1, mod = mod, map = map, speed = speed, softtimeout = softtimeout, hardtimeout = hardtimeout)
    Session.add(newmatchrequest)