Exemplo n.º 1
0
    def list(self):
        #FIXME: this should not be a part of a controller request
        botrunnerhelper.purgeExpiredSessions()
        Session.commit()

        botrunners = Session.query(BotRunner)

# if you know of a reliable way of just adding
#the following two data to  the business ojbects,
# go ahead:
        botrunnerdata = {}
        sessiondata = {}
        for botrunner in botrunners:
            rowspan = 1
            if len(botrunner.sessions) > 1:
                rowspan = len(botrunner.sessions)
            botrunnerdata[botrunner] = {}
            botrunnerdata[botrunner]['rowspan'] = rowspan
            for botSession in botrunner.sessions:
                sessiondata[botSession] = {}
                sessiondata[botSession]['pingtimestatus'] = 'down'
                if botSession.lastpingtime != None:
                    secondssincelastping = dates.timedifftototalseconds(
                            datetime.datetime.now() - botSession.lastpingtime)
                    sessiondata[botSession]['lastpingtimestring'] =\
                        str(botSession.lastpingtime)
                    if secondssincelastping < \
                        confighelper.getValue('expiresessionminutes') * 60:
                        sessiondata[botSession]['pingtimestatus'] = 'maybeok'
                    if secondssincelastping < confighelper.getValue(
                            'guimarksessionasmaybedownafterthismanyminutes') \
                            * 60:
                        sessiondata[botSession]['pingtimestatus'] = 'ok'

        c.botrunners = botrunners
        c.isIsLoggedIn = False
        if 'user' in session:
            c.isLoggedIn = True
            c.username = session['user']
        c.botrunnerData = botrunnerdata
        c.sessionData = sessiondata
        return render('viewbotrunners.html')
Exemplo 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])