Example #1
0
    def handle_read(self):
        self.read_buffer += self.recv(4096)
        while self.read_buffer:
            pkt = packet()
            pkt.ReadFromBuffer(self.read_buffer, False)

            if pkt.size > len(self.read_buffer):
                break

            self.read_buffer = self.read_buffer[pkt.size:]

            buffer = pkt.GetBuffer(False)
            self.sender.write_buffer += [buffer]
            print "%s:%d -> %s:%d  %d bytes" % (self.addr[0], self.addr[1],
                                                self.server.there[0],
                                                self.server.there[1], pkt.size)
            print "OpCode : %d" % (pkt.opCode)
            print pkt.data.encode("hex")
            #print buffer.encode("hex")
            print
Example #2
0
    def handle_read(self):
        self.read_buffer += self.recv(
            4096)  # Read a buffer of 4k append to the read_buffer string
        while self.read_buffer:  # for each packet in the read_buffer
            pkt = packet()  # Create a packet object
            pkt.ReadFromBuffer(self.read_buffer, False)

            if pkt.size > len(
                    self.read_buffer
            ):  # If the packet is not full we go out of the while loop
                break

            if pkt.sender == "UniverseAgent":
                if pkt.opCode == 1:
                    status = struct.unpack('!I', pkt.data[:4])
                    # 0x00000001 mean right login informations
                    if status == 0x00000001:
                        unk2, unk3, realmLength = struct.unpack(
                            '!IIH', pkt.data[4:14])
                        realmAdress, unk4, unk5 = struct.unpack(
                            '!%dsII' % (realmLength), pkt.data[14:])
                        realmAdress = realmAdress.split(':')
                        CharServer = proxy_server(realmAdress[0],
                                                  int(realmAdress[1]), 7001)
                        realmAdress = '%s:7001' % (self.receiver.addr[0])
                        realmLength = len(realmAdress)
                        pkt.data = struct.pack('!IIIH%dsII' % (realmLength),
                                               status, unk2, unk3, realmLength,
                                               realmAdress, unk4, unk5)

                    # 0xffffffff mean a failed login (wrong password)
                    elif status == 0xffffffff:
                        #unk1, unk2, unk3, unk4, unk5 = struct.unpack('!IIIIH', )
                        pkt.data = pkt.data[:20] + struct.pack('!H', 0x0000)

            elif pkt.sender == "PlayerAgent":
                if pkt.opCode == 5:
                    rlmEnum = realmEnum()
                    rlmEnum.ReadFromBuffer(pkt.data)

            elif pkt.sender == "ServerInterface":
                if pkt.opCode == 2:
                    WorldAddr = struct.unpack('!BBBBH', pkt.data[:6])
                    Unk1Addr = struct.unpack('!BBBBH', pkt.data[6:12])
                    print WorldAddr
                    print Unk1Addr
                    pkt.data = struct.pack('!BBBBHBBBBH', 127, 0, 0, 1, 7040,
                                           127, 0, 0, 1, 7038) + pkt.data[12:]
                    #WorldServer = proxy_server('%d.%d.%d.%d' % WorldAddr[:4], WorldAddr[4], 7040)
                    WorldServer = StdProxy.proxy_server(
                        '%d.%d.%d.%d' % WorldAddr[:4], WorldAddr[4], 7040)
                    Unk1Server = StdProxy.proxy_server(
                        '%d.%d.%d.%d' % Unk1Addr[:4], Unk1Addr[4], 7038)

                elif pkt.opCode == 3:
                    CSPlayerInterfaceAddr = struct.unpack(
                        '!BBBBH', pkt.data[:6])
                    print CSPlayerInterfaceAddr
                    pkt.data = struct.pack('!BBBBH', 127, 0, 0, 1,
                                           7037) + pkt.data[6:]
                    CSPlayerInterface_Proxy = proxy_server(
                        '%d.%d.%d.%d' % CSPlayerInterfaceAddr[:4],
                        CSPlayerInterfaceAddr[4], 7037)

            elif pkt.sender == "CSPlayerInterface":
                pass

            self.read_buffer = self.read_buffer[
                pkt.size:]  # remove datas of a full packet from the buffer

            buffer = pkt.GetBuffer(
                False)  # Return the full packet from the object
            self.receiver.write_buffer += [
                buffer
            ]  # Add this packet into the write buffer of the receiver
            print "%s:%d -> %s:%d  %d bytes" % (
                self.receiver.server.there[0], self.receiver.server.there[1],
                self.receiver.addr[0], self.receiver.addr[1], pkt.size)
            print "OpCode : %d" % (pkt.opCode)
            print pkt.data.encode("hex")
            #print buffer.encode("hex")
            print