Пример #1
0
        public void AddClientInfo(GameClientPeer clientPeer, string userName)
        {
            ClientInfo clientInfo = new ClientInfo();

            clientInfo.userName = userName;
            clientInfo.client   = clientPeer;
            clientInfo.roomID   = 0;
            clientInfos.Add(clientPeer, clientInfo);
        }
Пример #2
0
        public ClientInfo GetClientInfo(GameClientPeer peer)
        {
            ClientInfo clientInfo = null;

            if (!clientInfos.TryGetValue(peer, out clientInfo))
            {
                return(null);
            }
            return(clientInfo);
        }
Пример #3
0
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            if (initRequest.LocalPort == 4520)
            {
                Debug.Log("连接到Game服务器:" + initRequest.LocalIP);
                GameServerPeer serverPeer = new GameServerPeer(initRequest);
                serverPeers.Add(serverPeer);
                return(serverPeer);
            }
            GameClientPeer clientPeer = new GameClientPeer(initRequest);

            clientPeers.Add(clientPeer);
            return(clientPeer);
        }
Пример #4
0
        public void RemovePeer(GameClientPeer clientPeer)
        {
            clientPeers.Remove(clientPeer);
            ClientInfo clientInfo = null;

            if (clientInfos.TryGetValue(clientPeer, out clientInfo))
            {
                clientInfos.Remove(clientPeer);
            }
            if (clientInfo != null)
            {
                var room = GetRoom(clientInfo.roomID);
                if (room != null)
                {
                    room.RemoveClient(clientInfo);
                }
            }
        }
Пример #5
0
        public void JoinRoom(GameClientPeer client)
        {
            foreach (var kv in rooms)
            {
                Room room = kv.Value;
                if (room.clients.Count < room.maxClient)
                {
                    ClientInfo clientInfo = null;
                    if (clientInfos.TryGetValue(client, out clientInfo))
                    {
                        room.AddClient(clientInfo);
                    }
                    return;
                }
            }
            Room       r  = CreateRoom(Room.NormalRoomMaxClient);
            ClientInfo ci = null;

            if (clientInfos.TryGetValue(client, out ci))
            {
                r.AddClient(ci);
            }
        }