示例#1
0
        /// <summary>
        /// Called when all other extensions have been loaded
        /// </summary>
        public override void OnModLoad()
        {
            // Override default server settings
            var commandLine = new CommandLine(Environment.GetCommandLineArgs());

            if (commandLine.HasVariable("maxplayers"))
            {
                PlayerPrefs.SetInt("MpGamePlayerCount", int.Parse(commandLine.GetVariable("maxplayers")));
            }
            if (commandLine.HasVariable("hostname"))
            {
                PlayerPrefs.SetString("MpGameName", commandLine.GetVariable("hostname"));
            }
            if (commandLine.HasVariable("friendsonly"))
            {
                PlayerPrefs.SetInt("MpGameFriendsOnly", int.Parse(commandLine.GetVariable("friendsonly")));
            }
            if (commandLine.HasVariable("saveslot"))
            {
                PlayerPrefs.SetInt("MpGameSaveSlot", int.Parse(commandLine.GetVariable("saveslot")));
            }
            //if (commandLine.HasVariable("saveinterval")) // TODO: Make this work

            if (File.Exists(logFileName))
            {
                File.Delete(logFileName);
            }
            var logStream = File.AppendText(logFileName);

            logStream.AutoFlush = true;
            logWriter           = TextWriter.Synchronized(logStream);

            // Limit FPS to reduce CPU usage
            PlayerPreferences.MaxFrameRate = 60;

            if (!Interface.Oxide.EnableConsole())
            {
                return;
            }

            // Check if client should be disabled
            if (commandLine.HasVariable("batchmode") || commandLine.HasVariable("nographics"))
            {
                DisableClient = true;
            }

            // Disable client's sound if not dedicated
            if (DisableClient)
            {
                TheForestCore.DisableAudio();
            }

            Application.logMessageReceivedThreaded += HandleLog;
            Interface.Oxide.ServerConsole.Input    += ServerConsoleOnInput;
        }
