def setRoomName_434d(self, pkt): newName = util.stripZeros(pkt.data[0:63]) thisLobby = self.factory.getLobbies()[self._user.state.lobbyId] room = self._user.state.room data = '\0\0\0\0' if room: if newName != room.name: # prevent renaming to existing rooms if thisLobby.isRoom(newName): data = '\xff\xff\xff\xff' else: thisLobby.renameRoom(room, newName) room.usePassword = struct.unpack('!B',pkt.data[64:65])[0] == 1 if room.usePassword: room.password = util.stripZeros(pkt.data[65:80]) self.sendRoomUpdate(room) self.sendData(0x434e,data)
def joinRoom_4320(self, pkt): roomId = struct.unpack('!i', pkt.data[0:4])[0] thisLobby = self.factory.getLobbies()[self._user.state.lobbyId] room = thisLobby.getRoomById(roomId) if room is None: log.msg('ERROR: Room (id=%d) does not exist.' % roomId) self.sendData(0x4321, b'\0\0\0\1') else: if room.usePassword: enteredPassword = util.stripZeros(pkt.data[4:19]) if enteredPassword != room.password: log.msg('ERROR: Room (id=%d) password does not match.' % roomId) self.sendData(0x4321, b'\xff\xff\xfd\xda') else: room.enter(self._user) else: room.enter(self._user) self.sendRoomUpdate(room) self.sendPlayerUpdate(room.id) data = b'\0\0\0\0' if room.matchSettings: data += room.matchSettings.match_time self.sendData(0x4321, data) # give players in room stun of joiner # special 4330 packet self.do_4330(room) # give joiner stun of players in room self.sendZeros(0x4346, 0) for otherUsr in room.players: if otherUsr == self._user: continue data = (b'%(pad1)s%(ip1)s%(port1)s' b'%(ip2)s%(port2)s%(id)s' b'%(someField)s%(participate)s') % { b'pad1': b'\0' * 32, b'ip1': util.padWithZeros(otherUsr.state.ip1, 16), b'port1': struct.pack('!H', otherUsr.state.udpPort1), b'ip2': util.padWithZeros(otherUsr.state.ip2, 16), b'port2': struct.pack('!H', otherUsr.state.udpPort2), b'id': struct.pack('!i', otherUsr.profile.id), b'someField': struct.pack('!H', 0), b'participate': struct.pack('!B', room.getPlayerParticipate(otherUsr)), } self.sendData(0x4347, data) self.sendZeros(0x4348, 0)
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 createRoom_4310(self, pkt): thisLobby = self.factory.getLobbies()[self._user.state.lobbyId] roomName = util.stripZeros(pkt.data[0:64]) try: existing = thisLobby.getRoom(roomName) self.sendData(0x4311,'\xff\xff\xff\x10') except KeyError: room = lobby.Room(thisLobby) room.name = roomName room.usePassword = struct.unpack('!B',pkt.data[64:65])[0] == 1 if room.usePassword: room.password = util.stripZeros(pkt.data[65:80]) # put room creator into the room room.enter(self._user) # add room to the lobby thisLobby.addRoom(room) log.msg('Room created: %s' % str(room)) # notify all users in the lobby about the new room self.sendRoomUpdate(room) # notify all users in the lobby that player is now in a room self.sendPlayerUpdate(room.id) self.sendZeros(0x4311,4)