Skip to content

Commit

Permalink
Add command to allow adding/changing/removing server password (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
GooberRF authored Nov 16, 2024
1 parent d66d12c commit 3abb401
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Version 1.9.0 (not released yet)
- 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
- Fix cockpit not rendering for any jeeps after the first one entered each level load
- Add `server_password` command

Version 1.8.0 (released 2022-09-17)
-----------------------------------
Expand Down
1 change: 1 addition & 0 deletions game_patch/multi/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
const char* g_rcon_cmd_whitelist[] = {
"kick",
"level",
"server_password",
"map",
"ban",
"ban_ip",
Expand Down
22 changes: 22 additions & 0 deletions game_patch/os/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ DcCommandAlias map_info_cmd{
level_info_cmd,
};

ConsoleCommand2 server_password_cmd{
"server_password",
[](std::optional<std::string> new_password) {
if (!rf::is_multi || !rf::is_server) {
rf::console::print("This command can only be run as a server!");
return;
}

if (new_password) {
rf::netgame.password = new_password.value().c_str();
rf::console::print("Server password set to: {}", rf::netgame.password);
}
else {
rf::netgame.password = "";
rf::console::print("Server password removed.");
}
},
"Set or remove the server password.",
"server_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 +226,6 @@ void console_commands_init()
map_cmd.register_cmd();
level_info_cmd.register_cmd();
map_info_cmd.register_cmd();
server_password_cmd.register_cmd();
verify_level_cmd_hook.install();
}

0 comments on commit 3abb401

Please sign in to comment.