def playerCon(self,player): self.openLog() print "CONNECTED " +str(len(player.room.players)) # Close the room at 2 if(len(player.room.players) == 2): print "Chat started in " + player.room.roomID player.room.open = False # Tell players its time to chat messageChatStart = MessageWriter() messageChatStart.writeByte(MESSAGE_BEGIN_CHAT) messageChatStart.writeInt(1) for p in player.room.players: p.protocol.sendMessage(messageChatStart)
def playerDisconnected(self,player): if player == None: return messagePlayerDisconnected = MessageWriter() messagePlayerDisconnected.writeByte(MESSAGE_PLAYER_DISCONNECTED) messagePlayerDisconnected.writeInt(player.playerID) # Notify the other players that the player disconnected if player.room and len(player.room.players) > 0: for p in player.room.players: if p != player: p.protocol.sendMessage(messagePlayerDisconnected)
def handleMessage(self,messageId,message,player): print "Got " + str(messageId) if messageId == MESSAGE_PLAYER_CHAT: self.playerChat(player,message) elif messageId == MESSAGE_PLAYER_CONNECTED: self.playerCon(player) else: for p in player.room.players: if p != player: message.offset = 0 outgoingMessage = MessageWriter() outgoingMessage.data = message.data p.protocol.sendMessage(outgoingMessage)