diff --git a/src/Plugins/Plugin.Example/Example.cpp b/src/Plugins/Plugin.Example/Example.cpp index 16f454e..199a104 100644 --- a/src/Plugins/Plugin.Example/Example.cpp +++ b/src/Plugins/Plugin.Example/Example.cpp @@ -9,26 +9,28 @@ #include "Example.h" #include "IRC_Bot.h" +using namespace Jupiter::literals; + void ExamplePlugin::OnConnect(Jupiter::IRC::Client *server) { - server->sendNotice(STRING_LITERAL_AS_REFERENCE("Agent"), STRING_LITERAL_AS_REFERENCE("Honey, I'm home!")); + server->sendNotice("Agent"_jrs, "Honey, I'm home!"_jrs); } // Example IRC Command Implementation void ExampleIRCCommand::create() { - this->addTrigger(STRING_LITERAL_AS_REFERENCE("example")); + this->addTrigger("example"_jrs); } void ExampleIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { - source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("This is an example command!")); + source->sendMessage(channel, "This is an example command!"_jrs); } const Jupiter::ReadableString &ExampleIRCCommand::getHelp(const Jupiter::ReadableString &) { - static STRING_LITERAL_AS_NAMED_REFERENCE(helpmsg, "This is just an example command. It takes no parameters!"); + static auto helpmsg = "This is just an example command. It takes no parameters!"_jrs; return helpmsg; } diff --git a/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp b/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp index e492fa3..9f3f054 100644 --- a/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp +++ b/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp @@ -3240,6 +3240,56 @@ const Jupiter::ReadableString &NModeIRCCommand::getHelp(const Jupiter::ReadableS IRC_COMMAND_INIT(NModeIRCCommand) +// SMode IRC Command + +void SModeIRCCommand::create() +{ + this->addTrigger(STRING_LITERAL_AS_REFERENCE("smode")); + this->setAccessLevel(2); +} + +void SModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) +{ + if (parameters.isEmpty()) { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: smode ")); + return; + } + + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan == nullptr) { + return; + } + + Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); + if (servers.size() == 0) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } + + RenX::PlayerInfo *player; + RenX::Server *server; + unsigned int smodes = 0; + for (size_t i = 0; i != servers.size(); i++) { + server = servers.get(i); + if (server != nullptr) { + player = server->getPlayerByPartName(parameters); + if (player != nullptr) { + server->smodePlayer(*player); + ++smodes; + } + } + } + source->sendMessage(channel, Jupiter::StringS::Format("%u players smoded.", smodes)); +} + +const Jupiter::ReadableString &SModeIRCCommand::getHelp(const Jupiter::ReadableString &) +{ + static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: smode "); + return defaultHelp; +} + +IRC_COMMAND_INIT(SModeIRCCommand) + // CancelVote IRC Command void CancelVoteIRCCommand::create() @@ -4158,6 +4208,43 @@ const Jupiter::ReadableString &NModeGameCommand::getHelp(const Jupiter::Readable GAME_COMMAND_INIT(NModeGameCommand) +// SMode Game Command + +void SModeGameCommand::create() +{ + this->addTrigger(STRING_LITERAL_AS_REFERENCE("smode")); + this->setAccessLevel(1); +} + +void SModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) +{ + if (parameters.isEmpty()) { + source->sendMessage(*player, "Error: Too few parameters. Syntax: smode "_jrs); + return; + } + + RenX::PlayerInfo *target = source->getPlayerByPartName(parameters); + if (target == nullptr) { + source->sendMessage(*player, "Error: Player not found."_jrs); + return; + } + + if (!source->smodePlayer(*target)) { + source->sendMessage(*player, "Error: Could not set player's mode."_jrs); + return; + } + + source->sendMessage(*player, "Player's mode has been reset."_jrs); +} + +const Jupiter::ReadableString &SModeGameCommand::getHelp(const Jupiter::ReadableString &) +{ + static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: smode "); + return defaultHelp; +} + +GAME_COMMAND_INIT(SModeGameCommand) + // CancelVote Game Command void CancelVoteGameCommand::create() diff --git a/src/Plugins/RenX/RenX.Commands/RenX_Commands.h b/src/Plugins/RenX/RenX.Commands/RenX_Commands.h index 2d1cb6e..da7a18a 100644 --- a/src/Plugins/RenX/RenX.Commands/RenX_Commands.h +++ b/src/Plugins/RenX/RenX.Commands/RenX_Commands.h @@ -104,6 +104,7 @@ GENERIC_IRC_COMMAND(RefundIRCCommand) GENERIC_IRC_COMMAND(TeamChangeIRCCommand) GENERIC_IRC_COMMAND(TeamChange2IRCCommand) GENERIC_IRC_COMMAND(NModeIRCCommand) +GENERIC_IRC_COMMAND(SModeIRCCommand) GENERIC_IRC_COMMAND(CancelVoteIRCCommand) GENERIC_GAME_COMMAND(HelpGameCommand) @@ -126,6 +127,7 @@ GENERIC_GAME_COMMAND(AddBotsGameCommand) GENERIC_GAME_COMMAND(KillBotsGameCommand) GENERIC_GAME_COMMAND(PhaseBotsGameCommand) GENERIC_GAME_COMMAND(NModeGameCommand) +GENERIC_GAME_COMMAND(SModeGameCommand) GENERIC_GAME_COMMAND(CancelVoteGameCommand) #endif // _RENX_COMMANDS_H_HEADER \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.Core/RenX_Server.cpp b/src/Plugins/RenX/RenX.Core/RenX_Server.cpp index c04d05f..fca1c94 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Server.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Server.cpp @@ -964,6 +964,11 @@ bool RenX::Server::nmodePlayer(const RenX::PlayerInfo &player) return RenX::Server::send(Jupiter::StringS::Format("nmode pid%d", player.id)); } +bool RenX::Server::smodePlayer(const RenX::PlayerInfo &player) +{ + return RenX::Server::send(Jupiter::StringS::Format("smode pid%d", player.id)); +} + const Jupiter::ReadableString &RenX::Server::getPrefix() const { static Jupiter::String parsed; diff --git a/src/Plugins/RenX/RenX.Core/RenX_Server.h b/src/Plugins/RenX/RenX.Core/RenX_Server.h index 375050e..9665234 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Server.h +++ b/src/Plugins/RenX/RenX.Core/RenX_Server.h @@ -706,6 +706,14 @@ namespace RenX */ bool nmodePlayer(const RenX::PlayerInfo &player); + /** + * @brief Changes a player's mode to spectator + * + * @param player Player to change mode + * @return True on success, false otherwise. + */ + bool smodePlayer(const RenX::PlayerInfo &player); + /** * @brief Fetches a server's IRC logging prefix. *