Ejemplo n.º 1
0
        public virtual void Update(double elapsed)
        {
            mUdpCheckPool.Update(elapsed);

            int nPackageCount = 0;

            while (!mNeedHandlePackageQueue.IsEmpty)
            {
                NetPackage mNetPackage = null;
                if (!mNeedHandlePackageQueue.TryDequeue(out mNetPackage))
                {
                    break;
                }

                PackageManager.Instance.Execute(this as ClientPeer, mNetPackage);

                if (mNetPackage is NetCombinePackage)
                {
                    NetCombinePackage mCombinePackage = mNetPackage as NetCombinePackage;
                    ObjectPoolManager.Instance.mCombinePackagePool.recycle(mNetPackage as NetCombinePackage);
                }
                else if (mNetPackage is NetUdpFixedSizePackage)
                {
                    ObjectPoolManager.Instance.mUdpFixedSizePackagePool.recycle(mNetPackage as NetUdpFixedSizePackage);
                }

                nPackageCount++;
            }

            if (nPackageCount > 20)
            {
                DebugSystem.Log("服务器 处理逻辑的数量: " + nPackageCount);
            }
        }
Ejemplo n.º 2
0
        public void SendNetPackage(NetPackage mNetPackage)
        {
            NetEndPointPackage mPackage = ObjectPoolManager.Instance.mNetEndPointPackagePool.Pop();

            mPackage.mRemoteEndPoint = remoteEndPoint;
            mPackage.mPackage        = mNetPackage;

            SocketUdp_Server_Basic.Instance.SendNetPackage(mPackage);
        }
Ejemplo n.º 3
0
 public void Execute(ClientPeer peer, NetPackage mPackage)
 {
     if (mNetEventDic.ContainsKey(mPackage.nPackageId))
     {
         mNetEventDic [mPackage.nPackageId] (peer, mPackage);
     }
     else
     {
         DebugSystem.LogError("不存在的包Id: " + mPackage.nPackageId);
     }
 }
Ejemplo n.º 4
0
        private void SendNetStream(NetEndPointPackage mEndPointPacakge)
        {
            EndPoint   remoteEndPoint = mEndPointPacakge.mRemoteEndPoint;
            NetPackage mPackage       = mEndPointPacakge.mPackage;

            DebugSystem.Assert(mPackage.Length >= ServerConfig.nUdpPackageFixedHeadSize, "发送长度要大于等于 包头: " + mPackage.Length);
            int nSendLength = mSocket.SendTo(mPackage.buffer, 0, mPackage.Length, SocketFlags.None, remoteEndPoint);

            DebugSystem.Assert(nSendLength > 0, "Server 发送失败: " + nSendLength);

            ObjectPoolManager.Instance.mNetEndPointPackagePool.recycle(mEndPointPacakge);
        }
Ejemplo n.º 5
0
        public void ReceiveCheckPackage(NetPackage mPackage)
        {
            PackageCheckResult mPackageCheckResult = Protocol3Utility.getData <PackageCheckResult> (mPackage);
            UInt16             whoId    = (UInt16)(mPackageCheckResult.NWhoOrderId >> 16);
            UInt16             nOrderId = (UInt16)(mPackageCheckResult.NWhoOrderId & 0x0000FFFF);

            //DebugSystem.Log ("ServerCheck: nWhoId: " + whoId + " | nOrderId: " + nOrderId);
            bool bSender = bClient ? whoId == 1 : whoId == 2;

            if (bSender)
            {
                this.mUdpPeer.SendNetPackage(mPackage);

                CheckPackageInfo mRemovePackage = null;
                if (mWaitCheckSendDic.TryRemove(nOrderId, out mRemovePackage))
                {
                    ObjectPoolManager.Instance.mUdpFixedSizePackagePool.recycle(mRemovePackage.mPackage);
                    mRemovePackage.mPackage = null;

                    mCheckPackagePool.recycle(mRemovePackage);
                }
                else
                {
                    DebugSystem.LogError("Server 已经确认的Send OrderId: " + nOrderId);
                }
            }
            else
            {
                CheckPackageInfo mRemovePackage = null;
                if (mWaitCheckReceiveDic.TryRemove(nOrderId, out mRemovePackage))
                {
                    ObjectPoolManager.Instance.mUdpFixedSizePackagePool.recycle(mRemovePackage.mPackage);
                    mRemovePackage.mPackage = null;

                    mCheckPackagePool.recycle(mRemovePackage);
                }
                else
                {
                    DebugSystem.LogError("Server 已经确认的Receive OrderId: " + nOrderId);
                }
            }
        }
Ejemplo n.º 6
0
 public void AddLogicHandleQueue(NetPackage mPackage)
 {
     mNeedHandlePackageQueue.Enqueue(mPackage);
 }
Ejemplo n.º 7
0
 public static T getData <T>(NetPackage mPackage) where T : IMessage, new()
 {
     return(getData <T> (mPackage.buffer, ServerConfig.nUdpPackageFixedHeadSize, mPackage.Length - ServerConfig.nUdpPackageFixedHeadSize));
 }
Ejemplo n.º 8
0
 public void ReceiveUdpCheckPackage(NetPackage mPackage)
 {
     mUdpCheckPool.ReceiveCheckPackage(mPackage);
 }
Ejemplo n.º 9
0
        public void ReceiveUdpClientHeart(NetPackage mPackage)
        {
            HeartBeat msg = Protocol3Utility.getData <HeartBeat> (mPackage);

            SendHeartBeat();
        }
Ejemplo n.º 10
0
 private void ReceiveUdpCheckPackage(ClientPeer peer, NetPackage mPackage)
 {
     peer.ReceiveUdpCheckPackage(mPackage);
 }
Ejemplo n.º 11
0
 private void ReceiveServerHeartBeat(ClientPeer peer, NetPackage mPackage)
 {
     peer.ReceiveUdpClientHeart(mPackage);
 }