Ejemplo n.º 1
0
    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, '']
Ejemplo n.º 2
0
    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])
Ejemplo n.º 3
0
    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