示例#2
0
        /// <summary>
        /// Called when all other extensions have been loaded
        /// </summary>
        public override void OnModLoad()
        {
            if (!Interface.Oxide.EnableConsole())
            {
                return;
            }

            if (File.Exists(LogFileName))
            {
                File.Delete(LogFileName);
            }
            var logStream = File.AppendText(LogFileName);

            logStream.AutoFlush = true;
            logWriter           = TextWriter.Synchronized(logStream);

            Application.logMessageReceivedThreaded += HandleLog;
            Interface.Oxide.ServerConsole.Input    += ServerConsoleOnInput;

            // Override default server settings
            //var boltInit = UnityEngine.Object.FindObjectOfType<BoltInit>();
            //var serverAddress = typeof(BoltInit).GetField("serverAddress", BindingFlags.NonPublic | BindingFlags.Instance);
            //var serverPort = typeof(BoltInit).GetField("serverPort", BindingFlags.NonPublic | BindingFlags.Instance);
            var commandLine = new CommandLine(Environment.GetCommandLineArgs());

            //if (commandLine.HasVariable("ip")) serverAddress?.SetValue(boltInit, commandLine.GetVariable("ip"));
            //if (commandLine.HasVariable("port")) serverPort?.SetValue(boltInit, commandLine.GetVariable("port"));
            if (commandLine.HasVariable("maxplayers"))
            {
                PlayerPrefs.SetInt("MpGamePlayerCount", int.Parse(commandLine.GetVariable("maxplayers")));
            }
            if (commandLine.HasVariable("hostname"))
            {
                PlayerPrefs.SetString("MpGameName", commandLine.GetVariable("hostname"));
            }
            if (commandLine.HasVariable("friendsonly"))
            {
                PlayerPrefs.SetInt("MpGameFriendsOnly", int.Parse(commandLine.GetVariable("friendsonly")));
            }
            if (commandLine.HasVariable("saveslot"))
            {
                TitleScreen.StartGameSetup.Slot = (TitleScreen.GameSetup.Slots) int.Parse(commandLine.GetVariable("saveslot"));
            }
            //if (commandLine.HasVariable("saveinterval")) /* TODO */

            // Disable client audio for server
            TheForestCore.DisableAudio();

            // Limit FPS to reduce CPU usage
            PlayerPreferences.MaxFrameRate = 60;

            Interface.Oxide.ServerConsole.Title = () =>
            {
                if (CoopLobby.Instance == null)
                {
                    return(string.Empty);
                }
                var players  = CoopLobby.Instance.MemberCount;
                var hostname = CoopLobby.Instance.Info.Name;
                return(string.Concat(players, " | ", hostname));
            };

            Interface.Oxide.ServerConsole.Status1Left = () =>
            {
                if (CoopLobby.Instance == null)
                {
                    return(string.Empty);
                }
                var hostname = CoopLobby.Instance.Info.Name;
                return(string.Concat(" ", hostname));
            };
            Interface.Oxide.ServerConsole.Status1Right = () =>
            {
                var fps     = Mathf.RoundToInt(1f / Time.smoothDeltaTime);
                var seconds = TimeSpan.FromSeconds(Time.realtimeSinceStartup);
                var uptime  = $"{seconds.TotalHours:00}h{seconds.Minutes:00}m{seconds.Seconds:00}s".TrimStart(' ', 'd', 'h', 'm', 's', '0');
                return(string.Concat(fps, "fps, ", uptime));
            };

            Interface.Oxide.ServerConsole.Status2Left = () =>
            {
                if (CoopLobby.Instance == null)
                {
                    return(string.Empty);
                }
                var players     = CoopLobby.Instance.MemberCount;
                var playerLimit = CoopLobby.Instance.Info.MemberLimit;
                return(string.Concat(" ", players, "/", playerLimit, " players"));
            };
            Interface.Oxide.ServerConsole.Status2Right = () =>
            {
                // TODO: Network in/out
                return(string.Empty);
            };

            Interface.Oxide.ServerConsole.Status3Left = () =>
            {
                //var gameTime = TheForestAtmosphere.Instance?.TimeOfDay; // TODO: Fix NRE and format
                return(string.Concat(string.Empty /*, gameTime*/));
            };
            Interface.Oxide.ServerConsole.Status3Right = () =>
            {
                var gameVersion  = "0.30b"; // TODO: Grab version
                var oxideVersion = OxideMod.Version.ToString();
                return(string.Concat("Oxide ", oxideVersion, " for ", gameVersion));
            };
            Interface.Oxide.ServerConsole.Status3RightColor = ConsoleColor.Yellow;
        }
示例#3
0
        /// <summary>
        /// Called when all other extensions have been loaded
        /// </summary>
        public override void OnModLoad()
        {
            // Get the game's version from mainData
            var regex = new Regex(@"Version v(\d+\.\d+[a-z]?)");

            using (var reader = new StreamReader(Path.Combine(Application.dataPath, "mainData")))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var match = regex.Match(line);
                    if (!match.Success)
                    {
                        continue;
                    }
                    GameVersion = match.Groups[1].Value;
                }
            }

            if (!Directory.Exists("logs"))
            {
                Directory.CreateDirectory("logs");
            }
            if (File.Exists(logFileName))
            {
                File.Delete(logFileName);
            }
            var logStream = File.AppendText(logFileName);

            logStream.AutoFlush = true;
            logWriter           = TextWriter.Synchronized(logStream);
            Application.logMessageReceivedThreaded += HandleLog;

            // Limit FPS to reduce CPU usage
            PlayerPreferences.MaxFrameRate = 60;

            // Override default server settings
            var commandLine = new CommandLine(Environment.GetCommandLineArgs());

            if (commandLine.HasVariable("maxplayers"))
            {
                PlayerPrefs.SetInt("MpGamePlayerCount", int.Parse(commandLine.GetVariable("maxplayers")));
            }
            if (commandLine.HasVariable("hostname"))
            {
                PlayerPrefs.SetString("MpGameName", commandLine.GetVariable("hostname"));
            }
            if (commandLine.HasVariable("friendsonly"))
            {
                PlayerPrefs.SetInt("MpGameFriendsOnly", int.Parse(commandLine.GetVariable("friendsonly")));
            }
            if (commandLine.HasVariable("saveslot"))
            {
                PlayerPrefs.SetInt("MpGameSaveSlot", int.Parse(commandLine.GetVariable("saveslot")));
            }
            //if (commandLine.HasVariable("saveinterval")) // TODO: Make this work
            //if (commandLine.HasVariable("gamemode")) // TODO: Make this work

            // Check if client should be disabled
            if (commandLine.HasVariable("batchmode") || commandLine.HasVariable("nographics"))
            {
                TheForestCore.DisableAudio();
                DisableClient = true;
            }

            if (Interface.Oxide.EnableConsole())
            {
                Interface.Oxide.ServerConsole.Input += ServerConsoleOnInput;
            }
        }
