def sendInitialConnection(self): pckt = Packet.construct(Opcodes.MSG_INITIAL_CONNECTION) pckt.writeString("Raito Bezarius", "dg_classm32.gif") pckt.writeUint16(32) pckt.writeUint32(0, 0) self.sendPacket(pckt)
def onWorldLoaded(_): print ('Pushing the world in the game!') self.factory.game.popAllStates() self.factory.game.pushState(self.world) print ('Sending spawn request.') pckt = Packet.construct(Opcodes.CMSG_SPAWN_INGAME) self.sendPacket(pckt)
def say(text): self.onChat(text) pckt = Packet.construct(MSG_CHAT_MESSAGE) pckt.writeUint64(self.objectId) pckt.writeString(text) self.map.broadcastPacket(pckt)
def castSpell(spell, angle): pckt = Packet.construct(Opcodes.MSG_CAST_SPELL) pckt.writeUint64(self.objectId) pckt.writeUint32(spell.effect, spell.displayId) pckt.writeFloat(angle) pckt.writeUint16(self.map.generateSpellBoxID()) self.map.broadcastPacket(pckt) self.map.addSpell(self, spell, angle)
def sendPositionUpdateToMap(self, diff, packetId=None, ignoreMyself=False): pckt = Packet.construct(Opcodes.SMSG_MOVE_OBJECT) pckt.writeUint64(self.objectId) pckt.writeVector(self.position, self.velocity) self.map.broadcastPlayers(pckt, exclude=[self.objectId]) if not ignoreMyself: if packetId is not None: pckt.writeUint64(packetId) self.sendPacket(pckt)
def handleInitialConnection(self, packet): # Received initial parameters from client. # Window size, player name, etc... playerName = packet.readString() tilesetFilename = packet.readString() tileSize = packet.readUint16() tx, ty = packet.read('!II') tilesetPos = Vector2(tx, ty) plr = Player(playerName, tileSize, tilesetFilename, tilesetPos) plr.bindSession(self) self.player = plr # Answer by a initial connection with the player ID. pckt = Packet.construct(Opcodes.MSG_INITIAL_CONNECTION) pckt.writeBool(True) pckt.writeUint64(self.player.objectId) pckt.writeUint32(1) self.sendPacket(pckt) print ('Initial connection established with player: {}'.format(playerName))
def sendNotification(self, message): pckt = Packet.construct(SMSG_NOTIFICATION); pckt.writeString(message) self.sendPacket(pckt)
def sendMovementRequest(self, evtCode): pckt = Packet.construct(Opcodes.CMSG_MOVE) pckt.writeUint32(evtCode) self.world.me.doMovePrediction(pckt._id, evtCode) self.sendPacket(pckt)
def spellHit(spellBox): pckt = Packet.construct(Opcodes.MSG_REMOVE_SPELL) pckt.writeUint16(spellBox.boxId) self.map.broadcastPacket(pckt) self.takeDamage(spellBox.template.value, spellBox.caster)