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 /hasmap chat command and support for extensions in /vote map #297

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GooberRF
Copy link
Contributor

This PR:

  • Adds the is_level_name_valid utility function, which takes a level filename as input (with or without extension), adds the .rfl extension if missing, and returns whether the server has that level installed.
  • Adds the /hasmap server chat command (alias: /haslevel) - takes a level filename as input and outputs whether the map is installed on the server (and can therefore be voted for and played on).
  • Implements the new utility function into the /vote map logic - adds support for specifying extensions when voting for maps. (previously, /vote map dm02.rfl wouldn't work, it will now)
  • Adjusts the Vote passed message for change level votes to now print the level being switched to.

@is-this-c
Copy link
Contributor

I do not really see why /vote map dm02.rfl should be supported. Who would use it? It is just simpler not to support file extensions imo.

Perhaps /has_map dm02 instead or /map_exists dm02 or /status map dm02. I like /check map dm02.

/status map dm02 or /check map dm02 would be aligned with /find map blunder if it were developed although I think it should be a console command.

{
std::string level_name{level_name_input};

if (level_name.size() < 4 || level_name.compare(level_name.size() - 4, 4, ".rfl") != 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please use string_ends_with from string-utils.h

@@ -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") {
Copy link
Owner

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 have nextmap so I see why you made it like this.

Copy link
Contributor Author

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.

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

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

Two things:

  • I think this name is not good - validation of something (name in this case) usually means to check if it follows some rules, like not having denied characters, having a proper length, etc. In this case it's not really a validation but checking for existence. The name does_level_exist would be more clear
  • I think this function has too broad responsibility. I would rather prefer a function that adds extension (not necessary rfl) if it's missing (may be useful in other contexts) and another to check existence (this one is probably not needed because it's a single line). To be honest all that code could be inlined in the command too. It will be trivial after you use string_ends_with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid point (lol) on the use of the word valid. Something like is_level_loaded might fit a little better than does_level_exist though - WDYT?

I would rather prefer a function that adds extension (not necessary rfl) if it's missing (may be useful in other contexts)

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

is_level_loaded is kind of confusing. does_level_exist is imo much better.

Copy link
Owner

Choose a reason for hiding this comment

The 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 rf::level.flags & rf::LEVEL_LOADED.
Idk why does_level_exist is bad, but alternative could be is_level_available

@is-this-c
Copy link
Contributor

I think it better to have a remote_findmap console command. It would be useful and it would not spam chat like a chat command. It would also remove need for your suggested chat command.

@GooberRF
Copy link
Contributor Author

I think it better to have a remote_findmap console command.

I agree that this would be better, but my understanding is that this would need to on a technical level just be a console command that sends a chat packet, or it would need to have a new packet created. Am I correct there?

I wouldn't be opposed to a new packet being created for this, though that would be substantially more work than just handling it via a chat command. Is it worth it? WDYT?

@is-this-c
Copy link
Contributor

is-this-c commented Dec 12, 2024

or it would need to have a new packet created. Am I correct there?

Yes or maybe we could mark server chat packets so they are not displayed in UI.

though that would be substantially more work than just handling it via a chat command. Is it worth it? WDYT?

I think it is pretty straightforward.

Another idea is to just use rcon. We could make normal rcon cmds and rcon findmap for guests not display in the UI. But rcon findmap for guests is not intuitive. But I am wondering how many more commands we would want to support.

@GooberRF
Copy link
Contributor Author

Another idea is to just use rcon. We could make normal rcon cmds and rcon findmap for guests not display in the UI. But rcon findmap for guests is not intuitive. But I am wondering how many more commands we would want to support.

I think this could be an idea worth exploring in the future - having a set of rcon commands that can be used by anyone, separate from the set that in effect require elevation via entering an rcon password, not unlike standard user privileges vs. elevated privileges via sudo or UAC.

I do think that is a bit out of scope for this PR though and ought to be handled separately. I don't think having /hasmap as a chat command precludes us from going down the route of "non elevated rcon commands" at some point in the future either. Such rcon commands could include findmap, server_settings (to print the server's kill limit, cap limit, etc. for players), perhaps it even might make sense at that point to move the /info chat command (to print build info) to a "standard" rcon command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants