Browse Source

Merge pull request #15 from milanstephan/cancelvote

Add `cancelvote` IRC- and game-commands
pull/17/head
Jessica James 4 years ago
committed by GitHub
parent
commit
a737bc62eb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 127
      src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp
  2. 2
      src/Plugins/RenX/RenX.Commands/RenX_Commands.h

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

@ -3240,6 +3240,82 @@ const Jupiter::ReadableString &NModeIRCCommand::getHelp(const Jupiter::ReadableS
IRC_COMMAND_INIT(NModeIRCCommand) IRC_COMMAND_INIT(NModeIRCCommand)
// CancelVote IRC Command
void CancelVoteIRCCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvote"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvotes"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("cv"));
this->setAccessLevel(2);
}
void CancelVoteIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
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;
}
bool cancel_all = false;
RenX::TeamType target = RenX::TeamType::None;
if (parameters.isEmpty()) {
cancel_all = true;
} else {
if (parameters.equalsi("all") || parameters.equalsi("a")) {
cancel_all = true;
} else if (parameters.equalsi("public") || parameters.equalsi("p")) {
target = RenX::TeamType::None;
} else if (parameters.equalsi("gdi") || parameters.equalsi("g")) {
target = RenX::TeamType::GDI;
} else if (parameters.equalsi("blackhand") || parameters.equalsi("bh") || parameters.equalsi("b")) {
target = RenX::TeamType::GDI;
} else if (parameters.equalsi("nod") || parameters.equalsi("n")) {
target = RenX::TeamType::Nod;
} else {
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Invalid Team. Allowed values are all/a, public/p, gdi/g, nod/n, blackhand/bh/b."));
return;
}
}
if (cancel_all) {
for (size_t i = 0; i != servers.size(); i++) {
RenX::Server *server = servers.get(i);
if (server == nullptr) {
continue;
}
server->cancelVote(RenX::TeamType::None);
server->cancelVote(RenX::TeamType::GDI);
server->cancelVote(RenX::TeamType::Nod);
}
} else {
for (size_t i = 0; i != servers.size(); i++) {
RenX::Server *server = servers.get(i);
if (server == nullptr) {
continue;
}
server->cancelVote(target);
}
}
}
const Jupiter::ReadableString &CancelVoteIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Cancels active votes. Syntax: cancelvote [all|public|gdi|nod|blackhand]");
return defaultHelp;
}
IRC_COMMAND_INIT(CancelVoteIRCCommand)
/** Game Commands */ /** Game Commands */
// Help Game Command // Help Game Command
@ -4082,6 +4158,57 @@ const Jupiter::ReadableString &NModeGameCommand::getHelp(const Jupiter::Readable
GAME_COMMAND_INIT(NModeGameCommand) GAME_COMMAND_INIT(NModeGameCommand)
// CancelVote Game Command
void CancelVoteGameCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvote"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvotes"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("cv"));
this->setAccessLevel(1);
}
void CancelVoteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString &parameters)
{
bool cancel_all = false;
RenX::TeamType target = RenX::TeamType::None;
if (parameters.isEmpty()) {
cancel_all = true;
} else {
if (parameters.equalsi("all") || parameters.equalsi("a")) {
cancel_all = true;
} else if (parameters.equalsi("public") || parameters.equalsi("p")) {
target = RenX::TeamType::None;
} else if (parameters.equalsi("gdi") || parameters.equalsi("g")) {
target = RenX::TeamType::GDI;
} else if (parameters.equalsi("blackhand") || parameters.equalsi("bh") || parameters.equalsi("b")) {
target = RenX::TeamType::GDI;
} else if (parameters.equalsi("nod") || parameters.equalsi("n")) {
target = RenX::TeamType::Nod;
} else {
source->sendMessage(*player, STRING_LITERAL_AS_REFERENCE("Error: Invalid Team. Allowed values are all/a, public/p, gdi/g, nod/n, blackhand/bh/b."));
return;
}
}
if (cancel_all) {
source->cancelVote(RenX::TeamType::None);
source->cancelVote(RenX::TeamType::GDI);
source->cancelVote(RenX::TeamType::Nod);
} else {
source->cancelVote(target);
}
}
const Jupiter::ReadableString &CancelVoteGameCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Cancels active votes. Syntax: cancelvote [all|public|gdi|nod|blackhand]");
return defaultHelp;
}
GAME_COMMAND_INIT(CancelVoteGameCommand)
extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin()
{ {
return &pluginInstance; return &pluginInstance;

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(CancelVoteIRCCommand)
GENERIC_GAME_COMMAND(HelpGameCommand) GENERIC_GAME_COMMAND(HelpGameCommand)
GENERIC_GAME_COMMAND(ModsGameCommand) GENERIC_GAME_COMMAND(ModsGameCommand)
@ -125,5 +126,6 @@ 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(CancelVoteGameCommand)
#endif // _RENX_COMMANDS_H_HEADER #endif // _RENX_COMMANDS_H_HEADER
Loading…
Cancel
Save