/// <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(); // Invoke the event if (OnRoomDestroyedEvent != null) { OnRoomDestroyedEvent.Invoke(room); } }
/// <summary> /// Sends a request to destroy a room of a given room id /// </summary> public void DestroyRoom(int roomId, SuccessCallback callback, IClientSocket connection) { if (!connection.IsConnected) { callback.Invoke(false, "Not connected"); return; } connection.SendMessage((short)MsfMessageCodes.DestroyRoomRequest, roomId, (status, response) => { if (status != ResponseStatus.Success) { callback.Invoke(false, response.AsString("Unknown Error")); return; } if (_localCreatedRooms.TryGetValue(roomId, out RoomController destroyedRoom)) { _localCreatedRooms.Remove(roomId); callback.Invoke(true, null); // Invoke event OnRoomDestroyedEvent?.Invoke(destroyedRoom); } }); }
/// <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); }