Skip to content

Commit 5e46007

Browse files
committed
Add remote rekeying feature
1 parent 5378e79 commit 5e46007

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

docs/ErrorCodes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
6001 - Sync settings are not configured!
44
6002 - Sync error
5+
6003 - Sync remotely rekeyed (warning)
6+
6004 - Sync was remotely rekeyed, but it was unsuccessful
57

68
6011 - Ping error
79
6012 - Get public IP error

modCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public static void Handle(string inputCommand, string inputSource, string reques
4646
case "reboot" when inputData.Length == 2:
4747
case "restart" when inputData.Length == 2:
4848
if (inputData[1] == "host") { outputResponse = modSystem.RebootHost(); } break;
49+
case "remote" when inputData.Length == 4:
50+
if (inputData[1] == "rekey" && inputData[2].StartsWith("https://")) { outputResponse = modSync.RemoteRekey(inputData[2], inputData[3]); } break;
4951
case "reset" when inputData.Length == 3:
5052
if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.ResetInstalledSoftware(); } break;
5153
case "shutdown" when inputData.Length == 2:

modSync.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ public static void Unload()
5151
}
5252
}
5353

54+
/// <summary>
55+
/// Changes the sync server and Sandstorm token
56+
/// </summary>
57+
/// <param name="NewServerURL">(string) New server URL for sync</param>
58+
/// <param name="NewSandstormToken">(string) New Sandstorm token for sync</param>
59+
/// <returns>(string) Message about result</returns>
60+
public static string RemoteRekey(string NewServerURL, string NewSandstormToken)
61+
{
62+
int SuccessCount = 0;
63+
Sync_ServerURL = NewServerURL;
64+
Sync_SandstormToken = NewSandstormToken;
65+
SuccessCount += modDatabase.UpdateConfig(new modDatabase.Config { Key = "Sync_ServerURL", Value = NewServerURL });
66+
SuccessCount += modDatabase.UpdateConfig(new modDatabase.Config { Key = "Sync_SandstormToken", Value = NewSandstormToken });
67+
if (SuccessCount == 2)
68+
{
69+
modLogging.LogEvent("Sync remotely rekeyed", EventLogEntryType.Warning, 6003);
70+
return "Remote rekey successful";
71+
}
72+
else
73+
{
74+
modLogging.LogEvent("Sync was remotely rekeyed, but it was unsuccessful", EventLogEntryType.Error, 6004);
75+
return "Remote rekey failed";
76+
}
77+
}
78+
5479
/// <summary>
5580
/// Sends a message to the sync server
5681
/// </summary>

0 commit comments

Comments
 (0)