Ejemplo n.º 1
0
        public void Process()
        {
            GameManager.HandleRooms();

            while (IsListening && m_listener.Pending())
            {
                m_clients.Add(new GameClient(m_listener.AcceptTcpClient()));
            }

            List <GameClient> toRemove = new List <GameClient>();

            foreach (GameClient client in m_clients)
            {
                client.Tick();
                if (!client.IsConnected || client.InGame())
                {
                    toRemove.Add(client);
                }
            }

            while (toRemove.Count > 0)
            {
                m_clients.Remove(toRemove[0]);
                toRemove.RemoveAt(0);
            }
        }
Ejemplo n.º 2
0
        public void Process()
        {
            //在游戏的,则以房间为单位
            //接收到 游戏房间内任意一个玩家的发送内容,则在房间内传播
            GameManager.HandleRooms();

            //大量玩家连接服务端,可能耗时
            //while (IsListening && m_listener.Pending())
            //	m_clients.Add(new GameClient(m_listener.AcceptTcpClient()));

            //不在游戏房间的玩家
            List <GameClient> _clients = new List <GameClient>();

            m_mutexClients.WaitOne();
            _clients.AddRange(m_clients);
            m_mutexClients.ReleaseMutex();
            foreach (GameClient client in _clients)
            {
                client.Tick();
                if (!client.IsConnected || client.InGame())
                {
                    //断开,或者在游戏,一定时间内没有加入房间
                    //	Logger.WriteLine("player logout");
                    m_mutexClients.WaitOne();
                    m_clients.Remove(client);
                    m_mutexClients.ReleaseMutex();
                }
            }
        }