public void ProcessBytes(Session Session, ref byte[] Bytes)
        {
            if (Session == null)
            {
                return;
            }

            var ProcessType = ChooseProcessType(ref Bytes);

            switch (ProcessType)
            {
                case ByteProcessType.Unknown:
                    return;
                case ByteProcessType.Policy:
                    HandlePolicy(Session);
                    return;
                case ByteProcessType.Single:
                    HandleSingle(Session,true, ref Bytes);
                    return;
                case ByteProcessType.Multi:
                    HandleMulti(Session, ref Bytes);
                    return;
            }
        }
Beispiel #2
0
        public bool OptainSendObject(Session Session, out SocketAsyncEventArgs SendArgs)
        {
            this.SemaphoreOfSendSAEA.Wait();

            if (this.PoolOfSendSAEA.TryPop(out SendArgs))
            {
                SendArgs.AcceptSocket = Session.Socket;
                return true;
            }
            else
            {
                return false;
            }
        }
 private void HandlePolicy(Session Session)
 {
     Session.Write(PolicyResponse);
     Session.Push();
 }
        private void HandleSingle(Session Session, bool Scratch, ref byte[] Bytes)
        {
            using (var Reader = new BinaryReader(new MemoryStream(Bytes, false)))
            {
                var Index = Bytes.Length;

                if (Scratch)
                {
                    Index = Base64Encoding.DecodeInt32(Reader.ReadBytes(3));
                }

                var Header = (short)Base64Encoding.DecodeInt32(Reader.ReadBytes(2));
                var Content = Reader.ReadBytes(Index - 2);

                if (MessageEvents.ContainsKey(Header))
                {
                    Framework.Get<LogComponent>().BlurLine("MSG", ConsoleColor.Green, "[{0}] {1}", ConsoleColor.White, Header, MessageEvents[Header].ToString().Split('.').Last());
                    MessageEvents[Header].Invoke(Session, new MessageEvent(Header, Content));
                    Session.Push();
                }
                else if (UnknownMessageEvents.ContainsKey(Header))
                {
                    Framework.Get<LogComponent>().BlurLine("MSG", ConsoleColor.Gray, "[{0}] {1}", ConsoleColor.White, Header, UnknownMessageEvents[Header]);
                }
                else
                {
                    Framework.Get<LogComponent>().BlurLine("MSG", ConsoleColor.Red, "[{0}] Unknown", ConsoleColor.White, Header);
                }
            }
        }
        private void HandleMulti(Session Session, ref byte[] Bytes)
        {
            using (var Reader = new BinaryReader(new MemoryStream(Bytes,false)))
            {
                for (int i = 0; i < Bytes.Length; )
                {
                    var Index = Base64Encoding.DecodeInt32(Reader.ReadBytes(3)); i += 3;
                    var SingleBytes = Reader.ReadBytes(Index); i += Index;

                    HandleSingle(Session, false, ref SingleBytes);
                }
            }
        }