Exemple #1
0
        private static void OnReceivedServerConfig(NetworkConnection conn, ServerConfig config)
        {
            //Server has sent config twice in the same scene session? Probs a modified server
            if (clientHasPlayer)
            {
                Logger.Error("The server has sent it's config twice in the same scene session!");
                return;
            }

            //Set the game name
            netManager.serverConfig = config;

            ClientMotdMode = GameSettings.MultiplayerSettings.MOTDMode;

            //If the server has an MOTD, display it before creating a player object
            if (config.motdMode != Server.ServerMOTDMode.Disabled && ClientMotdMode != ClientMOTDMode.Disable)
            {
                try
                {
                    MOTDUI motdUILogic = Object.Instantiate(netManager.motdUIPrefab).GetComponent <MOTDUI>();
                    motdUILogic.Setup(config, () => RequestPlayerObject(conn));
                    return;
                }
                catch (InvalidMOTDSettings ex)
                {
                    Logger.Error(ex, "Something was wrong with the server's MOTD settings!");
                    netManager.StopHost();
                    return;
                }
            }

            RequestPlayerObject(conn);
        }
Exemple #2
0
        private static async UniTaskVoid DisplayMotdAndOrCreatePlayer()
        {
            await UniTask.WaitUntil(() => clientReceivedConfig);

            //If the server has an MOTD, display it before creating a player object
            if (netManager.serverConfig.motdMode != Server.ServerMOTDMode.Disabled && ClientMotdMode != ClientMOTDMode.Disable)
            {
                if (netManager.serverConfig.motdMode == Server.ServerMOTDMode.WebOnly && ClientMotdMode == ClientMOTDMode.TextOnly)
                {
                    RequestPlayerObject();
                    return;
                }

                try
                {
                    MOTDUI motdUILogic = Object.Instantiate(netManager.motdUIPrefab).GetComponent <MOTDUI>();
                    motdUILogic.Setup(netManager.serverConfig, RequestPlayerObject);
                    return;
                }
                catch (InvalidMOTDSettings ex)
                {
                    Logger.Error(ex, "Something was wrong with the server's MOTD settings!");
                    netManager.StopHost();
                    return;
                }
            }

            RequestPlayerObject();
        }
        private static void CloseServerIfNecessary(NetworkConnection conn)
        {
            //Our first connected client disconnected
            if (closeServerOnFirstClientDisconnect && conn.connectionId == firstConnectionId)
            {
                Logger.Info("Shutting down server due to first client disconnecting...");
                if (netManager != null)
                {
                    netManager.StopHost();
                }

                //Quit the game if we are headless
                if (Game.IsHeadless)
                {
                    Game.QuitGame();
                }
            }
        }
Exemple #4
0
        /// <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);
        }