Browse Source

Moved BanSearchIRCCommand from RenX.ModSystem to RenX.Commands.

pull/3/head
JustinAJ 10 years ago
parent
commit
ce113f6bef
  1. 101
      RenX.Commands/RenX_Commands.cpp
  2. 1
      RenX.Commands/RenX_Commands.h
  3. 101
      RenX.ModSystem/RenX_ModSystem.cpp
  4. 1
      RenX.ModSystem/RenX_ModSystem.h

101
RenX.Commands/RenX_Commands.cpp

@ -15,6 +15,7 @@
* Written by Justin James <justin.aj@hotmail.com>
*/
#include <functional>
#include "Jupiter/Functions.h"
#include "IRC_Bot.h"
#include "RenX_Commands.h"
@ -22,6 +23,7 @@
#include "RenX_Server.h"
#include "RenX_PlayerInfo.h"
#include "RenX_Functions.h"
#include "RenX_BanDatabase.h"
inline bool togglePhasing(RenX::Server *server, bool newState)
{
@ -670,6 +672,105 @@ const Jupiter::ReadableString &ModsIRCCommand::getHelp(const Jupiter::ReadableSt
IRC_COMMAND_INIT(ModsIRCCommand)
// BanSearch IRC Command
void BanSearchIRCCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("bansearch"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("bsearch"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("banfind"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("bfind"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("banlogs"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("blogs"));
this->setAccessLevel(2);
}
void BanSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
auto entries = RenX::banDatabase->getEntries();
if (parameters.isEmpty() == false)
{
if (entries.size() == 0)
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("The ban database is empty!"));
else
{
RenX::BanDatabase::Entry *entry;
Jupiter::ReferenceString params = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE);
std::function<bool(unsigned int)> isMatch = [&](unsigned int type_l) -> bool
{
switch (type_l)
{
default:
case 0: // ANY
return isMatch(1) || isMatch(2) || isMatch(3) || isMatch(4);
case 1: // IP
return entry->ip == params.asUnsignedInt();
case 2: // STEAM
return entry->steamid == params.asUnsignedLongLong();
case 3: // NAME
return entry->name.equalsi(params);
case 4: // BANNER
return entry->varData.get(STRING_LITERAL_AS_REFERENCE("RenX.Commands")).equalsi(params);
case 5: // ACTIVE
return entry->active == params.asBool();
case 6: // ALL
return true;
}
};
unsigned int type;
Jupiter::ReferenceString type_str = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("ip")))
type = 1;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("steam")))
type = 2;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("name")))
type = 3;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("banner")))
type = 4;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("active")))
type = 5;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("any")))
type = 0;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("all")) || type_str.equals('*'))
type = 6;
else
{
type = 0;
params = parameters;
}
Jupiter::String out(256);
char timeStr[256];
for (size_t i = 0; i != entries.size(); i++)
{
entry = entries.get(i);
if (isMatch(type))
{
Jupiter::StringS ip_str = Jupiter::Socket::ntop4(entry->ip);
const Jupiter::ReadableString &banner = entry->varData.get(STRING_LITERAL_AS_REFERENCE("RenX.Commands"));
strftime(timeStr, sizeof(timeStr), "%b %d %Y; Time: %H:%M:%S", localtime(&(entry->timestamp)));
out.format("ID: %lu; Status: %sactive; Date: %s; IP: %.*s; Steam: %llu; Name: %.*s%s", i, entry->active ? "" : "in", timeStr, ip_str.size(), ip_str.ptr(), entry->steamid, entry->name.size(), entry->name.ptr(), banner.isEmpty() ? "" : "; Banner: ");
out.concat(banner);
source->sendNotice(nick, out);
}
}
if (out.isEmpty())
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("No matches found."));
}
}
else
source->sendNotice(nick, Jupiter::StringS::Format("There are a total of %u entries in the ban database.", entries.size()));
}
const Jupiter::ReadableString &BanSearchIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Searches the ban database for an entry. Syntax: bsearch [ip/steam/name/banner/active/any/all = any] <player ip/steam/name/banner>");
return defaultHelp;
}
IRC_COMMAND_INIT(BanSearchIRCCommand)
// ShowRules IRC Command
void ShowRulesIRCCommand::create()

1
RenX.Commands/RenX_Commands.h

@ -51,6 +51,7 @@ GENERIC_IRC_COMMAND(SteamIRCCommand)
GENERIC_IRC_COMMAND(KillDeathRatioIRCCommand)
GENERIC_IRC_COMMAND(ShowModsIRCCommand)
GENERIC_IRC_COMMAND(ModsIRCCommand)
GENERIC_IRC_COMMAND(BanSearchIRCCommand)
GENERIC_IRC_COMMAND(ShowRulesIRCCommand)
GENERIC_IRC_COMMAND(RulesIRCCommand)
GENERIC_IRC_COMMAND(SetRulesIRCCommand)

