예제 #1
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);
            }
        }