/// <summary> /// This will be called when a room is created and registered to "master" /// </summary> protected virtual void OnRoomRegistered(RoomController controller) { if (IsStartingEditorServer && AutoJoinRoom) { //------------------------- // 1. Log into the server, if required. if (!Msf.Client.Auth.IsLoggedIn) { Logger.Debug("Logging in as guest..."); Msf.Client.Auth.LogInAsGuest((accInfo, loginError) => { if (accInfo == null) { Logger.Error("Failed to log in: " + loginError); return; } Logger.Debug("Logged in successfully"); //------------------------- // 2. Get access to join the room JoinRoom(controller); }); } else { //------------------------- // 2. Get access to join the room JoinRoom(controller); } } }
/// <summary> /// This method is called before creating a room. It can be used to /// extract some parameters from cmd args or from span task properties /// </summary> protected virtual void BeforeRegisteringRoom() { if (SpawnTaskController != null) { logger.Debug("Reading spawn task properties to override some of the room options"); // If this server was spawned, try to read some of the properties var prop = SpawnTaskController.Properties; // Room name if (prop.ContainsKey(MsfDictKeys.RoomName)) { roomName = prop[MsfDictKeys.RoomName]; } if (prop.ContainsKey(MsfDictKeys.MaxPlayers)) { maxPlayers = int.Parse(prop[MsfDictKeys.MaxPlayers]); } if (prop.ContainsKey(MsfDictKeys.RoomPassword)) { password = prop[MsfDictKeys.RoomPassword]; } if (prop.ContainsKey(MsfDictKeys.MapName)) { mapName = prop[MsfDictKeys.MapName]; } if (prop.ContainsKey(IOGamesModule.IsFirstRoomKey)) { isFirstRoom = bool.Parse(prop[IOGamesModule.IsFirstRoomKey]); } if (prop.ContainsKey(IOGamesModule.RoomSpawnTypeKey)) { roomType = prop[IOGamesModule.RoomSpawnTypeKey]; } if (prop.ContainsKey(IOGamesModule.GameRuleNameKey)) { gameRuleName = prop[IOGamesModule.GameRuleNameKey]; } } // Override the public address if (Msf.Args.IsProvided(Msf.Args.Names.MachineIp) && networkManager != null) { publicIp = Msf.Args.MachineIp; logger.Debug("Overriding rooms public IP address to: " + publicIp); } }
/// <summary> /// Destroys and unregisters the room /// </summary> public void Destroy() { Destroy((successful, error) => { if (!successful) { Logger.Error(error); } else { Logger.Debug("Unregistered room successfully: " + RoomId); } }); }
private IEnumerator StartConnection() { // Wait a fraction of a second, in case we're also starting a master server yield return(new WaitForSeconds(0.2f)); var connection = GetConnection(); connection.Connected += Connected; connection.Disconnected += Disconnected; while (true) { if (isCorrectVersion == false) { break; } // Skip one frame yield return(null); if (connection.IsConnected) { // If connected, wait a second before checking the status yield return(new WaitForSeconds(1)); continue; } // If we got here, we're not connected if (connection.IsConnecting) { Logger.Debug("Retrying to connect to server at: " + ServerIp + ":" + ServerPort); } else { Logger.Debug("Connecting to server at: " + ServerIp + ":" + ServerPort); } connection.Connect(ServerIp, ServerPort); // Give a few seconds to try and connect yield return(new WaitForSeconds(TimeToConnect)); // If we're still not connected if (!connection.IsConnected) { TimeToConnect = Mathf.Min(TimeToConnect * 2, MaxTimeToConnect); } } }
/// <summary> /// This will be called when a room is created and registered to "master" /// </summary> protected virtual void OnRoomRegistered(RoomController controller) { if (isStartingEditorServer && autoJoinRoom) { //------------------------- // 1. Log into the server logger.Debug("Logging in as guest..."); Msf.Client.Auth.LogInAsGuest((accInfo, loginError) => { if (accInfo == null) { logger.Error("Failed to log in: " + loginError); return; } logger.Debug("Logged in successfully"); //------------------------- // 2. Get access to join the room logger.Debug("Retrieving room access ..."); Msf.Client.Rooms.GetAccess(controller.RoomId, (access, accessError) => { if (access == null) { logger.Error("Failed to get the access to server: " + accessError); return; } // We have the access, try to connect to room logger.Debug("Access received: " + access); if (RoomConnector.Instance == null) { logger.Warn("RoomConnector was not found in the scene. Hopefully, " + "you handle the 'Msf.Client.Rooms.AccessReceived' " + "event manually."); } }); }); } }
/// <summary> /// Requests a specific spawner to spawn a process /// </summary> /// <param name="properties"></param> /// <param name="customArgs"></param> /// <param name="spawner"></param> /// <returns></returns> public virtual SpawnTask Spawn(Dictionary <string, string> properties, string customArgs, RegisteredSpawner spawner) { var task = new SpawnTask(GenerateSpawnTaskId(), spawner, properties, customArgs); SpawnTasks[task.SpawnId] = task; spawner.AddTaskToQueue(task); Logger.Debug("Spawner was found, and spawn task created: " + task); return(task); }
/// <summary> /// This method is called before creating a room. It can be used to /// extract some parameters from cmd args or from span task properties /// </summary> protected virtual void BeforeRegisteringRoom() { if (SpawnTaskController != null) { Logger.Debug("Reading spawn task properties to override some of the room options"); // If this server was spawned, try to read some of the properties var prop = SpawnTaskController.Properties; // Room name if (prop.ContainsKey(MsfDictKeys.RoomName)) { Name = prop[MsfDictKeys.RoomName]; } if (prop.ContainsKey(MsfDictKeys.MaxPlayers)) { MaxPlayers = int.Parse(prop[MsfDictKeys.MaxPlayers]); } if (prop.ContainsKey(MsfDictKeys.RoomPassword)) { Password = prop[MsfDictKeys.RoomPassword]; } if (prop.ContainsKey(MsfDictKeys.MapName)) { MapName = prop[MsfDictKeys.MapName]; } } // Override the public address if (Msf.Args.IsProvided(Msf.Args.Names.MachineIp) && NetworkManager != null) { PublicIp = Msf.Args.MachineIp; Logger.Debug("Overriding rooms public IP address to: " + PublicIp); } }
public override void ConnectToGame(RoomAccessPacket access) { if (SwitchScenesIfWrongScene && SceneManager.GetActiveScene().name != access.SceneName) { // Save the access RoomAccess = access; // Switch to correct scene SceneManager.LoadScene(access.SceneName); return; } NetworkManager = NetworkManager ?? FindObjectOfType <NetworkManager>(); // Remove the data after RoomAccess = null; // Just in case NetworkManager.maxConnections = 999; Logger.Debug("Trying to connect to server at address: " + access.RoomIp + ":" + access.RoomPort); if (!NetworkManager.IsClientConnected()) { // If we're not connected already NetworkManager.networkAddress = access.RoomIp; NetworkManager.networkPort = access.RoomPort; NetworkManager.StartClient(); } if (WaitConnectionCoroutine != null) { StopCoroutine(WaitConnectionCoroutine); } WaitConnectionCoroutine = StartCoroutine(WaitForConnection(access)); }
public override void StartServer(int port) { if (IsRunning) { return; } Logger.Debug("Starting on port: " + port + "..."); base.StartServer(port); Logger.Info("Started on port: " + port); // Notify about uninitialized modules var uninitializedModules = GetUninitializedModules(); if (uninitializedModules.Count > 0) { Logger.Warn("Some of the Master Server modules failed to initialize: \n" + string.Join(" \n", uninitializedModules.Select(m => m.GetType().ToString()).ToArray())); } // Notify about initialized modules if (Logger.IsLogging(LogLevel.Debug)) { Logger.Warn("Successfully initialized modules: \n" + string.Join(" \n", GetInitializedModules().Select(m => m.GetType().ToString()).ToArray())); } OnStarted(); IsMasterRunning = IsRunning; // Invoke the event if (MasterStarted != null) { MasterStarted.Invoke(this); } }