Exemplo n.º 1
0
 void m_server_SocketRecv(object sender, SocketRecvEventArgs <NetData> e)
 {
     //  数据原样送回
     e.Session.SendPackage(e.Buffer);
     m_recvCount++;
     m_recvBytes += e.Buffer.Length;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs <Session> e)
        {
            var session = e.Session.Data;

            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();

            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                var pid     = reader.GetPacketID();
                var handler = packetHandlersManager.GetHandler(pid);
                if (handler == null)
                {
                    Logs.Error("未知消息ID {0}", pid);
                }
                else
                {
                    //  网络的消息包都会压入任务队列里等待执行
                    taskManager.AppendTask(session, handler, reader);
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
Exemplo n.º 3
0
 void m_server_SocketRecv(object sender, SocketRecvEventArgs<NetData> e)
 {
     //  数据原样送回
     e.Session.SendPackage(e.Buffer);
     m_recvCount++;
     m_recvBytes += e.Buffer.Length;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs <Session> e)
        {
            var session = e.Session.Data;

            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();

            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                /*
                 * var pid = (OpCode)reader.GetPacketID();
                 *
                 * switch (pid)
                 * {
                 *  case OpCode.Login:
                 *      OnLogin(session, reader);
                 *      break;
                 *  case OpCode.SendMessage:
                 *      OnSendMessage(session, reader);
                 *      break;
                 *  case OpCode.SendPriviteMessage:
                 *      OnSendPrivateMessage(session, reader);
                 *      break;
                 *  default:
                 *      Logs.Error("未知消息ID {0}", (int)pid);
                 *      break;
                 * }
                 */

                var pid     = reader.GetPacketID();
                var handler = packetHandlersManager.GetHandler(pid);
                if (handler == null)
                {
                    Logs.Error("未知消息ID {0}", pid);
                }
                else
                {
                    handler.OnReceive(session, reader);
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            lock (sessions)
            {
                var session = e.Session.Data;
                DogBuffer buf;
                if (e.Buffer.Length > 1024*4)
                {
                    buf = DogBuffer.GetFromPool32K();
                }
                else
                {
                    buf = DogBuffer.GetFromPool4K();
                }

                Array.Copy(e.Buffer.Bytes, buf.Bytes, e.Buffer.Length);
                buf.Length = e.Buffer.Length;
                session.Client.SendPackage(buf);
                buf.Release();

                recvPackageCount++;
                recvPackageLength += e.Buffer.Length;
            }
        }
Exemplo n.º 6
0
 void server_SocketRecv(object sender, SocketRecvEventArgs <object> e)
 {
     //  把数据原样送回
     e.Session.SendPackage(e.Buffer);
     isRecv = true;
 }
Exemplo n.º 7
0
    /// <summary>
        /// 收到网络消息包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSocketRecv(object sender, SocketRecvEventArgs<NetState> e)
        {
            var netState = e.Session.Data;
            netState.ReceiveBuffer.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);
            if (netState.ReceiveBuffer.Length > MaxPackageSize)
            {
                //  缓冲区过多,一定发送了某种异常情况
                Logs.Error("client recv buff is full.");
                netState.NetSocket.CloseSocket();
                return;
            }

            while (netState.ReceiveBuffer.Length > 2)   // 大于包头长度才具备解析的需求
            {
                var len = netState.ReceiveBuffer.GetPacketLength();
                if (len == 0)
                {
                    Logs.Error("get package len is zero.");
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len < 4)
                {
                    Logs.Error("get package len is min 4.");
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len > MaxPackageSize)
                {
                    Logs.Error("get package len is error. size:{0}", len);
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len <= netState.ReceiveBuffer.Length)
                {

                    DogBuffer readBuffer;
                    if (len < 1024*4)
                        readBuffer = DogBuffer.GetFromPool4K();
                    else
                        readBuffer = DogBuffer.GetFromPool32K();

                    var get = netState.ReceiveBuffer.Dequeue(readBuffer.Bytes, 0, len);
                    if (get == len)
                    {
                        readBuffer.Length = len;

                        var packageReader = PacketReader.AcquireContent(readBuffer);
                        var packageId = packageReader.GetPacketID();
                        //Debug.Write("msgId = " + packageId.ToString());

                        var packetHandler = PacketHandlersManger.GetHandler(packageId);
                        if (packetHandler != null)
                        {
                            //  加入网络消息处理
                            if (_useManyTaskThread)
                            {
                                switch (packetHandler.TaskType)
                                {
                                    case TaskType.Low:
                                        lowTask.AppendTask(netState, packetHandler, packageReader);
                                        break;
                                    case TaskType.Assist:
                                        Logs.Debug("assist task.");
                                        assistTask.AppendTask(netState, packetHandler, packageReader);
                                        break;
                                    default:
                                        mainTask.AppendTask(netState, packetHandler, packageReader);
                                        break;
                                }
                            }
                            else
                            {
                                mainTask.AppendTask(netState, packetHandler, packageReader);
                            }
                        }
                        else
                        {
                            Logs.Error("unknow packetid. code={0}", packageId);
                            netState.ErrorCount++;
                            if (netState.ErrorCount >= 10)
                            {
                                //  错误达到极大值,则关闭连接
                                Logs.Error("ip {0} error count max.", netState.GetIP());
                                netState.NetSocket.CloseSocket();
                            }
                        }
                    }
                    continue;
                }
                break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            var session = e.Session.Data;
            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();
            if (packetlen > 1024*64)
            {
                session.Client.CloseSocket();
                return;
            }

            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                var pid = (OpCode)reader.GetPacketID();

                switch (pid)
                {
                    case OpCode.Login:
                    {
                        var userName = reader.ReadUTF8String();
                        var pwd = reader.ReadUTF8String();

                        if (string.IsNullOrEmpty(userName))
                        {
                            Logs.Error("连接的用户名是空");
                            session.Client.CloseSocket();
                        }

                        if (pwd != "123")
                        {
                            Logs.Error("用户名 {0} 速度的密码错误", userName);
                            var writer = new PacketWriter();
                            writer.SetNetCode((ushort) OpCode.LoginResult);
                            writer.Write(1); //  0表示登录成功 1表示密码错误
                            session.Client.SendPackage(writer.GetBuffer());
                            return;
                        }

                        //  如果玩家之前登录过,则把之前的客户端踢下线
                        var exists = sessions.FirstOrDefault(o => o.Name == userName);
                        if (exists != null)
                        {
                            exists.IsLogin = false;
                            sessions.Remove(exists);
                            exists.Client.CloseSocket();
                        }

                        //  登录完成
                        session.IsLogin = true;
                        nologinSessions.Remove(session);
                        sessions.Add(session);

                        session.Name = userName;
                        session.Pwd = pwd;
                        var writer2 = new PacketWriter();
                        writer2.SetNetCode((ushort) OpCode.LoginResult);
                        writer2.Write(0); //  0表示登录成功 1表示密码错误
                        session.Client.SendPackage(writer2.GetBuffer());
                    }
                        break;
                    case OpCode.SendMessage:
                    {
                        var message = reader.ReadUTF8String();
                        if (string.IsNullOrEmpty(message))
                        {
                            //  空消息
                            return;
                        }

                        //  广播给所有在线的用户
                        var writer = new PacketWriter();
                        writer.SetNetCode((ushort) OpCode.RecvMessage);
                        foreach (var ss in sessions)
                        {
                            ss.Client.SendPackage(writer.GetBuffer());
                        }
                    }
                        break;
                    case OpCode.SendPriviteMessage:
                    {
                        var userName = reader.ReadUTF8String();
                        var message = reader.ReadUTF8String();

                        if (message == null)
                            return;

                        var target = sessions.FirstOrDefault(o => o.Name == userName);
                        if (target == null)
                            return;

                        var writer = new PacketWriter();
                        writer.SetNetCode((ushort) OpCode.RecvPrivateMessage);
                        writer.WriteUTF8Null(session.Name);
                        writer.WriteUTF8Null(message);

                        target.Client.SendPackage(writer.GetBuffer());
                    }
                        break;
                    default:
                        Logs.Error("未知消息ID {0}", (int) pid);
                        break;
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            var session = e.Session.Data;
            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();
            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                var pid = reader.GetPacketID();
                var handler = packetHandlersManager.GetHandler(pid);
                if (handler == null)
                {
                    Logs.Error("未知消息ID {0}", pid);
                }
                else
                {
                    //  网络的消息包都会压入任务队列里等待执行
                    taskManager.AppendTask(session, handler, reader);
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 收到网络消息包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSocketRecv(object sender, SocketRecvEventArgs <NetState> e)
        {
            var netState = e.Session.Data;

            netState.ReceiveBuffer.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);
            if (netState.ReceiveBuffer.Length > MaxPackageSize)
            {
                //  缓冲区过多,一定发送了某种异常情况
                Logs.Error("client recv buff is full.");
                netState.NetSocket.CloseSocket();
                return;
            }

            while (netState.ReceiveBuffer.Length > 2)   // 大于包头长度才具备解析的需求
            {
                var len = netState.ReceiveBuffer.GetPacketLength();
                if (len == 0)
                {
                    Logs.Error("get package len is zero.");
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len < 4)
                {
                    Logs.Error("get package len is min 4.");
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len > MaxPackageSize)
                {
                    Logs.Error("get package len is error. size:{0}", len);
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len <= netState.ReceiveBuffer.Length)
                {
                    DogBuffer readBuffer;
                    if (len < 1024 * 4)
                    {
                        readBuffer = DogBuffer.GetFromPool4K();
                    }
                    else
                    {
                        readBuffer = DogBuffer.GetFromPool32K();
                    }

                    var get = netState.ReceiveBuffer.Dequeue(readBuffer.Bytes, 0, len);
                    if (get == len)
                    {
                        readBuffer.Length = len;

                        var packageReader = PacketReader.AcquireContent(readBuffer);
                        var packageId     = packageReader.GetPacketID();
                        //Debug.Write("msgId = " + packageId.ToString());

                        var packetHandler = PacketHandlersManger.GetHandler(packageId);
                        if (packetHandler != null)
                        {
                            //  加入网络消息处理
                            if (_useManyTaskThread)
                            {
                                switch (packetHandler.TaskType)
                                {
                                case TaskType.Low:
                                    lowTask.AppendTask(netState, packetHandler, packageReader);
                                    break;

                                case TaskType.Assist:
                                    Logs.Debug("assist task.");
                                    assistTask.AppendTask(netState, packetHandler, packageReader);
                                    break;

                                default:
                                    mainTask.AppendTask(netState, packetHandler, packageReader);
                                    break;
                                }
                            }
                            else
                            {
                                mainTask.AppendTask(netState, packetHandler, packageReader);
                            }
                        }
                        else
                        {
                            Logs.Error("unknow packetid. code={0}", packageId);
                            netState.ErrorCount++;
                            if (netState.ErrorCount >= 10)
                            {
                                //  错误达到极大值,则关闭连接
                                Logs.Error("ip {0} error count max.", netState.GetIP());
                                netState.NetSocket.CloseSocket();
                            }
                        }
                    }
                    continue;
                }
                break;
            }
        }
Exemplo n.º 11
0
        void NetSocket_SocketRecv(object sender, SocketRecvEventArgs <NetState> e)
        {
            var netState = e.Session.Data;

            netState.ReceiveBuffer.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            if (netState.ReceiveBuffer.Length > MaxPackageSize)
            {
                //  缓冲区过多,一定发送了某种异常情况
                Logs.Error("client recv buff is full.");
                netState.NetSocket.CloseSocket();
                return;
            }

            while (netState.ReceiveBuffer.Length > 2)
            {
                var len = netState.ReceiveBuffer.GetPacketLength();
                if (len == 0)
                {
                    Logs.Error("get package len is zero.");
                    netState.NetSocket.CloseSocket();
                    return;
                }

                if (len < 4)
                {
                    Logs.Error("package is min 4.");
                    netState.NetSocket.CloseSocket();
                    return;
                }


                if (len > MaxPackageSize)
                {
                    Logs.Error("get package len is error. size:{0}", len);
                    netState.NetSocket.CloseSocket();
                    return;
                }

                IsWaitCheckOnline = false;

                if (len <= netState.ReceiveBuffer.Length)
                {
                    DogBuffer readBuffer;
                    if (len < 1024 * 4)
                    {
                        readBuffer = DogBuffer.GetFromPool4K();
                    }
                    else
                    {
                        readBuffer = DogBuffer.GetFromPool32K();
                    }

                    if (len >= readBuffer.Bytes.Length)
                    {
                        readBuffer.UpdateCapacity(len);
                    }

                    var get = netState.ReceiveBuffer.Dequeue(readBuffer.Bytes, 0, len);
                    if (get == len)
                    {
                        readBuffer.Length = len;

                        var    packageReader = PacketReader.AcquireContent(readBuffer);
                        ushort id            = packageReader.GetPacketID();
                        Logs.Debug("msgid= {0}", id);

                        var packetHandler = PacketHandlersManger.GetHandler(id);
                        if (packetHandler != null)
                        {
                            //  加入网络消息处理
                            TaskManager.AppendTask(netState, packetHandler, packageReader);
                        }
                        else
                        {
                            Logs.Error("unknow packetid. code={0}", id);
                        }
                    }

                    continue;
                }

                break;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs <Session> e)
        {
            var session = e.Session.Data;

            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();

            if (packetlen > 1024 * 64)
            {
                session.Client.CloseSocket();
                return;
            }

            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                var pid = (OpCode)reader.GetPacketID();

                switch (pid)
                {
                case OpCode.Login:
                {
                    var userName = reader.ReadUTF8String();
                    var pwd      = reader.ReadUTF8String();

                    if (string.IsNullOrEmpty(userName))
                    {
                        Logs.Error("连接的用户名是空");
                        session.Client.CloseSocket();
                    }

                    if (pwd != "123")
                    {
                        Logs.Error("用户名 {0} 速度的密码错误", userName);
                        var writer = new PacketWriter();
                        writer.SetNetCode((ushort)OpCode.LoginResult);
                        writer.Write(1);     //  0表示登录成功 1表示密码错误
                        session.Client.SendPackage(writer.GetBuffer());
                        return;
                    }

                    //  如果玩家之前登录过,则把之前的客户端踢下线
                    var exists = sessions.FirstOrDefault(o => o.Name == userName);
                    if (exists != null)
                    {
                        exists.IsLogin = false;
                        sessions.Remove(exists);
                        exists.Client.CloseSocket();
                    }

                    //  登录完成
                    session.IsLogin = true;
                    nologinSessions.Remove(session);
                    sessions.Add(session);

                    session.Name = userName;
                    session.Pwd  = pwd;
                    var writer2 = new PacketWriter();
                    writer2.SetNetCode((ushort)OpCode.LoginResult);
                    writer2.Write(0);     //  0表示登录成功 1表示密码错误
                    session.Client.SendPackage(writer2.GetBuffer());
                }
                break;

                case OpCode.SendMessage:
                {
                    var message = reader.ReadUTF8String();
                    if (string.IsNullOrEmpty(message))
                    {
                        //  空消息
                        return;
                    }

                    //  广播给所有在线的用户
                    var writer = new PacketWriter();
                    writer.SetNetCode((ushort)OpCode.RecvMessage);
                    foreach (var ss in sessions)
                    {
                        ss.Client.SendPackage(writer.GetBuffer());
                    }
                }
                break;

                case OpCode.SendPriviteMessage:
                {
                    var userName = reader.ReadUTF8String();
                    var message  = reader.ReadUTF8String();

                    if (message == null)
                    {
                        return;
                    }

                    var target = sessions.FirstOrDefault(o => o.Name == userName);
                    if (target == null)
                    {
                        return;
                    }

                    var writer = new PacketWriter();
                    writer.SetNetCode((ushort)OpCode.RecvPrivateMessage);
                    writer.WriteUTF8Null(session.Name);
                    writer.WriteUTF8Null(message);

                    target.Client.SendPackage(writer.GetBuffer());
                }
                break;

                default:
                    Logs.Error("未知消息ID {0}", (int)pid);
                    break;
                }


                packetlen = session.RQ.GetPacketLength();
            }
        }
Exemplo n.º 13
0
 void server_SocketRecv(object sender, SocketRecvEventArgs<object> e)
 {
     //  把数据原样送回
     e.Session.SendPackage(e.Buffer);
     isRecv = true;
 }
Exemplo n.º 14
0
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            var session = e.Session.Data;
            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();
            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                /*
                var pid = (OpCode)reader.GetPacketID();

                switch (pid)
                {
                    case OpCode.Login:
                        OnLogin(session, reader);
                        break;
                    case OpCode.SendMessage:
                        OnSendMessage(session, reader);
                        break;
                    case OpCode.SendPriviteMessage:
                        OnSendPrivateMessage(session, reader);
                        break;
                    default:
                        Logs.Error("未知消息ID {0}", (int)pid);
                        break;
                }
                */

                var pid = reader.GetPacketID();
                var handler = packetHandlersManager.GetHandler(pid);
                if (handler == null)
                {
                    Logs.Error("未知消息ID {0}", pid);
                }
                else
                {
                    handler.OnReceive(session, reader);
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 收到网络消息包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSocketRecv(object sender, SocketRecvEventArgs<NetState> e)
        {
            var netState = e.Session.Data;
            netState.ReceiveBuffer.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var len = netState.ReceiveBuffer.GetPacketLength();
            do
            {
                if (len <= netState.ReceiveBuffer.Length)
                {

                    DogBuffer readBuffer;
                    if (len < 1024*4)
                        readBuffer = DogBuffer.GetFromPool4K();
                    else
                        readBuffer = DogBuffer.GetFromPool32K();

                    var get = netState.ReceiveBuffer.Dequeue(readBuffer.Bytes, 0, len);
                    if (get == len)
                    {
                        readBuffer.Length = len;

                        var packageReader = new PacketReader(readBuffer);
                        var packetHandler = PacketHandlersManger.GetHandler(packageReader.GetPacketID());
                        if (packetHandler != null)
                        {
                            //  加入网络消息处理
                            taskManager.AppendTask(netState, packetHandler, packageReader);
                        }
                        else
                        {
                            Logs.Error("unknow packetid. code={0}", packageReader.GetPacketID().ToString());
                        }
                    }
                }
                //  一次网络消息可能会对应多个消息包,因此这里用循环获得消息包
                len = netState.ReceiveBuffer.GetPacketLength();
            } while (len > 0);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 收到网络消息包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSocketRecv(object sender, SocketRecvEventArgs <NetState> e)
        {
            var netState = e.Session.Data;

            netState.ReceiveBuffer.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var len = netState.ReceiveBuffer.GetPacketLength();

            do
            {
                if (len <= netState.ReceiveBuffer.Length)
                {
                    DogBuffer readBuffer;
                    if (len < 1024 * 4)
                    {
                        readBuffer = DogBuffer.GetFromPool4K();
                    }
                    else
                    {
                        readBuffer = DogBuffer.GetFromPool32K();
                    }

                    var get = netState.ReceiveBuffer.Dequeue(readBuffer.Bytes, 0, len);
                    if (get == len)
                    {
                        readBuffer.Length = len;

                        var packageReader = new PacketReader(readBuffer);
                        var packageId     = packageReader.GetPacketID();
                        var packetHandler = PacketHandlersManger.GetHandler(packageId);
                        if (packetHandler != null)
                        {
                            //  加入网络消息处理
                            if (_useManyTaskThread)
                            {
                                switch (packetHandler.TaskType)
                                {
                                case TaskType.Low:
                                    lowTask.AppendTask(netState, packetHandler, packageReader);
                                    break;

                                case TaskType.Assist:
                                    Logs.Debug("assist task.");
                                    assistTask.AppendTask(netState, packetHandler, packageReader);
                                    break;

                                default:
                                    mainTask.AppendTask(netState, packetHandler, packageReader);
                                    break;
                                }
                            }
                            else
                            {
                                mainTask.AppendTask(netState, packetHandler, packageReader);
                            }
                        }
                        else
                        {
                            Logs.Error("unknow packetid. code={0}", packageId);
                        }
                    }
                }
                //  一次网络消息可能会对应多个消息包,因此这里用循环获得消息包
                len = netState.ReceiveBuffer.GetPacketLength();
            } while (len > 0);
        }