-
Notifications
You must be signed in to change notification settings - Fork 15
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 /hasmap
chat command and support for extensions in /vote map
#297
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#include "../main/main.h" | ||
#include <common/utils/list-utils.h> | ||
#include "../rf/player/player.h" | ||
#include "../rf/misc.h" | ||
#include "../rf/multi.h" | ||
#include "../rf/parse.h" | ||
#include "../rf/weapon.h" | ||
|
@@ -227,6 +228,16 @@ void handle_next_map_command(rf::Player* player) | |
send_chat_line_packet(msg.c_str(), player); | ||
} | ||
|
||
void handle_has_map_command(rf::Player* player, std::string_view level_name) | ||
{ | ||
auto [is_valid, checked_level_name] = is_level_name_valid(level_name); | ||
|
||
auto availability = is_valid ? "available" : "NOT available"; | ||
auto msg = std::format("Level {} is {} on the server.", checked_level_name, availability); | ||
|
||
send_chat_line_packet(msg.c_str(), player); | ||
} | ||
|
||
void handle_save_command(rf::Player* player, std::string_view save_name) | ||
{ | ||
auto& pdata = get_player_additional_data(player); | ||
|
@@ -328,6 +339,9 @@ bool handle_server_chat_command(std::string_view server_command, rf::Player* sen | |
else if (cmd_name == "stats") { | ||
send_private_message_with_stats(sender); | ||
} | ||
else if (cmd_name == "hasmap" || cmd_name == "haslevel") { | ||
handle_has_map_command(sender, cmd_arg); | ||
} | ||
else { | ||
return false; | ||
} | ||
|
@@ -554,6 +568,19 @@ static bool check_player_ac_status([[maybe_unused]] rf::Player* player) | |
return true; | ||
} | ||
|
||
std::pair<bool, std::string> is_level_name_valid(std::string_view level_name_input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid point (lol) on the use of the word
I like this idea - I don't know of another use case off the top of my head but I could see it coming up down the road. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is_level_loaded doesn't make sense. Loaded level is the current one. For example to check if any is loaded we use |
||
{ | ||
std::string level_name{level_name_input}; | ||
|
||
if (level_name.size() < 4 || level_name.compare(level_name.size() - 4, 4, ".rfl") != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
level_name += ".rfl"; | ||
} | ||
|
||
bool is_valid = rf::get_file_checksum(level_name.c_str()) != 0; | ||
|
||
return {is_valid, level_name}; | ||
} | ||
|
||
FunHook<void(rf::Player*)> multi_spawn_player_server_side_hook{ | ||
0x00480820, | ||
[](rf::Player* player) { | ||
|
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 wonder if we should merge words like this, instead of using
_
. For short commands it works but with 3 or more words it will be unreadable 🤔 WDYT? But we already havenextmap
so I see why you made it like this.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.
Indeed I made it this way to match
nextmap
.I think using
_
would be OK (perhaps even preferred) if these commands were entered via console (because then tab complete would make it much easier). Entered as chat commands though, I think making them more simple to type very quickly is important, and_
is a bit annoying for that purpose.For short chat commands like this at least, I think omitting the
_
is best... and I also don't think making long chat commands would be good anyway, so the question of how to handle 3 words probably won't come up.