Exemplo n.º 1
0
        public static byte[] GetAddonInfoData(CharacterSession session, byte[] packedData, int packedSize, int unpackedSize)
        {
            // Check ZLib header (normal mode)
            if (packedData[0] == 0x78 && packedData[1] == 0x9C)
            {
                var unpackedAddonData = new byte[unpackedSize];

                if (packedSize > 0)
                {
                    using (var inflate = new DeflateStream(new MemoryStream(packedData, 2, packedSize - 6), CompressionMode.Decompress))
                    {
                        var decompressed = new MemoryStream();
                        inflate.CopyTo(decompressed);

                        decompressed.Seek(0, SeekOrigin.Begin);

                        for (int i = 0; i < unpackedSize; i++)
                        {
                            unpackedAddonData[i] = (byte)decompressed.ReadByte();
                        }
                    }
                }

                return(unpackedAddonData);
            }
            else
            {
                Log.Message(LogType.Error, "Wrong AddonInfo for Client '{0}'.", session.GetClientInfo());

                session.Dispose();
            }

            return(null);
        }
Exemplo n.º 2
0
        public static async Task InvokeHandler <T>(Packet reader, CharacterSession session)
        {
            var message = reader.Header.Message;

            Tuple <MethodInfo, Type, SessionState> data;

            if (MessageHandlers.TryGetValue(message, out data))
            {
                if ((session.State & data.Item3) == SessionState.None)
                {
                    var clientInfo = session.GetClientInfo();

                    Log.Debug($"Client '{clientInfo}': Received not allowed packet for state '{session.State}'.");
                    Log.Debug($"Disconnecting '{clientInfo}'.");

                    session.Dispose();

                    return;
                }

                var handlerObj = Activator.CreateInstance(data.Item2) as ClientPacket;

                handlerObj.Packet = reader;

                await Task.Run(() => handlerObj.Read());

                if (handlerObj.IsReadComplete)
                {
                    data.Item1.Invoke(null, new object[] { handlerObj, session });
                }
                else
                {
                    Log.Error($"Packet read for '{data.Item2.Name}' failed.");
                }
            }
            else
            {
                var msgName = Enum.GetName(typeof(ClientMessage), message) ?? Enum.GetName(typeof(GlobalClientMessage), message);

                if (msgName == null)
                {
                    Log.Error($"Received unknown opcode '0x{message:X}, Length: {reader.Data.Length}'.");
                }
                else
                {
                    Log.Error($"Packet handler for '{msgName} (0x{message:X}), Length: {reader.Data.Length}' not implemented.");
                }
            }
        }
Exemplo n.º 3
0
 public static void HandleLogDisconnect(LogDisconnect logDisconnect, CharacterSession session)
 {
     Log.Debug($"{session.GetClientInfo()} disconnected (Reason: {logDisconnect.Reason}).");
 }
Exemplo n.º 4
0
 public static void HandleLogDisconnect(LogDisconnect logDisconnect, CharacterSession session)
 {
     Log.Message(LogType.Debug, "{0} disconnected (Reason: {1}).", session.GetClientInfo(), logDisconnect.Reason);
 }