101
RenX.ModSystem/RenX_ModSystem.cpp

@ -15,7 +15,6 @@
* Written by Justin James <justin.aj@hotmail.com>
*/
#include <functional>
#include "Jupiter/IRC_Client.h"
#include "IRC_Bot.h"
#include "RenX_ModSystem.h"
@ -23,7 +22,6 @@
#include "RenX_Server.h"
#include "RenX_Core.h"
#include "RenX_Functions.h"
#include "RenX_BanDatabase.h"
void RenX_ModSystemPlugin::init()
{
@ -607,105 +605,6 @@ const Jupiter::ReadableString &ForceAuthIRCCommand::getHelp(const Jupiter::Reada
IRC_COMMAND_INIT(ForceAuthIRCCommand)
// Ban Search IRC Command
void BanSearchIRCCommand::create()
{
this->addTrigger(STRING_LITERAL_AS_REFERENCE("bansearch"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("bsearch"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("banfind"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("bfind"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("banlogs"));
this->addTrigger(STRING_LITERAL_AS_REFERENCE("blogs"));
this->setAccessLevel(2);
}
void BanSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
auto entries = RenX::banDatabase->getEntries();
if (parameters.isEmpty() == false)
{
if (entries.size() == 0)
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("The ban database is empty!"));
else
{
RenX::BanDatabase::Entry *entry;
Jupiter::ReferenceString params = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE);
std::function<bool(unsigned int)> isMatch = [&](unsigned int type_l) -> bool
{
switch (type_l)
{
default:
case 0: // ANY
return isMatch(1) || isMatch(2) || isMatch(3) || isMatch(4);
case 1: // IP
return entry->ip == params.asUnsignedInt();
case 2: // STEAM
return entry->steamid == params.asUnsignedLongLong();
case 3: // NAME
return entry->name.equalsi(params);
case 4: // BANNER
return entry->varData.get(STRING_LITERAL_AS_REFERENCE("RenX.Commands")).equalsi(params);
case 5: // ACTIVE
return entry->active == params.asBool();
case 6: // ALL
return true;
}
};
unsigned int type;
Jupiter::ReferenceString type_str = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("ip")))
type = 1;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("steam")))
type = 2;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("name")))
type = 3;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("banner")))
type = 4;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("active")))
type = 5;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("any")))
type = 0;
else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("all")) || type_str.equals('*'))
type = 6;
else
{
type = 0;
params = parameters;
}
Jupiter::String out(256);
char timeStr[256];
for (size_t i = 0; i != entries.size(); i++)
{
entry = entries.get(i);
if (isMatch(type))
{
Jupiter::StringS ip_str = Jupiter::Socket::ntop4(entry->ip);
const Jupiter::ReadableString &banner = entry->varData.get(STRING_LITERAL_AS_REFERENCE("RenX.Commands"));
strftime(timeStr, sizeof(timeStr), "%b %d %Y; Time: %H:%M:%S", localtime(&(entry->timestamp)));
out.format("ID: %lu; Status: %sactive; Date: %s; IP: %.*s; Steam: %llu; Name: %.*s%s", i, entry->active ? "" : "in", timeStr, ip_str.size(), ip_str.ptr(), entry->steamid, entry->name.size(), entry->name.ptr(), banner.isEmpty() ? "" : "; Banner: ");
out.concat(banner);
source->sendNotice(nick, out);
}
}
if (out.isEmpty())
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("No matches found."));
}
}
else
source->sendNotice(nick, Jupiter::StringS::Format("There are a total of %u entries in the ban database.", entries.size()));
}
const Jupiter::ReadableString &BanSearchIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Searches the ban database for an entry. Syntax: bsearch [ip/steam/name/banner/active/any/all = any] <player ip/steam/name/banner>");
return defaultHelp;
}
IRC_COMMAND_INIT(BanSearchIRCCommand)
/** Game Commands */
// Auth Game Command

1
RenX.ModSystem/RenX_ModSystem.h

@ -117,7 +117,6 @@ private:
GENERIC_IRC_COMMAND(AuthIRCCommand)
GENERIC_IRC_COMMAND(ATMIRCCommand)
GENERIC_IRC_COMMAND(ForceAuthIRCCommand)
GENERIC_IRC_COMMAND(BanSearchIRCCommand)
GENERIC_GAME_COMMAND(AuthGameCommand)
GENERIC_GAME_COMMAND(ATMGameCommand)
GENERIC_GAME_COMMAND(ForceAuthGameCommand)

Loading…
Cancel
Save