def registerunsupportedai(self, botrunnername, sharedsecret, ainame, aiversion): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") if not aihelper.setbotrunnernotsupportsthisai(botrunnername, ainame, aiversion): return (False, "couldn't mark ai as not supported for botrunner") return (True, '')
def finisheddownloadingai(self, botrunnername, sharedsecret, sessionid, ai_name, ai_version): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") # get rid of any downloading ai marker for this session session = botrunnerhelper.getBotRunnerSession(botrunnername, sessionid) session.downloadingai = None Session.commit() return [True, '']
def registersupportedai(self, botrunnername, sharedsecret, ainame, aiversion): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") [success, errorMessage] = aihelper.addaiifdoesntexist(ainame, aiversion) if not success: return (False, "Couldn't register ai " + errorMessage) if not aihelper.setbotrunnersupportsthisai(botrunnername, ainame, aiversion): return (False, "couldn't mark ai as supported for botrunner") return (True, '')
def registersupportedmod(self, botrunnername, sharedsecret, modname, modarchivechecksum_string, sides): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") [success, errorMessage] = modhelper.addmodifdoesntexist(modname, long(modarchivechecksum_string), sides) if not success: return (False, "Couldn't register mod " + errorMessage) if not modhelper.setbotrunnersupportsthismod(botrunnername, modname): return (False, "couldn't mark mod as supported for botrunner") return (True, '')
def registersupportedmap(self, botrunnername, sharedsecret, mapname, maparchivechecksum_string): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") if not maphelper.addmapifdoesntexist(mapname, long(maparchivechecksum_string)): return (False, "Couldn't register map") if not maphelper.setbotrunnersupportsthismap(botrunnername, mapname): return (False, "couldn't mark map as supported for botrunner") return (True, '')
def submitresult(self, botrunnername, sharedsecret, matchrequestid, resultstring, uploaddatadict): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") # check if this matchrequest_id was actually assigned to this engine # otherwise ditch the result if not matchrequestcontroller.matchrequestvalidforthisserver( botrunnername, matchrequestid): return (False, "invalid matchrequestid") # store the result, and remove from queue # if the replay upload fails, well, that's a shame, but it's not the end # of the world... # or we could get the botrunner to retry several times, to be decided. matchrequestcontroller.storeresult(botrunnername, matchrequestid, resultstring) if 'replay' in uploaddatadict: # now to handle uploading the replay... replaycontentsraw = uploaddatadict['replay'].data if replaycontentsraw != None and replaycontentsraw != '': replayfilehandle = open(replaycontroller.getReplayPath( matchrequestid), "wb") replayfilehandle.write(replaycontentsraw) replayfilehandle.close() # really, we should validate that this match was assigned # to this server first... # also, ideally, if there is no upload, we should store that # info in the database somewhere if 'infolog' in uploaddatadict: contentsraw = uploaddatadict['infolog'].data if contentsraw != None and contentsraw != '': filehandle = open(replaycontroller.getInfologPath( matchrequestid), "wb") filehandle.write(contentsraw) filehandle.close() return (True, '')
def ping(self, botrunnername, sharedsecret, sessionid, status): if not botrunnerhelper.validatesharedsecret( botrunnername, sharedsecret): return (False, "Not authenticated") botrunner = botrunnerhelper.getBotRunner(botrunnername) if botrunner == None: return (False, '') targetsession = None for session in botrunner.sessions: if session.botrunner_session_id == sessionid: targetsession = session if targetsession == None: targetsession = BotRunnerSession(sessionid) botrunner.sessions.append(targetsession) targetsession.lastpingtime = datetime.datetime.now() targetsession.lastpingstatus = status Session.commit() return (True, '')
def getrequest(self, botrunnername, sharedsecret, sessionid): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") # get rid of any downloading ai marker for this session session = botrunnerhelper.getBotRunnerSession(botrunnername, sessionid) session.downloadingai = None Session.flush() requestitem = matchrequestcontroller.getcompatibleitemfromqueue( botrunnername, sessionid) if requestitem == None: return (True, []) # can't return None in python 2.4 else: Session.commit() # convert to dict, otherwise can't marshall :-/ # is there a better way to do this? requestitemdict = {} requestitemdict['matchrequest_id'] = requestitem.matchrequest_id requestitemdict['ai0_name'] = requestitem.ai0.ai_base.ai_base_name requestitemdict['ai0_version'] = requestitem.ai0.ai_version requestitemdict['ai1_name'] = requestitem.ai1.ai_base.ai_base_name requestitemdict['ai1_version'] = requestitem.ai1.ai_version requestitemdict['ai0_side'] = requestitem.ai0_side.mod_side_name requestitemdict['ai1_side'] = requestitem.ai1_side.mod_side_name requestitemdict['map_name'] = requestitem.map.map_name requestitemdict['mod_name'] = requestitem.mod.mod_name requestitemdict['speed'] = requestitem.speed requestitemdict['softtimeout'] = requestitem.softtimeout requestitemdict['hardtimeout'] = requestitem.hardtimeout requestitemdict['gameendstring'] = confighelper.getValue( 'gameendstring') return (True, [requestitemdict])
def getdownloadrequest(self, botrunnername, sharedsecret, sessionid): if not botrunnerhelper.validatesharedsecret(botrunnername, sharedsecret): return (False, "Not authenticated") botrunner = botrunnerhelper.getBotRunner(botrunnername) # first we'll look for an ai to download (one in the queue that this # botrunner doesn't have), then a map, then a mod # update: ignore sessions for now, since even aegis' cluster # doesn't use them ;-) aisbeingdownloaded = [] # list of ais being downloaded by this botrunner # we'll make sure that each botrunner can only download one of each # ai name/version pair # at any one time, for example, for aegis' cluster this makes sense, # since all botrunner # sessions share the same ai directory for session in botrunner.sessions: if session.downloadingai != None: # no point in including download for this specific session, # clearly this session aborted it, or it failed, or soemthing if session.botrunner_session_id != sessionid: aisbeingdownloaded.append(session.downloadingai) requests = Session.query(MatchRequest).\ filter(MatchRequest.matchresult == None).\ filter(MatchRequest.matchrequestinprogress == None).\ all() aistodownload = [] # just add all to list, and select randomly, # so dont centrate on # any failed ones mapstodownload = [] modstodownload = [] for request in requests: mapok = False modok = False ai0ok = False ai1ok = False # probably can add this stuff to the query abovee, but not sure # how compliated that # would look. fairly readable in this format at least for map in botrunner.supportedmaps: if map.map_name == request.map.map_name: mapok = True for mod in botrunner.supportedmods: if mod.mod_name == request.mod.mod_name: modok = True for ai in botrunner.supportedais: if ai.ai_base.ai_base_name == request.ai0.ai_base.ai_base_name and\ ai.ai_version == request.ai0.ai_version: ai0ok = True if ai.ai_base.ai_base_name == request.ai1.ai_base.ai_base_name and\ ai.ai_version == request.ai1.ai_version: ai1ok = True if not mapok: if request.map not in mapstodownload and\ request.map.map_url != None: mapstodownload.append(request.map) if not modok: if request.mod not in modstodownload and\ request.mod.mod_url != None: modstodownload.append(request.mod) if not ai0ok: if not request.ai0 in aistodownload and\ request.ai0.ai_downloadurl != None: aistodownload.append(request.ai0) if not ai1ok: if not request.ai1 in aistodownload and\ request.ai1.ai_downloadurl != None: aistodownload.append(request.ai1) if len(aistodownload) != 0: # select one at random... aitodownload = aistodownload[random.randint(0, len(aistodownload) - 1)] session = botrunnerhelper.getBotRunnerSession( botrunnername, sessionid) session.downloadingai = aitodownload dicttoreturn = {'ai_name': aitodownload.ai_name, 'ai_version': aitodownload.ai_version, 'ai_downloadurl': aitodownload.ai_downloadurl, 'ai_needscompiling': \ aitodownload.ai_needscompiling} Session.commit() return [True, [dicttoreturn]] # next up: try a map if len(mapstodownload) != 0: maptodownload = mapstodownload[random.randint(0, len(mapstodownload) - 1)] dicttoreturn = {'map_name': maptodownload.map_name, 'map_url': maptodownload.map_url} return [True, [dicttoreturn]] # next up: try a mod if len(modstodownload) != 0: modtodownload = modstodownload[random.randint(0, len(modstodownload) - 1)] dicttoreturn = {'mod_name': modtodownload.mod_name, 'mod_url': modtodownload.mod_url} return [True, [dicttoreturn]] # nothing to download... return [True, []] # cannot return None in python xmlrpclib 2.4