示例#4
0
        /// <summary>
        /// Called when all other extensions have been loaded
        /// </summary>
        public override void OnModLoad()
        {
            if (!Interface.Oxide.EnableConsole())
            {
                return;
            }

            if (File.Exists(logFileName))
            {
                File.Delete(logFileName);
            }
            var logStream = File.AppendText(logFileName);

            logStream.AutoFlush = true;
            logWriter           = TextWriter.Synchronized(logStream);

            Application.logMessageReceivedThreaded += HandleLog;
            Interface.Oxide.ServerConsole.Input    += ServerConsoleOnInput;

            // Override default server settings
            //var boltInit = UnityEngine.Object.FindObjectOfType<BoltInit>();
            //var serverAddress = typeof(BoltInit).GetField("serverAddress", BindingFlags.NonPublic | BindingFlags.Instance);
            //var serverPort = typeof(BoltInit).GetField("serverPort", BindingFlags.NonPublic | BindingFlags.Instance);
            var commandLine = new CommandLine(Environment.GetCommandLineArgs());

            //if (commandLine.HasVariable("ip")) serverAddress?.SetValue(boltInit, commandLine.GetVariable("ip")); // TODO: Fix and re-enable
            //if (commandLine.HasVariable("port")) serverPort?.SetValue(boltInit, commandLine.GetVariable("port")); // TODO: Fix and re-enable
            if (commandLine.HasVariable("maxplayers"))
            {
                PlayerPrefs.SetInt("MpGamePlayerCount", int.Parse(commandLine.GetVariable("maxplayers")));
            }
            if (commandLine.HasVariable("hostname"))
            {
                PlayerPrefs.SetString("MpGameName", commandLine.GetVariable("hostname"));
            }
            if (commandLine.HasVariable("friendsonly"))
            {
                PlayerPrefs.SetInt("MpGameFriendsOnly", int.Parse(commandLine.GetVariable("friendsonly")));
            }
            if (commandLine.HasVariable("saveslot"))
            {
                PlayerPrefs.SetInt("MpGameSaveSlot", int.Parse(commandLine.GetVariable("saveslot")));
            }
            //if (commandLine.HasVariable("saveinterval")) // TODO: Make this work

            TheForestCore.DisableAudio();        // Disable client audio for server
            PlayerPreferences.MaxFrameRate = 60; // Limit FPS to reduce CPU usage

            Interface.Oxide.ServerConsole.Title = () => $"{CoopLobby.Instance?.MemberCount ?? 0} | {CoopLobby.Instance?.Info.Name ?? "Unnamed"}";

            Interface.Oxide.ServerConsole.Status1Left  = () => string.Concat(" ", CoopLobby.Instance?.Info.Name ?? "Unnamed");
            Interface.Oxide.ServerConsole.Status1Right = () =>
            {
                var fps     = Mathf.RoundToInt(1f / Time.smoothDeltaTime);
                var seconds = TimeSpan.FromSeconds(Time.realtimeSinceStartup);
                var uptime  = $"{seconds.TotalHours:00}h{seconds.Minutes:00}m{seconds.Seconds:00}s".TrimStart(' ', 'd', 'h', 'm', 's', '0');
                return(string.Concat(fps, "fps, ", uptime));
            };

            Interface.Oxide.ServerConsole.Status2Left  = () => $" {CoopLobby.Instance?.MemberCount}/{CoopLobby.Instance?.Info.MemberLimit}";
            Interface.Oxide.ServerConsole.Status2Right = () =>
            {
                // TODO: Network in/out
                return(string.Empty);
            };

            Interface.Oxide.ServerConsole.Status3Left = () =>
            {
                return(string.Concat(" ", TheForestAtmosphere.Instance?.TimeOfDay.ToString() ?? string.Empty)); // TODO: Format time
            };
            Interface.Oxide.ServerConsole.Status3Right      = () => $"Oxide {OxideMod.Version} for 0.36b";
            Interface.Oxide.ServerConsole.Status3RightColor = ConsoleColor.Yellow;
        }
