Skip to content
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

Add command to allow adding/changing/removing rcon password #290

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Version 1.9.0 (not released yet)
- Add level filename to "Level Initializing" console message
- Properly handle WM_PAINT in dedicated server, may improve performance (DF bug)
- Fix crash when `verify_level` command is run without a level being loaded
- Add `server_rcon_password` command

Version 1.8.0 (released 2022-09-17)
-----------------------------------
Expand Down
29 changes: 29 additions & 0 deletions game_patch/os/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,34 @@ DcCommandAlias map_info_cmd{
level_info_cmd,
};

ConsoleCommand2 server_rcon_password_cmd{
"server_rcon_password",
[](std::optional<std::string> new_rcon_password) {
if (!rf::is_multi || !rf::is_dedicated_server) {
rf::console::print("This command can only be run on a dedicated server!");
return;
}

if (new_rcon_password) {
if (new_rcon_password->size() > 16) {
// game limits client requests to 16 characters
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is a bit wrong, the password is limited, not a "request" whatever that is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the term "request" because the command is rcon_request

But I can change the comment.

rf::console::print("Server rcon password cannot exceed 16 characters.");
return;
}

std::strncpy(rf::rcon_password, new_rcon_password->c_str(), sizeof(rf::rcon_password) - 1);
rf::rcon_password[sizeof(rf::rcon_password) - 1] = '\0'; // null terminator
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of using strncpy and setting the null character manually if you validated the length. Simple std::strcpy would do the job just fine

rf::console::print("Server rcon password set to: {}", rf::rcon_password);
}
else {
*rf::rcon_password = '\0';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer rf::rcon_password[0] syntax - it's an array, not a generic pointer

rf::console::print("Server rcon password removed.");
}
},
"Set or remove the server rcon password.",
"server_rcon_password <password>",
};

// only allow verify_level if a level is loaded (avoid a crash if command is run in menu)
FunHook<void()> verify_level_cmd_hook{
0x0045E1F0,
Expand Down Expand Up @@ -205,5 +233,6 @@ void console_commands_init()
map_cmd.register_cmd();
level_info_cmd.register_cmd();
map_info_cmd.register_cmd();
server_rcon_password_cmd.register_cmd();
verify_level_cmd_hook.install();
}
1 change: 1 addition & 0 deletions game_patch/rf/multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ namespace rf
static auto& is_dedicated_server = addr_as_ref<bool>(0x0064ECBB);
static auto& simultaneous_ping = addr_as_ref<uint32_t>(0x00599CD8);
static auto& tracker_addr = addr_as_ref<NetAddr>(0x006FC550);
static auto& rcon_password = addr_as_ref<char[20]>(0x0064ECD0);

enum ChatSayType {
CHAT_SAY_GLOBAL = 0,
Expand Down