public bool AddToRight(List <string> rItems, string itemName = "") { if (_serverGame == GameServer.DAYZ.FullName) { string modPath = ServerPath.GetConfigs(_serverId, "DayZActivatedMods.cfg"); string text = string.Join("\n", rItems.ToArray()); File.WriteAllText(modPath, text); return(true); } dynamic gameServer = GameServer.Data.Class.Get(_serverGame, null); if (gameServer is GameServer.Engine.Source) { string pluginPath = ServerPath.GetServerFiles(_serverId, gameServer.Game, @"addons\sourcemod\plugins"); string dpluginPath = ServerPath.GetServerFiles(_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); }
public static string GetSetting(string serverId, string settingName) { string configFile = ServerPath.GetConfigs(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].Trim('\"')); } } } } return(""); }
public List <string> GetLeftListBox() { var list = new List <string>(); if (_serverGame == GameServer.DAYZ.FullName) { string modPath = ServerPath.GetConfigs(_serverId, "DayZActivatedMods.cfg"); string activatedMods = File.Exists(modPath) ? File.ReadAllText(modPath) : ""; string[] folders = Directory.GetDirectories(ServerPath.GetServerFiles(_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, null); if (gameServer is GameServer.Engine.Source) { string dpluginPath = ServerPath.GetServerFiles(_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); }
public static bool ToggleSetting(string serverId, string settingName) { string configFile = ServerPath.GetConfigs(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); }
public List <string> GetRightListBox() { var list = new List <string>(); if (_serverGame == GameServer.DAYZ.FullName) { string modPath = ServerPath.GetConfigs(_serverId, "DayZActivatedMods.cfg"); if (File.Exists(modPath)) { foreach (string folderName in File.ReadLines(modPath)) { string metaPath = ServerPath.GetServerFiles(_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, null); if (gameServer is GameServer.Engine.Source) { string pluginPath = ServerPath.GetServerFiles(_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); }
public static void SetSetting(string serverId, string settingName, string data) { string configFile = ServerPath.GetConfigs(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 char[] { '=' }, 2); if (keyvalue.Length == 2 && settingName == keyvalue[0]) { textwriter.WriteLine($"{settingName}=\"{data}\""); saved = true; } else { textwriter.WriteLine(line); } } if (!saved) { textwriter.WriteLine($"{settingName}=\"{data}\""); } } } }
public bool IsWindowsGSMConfigExist() { string configpath = ServerPath.GetConfigs(ServerID, "WindowsGSM.cfg"); return(File.Exists(configpath)); }
public bool CreateWindowsGSMConfig(string servergame, string servername, string serverip, string serverport, string servermap, string servermaxplayer, string servergslt, string serverparam, bool toggleConsole) { CreateServerDirectory(); string configpath = ServerPath.GetConfigs(ServerID, "WindowsGSM.cfg"); if (!File.Exists(configpath)) { ServerGame = servergame; ServerName = servername; ServerIP = serverip; ServerPort = serverport; ServerMap = servermap; ServerMaxPlayer = servermaxplayer; ServerGSLT = servergslt; ServerParam = serverparam; AutoRestart = false; AutoStart = false; AutoUpdate = false; UpdateOnStart = false; DiscordAlert = false; DiscordMessage = ""; DiscordWebhook = ""; RestartCrontab = false; CrontabFormat = "0 6 * * *"; EmbedConsole = !toggleConsole; AutoStartAlert = true; AutoRestartAlert = true; AutoUpdateAlert = true; RestartCrontabAlert = true; CrashAlert = true; 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($"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); }