18 return "Error: Only the room host can kick players.";
23 return "Error: Missing player id. Usage: /kick <player_id>";
27 std::vector<uint32_t> players = context.
room->getPlayers();
30 if (args[0].empty() || std::stoul(args[0]) == 0) {
31 return "Error: Invalid player id.";
33 }
catch (std::invalid_argument &) {
34 return "Error: Invalid player id.";
38 uint32_t targetId = std::stoul(args[0]);
41 uint32_t targetPlayerId = 0;
42 for (uint32_t playerId : players) {
43 if (playerId == targetId) {
44 targetPlayerId = playerId;
49 if (targetPlayerId == 0) {
50 return "Error: Player not found in this room.";
54 if (targetPlayerId == context.
playerId) {
55 return "Error: You cannot kick yourself. Use /leave to exit the room.";
59 if (context.
room->hasSpectator(targetPlayerId)) {
60 return "Error: Cannot kick spectators.";
65 targetPlayerId,
") from room ", context.
room->getId());
71 return "Error: Failed to kick player from the room.";
74 return "Player has been kicked from the room.";
Context information for command execution.
uint32_t playerId
ID of the player executing the command.
std::string playerName
Name of the player executing the command.
std::shared_ptr< Room > room
Room where the command is executed.
::Server * server
Server instance for operations (global namespace)