def getmatchresultsv1(self): try: requests = Session.query(MatchRequest).filter(MatchRequest.matchresult != None ) resultstoreturn = [] for request in requests: options = [] for option in request.options: options.append(option.option_name) newresulttoreturn = { 'matchrequest_id': request.matchrequest_id, 'map_name': request.map.map_name, 'mod_name': request.mod.mod_name, 'ais': [ { 'ai_name': request.ai0.ai_name, 'ai_version': request.ai0.ai_version }, { 'ai_name': request.ai1.ai_name, 'ai_version': request.ai1.ai_version } ], 'options': options, 'botrunner_name': request.matchrequestinprogress.botrunner.botrunner_name, 'matchresult': request.matchresult.matchresult } if os.path.isfile( replaycontroller.getReplayPath(request.matchrequest_id) ): newresulttoreturn['replayrelativeurl'] = replaycontroller.getReplayWebRelativePath(request.matchrequest_id) if os.path.isfile( replaycontroller.getInfologPath(request.matchrequest_id) ): newresulttoreturn['infologrelativeurl'] = replaycontroller.getInfologWebRelativePath(request.matchrequest_id) resultstoreturn.append( newresulttoreturn ) return [True, resultstoreturn ] except: return (False,"An unexpected exception occurred: " + str( sys.exc_info() ) + "\n" + str( traceback.extract_tb( sys.exc_traceback ) ) )
def getmatchv1(self, matchrequest_id): try: request = Session.query(MatchRequest).filter(MatchRequest.matchrequest_id == matchrequest_id).first() if request is not None: options = [] for option in request.options: options.append(option.option_name) newresulttoreturn = { 'matchrequest_id': request.matchrequest_id, 'map_name': request.map.map_name, 'mod_name': request.mod.mod_name, 'ais': [ { 'ai_name': request.ai0.ai_name, 'ai_version': request.ai0.ai_version }, { 'ai_name': request.ai1.ai_name, 'ai_version': request.ai1.ai_version } ], 'options': options, 'ai0_side': { 'mod_side_name' : request.ai0_side.mod_side_name, 'mod_side_id' : request.ai0_side.mod_side_id}, 'ai1_side': { 'mod_side_name' : request.ai1_side.mod_side_name, 'mod_side_id' : request.ai1_side.mod_side_id} } if request.matchrequestinprogress.botrunner != None: newresulttoreturn['botrunner_name'] = [True, request.matchrequestinprogress.botrunner.botrunner_name] else: newresulttoreturn['botrunner_name'] = [False, ''] if request.matchresult != None: newresulttoreturn['matchresult'] = [True, request.matchresult.matchresult] else: newresulttoreturn['matchresult'] = [False, ''] if os.path.isfile(replaycontroller.getReplayPath(request.matchrequest_id) ): newresulttoreturn['replayrelativeurl'] = replaycontroller.getReplayWebRelativePath(request.matchrequest_id) if os.path.isfile( replaycontroller.getInfologPath(request.matchrequest_id) ): newresulttoreturn['infologrelativeurl'] = replaycontroller.getInfologWebRelativePath(request.matchrequest_id) return [True, newresulttoreturn] else: return [False, 'no match with such id'] except: return (False,"An unexpected exception occurred: " + str( sys.exc_info() ) + "\n" + str( traceback.extract_tb( sys.exc_traceback ) ) )
def schedulematchv1(self, map_name, mod_name, ais, options, speed, softtimeout, hardtimeout): map = Session.query(Map).filter(Map.map_name == map_name).first() mod = Session.query(Mod).filter(Mod.mod_name == mod_name).first() ai0 = Session.query(AI).filter(AI.ai_name == ais[0]['ai_name']).\ filter(AI.ai_version == ais[0]['ai_version']).first() ai1 = Session.query(AI).filter(AI.ai_name == ais[1]['ai_name']).\ filter(AI.ai_version == ais[1]['ai_version']).first() ai0Side = Session.query(ModSide).filter(ModSide.mod_side_name == \ ais[0]['ai_side']).filter(ModSide.mod_id == mod.mod_id).first() ai1Side = Session.query(ModSide).filter(ModSide.mod_side_name == \ ais[1]['ai_side']).filter(ModSide.mod_id == mod.mod_id).first() if map == None or mod == None or ai0 == None or ai1 == None: return [False, 'one of your parameters did not correspond to an existing map, mod or ai. Please check and try again.'] if softtimeout == None or hardtimeout == None: return [False, 'you need to specify both a hard timeout and a soft timeout for the match'] if speed == None: speed = 1 matchrequest = MatchRequest(ai0 = ai0, ai1 = ai1, map = map, mod = mod, speed = speed, softtimeout = softtimeout, hardtimeout = hardtimeout, ai0_side = ai0Side, ai1_side = ai1Side) Session.add(matchrequest) # add options: availableoptions = Session.query(AIOption) for option in availableoptions: if option.option_name in options: matchrequest.options.append(option) Session.commit() return [True, matchrequest.matchrequest_id]
def getmatchrequestqueuev1(self): try: requests = Session.query(MatchRequest).filter(MatchRequest.matchresult == None ) requeststoreturn = [] for request in requests: options = [] for option in request.options: options.append(option.option_name) requeststoreturn.append( { 'matchrequest_id': request.matchrequest_id, 'map_name': request.map.map_name, 'mod_name': request.mod.mod_name, 'ais': [ { 'ai_name': request.ai0.ai_name, 'ai_version': request.ai0.ai_version }, { 'ai_name': request.ai1.ai_name, 'ai_version': request.ai1.ai_version } ], 'options': options, 'ai0_side': { 'mod_side_name' : request.ai0_side.mod_side_name, 'mod_side_id' : request.ai0_side.mod_side_id}, 'ai1_side': { 'mod_side_name' : request.ai1_side.mod_side_name, 'mod_side_id' : request.ai1_side.mod_side_id} } ) return [True, requeststoreturn ] except: return (False,"An unexpected exception occurred: " + str( sys.exc_info() ) + "\n" + str( traceback.extract_tb( sys.exc_traceback ) ) )
def schedulematchesv1(self,matches): matchrequest_ids = [] for match in matches: map_name = match["map_name"] mod_name = match["mod_name"] options = match["options"] ais = match["ais"] softtimeout = match["softtimeout"] hardtimeout = match["hardtimeout"] speed = match["speed"] ai0_side = ais[0]['ai_side'] ai1_side = ais[1]['ai_side'] try: map = Session.query(Map).filter(Map.map_name == map_name ).first() mod = Session.query(Mod).filter(Mod.mod_name == mod_name ).first() ai0 = Session.query(AI).filter(AI.ai_name == ais[0]['ai_name']).filter(AI.ai_version == ais[0]['ai_version'] ).first() ai1 = Session.query(AI).filter(AI.ai_name == ais[1]['ai_name']).filter(AI.ai_version == ais[1]['ai_version'] ).first() ai0_side = Session.query(ModSide).filter(ModSide.mod_side_id == ai0_side).first() ai1_side = Session.query(ModSide).filter(ModSide.mod_side_id == ai1_side).first() if map == None or mod == None or ai0 == None or ai1 == None or ai0_side == None or ai1_side == None: return [False,'one of your parameters did not correspond to an existing map, mod, ai or ai sides. Please check and try again.'] if softtimeout == None or hardtimeout == None: return [False,'you need to specify both a hard timeout and a soft timeout for the match'] if speed == None: speed = 1 matchrequest = MatchRequest( ai0 = ai0, ai1 = ai1, map = map, mod = mod, speed = speed, softtimeout = softtimeout, hardtimeout = hardtimeout, ai0_side = ai0_side, ai1_side = ai1_side ) Session.add( matchrequest ) # add options: availableoptions = Session.query(AIOption) for option in availableoptions: if option.option_name in options: matchrequest.options.append( option ) matchrequest_ids.append(matchrequest.matchrequest_id) except: return (False,"An unexpected exception occurred: " + str( sys.exc_info() ) + "\n" + str( traceback.extract_tb( sys.exc_traceback ) ) ) Session.commit() return [True, matchrequest_ids]
def getais(self): ailist = [] for ai in Session.query(AI): ailist.append({'ai_name': ai.ai_name, 'ai_version': ai.ai_version, 'ai_id':ai.ai_id}) return ailist
def getmodsides(self): return [{"mod_side_name" : i.mod_side_name, "mod_side_id" : i.mod_side_id, "mod_name" : Session.query(Mod.mod_name).filter(Mod.mod_id == i.mod_id).first()[0]} for i in Session.query(ModSide).all()]
def getmods(self): return [i[0] for i in Session.query(Mod.mod_name)]
def getmaps(self): return [i[0] for i in Session.query(Map.map_name)]
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