示例#5
0
        /// <summary>
        /// Called when all other extensions have been loaded
        /// </summary>
        public override void OnModLoad()
        {
            if (!Interface.Oxide.EnableConsole())
            {
                return;
            }

            if (File.Exists(logFileName))
            {
                File.Delete(logFileName);
            }
            var logStream = File.AppendText(logFileName);

            logStream.AutoFlush = true;
            logWriter           = TextWriter.Synchronized(logStream);

            Application.logMessageReceivedThreaded += HandleLog;
            Interface.Oxide.ServerConsole.Input    += ServerConsoleOnInput;

            // Override default server settings
            var commandLine = new CommandLine(Environment.GetCommandLineArgs());

            if (commandLine.HasVariable("maxplayers"))
            {
                PlayerPrefs.SetInt("MpGamePlayerCount", int.Parse(commandLine.GetVariable("maxplayers")));
            }
            if (commandLine.HasVariable("hostname"))
            {
                PlayerPrefs.SetString("MpGameName", commandLine.GetVariable("hostname"));
            }
            if (commandLine.HasVariable("friendsonly"))
            {
                PlayerPrefs.SetInt("MpGameFriendsOnly", int.Parse(commandLine.GetVariable("friendsonly")));
            }
            if (commandLine.HasVariable("saveslot"))
            {
                PlayerPrefs.SetInt("MpGameSaveSlot", int.Parse(commandLine.GetVariable("saveslot")));
            }
            //if (commandLine.HasVariable("saveinterval")) // TODO: Make this work

            // Check if client should be disabled
            if (commandLine.HasVariable("batchmode") || commandLine.HasVariable("nographics"))
            {
                DisableClient = true;
            }

            // Disable client's sound if not dedicated
            if (DisableClient)
            {
                TheForestCore.DisableAudio();
            }

            // Limit FPS to reduce CPU usage
            PlayerPreferences.MaxFrameRate = 60;

            Interface.Oxide.ServerConsole.Title = () => $"{CoopLobby.Instance?.MemberCount ?? 0} | {CoopLobby.Instance?.Info?.Name ?? "Unnamed"}";

            Interface.Oxide.ServerConsole.Status1Left  = () => string.Concat(" ", CoopLobby.Instance?.Info?.Name ?? "Unnamed");
            Interface.Oxide.ServerConsole.Status1Right = () =>
            {
                var fps     = Mathf.RoundToInt(1f / Time.smoothDeltaTime);
                var seconds = TimeSpan.FromSeconds(Time.realtimeSinceStartup);
                var uptime  = $"{seconds.TotalHours:00}h{seconds.Minutes:00}m{seconds.Seconds:00}s".TrimStart(' ', 'd', 'h', 'm', 's', '0');
                return(string.Concat(fps, "fps, ", uptime));
            };

            Interface.Oxide.ServerConsole.Status2Left  = () => $" {CoopLobby.Instance?.MemberCount}/{CoopLobby.Instance?.Info?.MemberLimit}";
            Interface.Oxide.ServerConsole.Status2Right = () =>
            {
                // TODO: Network in/out
                return(string.Empty);
            };

            Interface.Oxide.ServerConsole.Status3Left = () =>
            {
                return(string.Concat(" ", TheForestAtmosphere.Instance?.TimeOfDay.ToString() ?? string.Empty)); // TODO: Format time
            };
            Interface.Oxide.ServerConsole.Status3Right      = () => $"Oxide {OxideMod.Version} for 0.38b";
            Interface.Oxide.ServerConsole.Status3RightColor = ConsoleColor.Yellow;
        }