private void OnPacket(byte[] data)
        {
            try
            {
                for (var index = 0; index < data.Length; index++)
                {
                    var headerData = new byte[6];
                    Array.Copy(data, index, headerData, 0, 6);

                    Decode(headerData, out var length, out var opcode);
                    var code = (RealmEnums)opcode;

                    Log.Print(LogType.RealmServer,
                              $"[{ConnectionSocket.RemoteEndPoint}] [<= RCVD] [{code.ToString().PadRight(25, ' ')}] = {length}");

                    var packetDate = new byte[length];
                    // TODO: Source array was to not long enough. Check srcIndex and length, and the array's lower bound
                    Array.Copy(data, index + 6, packetDate, 0, length - 4);
                    RealmServerRouter.CallHandler(this, code, packetDate);

                    index += 2 + (length - 1);
                }
            }
            catch (Exception e)
            {
                var trace = new StackTrace(e, true);
                Log.Print(LogType.Error,
                          $"{e.Message}: {e.Source}" +
                          $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
                Utils.DumpPacket(data);
                Disconnect();
            }
        }
Esempio n. 2
0
        private void OnPacket(byte[] data)
        {
            try
            {
                for (int index = 0; index < data.Length; index++)
                {
                    byte[] headerData = new byte[6];
                    Array.Copy(data, index, headerData, 0, 6);

                    ushort length;
                    short  opcode;

                    Decode(headerData, out length, out opcode);
                    Log.Print(LogType.RealmServer, $"[{ConnectionSocket.RemoteEndPoint}] [CLIENT] [{((RealmCMD)opcode).ToString().PadRight(25, ' ')}] = {length}");
                    RealmCMD code = (RealmCMD)opcode;

                    byte[] packetDate = new byte[length];
                    Array.Copy(data, index + 6, packetDate, 0, length - 4);
                    RealmServerRouter.CallHandler(this, code, packetDate);

                    index += 2 + (length - 1);
                }
            }
            catch (Exception e)
            {
                var trace = new StackTrace(e, true);
                Log.Print(LogType.Error, $"{e.Message}: {e.Source}\n{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
                DumpPacket(data, this);
            }
        }