示例#1
0
        protected override int ProcessInternal(byte[] data)
        {
            var packets   = WorldPacket.FromBuffer(data, WorldPacketFlags.GUIDPrefix);
            var bytesRead = 0;

            foreach (var pkt in packets)
            {
                WorldClient client;
                if (!WorldManager.Instance.GUIDClientMap.TryGetValue(pkt.GUID, out client)) // Assume it's the first we see of this client
                {
                    WorldManager.Instance.GUIDClientMap.Add(pkt.GUID, (client = new WorldClient(pkt.GUID)));
                }

                using (var ms = new MemoryStream(pkt.Payload.ToArray()))
                    using (var br = new BinaryReader(ms))
                    {
                        Log.WriteLine(WorldLogTypes.Packets, $"<- {pkt.Header.Opcode}({pkt.Header.Length}):\n\t{string.Join(" ", pkt.Payload.Select(b => b.ToString("X2")))}");
                        if (!WorldHandler.PacketHandlers.ContainsKey(pkt.Header.Opcode) || !WorldHandler.PacketHandlers[pkt.Header.Opcode](client, br))
                        {
                            Log.WriteLine(WorldLogTypes.Packets, $"Failed to handle command {pkt.Header.Opcode}");
                        }
                    }

                bytesRead += pkt.TotalLength;
            }

            return(bytesRead);
        }
示例#2
0
        protected override int ProcessInternal(byte[] data)
        {
            var packets   = WorldPacket.FromBuffer(data, flags: WorldPacketFlags.EncryptedHeader | WorldPacketFlags.BigEndianLength, crypt: Crypt);
            var bytesRead = 0;

            foreach (var pkt in packets)
            {
                Log.WriteLine(GatewayLogTypes.Packets, $"<- {pkt.Header.Opcode}({pkt.Header.Length}):\n\t{string.Join(" ", pkt.Payload.Select(b => b.ToString("X2")))}");

                var buffer = pkt.Payload.ToArray();
                using (var ms = new MemoryStream(buffer))
                    using (var br = new BinaryReader(ms))
                    {
                        if (!GatewayHandlers.PacketHandlers.ContainsKey(pkt.Header.Opcode) || !GatewayHandlers.PacketHandlers[pkt.Header.Opcode](this, br))
                        {
                            if (CharacterGUID == 0)
                            {
                                throw new Exception("Packet unhandled by Gateway -- Character GUID = 0");
                            }

                            Log.WriteLine(GatewayLogTypes.Packets, $"Forwarding {pkt.Header.Opcode} to world server");
                            SendWorldPacket(pkt.Header, buffer);
                        }
                    }

                bytesRead += pkt.TotalLength;
            }

            return(bytesRead);
        }
        protected override int ProcessInternal(byte[] data)
        {
            var packets   = WorldPacket.FromBuffer(data, flags: WorldPacketFlags.GUIDPrefix | WorldPacketFlags.Outbound);
            var bytesRead = 0;

            foreach (var pkt in packets)
            {
                GatewayConnection client;
                if (!((WorldGatewayServer)m_Server).GUIDClientMap.TryGetValue(pkt.GUID, out client))
                {
                    throw new Exception("World server refers to unconnected character");
                }

                // We need to reconstruct the entire packet and not just the payload, in other words, include the 4-byte (2 length, 2 opcode) header
                var packet = new ArraySegment <byte>(pkt.Payload.Array, pkt.Payload.Offset - 4, pkt.Payload.Count + 4);

                Log.WriteLine(GatewayLogTypes.Packets, $"Forwarding {pkt.Header.Opcode} to client");
                client.SendPacket(packet.ToArray());

                bytesRead += pkt.TotalLength;
            }

            return(bytesRead);
        }