Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mutliadmin/MultiAdmin/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ public void Reload()

config = new YamlConfig(configFile);
}

public string GetConfigFilePath()
{
return this.configFile;
}
}
}
7 changes: 7 additions & 0 deletions mutliadmin/MultiAdmin/OutputThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ private static void ProcessFile(Server server, string file)
}
}

if (stream.Contains("ServerMod successfully validated config file"))
{
display = false;
server.Log("ServerMod successfully validated config file");
server.RevalidateConfig();
}

if (display)
{
server.Write(stream.Trim(), color);
Expand Down
74 changes: 73 additions & 1 deletion mutliadmin/MultiAdmin/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using MultiAdmin.MultiAdmin.Commands;
using MultiAdmin.MultiAdmin.Features;
Expand All @@ -12,7 +13,7 @@ namespace MultiAdmin.MultiAdmin
{
public class Server
{
public static readonly string MA_VERSION = "2.1.3.1";
public static readonly string MA_VERSION = "2.1.4";

public bool HasServerMod { get; set; }
public string ServerModVersion { get; set; }
Expand Down Expand Up @@ -74,6 +75,26 @@ public string LogFolder
public Boolean nolog = false;
public int printSpeed = 150;

// This simple regex will match this entire piece
/*
* # 123 # 2019-12-12 22:22:22 # Smod config validator # Start
* something: true
* another_thing: true
* # 123 # 2019-12-12 22:22:22 # Smod config validator # Finish
* */
// First group would be
// # 123 # 2019-12-12 22:22:22
// Second group will contains only session ID
// 123
// Third group will have timestamp
// 2019-12-12 22:22:22
// And fourth group will contain actual configs being added
/*
* something: true
* another_thing: true
* */
public static readonly Regex VALIDATOR_REGEX = new Regex(@"(# ([0-9]+) # (.*?)) # Smod config validator # Start.*?^(.*?)\1 # Smod config validator # Finish", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.Multiline);

public Server(string serverDir, string configKey, Config multiAdminCfg, string mainConfigLocation, string configChain, bool multiMode)
{
this.multiMode = multiMode;
Expand Down Expand Up @@ -562,5 +583,56 @@ public static string Timestamp(string message)
message = "[" + now.Hour.ToString("00") + ":" + now.Minute.ToString("00") + ":" + now.Second.ToString("00") + "] " + message;
return message;
}

public bool GetMultimode()
{
return this.multiMode;
}

public void RevalidateConfig()
{
if (!this.GetMultimode())
{
this.Log("MultiAdmin is running in single server mode. No further action required.");
return;
}

bool success = false;
string data = File.ReadAllText(this.MainConfigLocation);
Match match = VALIDATOR_REGEX.Match(data);
while (match.Success)
{
if (match.Groups[2].Value != this.session_id)
{
match = match.NextMatch();
continue;
}

string newData = string.Format("{0}# {1} # Smod config validator{0}{2}{0}", Environment.NewLine, match.Groups[3].Value, match.Groups[4].Value);
try
{
File.AppendAllText(this.ServerConfig.GetConfigFilePath(), newData);
success = true;
}
catch (Exception e)
{
success = false;
this.Log(string.Format("Error: {0}", e.ToString()));
}

match = match.NextMatch();
}

if (success)
{
this.Log(string.Format("MultiAdmin saved new config to {0}", this.ServerConfig.GetConfigFilePath()));
this.SwapConfigs();
this.SendMessage("config reload");
}
else
{
this.Log(string.Format("MultiAdmin failed saving new config to {0}", this.ServerConfig.GetConfigFilePath()));
}
}
}
}