Browse Source

Added smode command

Push update to Plugin.Example that's apparently be laying around
release/1.0
Jessica James 4 years ago
parent
commit
9787ea45e6
  1. 10
      src/Plugins/Plugin.Example/Example.cpp
  2. 87
      src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp
  3. 2
      src/Plugins/RenX/RenX.Commands/RenX_Commands.h
  4. 5
      src/Plugins/RenX/RenX.Core/RenX_Server.cpp
  5. 8
      src/Plugins/RenX/RenX.Core/RenX_Server.h

10
src/Plugins/Plugin.Example/Example.cpp

@ -9,26 +9,28 @@
#include "Example.h" #include "Example.h"
#include "IRC_Bot.h" #include "IRC_Bot.h"
using namespace Jupiter::literals;
void ExamplePlugin::OnConnect(Jupiter::IRC::Client *server) 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 // Example IRC Command Implementation
void ExampleIRCCommand::create() 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 &parameters) void ExampleIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{ {
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 &) 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; return helpmsg;
} }

87
src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp

@ -3240,6 +3240,56 @@ const Jupiter::ReadableString &NModeIRCCommand::getHelp(const Jupiter::ReadableS
IRC_COMMAND_INIT(NModeIRCCommand) 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 &parameters)
{
if (parameters.isEmpty()) {
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: smode <Player>"));
return;
}
Jupiter::IRC::Client::Channel *chan = source->getChannel(channel);
if (chan == nullptr) {
return;
}
Jupiter::ArrayList<RenX::Server> 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 <player>");
return defaultHelp;
}
IRC_COMMAND_INIT(SModeIRCCommand)
// CancelVote IRC Command // CancelVote IRC Command
void CancelVoteIRCCommand::create() void CancelVoteIRCCommand::create()
@ -4158,6 +4208,43 @@ const Jupiter::ReadableString &NModeGameCommand::getHelp(const Jupiter::Readable
GAME_COMMAND_INIT(NModeGameCommand) 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 &parameters)
{
if (parameters.isEmpty()) {
source->sendMessage(*player, "Error: Too few parameters. Syntax: smode <player-name>"_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 <player-name>");
return defaultHelp;
}
GAME_COMMAND_INIT(SModeGameCommand)
// CancelVote Game Command // CancelVote Game Command
void CancelVoteGameCommand::create() void CancelVoteGameCommand::create()

2
src/Plugins/RenX/RenX.Commands/RenX_Commands.h

@ -104,6 +104,7 @@ GENERIC_IRC_COMMAND(RefundIRCCommand)
GENERIC_IRC_COMMAND(TeamChangeIRCCommand) GENERIC_IRC_COMMAND(TeamChangeIRCCommand)
GENERIC_IRC_COMMAND(TeamChange2IRCCommand) GENERIC_IRC_COMMAND(TeamChange2IRCCommand)
GENERIC_IRC_COMMAND(NModeIRCCommand) GENERIC_IRC_COMMAND(NModeIRCCommand)
GENERIC_IRC_COMMAND(SModeIRCCommand)
GENERIC_IRC_COMMAND(CancelVoteIRCCommand) GENERIC_IRC_COMMAND(CancelVoteIRCCommand)
GENERIC_GAME_COMMAND(HelpGameCommand) GENERIC_GAME_COMMAND(HelpGameCommand)
@ -126,6 +127,7 @@ GENERIC_GAME_COMMAND(AddBotsGameCommand)
GENERIC_GAME_COMMAND(KillBotsGameCommand) GENERIC_GAME_COMMAND(KillBotsGameCommand)
GENERIC_GAME_COMMAND(PhaseBotsGameCommand) GENERIC_GAME_COMMAND(PhaseBotsGameCommand)
GENERIC_GAME_COMMAND(NModeGameCommand) GENERIC_GAME_COMMAND(NModeGameCommand)
GENERIC_GAME_COMMAND(SModeGameCommand)
GENERIC_GAME_COMMAND(CancelVoteGameCommand) GENERIC_GAME_COMMAND(CancelVoteGameCommand)
#endif // _RENX_COMMANDS_H_HEADER #endif // _RENX_COMMANDS_H_HEADER

5
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)); 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 const Jupiter::ReadableString &RenX::Server::getPrefix() const
{ {
static Jupiter::String parsed; static Jupiter::String parsed;

8
src/Plugins/RenX/RenX.Core/RenX_Server.h

@ -706,6 +706,14 @@ namespace RenX
*/ */
bool nmodePlayer(const RenX::PlayerInfo &player); 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. * @brief Fetches a server's IRC logging prefix.
* *

Loading…
Cancel
Save