public static 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); }
public static 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); } }
public static 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); } } }
public static void SyncRooms(string gameKey, string group, List <SyncRoomInfo> syncInfo) { if (group != MatchManager.matchingGroup) { return; } if (syncInfo == null) { syncInfo = new List <SyncRoomInfo>(); } if (!_roomGroups.TryGetValue(gameKey, out var 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)); } }
public static void OnUserCountChange(string gameKey, string roomId, int changeCoung) { if (!_roomGroups.TryGetValue(gameKey, out var 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); } }
public static 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 }); } } }
public static void UpdateRoom(RoomInfo newRoomInfo) { OneRoomGroup oneGroup = _roomGroups[newRoomInfo.GameKey]; UpdateOneGroup(oneGroup, newRoomInfo.RoomId, newRoomInfo.UserCount); }