/// <summary> /// Registers a room to the server /// </summary> /// <param name="peer"></param> /// <param name="options"></param> /// <returns></returns> public virtual RegisteredRoom RegisterRoom(IPeer peer, RoomOptions options) { // Create the object var room = new RegisteredRoom(GenerateRoomId(), peer, options); var peerRooms = peer.GetProperty((int)MsfPropCodes.RegisteredRooms) as Dictionary <string, RegisteredRoom>; if (peerRooms == null) { // If this is the first time creating a room // Save the dictionary peerRooms = new Dictionary <string, RegisteredRoom>(); peer.SetProperty((int)MsfPropCodes.RegisteredRooms, peerRooms); // Listen to disconnect event peer.Disconnected += OnRegisteredPeerDisconnect; } // Add a new room to peer peerRooms[room.RoomId] = room; // Add the room to a list of all rooms Rooms[room.RoomId] = room; // Invoke the event if (RoomRegistered != null) { RoomRegistered.Invoke(room); } return(room); }
protected virtual void OnGameServerFinalized() { if (GameSpawnTask.FinalizationPacket == null) { return; } var data = GameSpawnTask.FinalizationPacket.FinalizationData; if (!data.ContainsKey(MsfDictKeys.roomId)) { BroadcastChatMessage("Game server finalized, but room ID cannot be found", true); return; } // Get room id from finalization data var roomId = int.Parse(data[MsfDictKeys.roomId]); var room = Module.RoomsModule.GetRoom(roomId); if (room == null) { return; } Room = room; GameIp = room.Options.RoomIp; GamePort = room.Options.RoomPort; room.OnDestroyedEvent += OnRoomDestroyed; }
/// <summary> /// Unregisters a room from a server /// </summary> /// <param name="room"></param> public virtual void DestroyRoom(RegisteredRoom room) { var peer = room.Peer; if (peer != null) { var peerRooms = peer.GetProperty((int)MsfPropCodes.RegisteredRooms) as Dictionary <string, RegisteredRoom>; // Remove the room from peer if (peerRooms != null) { peerRooms.Remove(room.RoomId); } } // Remove the room from all rooms Rooms.Remove(room.RoomId); room.Destroy(); // Invoke the event if (RoomDestroyed != null) { RoomDestroyed.Invoke(room); } }
public void OnRoomDestroyed(RegisteredRoom room) { room.OnDestroyedEvent -= OnRoomDestroyed; GameIp = ""; GamePort = -1; Room = null; GameSpawnTask = null; State = Config.PlayAgainEnabled ? LobbyState.Preparations : LobbyState.GameOver; }
/// <summary> /// Unregisters a room from a server /// </summary> /// <param name="room"></param> public virtual void DestroyRoom(RegisteredRoom room) { var peer = room.Peer; if (peer != null) { var peerRooms = peer.GetProperty((int)MsfPropCodes.RegisteredRooms) as Dictionary <int, RegisteredRoom>; // Remove the room from peer if (peerRooms != null) { peerRooms.Remove(room.RoomId); } } // Remove the room from all rooms roomsList.Remove(room.RoomId); room.Destroy(); logger.Debug($"Room {room.RoomId} has been successfully destroyed"); // Invoke the event OnRoomDestroyedEvent?.Invoke(room); }
public virtual Dictionary <string, string> GetPublicRoomProperties(IPeer player, RegisteredRoom room, Dictionary <string, string> playerFilters) { return(room.Options.Properties); }
public virtual void ChangeRoomOptions(RegisteredRoom room, RoomOptions options) { room.ChangeOptions(options); }
/// <summary> /// Returns list of properties of public room /// </summary> /// <param name="player"></param> /// <param name="room"></param> /// <param name="playerFilters"></param> /// <returns></returns> public virtual DictionaryOptions GetPublicRoomOptions(IPeer player, RegisteredRoom room, Dictionary <string, string> playerFilters) { return(room.Options.CustomOptions); }