Beispiel #1
0
        public static async Task InvokeHandler <T>(Packet reader, WorldSession 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.");
                }
            }
        }