Beispiel #1
0
        public void SetWorldSignalTest()
        {
            BaseWorld target = new BaseWorld(); // TODO: 初始化为适当的值

            target.SetWorldSignal();
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
Beispiel #2
0
        /// <summary>
        /// 开始连接服务端
        /// </summary>
        /// <param name="strHostNamePort">地址和端口</param>
        /// <returns></returns>
        public bool StartConnectServer(string strHostNamePort)
        {
            if (string.IsNullOrEmpty(strHostNamePort) == true)
            {
                throw new ArgumentException("Connecter.StartConnectServer(...) - string.IsNullOrEmpty(...) == true error!", "strHostNamePort");
            }

            if (m_World == null)
            {
                throw new Exception("Connecter.StartConnectServer(...) - m_World == null error!");
            }

            if (m_SocketClient.IsConnected == true)
            {
                throw new Exception("Connecter.StartConnectServer(...) - m_SocketClient.IsConnected == true error!");
            }

            if (m_SocketClient.StartConnectServer(strHostNamePort) == true)
            {
                // 初始化Disposed
                m_LockDisposed.SetValid();
                m_IsNeedSlice = true;

                LOGs.WriteLine(LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.ConnecterString001, m_ClientSocketManager.Address);

                // 有新的连接出去需要发送全局信号处理新的连接
                m_World.SetWorldSignal();

                return(true);
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        public void UpdateSlice()
        {
            BaseWorld tempWorld = m_World;

            if (tempWorld != null)
            {
                tempWorld.SliceUpdate.UpdateSlice(this);
                tempWorld.SetWorldSignal();
            }
            else
            {
                throw new Exception("BaseMap.UpdateSlice(...) - m_World == null error!");
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        public void UpdateSlice()
        {
            if (m_Deleted == true)
            {
                return;
            }

            BaseWorld tempWorld = m_World;

            if (tempWorld != null)
            {
                tempWorld.SliceUpdate.UpdateSlice(this);
                tempWorld.SetWorldSignal();
            }
            else
            {
                throw new Exception("GameEntity.UpdateSlice(...) - m_World == null error!");
            }
        }
        /// <summary>
        /// 网络上面有数据过来
        /// </summary>
        /// <param name="netState"></param>
        internal void OnReceive(NetState netState)
        {
            if (netState.InProcessQueue() == false)
            {
                return;
            }

            // 表示当前已加入在处理列表中(减少处理列表的长度)

            m_LockNetStateQueue.Enter();
            {
                m_NetStateQueue.Enqueue(netState);
            }
            m_LockNetStateQueue.Exit();

            Debug.Assert(m_World != null, "MessagePump.OnReceive(...) - m_World == null error!");

            // 有数据过来需要发送全局信号处理数据包
            if (m_World != null)
            {
                m_World.SetWorldSignal();
            }
        }
Beispiel #6
0
        /// <summary>
        /// 连接新的客户端的处理
        /// </summary>
        /// <param name="NonceClientHandler"></param>
        /// <param name="AllHandlerManager"></param>
        /// <param name="ClientHandlerAtServer"></param>
        private void OnAcceptor(object sender, AcceptorEventArgs eventArgs)
        {
            SocketConnectEventArgs socketConnectEventArgs = new SocketConnectEventArgs(eventArgs.AcceptorHandle);

            GlobalEvent.InvokeSocketConnect(socketConnectEventArgs);

            // 如果允许连接
            if (socketConnectEventArgs.AllowConnection == true)
            {
                ClientSocketManager newClientSocketHandler = new ClientSocketManager(this, eventArgs.AcceptorHandle, m_ReceiveQueuePool.AcquirePoolContent());

                m_LockAccepted.Enter();
                {
                    m_Accepted.Enqueue(newClientSocketHandler);
                }
                m_LockAccepted.Exit();

                LOGs.WriteLine(LogMessageType.MSG_INFO, LanguageString.SingletonInstance.ListenerString003, eventArgs.AcceptorHandle.ClientAddress, eventArgs.AcceptorHandleManager.OnlineClients, eventArgs.AcceptorHandleManager.TotalClients);

                // 有新的连接过来需要发送全局信号处理新的连接
                m_World.SetWorldSignal();
            }
            else // 不允许连接
            {
                try
                {
                    eventArgs.AcceptorHandle.CloseSocket();
                }
                catch
                {
                    Debug.WriteLine("Listener.OnAcceptor(...) - NonceClientHandler.CloseSocket(...) Exception error!");
                }

                LOGs.WriteLine(LogMessageType.MSG_WARNING, LanguageString.SingletonInstance.ListenerString004, eventArgs.AcceptorHandle.ClientAddress, eventArgs.AcceptorHandleManager.OnlineClients, eventArgs.AcceptorHandleManager.TotalClients);
            }
        }