示例#1
0
        public static void HandleEvent(Session Session, InMessage InMessage)
        {
            if (Session.Character == null)
            {
                if (InMessage.Id != 206 && InMessage.Id != 415)
                {
                    Solution.AppendPaint();
                    Solution.AppendLine("MessageHandler: ({0})Tried to bypass authenticating.", Session.Id);
                    SessionHandler.CloseClientSocket(Session.Args);
                    return;
                }
            }

            if (Events.ContainsKey(InMessage.Id))
            {
                var Event = Events[InMessage.Id];
                var EventName = Event.ToString().Split('.')[Event.ToString().Split('.').Count() - 1];

                try
                {
                    Event.Invoke(Session, InMessage);
                }
                catch (Exception e)
                {
                    Solution.AppendPaint();
                    Solution.AppendLine(e.ToString());
                }

                Solution.AppendLine("HandleEvent: ({0}){1}({2})", Session.Id, EventName, InMessage.Id);
            }
            else
            {
                Solution.AppendLine("HandleEvent: ({0}){1}({2})", Session.Id, Encoding.ASCII.GetString(InMessage.Context), InMessage.Id);
            }
        }
示例#2
0
        public static void HandleBytes(Session Session, ref byte[] Bytes)
        {
            if (Encoding.ASCII.GetString(Bytes) == "<policy-file-request/>\x0")
            {
                Session.Send(PolicyFileRequest);
                return;
            }

            var Pointer = new int();

            try
            {
                for (; Pointer < Bytes.Length; )
                {
                    var MessageLength = Base64Encoding.DecodeInt32(new byte[] { Bytes[Pointer++], Bytes[Pointer++], Bytes[Pointer++] });
                    var MessageId = Base64Encoding.DecodeInt32(new byte[] { Bytes[Pointer++], Bytes[Pointer++] });

                    var ContextLength = (MessageLength - 2);
                    var Context = new byte[ContextLength];

                    Array.Copy(Bytes, Pointer, Context, 0, ContextLength);

                    Pointer += ContextLength;

                    var InMessage = new InMessage(MessageId, Context);

                    HandleEvent(Session, InMessage);
                }
            }
            catch { }
        }
示例#3
0
        public static void HandleComposer(Session Session, IMessageComposer Composer, params object[] Parameters)
        {
            var Bytes = Composer.Invoke(Parameters).Result;

            if (Bytes.Count() > 0)
            {
                Session.Send(Bytes);
            }
        }
示例#4
0
        private static void HandleAsync(SocketAsyncEventArgs Args)
        {
            try
            {
                Interlocked.Increment(ref ConnectedAmount);

                var SingleSocketAsync = SocketPool.Pop();
                var Token = (AsyncUserToken)SingleSocketAsync.UserToken;

                Token.Socket = Args.AcceptSocket;

                var Session = new Session(Interlocked.Increment(ref Counter), Token.Socket, Args);

                Sessions.Add(Session.Id, Session);

                if (!Args.AcceptSocket.ReceiveAsync(SingleSocketAsync))
                {
                    HandleReceive(SingleSocketAsync);
                }
            }
            catch { }
            finally { WaitForAsync(Args); }
        }