/// <summary> /// Call this when the server is stopped /// </summary> internal static void OnStopServer() { Logger.Info("Stopping server..."); PingManager.ServerShutdown(); //Stop advertising the server when the server stops netManager.gameDiscovery.StopDiscovery(); Logger.Info("Server stopped!"); //Close server online file stream try { serverOnlineFileStream.Close(); serverOnlineFileStream.Dispose(); serverOnlineFileStream = null; } catch (Exception ex) { Logger.Error(ex, "An error occurred while shutting down the server!"); } netManager = null; //Double check that the file is deleted if (File.Exists(serverOnlineFilePath)) { File.Delete(serverOnlineFilePath); } }
/// <summary> /// Called when the client starts /// </summary> /// <param name="workingNetManager"></param> internal static void OnClientStart(TCNetworkManager workingNetManager) { clientHasPlayer = false; netManager = workingNetManager; //We register for ServerConfigurationMessage, so we get server info NetworkClient.RegisterHandler <ServerConfig>(OnReceivedServerConfig); PingManager.ClientSetup(); Logger.Info("Started client."); }
public override void Awake() { if (Instance != null) { Destroy(gameObject); return; } //Replace Mirror's logger with ours //LogFactory.ReplaceLogHandler(new MirrorLogHandler()); base.Awake(); Instance = this; }
public override void Awake() { if (Instance != null) { Destroy(gameObject); return; } //Replace Mirror's logger with ours //LogFactory.ReplaceLogHandler(new TCUnityLogger()); base.Awake(); Instance = this; tcAuthenticator = GetComponent <TCAuthenticator>(); }
/// <summary> /// Call this when the server is started /// </summary> internal static void OnStartServer(TCNetworkManager workingNetManager) { serverOnlineFilePath = $"{Game.GetGameExecutePath()}/{ServerOnlineFile}"; if (File.Exists(serverOnlineFilePath)) { throw new Exception("Server is already online!"); } netManager = workingNetManager; Logger.Info("Starting server..."); //Set what network address to use and start to advertise the server on lan netManager.networkAddress = NetHelper.LocalIpAddress(); netManager.gameDiscovery.AdvertiseServer(); //Start ping service PingManager.ServerSetup(); //Run the server autoexec config ConsoleBackend.ExecuteFile("server-autoexec"); SetupServerConfig(); //Create server online file try { serverOnlineFileStream = File.Create(serverOnlineFilePath, 128, FileOptions.DeleteOnClose); serverOnlineFileStream.Write(ServerOnlineFileMessage, 0, ServerOnlineFileMessage.Length); serverOnlineFileStream.Flush(); File.SetAttributes(serverOnlineFilePath, FileAttributes.Hidden); } catch (IOException ex) { Logger.Error(ex, "An error occurred while setting up the server!"); netManager.StopHost(); return; } Logger.Info("Server has started and is running on '{Address}' with max connections of {MaxPlayers}!", netManager.networkAddress, netManager.maxConnections); }
/// <summary> /// Call this when the server is started /// </summary> internal static void OnStartServer(TCNetworkManager workingNetManager) { serverOnlineFilePath = $"{Game.GetGameExecutePath()}/{ServerOnlineFile}"; if (File.Exists(serverOnlineFilePath)) { throw new Exception("Server is already online!"); } netManager = workingNetManager; Logger.Info("Starting server..."); //Get the online scene TCScene onlineScene = TCScenesManager.FindSceneInfo(Scene); if (onlineScene == null) { Logger.Error($"Failed to find scene {Scene}!"); throw new FileNotFoundException($"Scene {Scene} not found!"); } //Setup the server's config SetupServerConfig(); Application.targetFrameRate = netManager.serverTickRate; //Make some adjustments to scenes config if we are running headless if (Game.IsHeadless) { netManager.offlineScene = null; netManager.onlineScene = onlineScene.scene; TCScenesManager.LoadScene(onlineScene); } //Set what network address to use and start to advertise the server on lan netManager.networkAddress = NetHelper.LocalIpAddress(); netManager.gameDiscovery.AdvertiseServer(); //Setup ping related stuff PingManager.ServerSetup(); LagCompensationManager.ServerSetup(); //Run the server autoexec config ConsoleBackend.ExecuteFile("server-autoexec"); //Server chat NetworkServer.RegisterHandler <ChatMessage>(ServerChat.ReceivedChatMessage); //Create server online file try { serverOnlineFileStream = File.Create(serverOnlineFilePath, 128, FileOptions.DeleteOnClose); serverOnlineFileStream.Write(ServerOnlineFileMessage, 0, ServerOnlineFileMessage.Length); serverOnlineFileStream.Flush(); File.SetAttributes(serverOnlineFilePath, FileAttributes.Hidden); } catch (IOException ex) { Logger.Error(ex, "An error occurred while setting up the server!"); netManager.StopHost(); return; } Logger.Info("Server has started and is running on '{Address}' with max connections of {MaxPlayers}!", netManager.networkAddress, netManager.maxConnections); }