-
Notifications
You must be signed in to change notification settings - Fork 196
Add whitelist and rework command system #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
This might add a bit more to the memory consumption, or might not even be possible/hard to do, and also belong in it's own PR, but perhaps an even better way of command handling would be to:
Idk, maybe this is too 'involved' for, what is supposed to be, a simple barebones server, but it is a suggestion nonetheless |
|
In my opinion, add a config to enable commands and whitelisting. |
p2r3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At a glance, seems fine, just a few nitpicks. Haven't yet tested in-game, I hope I'll be able to get around to that soon.
include/globals.h
Outdated
| // #define WHITELIST | ||
|
|
||
| #ifdef WHITELIST | ||
| #define MAX_WHITELISTED_PLAYERS 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like WHITELIST is redundant if we've already got a whitelist limit. You could just check if MAX_WHITELISTED_PLAYERS is greater than 0.
src/commands.c
Outdated
| if (message_len <= 1) { | ||
| goto cleanup; | ||
| } | ||
|
|
||
| char* command = strtok((char *)recv_buffer, " "); | ||
| #ifdef WHITELIST | ||
| if (!strcmp(command, "!whitelist")) { | ||
| handleWhitelistCommand(player); | ||
| return; | ||
| } | ||
| #endif | ||
| if (!strcmp((char *) command, "!msg")) { | ||
| handleMessageCommand(player); | ||
| return; | ||
| } | ||
| if (!strcmp((char *) command, "!help")) { | ||
| handleHelpCommand(player); | ||
| return; | ||
| } | ||
|
|
||
| cleanup: | ||
| // Handle fall-through case | ||
| sc_systemChat(player->client_fd, "§7Unknown command. Type !help for help.", 40); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be cleaner with an if-else chain? The early exits don't make too much sense if the conditions are all the same size and don't nest any further. Would also eliminate the need for a goto label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces after if tokens, before opening bracket.
src/procedures.c
Outdated
| } | ||
|
|
||
| #ifdef WHITELIST | ||
| // Returns whether the username is on the server whitelist and if so, the index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems to be inaccurate?
Commands on their own are fairly lightweight. Whitelisting is already behind a
That's outside the scope of this issue/pull request. |
|
I think we should store properties like whitelist, and in a file other than world data. |
|
@siaeyy If you're suggesting we store configuration options in a file, I strongly disagree. The target platform is embedded systems, many of which do not have filesystems, and certainly not efficient ones. |
With a more advanced beef dump protocol we could also provide support to those platforms but yeah I changed my mind, probably doesnt worth it :D |
Closes #92
This PR also reworks the command system to make it easier to add new commands in the future.
The memory impact of this change is 128 bytes for storing the 8 whitelisted players and another byte for toggling the whitelist on and off.
Tested on a ESP32-WROOM-32 dev board.