Exemple #1
0
 def proxyProcessRequest(self, theRequest, receptionTime):
     """ generated source for method proxyProcessRequest """
     startSleeping = System.currentTimeMillis()
     timeToFinish = receptionTime
     timeToSleep = 0L
     try:
         if isinstance(theRequest, (PlayRequest, )):
             if self.theDefaultGamer.getMatch() != None:
                 timeToFinish = receptionTime + self.theDefaultGamer.getMatch().getPlayClock() * 1000 - self.PLAY_BUFFER
             else:
                 timeToFinish = System.currentTimeMillis()
             timeToSleep = timeToFinish - System.currentTimeMillis()
             if timeToSleep > 0:
                 Thread.sleep(timeToSleep)
         elif isinstance(theRequest, (StartRequest, )):
             GamerLogger.startFileLogging(self.theDefaultGamer.getMatch(), self.theDefaultGamer.getRoleName().__str__())
             print "Started playing " + self.theDefaultGamer.getMatch().getMatchId() + "."
             timeToFinish = receptionTime + self.theDefaultGamer.getMatch().getStartClock() * 1000 - self.METAGAME_BUFFER
             timeToSleep = timeToFinish - System.currentTimeMillis()
             if timeToSleep > 0:
                 Thread.sleep(timeToSleep)
         elif isinstance(theRequest, (StopRequest, )) or isinstance(theRequest, (AbortRequest, )):
             GamerLogger.stopFileLogging()
             self.needRestart = True
     except InterruptedException as ie:
         GamerLogger.log("Proxy", "[PROXY] Got woken up by final move!")
     GamerLogger.log("Proxy", "[PROXY] Proxy slept for " + (System.currentTimeMillis() - startSleeping) + ", and woke up " + (System.currentTimeMillis() - timeToFinish) + "ms late (started " + (startSleeping - receptionTime) + "ms after receiving message).")
Exemple #2
0
 def run(self):
     """ generated source for method run """
     while not isInterrupted():
         try:
             GamerLogger.log("Proxy", "[ProxyClient] Got message: " + theMessage)
             self.theCode = theMessage.messageCode
             self.notifyObservers(PlayerReceivedMessageEvent(in_))
             if isinstance(request, (StartRequest, )):
                 RequestFactory().create(theDefaultGamer, in_).process(1)
                 GamerLogger.startFileLogging(theDefaultGamer.getMatch(), theDefaultGamer.getRoleName().__str__())
                 GamerLogger.log("Proxy", "[ProxyClient] Got message: " + theMessage)
             outMessage.writeTo(self.theOutput)
             GamerLogger.log("Proxy", "[ProxyClient] Sent message: " + outMessage)
             self.notifyObservers(PlayerSentMessageEvent(out))
             if isinstance(request, (StopRequest, )):
                 GamerLogger.log("Proxy", "[ProxyClient] Got stop request, shutting down.")
                 System.exit(0)
             if isinstance(request, (AbortRequest, )):
                 GamerLogger.log("Proxy", "[ProxyClient] Got abort request, shutting down.")
                 System.exit(0)
         except Exception as e:
             GamerLogger.logStackTrace("Proxy", e)
             self.notifyObservers(PlayerDroppedPacketEvent())
     GamerLogger.log("Proxy", "[ProxyClient] Got interrupted, shutting down.")