def run(self): while True: ConnectionEngine.lock('openConnectionsSemaphore') for connection in ConnectionEngine.attribute('connectionList'): playerInput = connection.pollInput() parsedInput = playerInput.lower().strip() player = connection.attributes['player'] if len(playerInput) > 0: self.processInput(player, playerInput) ConnectionEngine.release('openConnectionsSemaphore') sleep(0.005)
def removeClosedConnections(self): ConnectionEngine.lock('closedConnectionSemaphore') for connection in ConnectionEngine.attribute('closedConnections'): ConnectionEngine.attribute('connectionList').remove(connection) connection.attributes['socket'].close() player = connection.attributes['player'] playerName = player.attributes['name'] logoutNotificationEvent = Event() logoutNotificationEvent.attributes['signature'] = 'broadcast_to_all_players' logoutNotificationEvent.attributes['data']['message'] = '{} logged off.'.format(playerName) ActorEngine.receiveEvent(logoutNotificationEvent) ConnectionEngine.setAttribute('closedConnections', []) ConnectionEngine.release('closedConnectionSemaphore')
def run(self): while True: ConnectionEngine.lock("openConnectionsSemaphore") for connection in ConnectionEngine.attribute("connectionList"): try: playerInput = connection.attributes["socket"].recv(1024) playerInput = playerInput.strip() if len(playerInput) > 0: connection.attributes["inputBuffer"].append(playerInput) except: pass # socket unavailable for now, we'll get it next time ConnectionEngine.release("openConnectionsSemaphore") sleep(0.005)
def run(self): while True: ConnectionEngine.lock('openConnectionsSemaphore') for connection in ConnectionEngine.attribute('connectionList'): try: for line in connection.attributes['outputBuffer']: connection.attributes['socket'].send(line) connection.attributes['outputBuffer'] = [] except: #socket unavailable for now, we'll get it next time pass ConnectionEngine.release('openConnectionsSemaphore') sleep(0.005)
def run(self): while True: ConnectionEngine.lock('openConnectionsSemaphore') for connection in ConnectionEngine.attribute('connectionList'): try: playerInput = connection.attributes['socket'].recv(1024) playerInput = playerInput.strip() if len(playerInput) > 0: connection.attributes['inputBuffer'].append( playerInput) except: pass #socket unavailable for now, we'll get it next time ConnectionEngine.release('openConnectionsSemaphore') sleep(0.005)
def addNewConnections(self): ConnectionEngine.lock('newConnectionSemaphore') for connection in ConnectionEngine.attribute('newConnections'): player = connection.attributes['player'] loginEvent = Event() loginEvent.attributes['signature'] = 'player_login' loginEvent.attributes['data']['player'] = player RoomEngine.receiveEvent(loginEvent) ConnectionEngine.attribute('connectionList').append(connection) playerName = player.attributes['name'] loginNotificationEvent = Event() loginNotificationEvent.attributes['signature'] = 'broadcast_to_all_players' loginNotificationEvent.attributes['data']['message'] = '{} just logged in.'.format(playerName) ActorEngine.receiveEvent(loginNotificationEvent) ConnectionEngine.setAttribute('newConnections', []) ConnectionEngine.release('newConnectionSemaphore')
def run(self): while True: ConnectionEngine.lock('openConnectionsSemaphore') ConnectionEngine.lock('openConnectionsSemaphore') ConnectionEngine.lock('openConnectionsSemaphore') self.removeClosedConnections() self.addNewConnections() ConnectionEngine.release('openConnectionsSemaphore') ConnectionEngine.release('openConnectionsSemaphore') ConnectionEngine.release('openConnectionsSemaphore') sleep(0.5)