コード例 #1
0
 def onMapInfo(self, packet):
     print("Connected to", self.nexusServer["name"], packet.name)
     if self.needsNewChar:
         print("Creating new char")
         create_packet = PacketHelper.CreatePacket("CREATE")
         create_packet.classType = Classes.WIZARD
         create_packet.skinType = 0
         self.send(create_packet)
         self.needsNewChar = False
     else:
         load_packet = PacketHelper.CreatePacket("LOAD")
         load_packet.charId = self.charData.currentCharId
         self.send(load_packet)
     self.random.setSeed(packet.fp)
コード例 #2
0
 def onUpdate(self, packet):
     updateAck_packet = PacketHelper.CreatePacket("UPDATEACK")
     self.send(updateAck_packet)
     for obj in packet.newObjs:
         if obj.status.objectId == self.objectId:
             self.pos = obj.status.pos
             self.playerData.parse(obj)
コード例 #3
0
 def onNewTick(self, packet):
     move_packet = PacketHelper.CreatePacket("MOVE")
     move_packet.tickId = packet.tickId
     move_packet.time = self.lastFrameTime
     move_packet.serverRealTimeMS = packet.serverRealTimeMS
     move_packet.newPos = self.pos
     move_packet.records = []
     self.send(move_packet)
     for status in packet.statuses:
         if status.objectId == self.objectId:
             self.playerData.parseStats(status.stats)
コード例 #4
0
 def sendHelloPacket(self):
     hello_packet = PacketHelper.CreatePacket("HELLO")
     hello_packet.buildVersion = self.buildVersion
     hello_packet.gameId = self.gameId
     hello_packet.accessToken = self.accessToken
     hello_packet.keyTime = self.keyTime
     hello_packet.key = self.key
     hello_packet.gameNet = "rotmg"
     hello_packet.playPlatform = "rotmg"
     hello_packet.userToken = self.clientToken
     self.send(hello_packet)
コード例 #5
0
 def hook(self, packet_type, func):
     if not self.active:
         print("Socket manager is not active")
         return
     if packet_type in self.hooks.keys():
         print("Packet type", packet_type, "is already hooked to function",
               self.hooks[packet_type])
         return
     if not PacketHelper.isValidPacket(
             packet_type) and packet_type != "ANY":
         print("Invalid packet_type:", packet_type)
         return
     self.hooks[packet_type] = func
コード例 #6
0
    def _listen(self):
        if not self.active:
            print("Socket manager is not active")
            return
        while 1:
            recv = None
            try:
                recv = self.sock.recv(HEADERSIZE)
                while len(recv) < HEADERSIZE:
                    recv += self.sock.recv(HEADERSIZE - len(recv))
            except ConnectionResetError:
                print("Client forcefully disconnected from", self.ip)
                if self.connected:
                    self.disconnect(False)
                return
            except ConnectionAbortedError:
                print("Stopped connection to", self.ip)
                if self.connected:
                    self.disconnect(False)
                return
            except OSError:  #Socket is closed
                return

            packet_id = recv[4]
            size = struct.unpack("!i", recv[:4])[0]
            msg = recv
            while len(msg) < size:
                recv = self.sock.recv(size - len(msg))
                msg += self.incomming_decoder.process(recv)
            try:
                packet_type = PacketId.idToType[packet_id]
            except KeyError:
                ##                print("Unknown packet id:", packet_id)
                ##                print(msg)
                continue
            if not "UNKNOWN" in packet_type:
                packet = PacketHelper.CreatePacket(packet_type)
                self.reader.resizeAndReset(size)
                self.reader.buffer = msg
                packet.read(self.reader)
                if packet.type in self.hooks.keys():
                    deamon_thread = threading.Thread(
                        target=self.hooks[packet.type], args=(packet, ))
                    deamon_thread.deamon = True
                    deamon_thread.start()
                if "ANY" in self.hooks.keys():
                    deamon_thread = threading.Thread(target=self.hooks["ANY"],
                                                     args=(packet, ))
                    deamon_thread.deamon = True
                    deamon_thread.start()
コード例 #7
0
    def shoot(self, angle):
        if self.clientManager.weapons is None:
            print("Weapons not loaded")
            return False
        if self.hasEffect(ConditionEffect.STUNNED, ConditionEffect.PAUSED,
                          ConditionEffect.PETRIFIED):
            return False
        if not self.playerData.inv[0] in self.clientManager.weapons.keys():
            return False
        time = self.getTime()
        attackPeriod = 1 / self.attackFreq() * (1 / 1)  #TODO
        if time < self.lastAttackTime + attackPeriod:
            return False
        self.lastAttackTime = time

        shootPacket = PacketHelper.CreatePacket("PLAYERSHOOT")
        shootPacket.time = time
        shootPacket.containerType = self.playerData.inv[0]
        shootPacket.speedMult = self.playerData.projSpeedMult
        shootPacket.lifeMult = self.playerData.projLifeMult

        weapon = self.clientManager.weapons[shootPacket.containerType]
        arcRads = weapon.arcGap * math.pi / 180
        totalArc = arcRads * (weapon.numProjectiles - 1)
        if totalArc < 0:
            totalArc = 0
        angle -= totalArc / 2

        for i in range(weapon.numProjectiles):
            shootPacket.bulletId = self.getBulletId()
            shootPacket.pos = self.pos.clone()
            shootPacket.pos.x += math.cos(angle) * 0.3
            shootPacket.pos.y += math.sin(angle) * 0.3
            shootPacket.angle = angle
            if arcRads > 0:
                angle += arcRads
            self.send(shootPacket)

        return True
コード例 #8
0
 def onEnemyShoot(self, packet):
     shootAck = PacketHelper.CreatePacket("SHOOTACK")
     shootAck.time = self.lastFrameTime
     self.send(shootAck)
コード例 #9
0
 def onServerPlayerShoot(self, packet):
     if packet.ownerId == self.objectId:
         shootAck = PacketHelper.CreatePacket("SHOOTACK")
         shootAck.time = self.lastFrameTime
         self.send(shootAck)
コード例 #10
0
 def onPing(self, packet):
     pong_packet = PacketHelper.CreatePacket("PONG")
     pong_packet.serial = packet.serial
     pong_packet.time = self.getTime()
     self.send(pong_packet)
コード例 #11
0
 def onGoto(self, packet):
     gotoAck_packet = PacketHelper.CreatePacket("GOTOACK")
     gotoAck_packet.time = self.lastFrameTime
     self.send(gotoAck_packet)
     if packet.objectId == self.objectId:
         self.pos = packet.pos.clone()
コード例 #12
0
 def nexus(self):
     packet = PacketHelper.CreatePacket("ESCAPE")
     self.send(packet)
     self.gameId = GameId.nexus
     self.key = []
     self.keyTime = -1