diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index b4afbac1..345dd704 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -47,7 +47,6 @@ namespace TShockAPI public bool SpamChecks = false; public bool DisableBuild = false; public int TileThreshold = 20; - public string ServerName = ""; public float[] AdminChatRGB = { 255, 0, 0 }; public string AdminChatPrefix = "(Admin) "; @@ -70,6 +69,8 @@ namespace TShockAPI public string RconPassword = ""; public int RconPort = 7777; + public string ServerName = ""; + public string MasterServer = "127.0.0.1"; public static ConfigFile Read(string path) { diff --git a/TShockAPI/RconHandler.cs b/TShockAPI/RconHandler.cs index 9096f129..6a2ad060 100644 --- a/TShockAPI/RconHandler.cs +++ b/TShockAPI/RconHandler.cs @@ -32,15 +32,20 @@ namespace TShockAPI { public static string Password = ""; private static DateTime LastRequest; + private static DateTime LastHeartbeat; public static int ListenPort; public static bool ContinueServer = true; public static string Response = ""; private static bool Started = false; + private static UdpClient listener; public static void StartThread() { if (!Started) + { (new Thread(Start)).Start(); + (new Thread(SendHeartbeat)).Start(); + } Started = true; } @@ -74,7 +79,7 @@ namespace TShockAPI private static void Listener() { - UdpClient listener = new UdpClient(ListenPort); + listener = new UdpClient(ListenPort); while (ContinueServer) { try @@ -132,6 +137,7 @@ namespace TShockAPI args[1] = ""; string command = string.Join(" ", args.ToArray()); command = command.TrimEnd(' ').TrimEnd('\0'); + Log.ConsoleInfo("Rcon from " + EP.ToString() + ":" + command); Response = ""; response = ExecuteCommand(command); response += "\n" + Response; @@ -140,8 +146,8 @@ namespace TShockAPI } else { - response = "Invalid password."; - Log.ConsoleInfo("Bad rcon password from " + EP.ToString()); + response = "Bad rconpassword.\n"; + Log.ConsoleInfo("Bad rconpassword from " + EP.ToString()); } } else @@ -149,7 +155,7 @@ namespace TShockAPI } else { - response = "The server must set a password for clients to use rcon."; + response = "No rconpassword set on the server.\n"; Log.Info("No password for rcon set"); } } @@ -297,6 +303,23 @@ namespace TShockAPI return returnpacket; } + private static void SendHeartbeat() + { + LastHeartbeat = DateTime.UtcNow.Subtract(new TimeSpan(0, 0, 30)); + while (true) + { + if ((DateTime.UtcNow - LastHeartbeat).Seconds >= 30) + { + var packet = ConstructPacket("heartbeat TERRARIA", false); + if (listener == null) + listener = new UdpClient(ListenPort); + listener.Send(packet, packet.Length, TShock.Config.MasterServer, 27950); + LastHeartbeat = DateTime.UtcNow; + } + Thread.Sleep(10000); + } + } + #region ParseParams private static List ParseParameters(string str) {