def _closeIdleConnections(self): t = time.time() - 20.0 #20 seconds until considered idle for sessionid, sm in self._serverMessage.items(): if sm.last_active < t: log("Close connection with sessionid %s because it was idle for %.1f seconds" % (sessionid, time.time() - sm.last_active)) if sm.socket is not None: sm.socket.close() del self._serverMessage[sessionid]
def _closeIdleConnections(self): t = time.time() - 20.0 #20 seconds until considered idle for sessionid, sm in self._serverMessage.items(): if sm.last_active < t: log("Close connection with sessionid %s because it was idle for %.1f seconds" % ( sessionid, time.time() - sm.last_active)) if sm.socket is not None: sm.socket.close() del self._serverMessage[sessionid]
def getport(self): if hasattr(self, '_port'): return self._port try: port = re.findall('value=".*"', urllib.urlopen('http://%s:8000' % self.host).read())[0] port = int(port[7:-1]) except IOError: log("ERROR: Can't connect to BnB server on %s:8000" % self.host) raise IOError except IndexError: log("ERROR: Connected to BnB server but unable to detect a running game") raise IOError self._port = port return port
def getport(self): if hasattr(self, '_port'): return self._port try: port = re.findall( 'value=".*"', urllib.urlopen('http://%s:8000' % self.host).read())[0] port = int(port[7:-1]) except IOError: log("ERROR: Can't connect to BnB server on %s:8000" % self.host) raise IOError except IndexError: log("ERROR: Connected to BnB server but unable to detect a running game" ) raise IOError self._port = port return port
def remove_player(self, player_id=0, sessionid=""): log("Remove player " + player_id) socket = self.sessionSocket(sessionid) socket.send(message(CMSG_REMOVE_PLAYER, int(player_id)))
def add_player(self, player_id=0, sessionid=""): log("Adding player " + player_id) socket = self.sessionSocket(sessionid) socket.send(message(CMSG_ADD_PLAYER, int(player_id)))
def player_name(self, player_id=0, name="", sessionid=""): log("Changing player #%s name to %s" % (player_id, name)) socket = self.sessionSocket(sessionid) socket.send(message(CMSG_PLAYER_NAME, int(player_id), name))