Exemplo n.º 1
0
        public override async Task DoWork(Socket client)
        {
            var worker = new WorldSession(client);

            worker.Id = ++Manager.Session.LastSessionId;

            if (Manager.Session.Add(worker.Id, worker))
                await Task.Factory.StartNew(Manager.Session.Sessions[worker.Id].Accept);
        }
Exemplo n.º 2
0
        public static async Task InvokeHandler <T>(Packet reader, ElleWorld.Core.Network.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.Error($"Client '{clientInfo}': Received not allowed packet for state '{session.State}'.");
                    Log.Error($"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.Message($"Packet handler for '{msgName} (0x{message:X}), Length: {reader.Data.Length}' not implemented.");
                }
            }
        }