Exemplo n.º 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);
            }
        }
Exemplo n.º 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 { }
        }