def chat_4400(self, pkt): thisLobby = self.factory.getLobbies()[self._user.state.lobbyId] chatType = pkt.data[0:2] message = util.stripZeros(pkt.data[10:]) data = '%s%s%s%s%s' % ( chatType, pkt.data[2:6], struct.pack('!i',self._user.profile.id), util.padWithZeros(self._user.profile.name,48), #util.padWithZeros(message, 128)) message[:126]+'\0\0') if chatType=='\x00\x01': # add to lobby chat history thisLobby.addToChatHistory( lobby.ChatMessage(self._user.profile, message)) # lobby chat for usr in thisLobby.players.itervalues(): usr.sendData(0x4402, data) elif chatType=='\x01\x08': # room chat room = self._user.state.room if room: for usr in room.players: usr.sendData(0x4402, data) elif chatType=='\x00\x02': # private message profileId = struct.unpack('!i',pkt.data[6:10])[0] usr = thisLobby.getPlayerByProfileId(profileId) if usr: # add to lobby chat history thisLobby.addToChatHistory( lobby.ChatMessage( self._user.profile, message, usr.profile, pkt.data[2:6])) usr.sendData(0x4402, data) if usr != self._user: self._user.sendData(0x4402, data) # echo to self else: log.msg( 'WARN: user with profile id = ' '%d not found.' % profileId) elif chatType=='\x01\x05': # match chat room = self._user.state.room if room: for usr in room.players: usr.sendData(0x4402, data) elif chatType=='\x01\x07': # stadium chat room = self._user.state.room if room: for usr in room.players: usr.sendData(0x4402, data)
def broadcastRoomChat(self, room, text): chatMessage = lobby.ChatMessage(lobby.SYSTEM_PROFILE, text) for usr in room.players: data = b'%s%s%s%s%s' % ( b'\x01\x08', b'\0\0\0\0', struct.pack('!i', chatMessage.fromProfile.id), util.padWithZeros(chatMessage.fromProfile.name, 48), chatMessage.text.encode('utf-8')[:126] + b'\0\0') usr.sendData(0x4402, data)
def broadcastSystemChat(self, aLobby, text): chatMessage = lobby.ChatMessage(lobby.SYSTEM_PROFILE, text) for usr in aLobby.players.values(): data = b'%s%s%s%s%s' % ( b'\0\1', b'\0\0\0\0', struct.pack('!i', chatMessage.fromProfile.id), util.padWithZeros(chatMessage.fromProfile.name, 48), chatMessage.text.encode('utf-8')[:126] + b'\0\0') usr.sendData(0x4402, data) aLobby.addToChatHistory(chatMessage)
def systemDayChange(self): message = 'Date: %s %s' % (time.ctime(), time.tzname[time.localtime().tm_isdst]) for aLobby in self.lobbies: try: player = next(iter(aLobby.players.values())) except StopIteration: aLobby.addToChatHistory( lobby.ChatMessage(lobby.SYSTEM_PROFILE, message)) else: if player.lobbyConnection: player.lobbyConnection.broadcastSystemChat(aLobby, message) # purge old chat messages aLobby.purgeOldChat() # reschedule for next day change now = datetime.now() today = datetime(now.year, now.month, now.day) td = today + timedelta(days=1) - now reactor.callLater(td.seconds + 1, self.systemDayChange)