diff --git a/RenX.Commands/RenX_Commands.cpp b/RenX.Commands/RenX_Commands.cpp index 9fde8ae..9d84cf2 100644 --- a/RenX.Commands/RenX_Commands.cpp +++ b/RenX.Commands/RenX_Commands.cpp @@ -15,6 +15,7 @@ * Written by Justin James */ +#include #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 ¶meters) +{ + 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 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] "); + return defaultHelp; +} + +IRC_COMMAND_INIT(BanSearchIRCCommand) + // ShowRules IRC Command void ShowRulesIRCCommand::create() diff --git a/RenX.Commands/RenX_Commands.h b/RenX.Commands/RenX_Commands.h index 6e978df..1eedfcd 100644 --- a/RenX.Commands/RenX_Commands.h +++ b/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) diff --git a/RenX.ModSystem/RenX_ModSystem.cpp b/RenX.ModSystem/RenX_ModSystem.cpp index 1c4d2b8..ed39530 100644 --- a/RenX.ModSystem/RenX_ModSystem.cpp +++ b/RenX.ModSystem/RenX_ModSystem.cpp @@ -15,7 +15,6 @@ * Written by Justin James */ -#include #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 ¶meters) -{ - 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 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] "); - return defaultHelp; -} - -IRC_COMMAND_INIT(BanSearchIRCCommand) - /** Game Commands */ // Auth Game Command diff --git a/RenX.ModSystem/RenX_ModSystem.h b/RenX.ModSystem/RenX_ModSystem.h index 307f9c0..0d4093e 100644 --- a/RenX.ModSystem/RenX_ModSystem.h +++ b/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)