now sends heartbeats to a q3 master server
This commit is contained in:
parent
b382125cc5
commit
1fca9b6860
2 changed files with 29 additions and 5 deletions
|
|
@ -47,7 +47,6 @@ namespace TShockAPI
|
||||||
public bool SpamChecks = false;
|
public bool SpamChecks = false;
|
||||||
public bool DisableBuild = false;
|
public bool DisableBuild = false;
|
||||||
public int TileThreshold = 20;
|
public int TileThreshold = 20;
|
||||||
public string ServerName = "";
|
|
||||||
|
|
||||||
public float[] AdminChatRGB = { 255, 0, 0 };
|
public float[] AdminChatRGB = { 255, 0, 0 };
|
||||||
public string AdminChatPrefix = "(Admin) ";
|
public string AdminChatPrefix = "(Admin) ";
|
||||||
|
|
@ -70,6 +69,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
public string RconPassword = "";
|
public string RconPassword = "";
|
||||||
public int RconPort = 7777;
|
public int RconPort = 7777;
|
||||||
|
public string ServerName = "";
|
||||||
|
public string MasterServer = "127.0.0.1";
|
||||||
|
|
||||||
public static ConfigFile Read(string path)
|
public static ConfigFile Read(string path)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,20 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
public static string Password = "";
|
public static string Password = "";
|
||||||
private static DateTime LastRequest;
|
private static DateTime LastRequest;
|
||||||
|
private static DateTime LastHeartbeat;
|
||||||
public static int ListenPort;
|
public static int ListenPort;
|
||||||
public static bool ContinueServer = true;
|
public static bool ContinueServer = true;
|
||||||
public static string Response = "";
|
public static string Response = "";
|
||||||
private static bool Started = false;
|
private static bool Started = false;
|
||||||
|
private static UdpClient listener;
|
||||||
|
|
||||||
public static void StartThread()
|
public static void StartThread()
|
||||||
{
|
{
|
||||||
if (!Started)
|
if (!Started)
|
||||||
|
{
|
||||||
(new Thread(Start)).Start();
|
(new Thread(Start)).Start();
|
||||||
|
(new Thread(SendHeartbeat)).Start();
|
||||||
|
}
|
||||||
Started = true;
|
Started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +79,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
private static void Listener()
|
private static void Listener()
|
||||||
{
|
{
|
||||||
UdpClient listener = new UdpClient(ListenPort);
|
listener = new UdpClient(ListenPort);
|
||||||
while (ContinueServer)
|
while (ContinueServer)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -132,6 +137,7 @@ namespace TShockAPI
|
||||||
args[1] = "";
|
args[1] = "";
|
||||||
string command = string.Join(" ", args.ToArray());
|
string command = string.Join(" ", args.ToArray());
|
||||||
command = command.TrimEnd(' ').TrimEnd('\0');
|
command = command.TrimEnd(' ').TrimEnd('\0');
|
||||||
|
Log.ConsoleInfo("Rcon from " + EP.ToString() + ":" + command);
|
||||||
Response = "";
|
Response = "";
|
||||||
response = ExecuteCommand(command);
|
response = ExecuteCommand(command);
|
||||||
response += "\n" + Response;
|
response += "\n" + Response;
|
||||||
|
|
@ -140,8 +146,8 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response = "Invalid password.";
|
response = "Bad rconpassword.\n";
|
||||||
Log.ConsoleInfo("Bad rcon password from " + EP.ToString());
|
Log.ConsoleInfo("Bad rconpassword from " + EP.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -149,7 +155,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
else
|
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");
|
Log.Info("No password for rcon set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,6 +303,23 @@ namespace TShockAPI
|
||||||
return returnpacket;
|
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
|
#region ParseParams
|
||||||
private static List<String> ParseParameters(string str)
|
private static List<String> ParseParameters(string str)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue