Browse Source

Added amsg/pamsg IRC commands

warnings now use warn RCON command
release/0.19
Jessica James 5 years ago
parent
commit
802cacf084
  1. 87
      src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp
  2. 2
      src/Plugins/RenX/RenX.Commands/RenX_Commands.h
  3. 26
      src/Plugins/RenX/RenX.Core/RenX_Server.cpp
  4. 26
      src/Plugins/RenX/RenX.Core/RenX_Server.h
  5. 27
      src/Plugins/RenX/RenX.Warn/RenX_Warn.cpp

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

@ -309,6 +309,93 @@ const Jupiter::ReadableString &HostMsgIRCCommand::getHelp(const Jupiter::Readabl
IRC_COMMAND_INIT(HostMsgIRCCommand)
// Admin Msg IRC Command
void AdminMsgIRCCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("amsg"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("asay"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("adminmessage"));
this->setAccessLevel(4);
}
void AdminMsgIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
if (parameters.isNotEmpty())
{
int type = source->getChannel(channel)->getType();
bool success = false;
for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++)
{
RenX::Server *server = RenX::getCore()->getServer(i);
if (server->isLogChanType(type))
success = server->sendAdminMessage(parameters) > 0;
}
if (!success)
source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers."));
}
else source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: amsg <Message>"));
}
const Jupiter::ReadableString &AdminMsgIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends an admin message in-game. Syntax: amsg <Message>");
return defaultHelp;
}
IRC_COMMAND_INIT(AdminMsgIRCCommand)
// PAdminMsg IRC Command
void PAdminMsgIRCCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("pamsg"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("pasay"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("apage"));
this->setAccessLevel(1);
}
void PAdminMsgIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
if (parameters.wordCount(WHITESPACE) >= 2)
{
int type = source->getChannel(channel)->getType();
Jupiter::ReferenceString name = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
RenX::PlayerInfo *player;
Jupiter::StringL msg;
char prefix = source->getChannel(channel)->getUserPrefix(nick);
if (prefix != '\0')
msg += prefix;
msg += nick;
msg += "@IRC: ";
msg += Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE);
if (parameters.isNotEmpty())
{
for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++)
{
RenX::Server *server = RenX::getCore()->getServer(i);
if (server->isLogChanType(type))
{
player = server->getPlayerByPartName(name);
if (player != nullptr)
server->sendAdminMessage(*player, msg);
else source->sendNotice(nick, Jupiter::StringS::Format("Error: Player \"%.*s\" not found.", name.size(), name.ptr()));
}
}
}
}
else source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: pamsg <Player> <Message>"));
}
const Jupiter::ReadableString &PAdminMsgIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends an admin message in-game. Syntax: pamsg <Player> <Message>");
return defaultHelp;
}
IRC_COMMAND_INIT(PAdminMsgIRCCommand)
// Players IRC Command
void PlayersIRCCommand::create()

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

@ -58,6 +58,8 @@ GENERIC_CONSOLE_COMMAND(RCONConsoleCommand)
GENERIC_IRC_COMMAND(MsgIRCCommand)
GENERIC_IRC_COMMAND(PMsgIRCCommand)
GENERIC_IRC_COMMAND(HostMsgIRCCommand)
GENERIC_IRC_COMMAND(AdminMsgIRCCommand)
GENERIC_IRC_COMMAND(PAdminMsgIRCCommand)
GENERIC_IRC_COMMAND(PlayersIRCCommand)
GENERIC_IRC_COMMAND(PlayerTableIRCCommand)
GENERIC_IRC_COMMAND(PlayerInfoIRCCommand)

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

