protected virtual void JoinTheRoom() { Msf.Events.Invoke(MsfEventKeys.showLoadingInfo, $"Joinig room {roomAccess.RoomId}... Please wait!"); // Wait for connection to mirror server MsfTimer.WaitWhile(() => !NetworkClient.isConnected, isSuccessful => { Msf.Events.Invoke(MsfEventKeys.hideLoadingInfo); if (!isSuccessful) { logger.Error("We could not connect to room. Please try again later or contact to administrator"); MirrorNetworkManager.StopClient(); } else { OnConnectedToMirrorServerEventHandler(NetworkClient.connection); } }, roomConnectionTimeout); // If we are not connected to mirror server if (!NetworkClient.isConnected) { // Let's set the IP before we start connection SetAddress(roomAccess.RoomIp); // Let's set the port before we start connection SetPort(roomAccess.RoomPort); logger.Debug("Connecting to mirror server..."); // Start mirror client MirrorNetworkManager.StartClient(); } }
public void CreateNewRoom() { if (!createNewRoomView) { ViewsManager.NotifyNoViewFound("CreateNewRoomView"); return; } createNewRoomView.Hide(); Msf.Events.Invoke(MsfEventKeys.showLoadingInfo, "Starting room... Please wait!"); // Spawn options for spawner controller var spawnOptions = new DictionaryOptions(); spawnOptions.Add(MsfDictKeys.maxPlayers, createNewRoomView.MaxConnections); spawnOptions.Add(MsfDictKeys.roomName, createNewRoomView.RoomName); spawnOptions.Add(MsfDictKeys.roomPassword, createNewRoomView.Password); // Custom options that will be given to room directly var customSpawnOptions = new DictionaryOptions(); customSpawnOptions.Add(Msf.Args.Names.StartClientConnection, string.Empty); Msf.Client.Spawners.RequestSpawn(spawnOptions, customSpawnOptions, createNewRoomView.RegionName, (controller, error) => { if (controller == null) { Msf.Events.Invoke(MsfEventKeys.hideLoadingInfo); Msf.Events.Invoke(MsfEventKeys.showOkDialogBox, new OkDialogBoxEventMessage(error, null)); return; } Msf.Events.Invoke(MsfEventKeys.showLoadingInfo, "Room started. Finalizing... Please wait!"); MsfTimer.WaitWhile(() => { return(controller.Status != SpawnStatus.Finalized); }, (isSuccess) => { Msf.Events.Invoke(MsfEventKeys.hideLoadingInfo); if (!isSuccess) { Msf.Client.Spawners.AbortSpawn(controller.SpawnTaskId); logger.Error("Failed spawn new room. Time is up!"); Msf.Events.Invoke(MsfEventKeys.showOkDialogBox, new OkDialogBoxEventMessage("Failed spawn new room. Time is up!", null)); return; } OnRoomStartedEvent?.Invoke(); logger.Info("You have successfully spawned new room"); }, 60f); }); }
private static void SendRequestSpawn(CommandArg[] args) { var options = new DictionaryOptions(); options.Add(MsfDictKeys.roomName, args[0].String.Replace('+', ' ')); if (args.Length > 1) { options.Add(MsfDictKeys.maxPlayers, args[1].String); } var customOptions = new DictionaryOptions(); customOptions.Add("-myName", "\"John Adams\""); customOptions.Add("-myAge", 45); customOptions.Add("-msfStartClientConnection", string.Empty); Msf.Client.Spawners.RequestSpawn(options, customOptions, string.Empty, (controller, error) => { if (controller == null) { return; } MsfTimer.WaitWhile(() => { return(controller.Status != SpawnStatus.Finalized); }, (isSuccess) => { if (!isSuccess) { Msf.Client.Spawners.AbortSpawn(controller.SpawnTaskId); Logs.Error("You have failed to spawn new room"); } Logs.Info("You have successfully spawned new room"); }, 60f); }); }