Ejemplo n.º 1
0
        public void  UpdateOneGroup(OneRoomGroup oneGroup, string roomId, int userCount)
        {
            var findedRoom = oneGroup.FindRoom(roomId);

            if (findedRoom == null)
            {
                throw new Exception($"somthing error cannot find room{roomId}");
            }

            //从匹配队列和空闲队列中出队列
            if (findedRoom.IsEmpty())
            {
                oneGroup.RemoveEmptyRoom(findedRoom.Blind, findedRoom.RoomId);
            }
            else if (findedRoom.IsFull())
            {
            }
            else
            {
                _matchingQueue.TryGetValue(findedRoom.Blind, out var sset);
                if (sset != null)
                {
                    sset.Remove(findedRoom);
                }
            }
            findedRoom.UpdateUserCount(userCount);
            InsertNewInfo(oneGroup, findedRoom);
        }
Ejemplo n.º 2
0
        public void SyncRoom(OneRoomGroup oneGroup, RoomInfo newRoomInfo)
        {
            var findedRoom = oneGroup.FindRoom(newRoomInfo.RoomId);

            if (findedRoom == null)
            {
                findedRoom = newRoomInfo;
                oneGroup.CreatRoom(findedRoom);
                _allRoomId.Add(newRoomInfo.RoomId);
                if (findedRoom.IsEmpty())
                {
                    oneGroup.AddEmptyRoom(findedRoom);
                }
                else if (findedRoom.IsFull())
                {
                }
                else
                {
                    if (_matchingQueue.TryGetValue(findedRoom.Blind, out var sset))
                    {
                        sset.Add(findedRoom);
                    }
                    else
                    {
                        _matchingQueue.Add(findedRoom.Blind, new SortedSet <RoomInfo>()
                        {
                            findedRoom
                        });
                    }
                }
            }

            else
            {
                //从匹配队列和空闲队列中出队列
                if (findedRoom.IsEmpty())
                {
                    oneGroup.RemoveEmptyRoom(findedRoom.Blind, findedRoom.RoomId);
                }
                else if (findedRoom.IsFull())
                {
                }
                else
                {
                    _matchingQueue.TryGetValue(findedRoom.Blind, out var sset);
                    if (sset != null)
                    {
                        sset.Remove(findedRoom);
                    }
                }
                findedRoom.UpdateUserCount(newRoomInfo.UserCount);
                InsertNewInfo(oneGroup, findedRoom);
            }
        }
Ejemplo n.º 3
0
        public void RemoveUnExistRoom(OneRoomGroup oneGroup, List <SyncRoomInfo> existRooms)
        {
            var deletedRooms = oneGroup.RemoveNoExist(existRooms);

            foreach (var room in deletedRooms)
            {
                if (_matchingQueue.TryGetValue(room.Blind, out var matchingRooms))
                {
                    matchingRooms.Remove(room);
                }
            }
        }
Ejemplo n.º 4
0
        public void JoinOneRoomFailed(string gameKey, string roomId)
        {
            OneRoomGroup oneGroup = null;

            if (!_roomGroups.TryGetValue(gameKey, out oneGroup))
            {
                return;
            }
            var room = oneGroup.FindRoom(roomId);

            if (room == null)
            {
                return;
            }
            UpdateOneGroup(oneGroup, room.RoomId, room.UserCount - 1);
        }
Ejemplo n.º 5
0
        public bool JoinOneRoom(string gameKey, string roomId)
        {
            OneRoomGroup oneGroup = null;

            if (!_roomGroups.TryGetValue(gameKey, out oneGroup))
            {
                return(false);
            }
            var room = oneGroup.FindRoom(roomId);

            if (room == null)
            {
                return(false);
            }
            if (room.IsFull())
            {
                return(false);
            }
            UpdateOneGroup(oneGroup, room.RoomId, room.UserCount + 1);
            return(true);
        }
Ejemplo n.º 6
0
        public void OnUserCountChange(string gameKey, string roomId, long blind, int changeCoung)
        {
            OneRoomGroup oneGroup = null;

            if (!_roomGroups.TryGetValue(gameKey, out oneGroup))
            {
                oneGroup = new OneRoomGroup();
                _roomGroups.Add(gameKey, oneGroup);
            }

            var findedRoom = oneGroup.FindRoom(roomId);

            if (findedRoom == null)
            {
                return;
            }
            else
            {
                //从匹配队列和空闲队列中出队列
                if (findedRoom.IsEmpty())
                {
                    oneGroup.RemoveEmptyRoom(findedRoom.Blind, findedRoom.RoomId);
                }
                else if (findedRoom.IsFull())
                {
                }
                else
                {
                    _matchingQueue.TryGetValue(findedRoom.Blind, out var sset);
                    if (sset != null)
                    {
                        sset.Remove(findedRoom);
                    }
                }
                findedRoom.AddUserCount(changeCoung);
                InsertNewInfo(oneGroup, findedRoom);
            }
        }
Ejemplo n.º 7
0
 public void InsertNewInfo(OneRoomGroup oneGroup, RoomInfo info)
 {
     if (info.IsEmpty())
     {
         oneGroup.AddEmptyRoom(info);
     }
     else if (info.IsFull())
     {
     }
     else
     {
         if (_matchingQueue.TryGetValue(info.Blind, out var sset))
         {
             sset.Add(info);
         }
         else
         {
             _matchingQueue.Add(info.Blind, new SortedSet <RoomInfo>()
             {
                 info
             });
         }
     }
 }
Ejemplo n.º 8
0
        public void SyncRooms(string gameKey, string group, List <SyncRoomInfo> syncInfo)
        {
            if (group != MatchingManager.matchingGroup)
            {
                return;
            }
            if (syncInfo == null)
            {
                syncInfo = new List <SyncRoomInfo>();
            }
            OneRoomGroup oneGroup = null;

            if (!_roomGroups.TryGetValue(gameKey, out oneGroup))
            {
                oneGroup = new OneRoomGroup();
                _roomGroups.Add(gameKey, oneGroup);
            }
            //先移除不存在的
            RemoveUnExistRoom(oneGroup, syncInfo);
            foreach (var info in syncInfo)
            {
                SyncRoom(oneGroup, new RoomInfo(info.RoomId, info.UserCount, gameKey, info.Blind));
            }
        }
Ejemplo n.º 9
0
        public void UpdateRoom(RoomInfo newRoomInfo)
        {
            OneRoomGroup oneGroup = _roomGroups[newRoomInfo.GameKey];

            UpdateOneGroup(oneGroup, newRoomInfo.RoomId, newRoomInfo.UserCount);
        }