public static void RemoveClient(ClientContainer clientContainer) { System.Console.WriteLine("removing client"); AllClients.Remove(clientContainer.Id); if (UsingRoomHandling) { var p = clientContainer.StoredData["Room"] as string; if (Rooms.ContainsKey(p)) { Rooms[p].RoomClients.Remove(clientContainer.Id); foreach (var item in Rooms[p].RoomClients.Values) { Server.MessagesToSend.Enqueue(new SendableMessage { Address = item.Id, Message = new PlayerRemovedMessage { ApplicationVersion = Server.ApplicationVersion, DetourVersion = DetourVersion, MessageType = 5, Id = clientContainer.Id, RoomId = p } }); } } } ClientRemoved?.Invoke(clientContainer.Id); }
public bool AddToRoom(ClientContainer Client) { if (RoomClientCount < RoomClientCapacity) { if (RoomClients.ContainsKey(Client.Id)) { RoomClients[Client.Id] = Client; return(true); } else { RoomClients.Add(Client.Id, Client); return(true); } } else { return(false); } }
public static string MatchToRoom(string RoomTypeRequested, ClientContainer ClientToMatch) { var _AvailableRooms = Rooms.Where(x => x.Value.RoomType == RoomTypeRequested).ToList(); if (_AvailableRooms.Count > 0) { var _SelectedRoom = _AvailableRooms[Tumbler.Next(0, _AvailableRooms.Count)]; _SelectedRoom.Value.AddToRoom(ClientToMatch); Console.WriteLine("client added to existing room"); return(_SelectedRoom.Key); } else { var _newRoomId = System.Guid.NewGuid().ToString(); var RequestedRoomType = RoomTypes[RoomTypeRequested]; Rooms.Add(_newRoomId, new Room { RoomId = _newRoomId, RoomClientCapacity = RequestedRoomType.RoomCapacity, RoomType = RequestedRoomType.RoomType, RoomStartPoints = RequestedRoomType.StartPoints }); RoomTypes[RoomTypeRequested].OnRoomInitialized.Invoke(_newRoomId, RoomTypeRequested); Rooms[_newRoomId].AddToRoom(ClientToMatch); Console.WriteLine("client added to new room"); return(_newRoomId); } }
/// <summary> /// Adds a client to the Dictionary of clients. /// </summary> public static ClientContainer AddClient(ClientContainer Client) { AllClients.Add(Client.Id, Client); return(AllClients[Client.Id]); }