From d0350cff0119351adbe10e69971c1369cc1cca72 Mon Sep 17 00:00:00 2001 From: TomCube <121310847+yomcube@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:27:15 -0500 Subject: [PATCH 1/3] Add MOTD command --- src/Commands.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Commands.c b/src/Commands.c index 7276ba91a..7e3d25b9e 100644 --- a/src/Commands.c +++ b/src/Commands.c @@ -267,6 +267,31 @@ static struct ChatCommand ClearDeniedCommand = { } }; +static void MotdCommand_Execute(const cc_string* args, int argsCount) { + if (Server.IsSinglePlayer) { + Chat_AddRaw("&eThis command can only be used in multiplayer."); + return; + } + char namebuff[70]; + char motdbuff[70]; + cc_string name, motd; + + String_InitArray(name, namebuff); + String_InitArray(motd, motdbuff); + String_Format1(&name, "Name: %s", &Server.Name); + String_Format1(&motd, "MOTD: %s", &Server.MOTD); + Chat_Add(&name); + Chat_Add(&motd); +} + +static struct ChatCommand MotdCommand = { + "Motd", MotdCommand_Execute, + COMMAND_FLAG_UNSPLIT_ARGS, + { + "&a/client motd", + "&eDisplays the server's name and MOTD." + } +}; /*########################################################################################################################* *-------------------------------------------------------DrawOpCommand-----------------------------------------------------* @@ -709,6 +734,7 @@ static void OnInit(void) { Commands_Register(&ModelCommand); Commands_Register(&TeleportCommand); Commands_Register(&ClearDeniedCommand); + Commands_Register(&MotdCommand); Commands_Register(&BlockEditCommand); Commands_Register(&CuboidCommand); Commands_Register(&ReplaceCommand); From 1ebfbc9a6ad13c8a14a586e0d4f7618f4fe746d9 Mon Sep 17 00:00:00 2001 From: TomCube <121310847+yomcube@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:34:05 -0500 Subject: [PATCH 2/3] Add color to MOTD command output --- src/Commands.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Commands.c b/src/Commands.c index 7e3d25b9e..53adf8a52 100644 --- a/src/Commands.c +++ b/src/Commands.c @@ -272,14 +272,14 @@ static void MotdCommand_Execute(const cc_string* args, int argsCount) { Chat_AddRaw("&eThis command can only be used in multiplayer."); return; } - char namebuff[70]; - char motdbuff[70]; + char namebuff[74]; + char motdbuff[74]; cc_string name, motd; String_InitArray(name, namebuff); String_InitArray(motd, motdbuff); - String_Format1(&name, "Name: %s", &Server.Name); - String_Format1(&motd, "MOTD: %s", &Server.MOTD); + String_Format1(&name, "&eName: &f%s", &Server.Name); + String_Format1(&motd, "&eMOTD: &f%s", &Server.MOTD); Chat_Add(&name); Chat_Add(&motd); } From 66a77e6242fe4db38cda66ab2bee4e4e9904025c Mon Sep 17 00:00:00 2001 From: TomCube <121310847+yomcube@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:47:16 -0500 Subject: [PATCH 3/3] Use `Chat_Add1` instead of `String_Format1` and `Chat_Add` --- src/Commands.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Commands.c b/src/Commands.c index 53adf8a52..b64e84fcc 100644 --- a/src/Commands.c +++ b/src/Commands.c @@ -272,16 +272,8 @@ static void MotdCommand_Execute(const cc_string* args, int argsCount) { Chat_AddRaw("&eThis command can only be used in multiplayer."); return; } - char namebuff[74]; - char motdbuff[74]; - cc_string name, motd; - - String_InitArray(name, namebuff); - String_InitArray(motd, motdbuff); - String_Format1(&name, "&eName: &f%s", &Server.Name); - String_Format1(&motd, "&eMOTD: &f%s", &Server.MOTD); - Chat_Add(&name); - Chat_Add(&motd); + Chat_Add1("&eName: &f%s", &Server.Name); + Chat_Add1("&eMOTD: &f%s", &Server.MOTD); } static struct ChatCommand MotdCommand = {