|
59 | 59 | #include "tracks/track.hpp"
|
60 | 60 | #include "tracks/track_manager.hpp"
|
61 | 61 | #include "utils/file_utils.hpp"
|
| 62 | +#include "utils/hourglass_reason.hpp" |
62 | 63 | #include "utils/log.hpp"
|
63 | 64 | #include "utils/random_generator.hpp"
|
64 | 65 | #include "utils/string_utils.hpp"
|
@@ -457,6 +458,7 @@ void CommandManager::initCommands()
|
457 | 458 | applyFunctionIfPossible("history =", &CM::process_history_assign);
|
458 | 459 | applyFunctionIfPossible("voting", &CM::process_voting);
|
459 | 460 | applyFunctionIfPossible("voting =", &CM::process_voting_assign);
|
| 461 | + applyFunctionIfPossible("whyhourglass", &CM::process_why_hourglass); |
460 | 462 |
|
461 | 463 | applyFunctionIfPossible("addondownloadprogress", &CM::special);
|
462 | 464 | applyFunctionIfPossible("stopaddondownload", &CM::special);
|
@@ -3965,6 +3967,100 @@ void CommandManager::process_voting_assign(Context& context)
|
3965 | 3967 | } // process_history_assign
|
3966 | 3968 | // ========================================================================
|
3967 | 3969 |
|
| 3970 | +void CommandManager::process_why_hourglass(Context& context) |
| 3971 | +{ |
| 3972 | + std::string response; |
| 3973 | + std::string player_name; |
| 3974 | + auto& argv = context.m_argv; |
| 3975 | + auto peer = context.m_peer.lock(); |
| 3976 | + if (!peer) |
| 3977 | + { |
| 3978 | + error(context, true); |
| 3979 | + return; |
| 3980 | + } |
| 3981 | + if (argv.size() < 2) |
| 3982 | + { |
| 3983 | + if (peer->getPlayerProfiles().empty()) |
| 3984 | + { |
| 3985 | + Log::warn("CommandManager", "whyhourglass: no existing player profiles??"); |
| 3986 | + error(context); |
| 3987 | + return; |
| 3988 | + } |
| 3989 | + player_name = StringUtils::wideToUtf8( |
| 3990 | + peer->getPlayerProfiles()[0]->getName()); |
| 3991 | + } |
| 3992 | + else |
| 3993 | + { |
| 3994 | + if (hasTypo(peer, context.m_voting, context.m_argv, context.m_cmd, |
| 3995 | + 1, m_stf_present_users, 3, false, false)) |
| 3996 | + return; |
| 3997 | + player_name = argv[1]; |
| 3998 | + } |
| 3999 | + std::shared_ptr<STKPeer> player_peer = STKHost::get()->findPeerByName( |
| 4000 | + StringUtils::utf8ToWide(player_name)); |
| 4001 | + if (player_name.empty() || !player_peer) |
| 4002 | + { |
| 4003 | + error(context); |
| 4004 | + return; |
| 4005 | + } |
| 4006 | + auto it = m_lobby->m_why_peer_cannot_play.find(player_peer.get()); |
| 4007 | + if (it == m_lobby->m_why_peer_cannot_play.end()) |
| 4008 | + { |
| 4009 | + response = "For some reason, server doesn't know about the hourglass status of this player."; |
| 4010 | + } |
| 4011 | + else |
| 4012 | + { |
| 4013 | + switch (it->second) |
| 4014 | + { |
| 4015 | + case HR_NONE: |
| 4016 | + response = "%s can play (but if hourglass is present, there are not enough slots on the server)."; |
| 4017 | + break; |
| 4018 | + case HR_ABSENT_PEER: |
| 4019 | + response = "Player %s is not present on the server."; |
| 4020 | + break; |
| 4021 | + case HR_NOT_A_TOURNAMENT_PLAYER: |
| 4022 | + response = "%s is not a tournament player for this game."; |
| 4023 | + break; |
| 4024 | + case HR_SPECTATOR_BY_LIMIT: |
| 4025 | + response = "Not enough slots to fit %s."; |
| 4026 | + break; |
| 4027 | + case HR_NO_KARTS_AFTER_FILTER: |
| 4028 | + response = "After applying all kart filters, %s doesn't have karts to play."; |
| 4029 | + break; |
| 4030 | + case HR_NO_MAPS_AFTER_FILTER: |
| 4031 | + response = "After applying all map filters, %s doesn't have maps to play."; |
| 4032 | + break; |
| 4033 | + case HR_LACKING_REQUIRED_MAPS: |
| 4034 | + response = "%s lacks required maps."; |
| 4035 | + break; |
| 4036 | + case HR_ADDON_KARTS_PLAY_THRESHOLD: |
| 4037 | + response = "Player %s doesn't have enough addon karts."; |
| 4038 | + break; |
| 4039 | + case HR_ADDON_TRACKS_PLAY_THRESHOLD: |
| 4040 | + response = "Player %s doesn't have enough addon tracks."; |
| 4041 | + break; |
| 4042 | + case HR_ADDON_ARENAS_PLAY_THRESHOLD: |
| 4043 | + response = "Player %s doesn't have enough addon arenas."; |
| 4044 | + break; |
| 4045 | + case HR_ADDON_FIELDS_PLAY_THRESHOLD: |
| 4046 | + response = "Player %s doesn't have enough addon fields."; |
| 4047 | + break; |
| 4048 | + case HR_OFFICIAL_KARTS_PLAY_THRESHOLD: |
| 4049 | + response = "The number of official karts for %s is lower than the threshold."; |
| 4050 | + break; |
| 4051 | + case HR_OFFICIAL_TRACKS_PLAY_THRESHOLD: |
| 4052 | + response = "The number of official tracks for %s is lower than the threshold."; |
| 4053 | + break; |
| 4054 | + default: |
| 4055 | + response = ""; |
| 4056 | + break; |
| 4057 | + } |
| 4058 | + response = StringUtils::insertValues(response, player_name.c_str()); |
| 4059 | + } |
| 4060 | + m_lobby->sendStringToPeer(response, peer); |
| 4061 | +} // process_why_hourglass |
| 4062 | +// ======================================================================== |
| 4063 | + |
3968 | 4064 | void CommandManager::special(Context& context)
|
3969 | 4065 | {
|
3970 | 4066 | auto peer = context.m_peer.lock();
|
|
0 commit comments