@ -309,6 +309,21 @@ int RenX::Server::sendMessage(const RenX::PlayerInfo &player, const Jupiter::Rea
return RenX::Server::sendSocket("chostprivatesay pid"_jrs + Jupiter::StringS::Format("%d ", player.id) + RenX::escapifyRCON(message) + '\n');
}
int RenX::Server::sendAdminMessage(const Jupiter::ReadableString &message)
{
return RenX::Server::sendSocket("camsg "_jrs + RenX::escapifyRCON(message) + '\n');
}
int RenX::Server::sendAdminMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message)
{
return RenX::Server::sendSocket("cpamsg pid"_jrs + Jupiter::StringS::Format("%d ", player.id) + RenX::escapifyRCON(message) + '\n');
}
int RenX::Server::sendWarnMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message)
{
return RenX::Server::sendSocket("cwarn pid"_jrs + Jupiter::StringS::Format("%d ", player.id) + RenX::escapifyRCON(message) + '\n');
}
int RenX::Server::sendData(const Jupiter::ReadableString &data)
{
return RenX::Server::sendSocket(data);
@ -2953,15 +2968,8 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
Jupiter::ReferenceString command = gotoToken(4);
Jupiter::ReferenceString cmd = command.getWord(0, " ");
if (cmd.equalsi("hostprivatesay"))
{
RenX::PlayerInfo *player = this->getPlayerByName(command.getWord(1, " "));
for (size_t i = 0; i < xPlugins.size(); i++)
xPlugins.get(i)->RenX_OnExecute(*this, user, command);
}
else
for (size_t i = 0; i < xPlugins.size(); i++)
xPlugins.get(i)->RenX_OnExecute(*this, user, command);
for (size_t i = 0; i < xPlugins.size(); i++)
xPlugins.get(i)->RenX_OnExecute(*this, user, command);
if (this->rconUser.equals(user))
{

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

@ -252,6 +252,32 @@ namespace RenX
*/
int sendMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message);
/**
* @brief Sends an in-game admin message to the server.
*
* @param message Message to send in-game.
* @return The number of bytes sent on success, less than or equal to zero otherwise.
*/
int sendAdminMessage(const Jupiter::ReadableString &message);
/**
* @brief Sends an in-game admin message to a player in the server.
*
* @param player Data of the player to send a message to.
* @param message Message to send in-game.
* @return The number of bytes sent on success, less than or equal to zero otherwise.
*/
int sendAdminMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message);
/**
* @brief Sends an in-game warning message to a player in the server.
*
* @param player Data of the player to send a message to.
* @param message Message to send in-game.
* @return The number of bytes sent on success, less than or equal to zero otherwise.
*/
int sendWarnMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message);
/**
* @brief Sends data to the server.
*

27
src/Plugins/RenX/RenX.Warn/RenX_Warn.cpp

@ -52,7 +52,7 @@ void WarnIRCCommand::create()
void WarnIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
if (parameters.isNotEmpty())
if (parameters.wordCount(WHITESPACE) >= 2)
{
Jupiter::IRC::Client::Channel *chan = source->getChannel(channel);
if (chan != nullptr)
@ -60,6 +60,9 @@ void WarnIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &cha
Jupiter::ArrayList<RenX::Server> servers = RenX::getCore()->getServers(chan->getType());
if (servers.size() != 0)
{
Jupiter::ReferenceString name = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
Jupiter::ReferenceString reason = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE);
RenX::PlayerInfo *player;
RenX::Server *server;
for (size_t i = 0; i != servers.size(); i++)
@ -67,7 +70,7 @@ void WarnIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &cha
server = servers.get(i);
if (server != nullptr)
{
player = server->getPlayerByPartName(parameters);
player = server->getPlayerByPartName(name);
if (player != nullptr)
{
int warns = player->varData[pluginInstance.getName()].get<int>(WARNS_KEY) + 1;
@ -81,14 +84,14 @@ void WarnIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &cha
break;
default:
server->banPlayer(*player, "Jupiter Bot/RenX.Warn"_jrs, Jupiter::StringS::Format("Warning limit reached (%d warnings)", warns), std::chrono::seconds(pluginInstance.warnAction));
source->sendNotice(nick, Jupiter::StringS::Format("%.*s has been banned from the server for exceeding the warning limit (%d warnings).", player->name.size(), player->name.ptr(), warns));
source->sendNotice(nick, Jupiter::StringS::Format("%.*s has been banned from the server for exceeding the warning limit (%d warnings).", player->name.size(), player->name.ptr(), reason.size(), reason.ptr(), warns));
break;
}
}
else
{
player->varData[pluginInstance.getName()].set(WARNS_KEY, Jupiter::StringS::Format("%d", warns));
server->sendMessage(*player, Jupiter::StringS::Format("You have been warned by %.*s@IRC; improve your behavior, or you will be disciplined. You have %d warnings.", nick.size(), nick.ptr(), warns));
server->sendWarnMessage(*player, Jupiter::StringS::Format("You have been warned by %.*s@IRC for: %.*s. You have %d warnings.", nick.size(), nick.ptr(), reason.size(), reason.ptr(), warns));
source->sendNotice(nick, Jupiter::StringS::Format("%.*s has been warned; they now have %d warnings.", player->name.size(), player->name.ptr(), warns));
}
}
@ -100,12 +103,12 @@ void WarnIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &cha
}
}
else
source->sendNotice(nick, "Error: Too Few Parameters. Syntax: Warn <Player>"_jrs);
source->sendNotice(nick, "Error: Too Few Parameters. Syntax: Warn <Player> <Reason>"_jrs);
}
const Jupiter::ReadableString &WarnIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Warns a player. Syntax: Warn <Player>");
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Warns a player. Syntax: Warn <Player> <Reason>");
return defaultHelp;
}
@ -175,11 +178,13 @@ void WarnGameCommand::create()
void WarnGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString &parameters)
{
if (parameters.isNotEmpty())
if (parameters.wordCount(WHITESPACE) >= 2)
{
RenX::PlayerInfo *target = source->getPlayerByPartName(parameters);
Jupiter::ReferenceString name = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
RenX::PlayerInfo *target = source->getPlayerByPartName(name);
if (target != nullptr)
{
Jupiter::ReferenceString reason = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE);
int warns = target->varData[pluginInstance.getName()].get<int>(WARNS_KEY) + 1;
if (warns > pluginInstance.maxWarns)
{
@ -198,18 +203,18 @@ void WarnGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, co
else
{
target->varData[pluginInstance.getName()].set(WARNS_KEY, Jupiter::StringS::Format("%d", warns));
source->sendMessage(*target, Jupiter::StringS::Format("You have been warned by %.*s; improve your behavior, or you will be disciplined. You have %d warnings.", player->name.size(), player->name.ptr(), warns));
source->sendWarnMessage(*target, Jupiter::StringS::Format("You have been warned by %.*s for: %.*s. You have %d warnings.", player->name.size(), player->name.ptr(), reason.size(), reason.ptr(), warns));
source->sendMessage(*player, Jupiter::StringS::Format("%.*s has been warned; they now have %d warnings.", target->name.size(), target->name.ptr(), warns));
}
}
}
else
source->sendMessage(*player, "Error: Too few parameters. Syntax: Warn <Player>"_jrs);
source->sendMessage(*player, "Error: Too few parameters. Syntax: Warn <Player> <Reason>"_jrs);
}
const Jupiter::ReadableString &WarnGameCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Warns a player. Syntax: Warn <Player>");
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Warns a player. Syntax: Warn <Player> <Reason>");
return defaultHelp;
}

Loading…
Cancel
Save