Exemplo n.º 1
0
        public static void StartServerCommand(string[] args)
        {
            NetworkManager networkManager = NetworkManager.singleton;
            string         scene          = args[0];
            TCScene        tcScene        = TCScenesManager.FindSceneInfo(scene);

            if (tcScene == null)
            {
                Logger.Error("That scene doesn't exist!");
                return;
            }

            Scene = tcScene.SceneFileName;
            networkManager.onlineScene = tcScene.scene;

            networkManager.StartServer();
        }
 private void OnBeginSceneLoading(AsyncOperation operation, string sceneName)
 {
     StartCoroutine(OnStartSceneLoadAsync(operation, TCScenesManager.FindSceneInfo(sceneName)));
 }
Exemplo n.º 3
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...");

            //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);
        }