Example #1
0
        /// <summary>
        /// Reading Length And Handles Data By [HandleReceived(byte[])] Without Length.
        /// </summary>
        /// <param name="e"></param>
        private void ProceedReceiving(SocketAsyncEventArgs e)
        {
            int transfered = e.BytesTransferred;

            if (e.SocketError != SocketError.Success || transfered <= 0)
            {
                if (DisconnectedEvent != null)
                {
                    DisconnectedEvent(this, EventArgs.Empty);
                }
                return;
            }

#if DEBUG
            //--- Console Hexadecimal
            StringBuilder builder = new StringBuilder();
            builder.Append("\n");
            for (int i = 0; i < transfered; i++)
            {
                builder.AppendFormat("{0:x2} ".ToUpper(), m_RecvBuffer[i]);
            }

            Logger.Trace(builder.ToString());
            //--- Console Hexadecimal
#endif

            PacketReader reader = new PacketReader(m_RecvBuffer, 0);
            short        length = m_LittleEndian ? reader.ReadLEInt16() : reader.ReadInt16();

            byte[] data = new byte[length];
            Buffer.BlockCopy(m_RecvBuffer, 2, data, 0, length);
            HandleReceived(data);
            reader = null;
        }
Example #2
0
        /// <summary>
        /// Reading Length And Handles Data By [HandleReceived(byte[])] Without Length.
        /// </summary>
        /// <param name="e"></param>
        private void ProceedReceiving(SocketAsyncEventArgs e)
        {
            int transfered = e.BytesTransferred;

            if (e.SocketError != SocketError.Success || transfered <= 0)
            {
                if (DisconnectedEvent != null)
                {
                    DisconnectedEvent(this, EventArgs.Empty);
                }
                return;
            }

#if DEBUG
            //--- Console Hexadecimal
            StringBuilder builder = new StringBuilder();
            builder.Append("收到:\n");
            for (int i = 0; i < transfered; i++)
            {
                builder.AppendFormat("{0:x2} ".ToUpper(), m_RecvBuffer[i]);
            }

            Logger.Trace(builder.ToString());
            //--- Console Hexadecimal
#endif
            //此处加了一层循环,因有时  多条数据会并和一起接收到。此处将多条数据拆分处理
            short rest = 0;
            short end  = 0x00;



            string       path = "d:\\1.txt";//文件的路径,保证文件存在。
            FileStream   fs   = new FileStream(path, FileMode.Append);
            StreamWriter sw   = new StreamWriter(fs);
            //filestream fs = new filestream(path, filemode.append);
            //streamwriter sw = new streamwriter(fs);
            sw.WriteLine(builder.ToString());
            sw.Close();
            fs.Close();

            PacketReader reader = new PacketReader(m_RecvBuffer, 0);
            //for (int i = 0; i < 10; i++)
            //{
            short length = m_LittleEndian ? reader.ReadLEInt16() : reader.ReadInt16();
            //if (length == end)
            //{
            //    reader = null;
            //    m_RecvBuffer = null;
            //    break;

            //}
            byte[] data = new byte[length];
            Buffer.BlockCopy(m_RecvBuffer, 2, data, rest, length);
            HandleReceived(data);
            //reader.Offset= length+3;
            //rest = length;
            // }

            reader = null;
        }
Example #3
0
        public override void HandleReceived(byte[] data)
        {
            PacketReader reader = new PacketReader(data, 0);
            reader.Offset += 1; //Undefined Random Byte
            byte level = reader.ReadByte(); //Packet Level
            short opcode = reader.ReadLEInt16(); //Packet Opcode

            if (!DelegateList.ClientHandlers.ContainsKey(level))
            {
                Logger.Trace("Received Undefined Level {0} - Opcode 0x{1:X2}", level, opcode);
                return;
            }

            PacketHandler<ClientConnection> handler = DelegateList.ClientHandlers[level][opcode];
            if (handler != null)
                handler.OnReceive(this, reader);
            else
                Logger.Trace("Received Undefined Packet Level - {0} Op - 0x{1:X2}", level, opcode);
        }
Example #4
0
        public override void HandleReceived(byte[] data)
        {
            PacketReader reader = new PacketReader(data, 0);
            short opcode = reader.ReadLEInt16();
            if (opcode > PacketList.LHandlers.Length)
            {
                Logger.Trace("Not Enough Lenght For LHandlers, Disposing...");
                Dispose();
                return;
            }

            PacketHandler<ArcheAgeConnection> handler = PacketList.LHandlers[opcode];
            if (handler != null)
                handler.OnReceive(this, reader);
            else
                Logger.Trace("Received Undefined Packet 0x{0:x2}", opcode);

            reader = null;
        }
Example #5
0
        /// <summary>
        /// Reading Length And Handles Data By [HandleReceived(byte[])] Without Length.
        /// </summary>
        /// <param name="e"></param>
        private void ProceedReceiving(SocketAsyncEventArgs e)
        {
            int transfered = e.BytesTransferred;
            if (e.SocketError != SocketError.Success || transfered <= 0)
            {
                if (DisconnectedEvent != null)
                    DisconnectedEvent(this, EventArgs.Empty);
                return;
            }

            #if DEBUG
            //--- Console Hexadecimal
            StringBuilder builder = new StringBuilder();
            builder.Append("\n");
            for (int i = 0; i < transfered; i++)
                builder.AppendFormat("{0:x2} ".ToUpper(), m_RecvBuffer[i]);

            Logger.Trace(builder.ToString());
            //--- Console Hexadecimal
            #endif

            PacketReader reader = new PacketReader(m_RecvBuffer, 0);
            short length = m_LittleEndian ? reader.ReadLEInt16() : reader.ReadInt16();

            byte[] data = new byte[length];
            Buffer.BlockCopy(m_RecvBuffer, 2, data, 0, length);
            HandleReceived(data);
            reader = null;
        }
Example #6
0
        private static void Handle_SignIn(ArcheAgeConnection net, PacketReader reader)
        {
            reader.Offset += 10; //Static Data - 0A 00 00 00 07 00 00 00 00 00

            string m_RLogin = reader.ReadStringSafe(reader.ReadLEInt16()); //Reading Login

            Account n_Current = AccountHolder.AccountList.FirstOrDefault(n => n.Name == m_RLogin);
            if (n_Current == null)
            {
                //Make New Temporary
                if (Settings.Default.Account_AutoCreation)
                {
                    Account m_New = new Account();
                    m_New.AccountId = AccountHolder.AccountList.Count + 1;
                    m_New.LastEnteredTime = Utility.CurrentTimeMilliseconds();
                    m_New.AccessLevel = 0;
                    m_New.LastIp = net.ToString();
                    m_New.Membership = 0;
                    m_New.Name = m_RLogin;
                    net.CurrentAccount = m_New;
                    AccountHolder.AccountList.Add(m_New);
                }
                else
                    net.CurrentAccount = null;
            }
            else
            {
                net.CurrentAccount = n_Current;
            }
            net.SendAsync(new NP_AcceptLogin());
            net.SendAsync(new NP_AESKey());
        }