Esempio n. 1
0
        public bool AddToRight(List <string> rItems, string itemName = "")
        {
            if (_serverGame == GameServer.DAYZ.FullName)
            {
                string modPath = ServerPath.GetServersConfigs(_serverId, "DayZActivatedMods.cfg");
                string text    = string.Join("\n", rItems.ToArray());
                File.WriteAllText(modPath, text);
                return(true);
            }

            dynamic gameServer = GameServer.Data.Class.Get(_serverGame);

            if (gameServer is GameServer.Engine.Source)
            {
                string pluginPath  = ServerPath.GetServersServerFiles(_serverId, gameServer.Game, @"addons\sourcemod\plugins");
                string dpluginPath = ServerPath.GetServersServerFiles(_serverId, gameServer.Game, @"addons\sourcemod\plugins\disabled");
                if (Directory.Exists(pluginPath) && Directory.Exists(dpluginPath))
                {
                    try
                    {
                        File.Move(Path.Combine(dpluginPath, itemName), Path.Combine(pluginPath, itemName));
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        public static string GetSetting(string serverId, string settingName)
        {
            string configFile = ServerPath.GetServersConfigs(serverId, "WindowsGSM.cfg");

            if (File.Exists(configFile))
            {
                //Read the config lines
                string[] lines = File.ReadAllLines(configFile);

                //Read all lines
                foreach (string line in lines)
                {
                    string[] keyvalue = line.Split(new char[] { '=' }, 2);
                    if (keyvalue.Length == 2)
                    {
                        if (settingName == keyvalue[0])
                        {
                            return(keyvalue[1].Substring(1, keyvalue[1].Length - 2));
                        }
                    }
                }
            }

            return(string.Empty);
        }
Esempio n. 3
0
        public bool CreateWindowsGSMConfig()
        {
            CreateServerDirectory();

            string configpath = ServerPath.GetServersConfigs(ServerID, "WindowsGSM.cfg");

            if (!File.Exists(configpath))
            {
                File.Create(configpath).Dispose();

                using (TextWriter textwriter = new StreamWriter(configpath))
                {
                    textwriter.WriteLine($"{SettingName.ServerGame}=\"{ServerGame}\"");
                    textwriter.WriteLine($"{SettingName.ServerName}=\"{ServerName}\"");
                    textwriter.WriteLine($"{SettingName.ServerIP}=\"{ServerIP}\"");
                    textwriter.WriteLine($"{SettingName.ServerPort}=\"{ServerPort}\"");
                    textwriter.WriteLine($"{SettingName.ServerQueryPort}=\"{ServerQueryPort}\"");
                    textwriter.WriteLine($"{SettingName.ServerMap}=\"{ServerMap}\"");
                    textwriter.WriteLine($"{SettingName.ServerMaxPlayer}=\"{ServerMaxPlayer}\"");
                    textwriter.WriteLine($"{SettingName.ServerGSLT}=\"{ServerGSLT}\"");
                    textwriter.WriteLine($"{SettingName.ServerParam}=\"{ServerParam}\"");
                    textwriter.WriteLine(string.Empty);
                    textwriter.WriteLine($"{SettingName.CPUPriority}=\"{CPUPriority}\"");
                    textwriter.WriteLine($"{SettingName.CPUAffinity}=\"{CPUAffinity}\"");
                    textwriter.WriteLine(string.Empty);
                    textwriter.WriteLine($"{SettingName.AutoRestart}=\"0\"");
                    textwriter.WriteLine($"{SettingName.AutoStart}=\"0\"");
                    textwriter.WriteLine($"{SettingName.AutoUpdate}=\"0\"");
                    textwriter.WriteLine($"{SettingName.UpdateOnStart}=\"0\"");
                    textwriter.WriteLine($"{SettingName.BackupOnStart}=\"0\"");
                    textwriter.WriteLine(string.Empty);
                    textwriter.WriteLine($"{SettingName.DiscordAlert}=\"0\"");
                    textwriter.WriteLine($"{SettingName.DiscordMessage}=\"{DiscordMessage}\"");
                    textwriter.WriteLine($"{SettingName.DiscordWebhook}=\"{DiscordWebhook}\"");
                    textwriter.WriteLine(string.Empty);
                    textwriter.WriteLine($"{SettingName.RestartCrontab}=\"0\"");
                    textwriter.WriteLine($"{SettingName.CrontabFormat}=\"{CrontabFormat}\"");
                    textwriter.WriteLine(string.Empty);
                    textwriter.WriteLine($"{SettingName.EmbedConsole}=\"{(EmbedConsole ? "1" : "0")}\"");
                    textwriter.WriteLine($"{SettingName.AutoScroll}=\"{(AutoScroll ? "1" : "0")}\"");
                    textwriter.WriteLine(string.Empty);
                    textwriter.WriteLine($"{SettingName.AutoStartAlert}=\"1\"");
                    textwriter.WriteLine($"{SettingName.AutoRestartAlert}=\"1\"");
                    textwriter.WriteLine($"{SettingName.AutoUpdateAlert}=\"1\"");
                    textwriter.WriteLine($"{SettingName.RestartCrontabAlert}=\"1\"");
                    textwriter.WriteLine($"{SettingName.CrashAlert}=\"1\"");
                }

                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public BackupConfig(string serverId)
        {
            _serverId = serverId;
            string configPath = ServerPath.GetServersConfigs(_serverId, "BackupConfig.cfg");

            if (!File.Exists(configPath))
            {
                File.WriteAllText(configPath, $"{SettingName.BackupLocation}=\"{Path.Combine(MainWindow.WGSM_PATH, "Backups", serverId)}\"{Environment.NewLine}{SettingName.MaximumBackups}=\"{DefaultMaximumBackups}\"");
            }

            LoadConfig();
        }
Esempio n. 5
0
        public bool CreateWindowsGSMConfig()
        {
            CreateServerDirectory();

            string configpath = ServerPath.GetServersConfigs(ServerID, "WindowsGSM.cfg");

            if (!File.Exists(configpath))
            {
                File.Create(configpath).Dispose();

                using (TextWriter textwriter = new StreamWriter(configpath))
                {
                    textwriter.WriteLine($"servergame=\"{ServerGame}\"");
                    textwriter.WriteLine($"servername=\"{ServerName}\"");
                    textwriter.WriteLine($"serverip=\"{ServerIP}\"");
                    textwriter.WriteLine($"serverport=\"{ServerPort}\"");
                    textwriter.WriteLine($"serverqueryport=\"{ServerQueryPort}\"");
                    textwriter.WriteLine($"servermap=\"{ServerMap}\"");
                    textwriter.WriteLine($"servermaxplayer=\"{ServerMaxPlayer}\"");
                    textwriter.WriteLine($"servergslt=\"{ServerGSLT}\"");
                    textwriter.WriteLine($"serverparam=\"{ServerParam}\"");
                    textwriter.WriteLine("");
                    textwriter.WriteLine("autorestart=\"0\"");
                    textwriter.WriteLine("autostart=\"0\"");
                    textwriter.WriteLine("autoupdate=\"0\"");
                    textwriter.WriteLine("updateonstart=\"0\"");
                    textwriter.WriteLine("");
                    textwriter.WriteLine("discordalert=\"0\"");
                    textwriter.WriteLine($"discordmessage=\"{DiscordMessage}\"");
                    textwriter.WriteLine($"discordwebhook=\"{DiscordWebhook}\"");
                    textwriter.WriteLine("");
                    textwriter.WriteLine("restartcrontab=\"0\"");
                    textwriter.WriteLine($"crontabformat=\"{CrontabFormat}\"");
                    textwriter.WriteLine("");
                    textwriter.WriteLine($"embedconsole=\"{(EmbedConsole ? "1" : "0")}\"");
                    textwriter.WriteLine("");
                    textwriter.WriteLine("autostartalert=\"1\"");
                    textwriter.WriteLine("autorestartalert=\"1\"");
                    textwriter.WriteLine("autoupdatealert=\"1\"");
                    textwriter.WriteLine("restartcrontabalert=\"1\"");
                    textwriter.WriteLine("crashalert=\"1\"");
                }

                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        public List <string> GetLeftListBox()
        {
            var list = new List <string>();

            if (_serverGame == GameServer.DAYZ.FullName)
            {
                string   modPath       = ServerPath.GetServersConfigs(_serverId, "DayZActivatedMods.cfg");
                string   activatedMods = File.Exists(modPath) ? File.ReadAllText(modPath) : "";
                string[] folders       = Directory.GetDirectories(ServerPath.GetServersServerFiles(_serverId), "@*", SearchOption.TopDirectoryOnly);

                foreach (string folder in folders)
                {
                    string metaFile = Path.Combine(folder, "meta.cpp");
                    if (!File.Exists(metaFile))
                    {
                        continue;
                    }

                    string folderName = Path.GetFileName(folder);
                    if (activatedMods.Contains(folderName))
                    {
                        continue;
                    }

                    list.Add(folderName);
                }
            }

            dynamic gameServer = GameServer.Data.Class.Get(_serverGame);

            if (gameServer is GameServer.Engine.Source)
            {
                string dpluginPath = ServerPath.GetServersServerFiles(_serverId, gameServer.Game, @"addons\sourcemod\plugins\disabled");
                if (Directory.Exists(dpluginPath))
                {
                    string[] smxFiles = Directory.GetFiles(dpluginPath, "*.smx", SearchOption.TopDirectoryOnly);
                    foreach (string smxFile in smxFiles)
                    {
                        list.Add(Path.GetFileName(smxFile));
                    }
                }

                return(list);
            }

            return(list);
        }
Esempio n. 7
0
        public static bool ToggleSetting(string serverId, string settingName)
        {
            string configFile = ServerPath.GetServersConfigs(serverId, "WindowsGSM.cfg");

            if (File.Exists(configFile))
            {
                bool?returnBool = null;

                //Read the config lines
                string[] lines = File.ReadAllLines(configFile);

                //Overwrite the config file
                File.Create(configFile).Dispose();

                //Create the TextWriter
                using (TextWriter textwriter = new StreamWriter(configFile))
                {
                    //Write all lines
                    foreach (string line in lines)
                    {
                        string[] keyvalue = line.Split(new char[] { '=' }, 2);
                        if (keyvalue.Length == 2 && settingName == keyvalue[0])
                        {
                            keyvalue[1] = keyvalue[1].Trim('\"');
                            returnBool  = (keyvalue[1] == "1") ? false : true;
                            string nextBool = (keyvalue[1] == "1") ? "0" : "1";
                            textwriter.WriteLine($"{keyvalue[0]}=\"{nextBool}\"");
                        }
                        else
                        {
                            textwriter.WriteLine(line);
                        }
                    }

                    if (returnBool == null)
                    {
                        returnBool = true;
                        textwriter.WriteLine($"{settingName}=\"1\"");
                    }
                }

                return(returnBool ?? true);
            }

            return(false);
        }
Esempio n. 8
0
        public List <string> GetRightListBox()
        {
            var list = new List <string>();

            if (_serverGame == GameServer.DAYZ.FullName)
            {
                string modPath = ServerPath.GetServersConfigs(_serverId, "DayZActivatedMods.cfg");
                if (File.Exists(modPath))
                {
                    foreach (string folderName in File.ReadLines(modPath))
                    {
                        string metaPath = ServerPath.GetServersServerFiles(_serverId, folderName.Trim());
                        if (Directory.Exists(metaPath))
                        {
                            if (File.Exists(Path.Combine(metaPath, "meta.cpp")))
                            {
                                list.Add(folderName.Trim());
                            }
                        }
                    }
                }

                return(list);
            }

            dynamic gameServer = GameServer.Data.Class.Get(_serverGame);

            if (gameServer is GameServer.Engine.Source)
            {
                string pluginPath = ServerPath.GetServersServerFiles(_serverId, gameServer.Game, @"addons\sourcemod\plugins");
                if (Directory.Exists(pluginPath))
                {
                    string[] smxFiles = Directory.GetFiles(pluginPath, "*.smx", SearchOption.TopDirectoryOnly);
                    foreach (string smxFile in smxFiles)
                    {
                        list.Add(Path.GetFileName(smxFile));
                    }
                }

                return(list);
            }

            return(list);
        }
Esempio n. 9
0
        private void LoadConfig()
        {
            string configPath = ServerPath.GetServersConfigs(_serverId, "BackupConfig.cfg");

            foreach (string line in File.ReadLines(configPath))
            {
                string[] keyvalue = line.Split(new[] { '=' }, 2);
                if (keyvalue.Length == 2)
                {
                    keyvalue[1] = keyvalue[1].Trim('\"');
                    switch (keyvalue[0])
                    {
                    case SettingName.BackupLocation: BackupLocation = keyvalue[1]; break;

                    case SettingName.MaximumBackups: MaximumBackups = int.TryParse(keyvalue[1], out int max) ? ((max <= 0) ? 1 : max) : DefaultMaximumBackups; break;
                    }
                }
            }
        }
Esempio n. 10
0
        public static void SetSetting(string serverId, string settingName, string data)
        {
            string configFile = ServerPath.GetServersConfigs(serverId, "WindowsGSM.cfg");

            if (File.Exists(configFile))
            {
                bool saved = false;

                //Read the config lines
                string[] lines = File.ReadAllLines(configFile);

                //Overwrite the config file
                File.Create(configFile).Dispose();

                //Create the TextWriter
                using (TextWriter textwriter = new StreamWriter(configFile))
                {
                    //Write lines
                    foreach (string line in lines)
                    {
                        string[] keyvalue = line.Split(new[] { '=' }, 2);
                        if (keyvalue.Length == 2 && settingName == keyvalue[0])
                        {
                            textwriter.WriteLine($"{settingName}=\"{data}\"");
                            saved = true;
                        }
                        else
                        {
                            textwriter.WriteLine(line);
                        }
                    }

                    if (!saved)
                    {
                        textwriter.WriteLine($"{settingName}=\"{data}\"");
                    }
                }
            }
        }
Esempio n. 11
0
        public ServerConfig(string serverid)
        {
            //Get next available ServerID
            if (string.IsNullOrEmpty(serverid))
            {
                for (int id = 1; id <= MainWindow.MAX_SERVER; id++)
                {
                    string serverid_dir = MainWindow.WGSM_PATH + @"\servers\" + id;
                    if (Directory.Exists(serverid_dir))
                    {
                        string config = MainWindow.WGSM_PATH + @"\servers\" + id + @"\configs\WindowsGSM.cfg";
                        if (!File.Exists(config))
                        {
                            ServerID = id.ToString();
                            break;
                        }
                    }
                    else
                    {
                        ServerID = id.ToString();
                        break;
                    }
                }

                return;
            }

            ServerID = serverid;

            //Get values from configpath
            string configpath = ServerPath.GetServersConfigs(serverid, "WindowsGSM.cfg");

            if (File.Exists(configpath))
            {
                foreach (string line in File.ReadLines(configpath))
                {
                    string[] keyvalue = line.Split(new[] { '=' }, 2);
                    if (keyvalue.Length == 2)
                    {
                        keyvalue[1] = keyvalue[1].Substring(1, keyvalue[1].Length - 2);

                        switch (keyvalue[0])
                        {
                        case SettingName.ServerGame: ServerGame = keyvalue[1]; break;

                        case SettingName.ServerName: ServerName = keyvalue[1]; break;

                        case SettingName.ServerIP: ServerIP = keyvalue[1]; break;

                        case SettingName.ServerPort: ServerPort = keyvalue[1]; break;

                        case SettingName.ServerQueryPort: ServerQueryPort = keyvalue[1]; break;

                        case SettingName.ServerMap: ServerMap = keyvalue[1]; break;

                        case SettingName.ServerMaxPlayer: ServerMaxPlayer = keyvalue[1]; break;

                        case SettingName.ServerGSLT: ServerGSLT = keyvalue[1]; break;

                        case SettingName.ServerParam: ServerParam = keyvalue[1]; break;

                        case SettingName.AutoRestart: AutoRestart = keyvalue[1] == "1"; break;

                        case SettingName.AutoStart: AutoStart = keyvalue[1] == "1"; break;

                        case SettingName.AutoUpdate: AutoUpdate = keyvalue[1] == "1"; break;

                        case SettingName.UpdateOnStart: UpdateOnStart = keyvalue[1] == "1"; break;

                        case SettingName.BackupOnStart: BackupOnStart = keyvalue[1] == "1"; break;

                        case SettingName.DiscordAlert: DiscordAlert = keyvalue[1] == "1"; break;

                        case SettingName.DiscordMessage: DiscordMessage = keyvalue[1]; break;

                        case SettingName.DiscordWebhook: DiscordWebhook = keyvalue[1]; break;

                        case SettingName.RestartCrontab: RestartCrontab = keyvalue[1] == "1"; break;

                        case SettingName.CrontabFormat: CrontabFormat = keyvalue[1]; break;

                        case SettingName.EmbedConsole: EmbedConsole = keyvalue[1] == "1"; break;

                        case SettingName.AutoStartAlert: AutoStartAlert = keyvalue[1] == "1"; break;

                        case SettingName.AutoRestartAlert: AutoRestartAlert = keyvalue[1] == "1"; break;

                        case SettingName.AutoUpdateAlert: AutoUpdateAlert = keyvalue[1] == "1"; break;

                        case SettingName.RestartCrontabAlert: RestartCrontabAlert = keyvalue[1] == "1"; break;

                        case SettingName.CrashAlert: CrashAlert = keyvalue[1] == "1"; break;

                        case SettingName.CPUPriority: CPUPriority = keyvalue[1]; break;

                        case SettingName.CPUAffinity: CPUAffinity = keyvalue[1]; break;
                        }
                    }
                }
            }
        }
Esempio n. 12
0
 public void CreateServerDirectory()
 {
     Directory.CreateDirectory(ServerPath.GetServers(ServerID));
     Directory.CreateDirectory(ServerPath.GetServersConfigs(ServerID));
     Directory.CreateDirectory(ServerPath.GetServersServerFiles(ServerID));
 }
Esempio n. 13
0
        public bool IsWindowsGSMConfigExist()
        {
            string configpath = ServerPath.GetServersConfigs(ServerID, "WindowsGSM.cfg");

            return(File.Exists(configpath));
        }
Esempio n. 14
0
 public void Open()
 {
     Process.Start(ServerPath.GetServersConfigs(_serverId, "BackupConfig.cfg"));
 }
Esempio n. 15
0
        public ServerConfig(string serverid)
        {
            //Get next available ServerID
            if (serverid == null || serverid == "")
            {
                for (int id = 1; id <= MainWindow.MAX_SERVER; id++)
                {
                    string serverid_dir = MainWindow.WGSM_PATH + @"\servers\" + id.ToString();
                    if (Directory.Exists(serverid_dir))
                    {
                        string config = MainWindow.WGSM_PATH + @"\servers\" + id.ToString() + @"\configs\WindowsGSM.cfg";
                        if (!File.Exists(config))
                        {
                            ServerID = id.ToString();
                            break;
                        }
                    }
                    else
                    {
                        ServerID = id.ToString();
                        break;
                    }
                }

                return;
            }

            ServerID = serverid;

            //Get values from configpath
            string configpath = ServerPath.GetServersConfigs(serverid, "WindowsGSM.cfg");

            if (File.Exists(configpath))
            {
                foreach (string line in File.ReadLines(configpath))
                {
                    string[] keyvalue = line.Split(new char[] { '=' }, 2);

                    if (keyvalue.Length == 2)
                    {
                        keyvalue[1] = keyvalue[1].Trim('\"');

                        switch (keyvalue[0])
                        {
                        case "servergame": ServerGame = keyvalue[1]; break;

                        case "servername": ServerName = keyvalue[1]; break;

                        case "serverip": ServerIP = keyvalue[1]; break;

                        case "serverport": ServerPort = keyvalue[1]; break;

                        case "serverqueryport": ServerQueryPort = keyvalue[1]; break;

                        case "servermap": ServerMap = keyvalue[1]; break;

                        case "servermaxplayer": ServerMaxPlayer = keyvalue[1]; break;

                        case "servergslt": ServerGSLT = keyvalue[1]; break;

                        case "serverparam": ServerParam = keyvalue[1]; break;

                        case "autorestart": AutoRestart = (keyvalue[1] == "1") ? true : false; break;

                        case "autostart": AutoStart = (keyvalue[1] == "1") ? true : false; break;

                        case "autoupdate": AutoUpdate = (keyvalue[1] == "1") ? true : false; break;

                        case "updateonstart": UpdateOnStart = (keyvalue[1] == "1") ? true : false; break;

                        case "discordalert": DiscordAlert = (keyvalue[1] == "1") ? true : false; break;

                        case "discordmessage": DiscordMessage = keyvalue[1]; break;

                        case "discordwebhook": DiscordWebhook = keyvalue[1]; break;

                        case "restartcrontab": RestartCrontab = (keyvalue[1] == "1") ? true : false; break;

                        case "crontabformat": CrontabFormat = keyvalue[1]; break;

                        case "embedconsole": EmbedConsole = (keyvalue[1] == "1") ? true : false; break;

                        case "autostartalert": AutoStartAlert = (keyvalue[1] == "1") ? true : false; break;

                        case "autorestartalert": AutoRestartAlert = (keyvalue[1] == "1") ? true : false; break;

                        case "autoupdatealert": AutoUpdateAlert = (keyvalue[1] == "1") ? true : false; break;

                        case "restartcrontabalert": RestartCrontabAlert = (keyvalue[1] == "1") ? true : false; break;

                        case "crashalert": CrashAlert = (keyvalue[1] == "1") ? true : false; break;
                        }
                    }
                }
            }
        }