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 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