Skip to content

Commit 0ce88d4

Browse files
committed
Added /Software
Can now change the colors and capitalization of how the server software shows up on the server list.
1 parent 17a9349 commit 0ce88d4

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

fCraft/Commands/MaintenanceCommands.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal static void Init() {
2727
CommandManager.RegisterCommand(CdSave);
2828
CommandManager.RegisterCommand(CdCheckUpdate);
2929
CommandManager.RegisterCommand( CdAutoRankCheck );
30+
CommandManager.RegisterCommand( CdSoftware );
3031
}
3132
#region DumpStats
3233

@@ -1406,5 +1407,47 @@ static void AutoRankCheckHandler( Player player, CommandReader cmd ) {
14061407
}
14071408

14081409
#endregion
1410+
#region Software
1411+
static readonly CommandDescriptor CdSoftware = new CommandDescriptor
1412+
{
1413+
Name = "Software",
1414+
Aliases = new[] { "SetSoftware", "SW" },
1415+
Category = CommandCategory.New | CommandCategory.Maintenance,
1416+
Permissions = new[] { Permission.EditPlayerDB },
1417+
IsConsoleSafe = true,
1418+
Help = "Set the colors of the server software name on the server list. &NOnly console may change the actual software name. &NUse reset/default/normal to change it back to &cP&4R&6O&eC&aR&2A&bF&3T",
1419+
Usage = "/Software <new software name>",
1420+
Handler = SoftwareHandler
1421+
};
1422+
1423+
static void SoftwareHandler(Player player, CommandReader cmd) {
1424+
1425+
1426+
string newSW = cmd.NextAll().Replace('%', '&');
1427+
string oldSW = Server.Software;
1428+
if (String.IsNullOrEmpty(newSW)) {
1429+
player.Message("The current software name is \"&F{0}&S\"", Server.Software);
1430+
return;
1431+
}
1432+
if (newSW.CaselessEquals("reset") || newSW.CaselessEquals("default") || newSW.CaselessEquals("normal")) {
1433+
newSW = "&cP&4R&6O&eC&aR&2A&bF&3T";
1434+
}
1435+
1436+
if (newSW == oldSW) {
1437+
player.Message("Server software is already set to \"&F{1}&S\"", newSW);
1438+
return;
1439+
} else if (!Color.StripColors(newSW, true).CaselessEquals(Server.Software) && player != Player.Console) {
1440+
player.Message("&COnly console may change the actual name of the software.");
1441+
return;
1442+
}
1443+
if (!cmd.IsConfirmed) {
1444+
player.Confirm(cmd, "This will change how the server software shows up on the server list from \"&F{0}&S\" to \"&F{1}&S\"", oldSW, newSW);
1445+
return;
1446+
}
1447+
1448+
Server.Software = newSW;
1449+
player.Message("Server software was changed from \"&F{0}&S\" to \"&F{1}&S\"", oldSW, newSW);
1450+
}
1451+
#endregion
14091452
}
14101453
}

fCraft/Network/Heartbeat.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,15 @@ internal HeartbeatData([NotNull] Uri heartbeatUri) {
298298
internal Uri CreateUri() {
299299
UriBuilder ub = new UriBuilder(HeartbeatUri);
300300
StringBuilder sb = new StringBuilder();
301-
sb.AppendFormat("public={0}&max={1}&users={2}&port={3}&version={4}&salt={5}&name={6}&software=ProCraft",
301+
sb.AppendFormat("public={0}&max={1}&users={2}&port={3}&version={4}&salt={5}&name={6}&software={7}",
302302
IsPublic,
303303
MaxPlayers,
304304
PlayerCount,
305305
Port,
306306
ProtocolVersion,
307307
Uri.EscapeDataString(Salt),
308-
Uri.EscapeDataString(ServerName));
308+
Uri.EscapeDataString(ServerName),
309+
Server.Software.Replace("&", "%26"));
309310
foreach (var pair in CustomData) {
310311
sb.AppendFormat("&{0}={1}",
311312
Uri.EscapeDataString(pair.Key),

fCraft/System/Server.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public static partial class Server {
4343
/// <summary> Default terrain file for each world.</summary>
4444
public static string DefaultTerrain { get; set; }
4545

46-
46+
/// <summary> Software name that shows up on the server list on classicube.</summary>
47+
public static string Software = "&cP&4R&6O&eC&aR&2A&bF&3T";
4748

4849
internal static int MaxUploadSpeed, // set by Config.ApplyConfig
4950
BlockUpdateThrottling; // used when there are no players in a world

0 commit comments

Comments
 (0)