Browse Source

Add `nmode` IRC- and game-commands

pull/13/head
Milan Stephan 4 years ago
parent
commit
f06fdafb76
  1. 87
      src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp
  2. 2
      src/Plugins/RenX/RenX.Commands/RenX_Commands.h
  3. 5
      src/Plugins/RenX/RenX.Core/RenX_Server.cpp
  4. 8
      src/Plugins/RenX/RenX.Core/RenX_Server.h

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

@ -3190,6 +3190,56 @@ const Jupiter::ReadableString &TeamChange2IRCCommand::getHelp(const Jupiter::Rea
IRC_COMMAND_INIT(TeamChange2IRCCommand) IRC_COMMAND_INIT(TeamChange2IRCCommand)
// NMode IRC Command
void NModeIRCCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("nmode"));
this->setAccessLevel(2);
}
void NModeIRCCommand::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: nmode <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 nmodes = 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->nmodePlayer(*player);
++nmodes;
}
}
}
source->sendMessage(channel, Jupiter::StringS::Format("%u players nmoded.", nmodes));
}
const Jupiter::ReadableString &NModeIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: nmode <player>");
return defaultHelp;
}
IRC_COMMAND_INIT(NModeIRCCommand)
/** Game Commands */ /** Game Commands */
// Help Game Command // Help Game Command
@ -3995,6 +4045,43 @@ const Jupiter::ReadableString &PhaseBotsGameCommand::getHelp(const Jupiter::Read
GAME_COMMAND_INIT(PhaseBotsGameCommand) GAME_COMMAND_INIT(PhaseBotsGameCommand)
// NMode Game Command
void NModeGameCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("nmode"));
this->setAccessLevel(1);
}
void NModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString &parameters)
{
if (parameters.isEmpty()) {
source->sendMessage(*player, "Error: Too few parameters. Syntax: nmode <player-name>"_jrs);
return;
}
RenX::PlayerInfo *target = source->getPlayerByPartName(parameters);
if (target == nullptr) {
source->sendMessage(*player, "Error: Player not found."_jrs);
return;
}
if (!source->nmodePlayer(*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 &NModeGameCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: nmode <player-name>");
return defaultHelp;
}
GAME_COMMAND_INIT(NModeGameCommand)
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

@ -103,6 +103,7 @@ GENERIC_IRC_COMMAND(RCONIRCCommand)
GENERIC_IRC_COMMAND(RefundIRCCommand) 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_GAME_COMMAND(HelpGameCommand) GENERIC_GAME_COMMAND(HelpGameCommand)
GENERIC_GAME_COMMAND(ModsGameCommand) GENERIC_GAME_COMMAND(ModsGameCommand)
@ -123,5 +124,6 @@ GENERIC_GAME_COMMAND(KickBanGameCommand)
GENERIC_GAME_COMMAND(AddBotsGameCommand) GENERIC_GAME_COMMAND(AddBotsGameCommand)
GENERIC_GAME_COMMAND(KillBotsGameCommand) GENERIC_GAME_COMMAND(KillBotsGameCommand)
GENERIC_GAME_COMMAND(PhaseBotsGameCommand) GENERIC_GAME_COMMAND(PhaseBotsGameCommand)
GENERIC_GAME_COMMAND(NModeGameCommand)
#endif // _RENX_COMMANDS_H_HEADER #endif // _RENX_COMMANDS_H_HEADER

5
src/Plugins/RenX/RenX.Core/RenX_Server.cpp

@ -959,6 +959,11 @@ bool RenX::Server::changeTeam(RenX::PlayerInfo &player, bool resetCredits)
return RenX::Server::changeTeam(player.id, resetCredits); return RenX::Server::changeTeam(player.id, resetCredits);
} }
bool RenX::Server::nmodePlayer(const RenX::PlayerInfo &player)
{
return RenX::Server::send(Jupiter::StringS::Format("nmode 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

@ -698,6 +698,14 @@ namespace RenX
*/ */
bool changeTeam(RenX::PlayerInfo &player, bool resetCredits = true); bool changeTeam(RenX::PlayerInfo &player, bool resetCredits = true);
/**
* @brief Changes a player's mode from spectator to normal
*
* @param player Player to change mode
* @return True on success, false otherwise.
*/
bool nmodePlayer(const RenX::PlayerInfo &player);
/** /**
* @brief Fetches a server's IRC logging prefix. * @brief Fetches a server's IRC logging prefix.
* *

Loading…
Cancel
Save