public virtual void RegisterRoom() { var isUsingLobby = Msf.Args.IsProvided(Msf.Args.Names.LobbyId); var properties = SpawnTaskController != null ? SpawnTaskController.Properties : new Dictionary <string, string>(); if (!properties.ContainsKey(MsfDictKeys.MapName)) { properties[MsfDictKeys.MapName] = MapName; } properties[MsfDictKeys.SceneName] = SceneManager.GetActiveScene().name; // 1. Create options object var options = new RoomOptions() { RoomIp = PublicIp, RoomPort = NetworkManager.networkPort, Name = Name, MaxPlayers = MaxPlayers, // Lobby rooms should be private, because they are accessed differently IsPublic = isUsingLobby ? false : IsPublic, AllowUsersRequestAccess = isUsingLobby ? false : AllowUsersRequestAccess, Password = Password, Properties = new Dictionary <string, string>() { { MsfDictKeys.MapName, MapName }, // Show the name of the map { MsfDictKeys.SceneName, SceneManager.GetActiveScene().name } // Add the scene name } }; BeforeSendingRegistrationOptions(options, properties); // 2. Send a request to create a room Msf.Server.Rooms.RegisterRoom(options, (controller, error) => { if (controller == null) { Logger.Error("Failed to create a room: " + error); return; } // Save the controller Controller = controller; Logger.Debug("Room Created successfully. Room ID: " + controller.RoomId); OnRoomRegistered(controller); }); }
/// <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); } }); }
public override void Initialize(IServer server) { base.Initialize(server); // Set handlers server.SetHandler((short)MsfOpCodes.PickUsername, HandlePickUsername); server.SetHandler((short)MsfOpCodes.JoinChannel, HandleJoinChannel); server.SetHandler((short)MsfOpCodes.LeaveChannel, HandleLeaveChannel); server.SetHandler((short)MsfOpCodes.GetCurrentChannels, HandeGetCurrentChannels); server.SetHandler((short)MsfOpCodes.ChatMessage, HandleSendChatMessage); server.SetHandler((short)MsfOpCodes.GetUsersInChannel, HandleGetUsersInChannel); server.SetHandler((short)MsfOpCodes.SetDefaultChannel, HandleSetDefaultChannel); // Setup auth dependencies var auth = server.GetModule <AuthModule>(); if (UseAuthModule && auth != null) { auth.LoggedIn += OnUserLoggedIn; auth.LoggedOut += OnUserLoggedOut; } else if (UseAuthModule) { Logger.Error("Chat module was set to use Auth module, but " + "Auth module was not found"); } }
protected virtual IEnumerator StartQueueUpdater() { while (true) { yield return(new WaitForSeconds(QueueUpdateFrequency)); foreach (var spawner in Spawners.Values) { try{ spawner.UpdateQueue(); } catch (Exception e) { Logger.Error(e); } } } }
protected virtual void OnMessageReceived(IIncommingMessage message) { try { IPacketHandler handler; Handlers.TryGetValue(message.OpCode, out handler); if (handler == null) { Logger.Warn(string.Format("Handler for OpCode {0} does not exist", message.OpCode)); if (message.IsExpectingResponse) { message.Respond(InternalServerErrorMessage, ResponseStatus.NotHandled); return; } return; } handler.Handle(message); } catch (Exception e) { if (Msf.Runtime.IsEditor) { throw; } Logger.Error("Error while handling a message from Client. OpCode: " + message.OpCode); Logger.Error(e); if (!message.IsExpectingResponse) { return; } try { message.Respond(InternalServerErrorMessage, ResponseStatus.Error); } catch (Exception exception) { Logs.Error(exception); } } }
public virtual void RegisterRoom() { var isUsingLobby = Msf.Args.IsProvided(Msf.Args.Names.LobbyId); // 1. Create options object var options = new RoomOptions() { RoomIp = publicIp, RoomPort = networkManager.networkPort, Name = roomName, MaxPlayers = maxPlayers, // Lobby rooms should be private, because they are accessed differently IsPublic = isUsingLobby ? false : isPublic, AllowUsersRequestAccess = isUsingLobby ? false : allowUsersRequestAccess, Password = password, Properties = new Dictionary <string, string>() { { MsfDictKeys.MapName, mapName }, { MsfDictKeys.SceneName, SceneManager.GetActiveScene().name }, { IOGamesModule.RoomSpawnTypeKey, roomType }, { IOGamesModule.GameRuleNameKey, gameRuleName }, } }; // 2. Send a request to create a room Msf.Server.Rooms.RegisterRoom(options, (controller, error) => { if (controller == null) { logger.Error("Failed to create a room: " + error); return; } // Save the controller roomController = controller; logger.Debug("Room Created successfully. Room ID: " + controller.RoomId); OnRoomRegistered(controller); }); }
public bool AddLobby(ILobby lobby) { if (Lobbies.ContainsKey(lobby.Id)) { Logger.Error("Failed to add a lobby - lobby with same id already exists"); return(false); } Lobbies.Add(lobby.Id, lobby); lobby.Destroyed += OnLobbyDestroyed; return(true); }
protected virtual void Start() { if (ShouldStartServerInEditor() && StartMaster) { // If we need to start the master server if (MasterServerObject == null) { Logger.Error("You have selected to start a master server, but there's no " + "master server object in the scene"); return; } // Enable master server object MasterServerObject.gameObject.SetActive(true); // If auto start in editor is not selected if (!MasterServerObject.AutoStartInEditor) { MasterServerObject.StartServer(); } } }
public override void Initialize(IServer server) { Database = Msf.Server.DbAccessors.GetAccessor <IProfilesDatabase>(); if (Database == null) { Logger.Error("Profiles database implementation was not found"); } server.SetHandler((short)MsfOpCodes.ClientProfileRequest, HandleClientProfileRequest); // Auth dependency setup _auth = server.GetModule <AuthModule>(); if (_auth != null) { _auth.LoggedIn += OnLoggedIn; } // Games dependency setup server.SetHandler((short)MsfOpCodes.ServerProfileRequest, HandleGameServerProfileRequest); server.SetHandler((short)MsfOpCodes.UpdateServerProfile, HandleProfileUpdates); }
protected virtual void Update() { // Log errors for any exceptions that might have occured // when sending mail if (_sendMailExceptions.Count > 0) { lock (_sendMailExceptions) { foreach (var exception in _sendMailExceptions) { Logger.Error(exception); } _sendMailExceptions.Clear(); } } }
public virtual void StartSpawner() { // In case we went from one scene to another, but we've already started the spawner if (IsSpawnerStarted) { return; } if (DontDestroyIfStarted) { // Move to hierarchy root, so that we can't destroy it if (transform.parent != null) { transform.SetParent(null, false); } // Make sure this object is not destroyed DontDestroyOnLoad(gameObject); } IsSpawnerStarted = true; var spawnerOptions = new SpawnerOptions(); spawnerOptions.MaxProcesses = MaxSpawnedProcesses; if (Msf.Args.IsProvided(Msf.Args.Names.MaxProcesses)) { spawnerOptions.MaxProcesses = Msf.Args.MaxProcesses; } // If we're running in editor, and we want to override the executable path if (Msf.Runtime.IsEditor && OverrideExePathInEditor) { DefaultExePath = ExePathFromEditor; } Logger.Info("Registering as a spawner with options: \n" + spawnerOptions); // 1. Register the spawner Msf.Server.Spawners.RegisterSpawner(spawnerOptions, (spawner, error) => { if (error != null) { Logger.Error("Failed to create spawner: " + error); return; } SpawnerController = spawner; spawner.DefaultSpawnerSettings.AddWebGlFlag = Msf.Args.IsProvided(Msf.Args.Names.WebGl) ? Msf.Args.WebGl : SpawnWebglServers; // Set to run in batchmode spawner.DefaultSpawnerSettings.RunInBatchmode = Msf.Args.IsProvided(Msf.Args.Names.SpawnInBatchmode) ? Msf.Args.SpawnInBatchmode : DefaultSpawnInBatchmode; // 2. Set the default executable path spawner.DefaultSpawnerSettings.ExecutablePath = Msf.Args.IsProvided(Msf.Args.Names.ExecutablePath) ? Msf.Args.ExecutablePath : DefaultExePath; // 3. Set the machine IP spawner.DefaultSpawnerSettings.MachineIp = Msf.Args.IsProvided(Msf.Args.Names.MachineIp) ? Msf.Args.MachineIp : DefaultMachineIp; // 4. (Optional) Set the method which does the spawning, if you want to // fully control how processes are spawned spawner.SetSpawnRequestHandler(HandleSpawnRequest); // 5. (Optional) Set the method, which kills processes when kill request is received spawner.SetKillRequestHandler(HandleKillRequest); Logger.Info("Spawner successfully created. Id: " + spawner.SpawnerId); }); }