From 255aaa9c26a37e37e68767c3aa265af5b30aa33d Mon Sep 17 00:00:00 2001 From: Trumeet Date: Sat, 27 Feb 2021 14:48:41 -0800 Subject: feat: limit admin commands --- README | 13 ++++++++++++- main.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README b/README index 51f3385..a24bb5c 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ make install CONFIGURATION -TG_ADMIN=114514 # UID allowed to execute rcon commands other than /list. Equivalent to OP4. +TG_ADMIN=114514 # UID allowed to execute more rcon commands other than /list. A complete list of commands supported is listed below. TG_CHAT=-114514 # Chat that is allowed to send message to and from. TG_LINK_FMT=https://t.me/c/xxx/%d # Format of Telegram links. %d: Message ID. TG_API=114514:1919810 # Telegram bot API Key. @@ -34,6 +34,17 @@ LIMITATIONS Cannot start the server if it is not running. +COMMANDS + +Any users in the chat can use `/list` or `/list uuids` to check online players. + +In additional to these two commands, the administrator can use the following commands as well: + +`/debug ` +`/data ` +`/whitelist ` +`/reload` + ACKNOWLEDGEMENTS mcrcon: https://github.com/Tiiffi/mcrcon/tree/b02201d689b3032bc681b28f175fd3d83d167293 diff --git a/main.c b/main.c index 5dd7507..d130318 100644 --- a/main.c +++ b/main.c @@ -114,8 +114,18 @@ run: if(entity.offset == 0 && !strcmp(entity.type, "bot_command")) { - if(tgmsg->from->id == env->tg_admin || - !strcmp(tgmsg->text, "/list")) + char is_admin = tgmsg->from->id == env->tg_admin; + if((is_admin && ( + !strncmp(tgmsg->text, "/whitelist ", strlen("/whitelist ")) || + !strncmp(tgmsg->text, "/debug ", strlen("/debug ")) || + !strncmp(tgmsg->text, "/data ", strlen("/data ")) || + !strcmp(tgmsg->text, "/reload") + )) || + ( + !strcmp(tgmsg->text, "/list") || + !strcmp(tgmsg->text, "/list uuids") + ) + ) { is_command = 1; strcpy(msg, tgmsg->text + 1); -- cgit v1.2.3