From dc4f891a992a46a21a4d1c8cf67a717ea3215d4b Mon Sep 17 00:00:00 2001 From: Jessica James Date: Fri, 23 Dec 2016 18:40:05 -0500 Subject: [PATCH] Commands is now a subsection of server sections Updated Jupiter; refactored as necessary Various bug fixes --- Bot/IRC_Bot.cpp | 90 +++++++++++++++---------------- Bot/IRC_Bot.h | 2 +- Configs/IRC.Core.ini | 54 ++++++++----------- Jupiter | 2 +- RenX.Core/RenX_Functions.cpp | 2 +- RenX.Core/RenX_Server.cpp | 56 +++++++++---------- RenX.ModSystem/RenX_ModSystem.cpp | 13 ++++- 7 files changed, 109 insertions(+), 110 deletions(-) diff --git a/Bot/IRC_Bot.cpp b/Bot/IRC_Bot.cpp index 031dcdf..9acf922 100644 --- a/Bot/IRC_Bot.cpp +++ b/Bot/IRC_Bot.cpp @@ -27,7 +27,7 @@ using namespace Jupiter::literals; -IRC_Bot::IRC_Bot(const Jupiter::Config *in_primary_section, const Jupiter::Config *in_secondary_section) : Client(in_primary_section, in_secondary_section) +IRC_Bot::IRC_Bot(Jupiter::Config *in_primary_section, Jupiter::Config *in_secondary_section) : Client(in_primary_section, in_secondary_section) { IRC_Bot::commandPrefix = this->readConfigValue("Prefix"_jrs); @@ -106,66 +106,64 @@ Jupiter::StringL IRC_Bot::getTriggers(Jupiter::ArrayList &cmds) void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) { - auto set_command_access_levels = [this, in_command](const Jupiter::ReadableString §ion_name) + auto set_command_access_levels = [this, in_command](Jupiter::Config *in_section) { - Jupiter::Config *section = serverManager->getConfig().getSection(section_name); + if (in_section == nullptr) + return; - if (section != nullptr) - { - auto read_section = [this, section, in_command](Jupiter::HashTable::Bucket::Entry &in_entry) - { - size_t tmp_index; - Jupiter::ReferenceString tmp_key, tmp_sub_key; - IRCCommand *command; + Jupiter::Config *section = in_section->getSection("Commands"_jrs); - tmp_index = in_entry.key.find('.'); - if (tmp_index != Jupiter::INVALID_INDEX) - { - // non-default access assignment + if (section == nullptr) + return; - tmp_key.set(in_entry.key.ptr(), tmp_index); + auto read_section = [this, section, in_command](Jupiter::HashTable::Bucket::Entry &in_entry) + { + size_t tmp_index; + Jupiter::ReferenceString tmp_key, tmp_sub_key; + IRCCommand *command; - tmp_sub_key = in_entry.key; - tmp_sub_key.shiftRight(tmp_index + 1); + tmp_index = in_entry.key.find('.'); + if (tmp_index != Jupiter::INVALID_INDEX) + { + // non-default access assignment - if (tmp_sub_key.findi("Type."_jrs) == 0) - { - tmp_sub_key.shiftRight(5); // shift beyond "Type." + tmp_key.set(in_entry.key.ptr(), tmp_index); - command = this->getCommand(tmp_key); - if (command != nullptr && (in_command == nullptr || in_command == command)) - command->setAccessLevel(tmp_sub_key.asInt(), in_entry.value.asInt()); - } - else if (tmp_sub_key.findi("Channel."_jrs) == 0) - { - tmp_sub_key.shiftRight(8); // shift beyond "Channel." + tmp_sub_key = in_entry.key; + tmp_sub_key.shiftRight(tmp_index + 1); - // Assign access level to command (if command exists) - command = this->getCommand(tmp_key); - if (command != nullptr && (in_command == nullptr || in_command == command)) - command->setAccessLevel(tmp_sub_key, in_entry.value.asInt()); - } + if (tmp_sub_key.findi("Type."_jrs) == 0) + { + tmp_sub_key.shiftRight(5); // shift beyond "Type." + + command = this->getCommand(tmp_key); + if (command != nullptr && (in_command == nullptr || in_command == command)) + command->setAccessLevel(tmp_sub_key.asInt(), in_entry.value.asInt()); } - else + else if (tmp_sub_key.findi("Channel."_jrs) == 0) { + tmp_sub_key.shiftRight(8); // shift beyond "Channel." + // Assign access level to command (if command exists) - command = this->getCommand(in_entry.key); + command = this->getCommand(tmp_key); if (command != nullptr && (in_command == nullptr || in_command == command)) - command->setAccessLevel(in_entry.value.asInt()); + command->setAccessLevel(tmp_sub_key, in_entry.value.asInt()); } - }; - } - }; + } + else + { + // Assign access level to command (if command exists) + command = this->getCommand(in_entry.key); + if (command != nullptr && (in_command == nullptr || in_command == command)) + command->setAccessLevel(in_entry.value.asInt()); + } + }; - const Jupiter::Config *section; - - section = this->getSecondaryConfigSection(); - if (section != nullptr) - set_command_access_levels(section->getName() + "Commands"_jrs); + section->getTable().callback(read_section); + }; - section = this->getPrimaryConfigSection(); - if (section != nullptr) - set_command_access_levels(section->getName() + "Commands"_jrs); + set_command_access_levels(this->getSecondaryConfigSection()); + set_command_access_levels(this->getPrimaryConfigSection()); } void IRC_Bot::OnChat(const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message) diff --git a/Bot/IRC_Bot.h b/Bot/IRC_Bot.h index ef0b82c..a6edbf0 100644 --- a/Bot/IRC_Bot.h +++ b/Bot/IRC_Bot.h @@ -110,7 +110,7 @@ public: bool OnBadRehash(bool removed) { return removed; }; /** Constructor for IRC_Bot */ - IRC_Bot(const Jupiter::Config *in_primary_section, const Jupiter::Config *in_secondary_section); + IRC_Bot(Jupiter::Config *in_primary_section, Jupiter::Config *in_secondary_section); /** Destructor for IRC_Bot */ ~IRC_Bot(); diff --git a/Configs/IRC.Core.ini b/Configs/IRC.Core.ini index b07adb5..211b864 100644 --- a/Configs/IRC.Core.ini +++ b/Configs/IRC.Core.ini @@ -72,31 +72,7 @@ PrintOutput=1 Channel.Type=-1 Prefix=! -; [(ServerName)] -; -; Anything which can be set within the Default block can -; also be applied here. Values here supercede any value -; which is set within the Default block. -; - -[CnCIRC] -; CnCIRC includes the Renegade X IRC server. :) -Hostname=irc.cncirc.net -Channel.1=#RenX-IRC -Channel.1.Type=1 -Channel.2=#RenX-IRC.Admin -Channel.2.Type=2 -SASL.Password=your_NickServ_Password - -[CT] -Hostname=irc.ConstructiveTyranny.com -Channel.1=#RenX-IRC -Channel.1.Type=1 -Channel.2=#RenX-IRC.Admin -Channel.2.Type=2 -RawData.1=PRIVMSG NickServ :IDENTIFY your_NickServ_Password - -; [DefaultCommands] +; [[Commands]] ; You can modify the access requirements for any command here. ; Values set here will be set across all servers that do not have ; server-specific values set. @@ -106,7 +82,7 @@ RawData.1=PRIVMSG NickServ :IDENTIFY your_NickServ_Password ; Syntax: CommandTrigger=AccessLevel ; -[DefaultCommands] +[[Commands]] rehash=4 select=4 deselect=4 @@ -120,12 +96,28 @@ ircconnect=5 ircdisconnect=5 plugin=5 -; [(ServerName)Commands] -; You can modify the access requirements for any command here, on a -; per-server basis. Values specified here supercede those which are set -; in the DefaultCommands block. +; [(ServerName)] +; +; Anything which can be set within the Default block can +; also be applied here. Values here supercede any value +; which is set within the Default block. ; -[CnCIRCCommands] +[CnCIRC] +; CnCIRC includes the Renegade X IRC server. :) +Hostname=irc.cncirc.net +Channel.1=#RenX-IRC +Channel.1.Type=1 +Channel.2=#RenX-IRC.Admin +Channel.2.Type=2 +SASL.Password=your_NickServ_Password + +[CT] +Hostname=irc.ConstructiveTyranny.com +Channel.1=#RenX-IRC +Channel.1.Type=1 +Channel.2=#RenX-IRC.Admin +Channel.2.Type=2 +RawData.1=PRIVMSG NickServ :IDENTIFY your_NickServ_Password ;EOF \ No newline at end of file diff --git a/Jupiter b/Jupiter index d52d8cb..8fbb123 160000 --- a/Jupiter +++ b/Jupiter @@ -1 +1 @@ -Subproject commit d52d8cbbfbe8f8c1b74d01096d7d90c0c46d9518 +Subproject commit 8fbb12310ea9be59420f59406e3d3054686d2a2c diff --git a/RenX.Core/RenX_Functions.cpp b/RenX.Core/RenX_Functions.cpp index ba4a67d..fd6aa4f 100644 --- a/RenX.Core/RenX_Functions.cpp +++ b/RenX.Core/RenX_Functions.cpp @@ -490,7 +490,7 @@ const Jupiter::ReferenceString RenX::translateName(const Jupiter::ReadableString if (obj.isEmpty()) return Jupiter::ReferenceString::empty; - Jupiter::ReferenceString iniTranslation = RenX::getCore()->getConfig().get(STRING_LITERAL_AS_REFERENCE("Name"), obj); + Jupiter::ReferenceString iniTranslation = RenX::getCore()->getConfig()["Name"_jrs].get(obj); if (iniTranslation.isNotEmpty()) return iniTranslation; diff --git a/RenX.Core/RenX_Server.cpp b/RenX.Core/RenX_Server.cpp index 09174d9..8263576 100644 --- a/RenX.Core/RenX_Server.cpp +++ b/RenX.Core/RenX_Server.cpp @@ -1624,35 +1624,35 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { Jupiter::ReadableString *value; - value = table.get("Kills"_jrs); + value = table.get("KILLS"_jrs); if (value != nullptr) player->kills = value->asUnsignedInt(); - value = table.get("Deaths"_jrs); + value = table.get("DEATHS"_jrs); if (value != nullptr) player->deaths = value->asUnsignedInt(); - value = table.get("Score"_jrs); + value = table.get("SCORE"_jrs); if (value != nullptr) player->score = value->asDouble(); - value = table.get("Credits"_jrs); + value = table.get("CREDITS"_jrs); if (value != nullptr) player->credits = value->asDouble(); - value = table.get("Character"_jrs); + value = table.get("CHARACTER"_jrs); if (value != nullptr) player->character = *value; - value = table.get("Vehicle"_jrs); + value = table.get("VEHICLE"_jrs); if (value != nullptr) player->vehicle = *value; - value = table.get("Ping"_jrs); + value = table.get("PING"_jrs); if (value != nullptr) player->ping = value->asUnsignedInt(); - value = table.get("Admin"_jrs); + value = table.get("ADMIN"_jrs); if (value != nullptr) { if (value->equals("None"_jrs)) @@ -1661,12 +1661,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) player->adminType = *value; } }; - Jupiter::ReadableString *value = table.get("PlayerLog"_jrs); + Jupiter::ReadableString *value = table.get("PLAYERLOG"_jrs); if (value != nullptr) parse(getPlayerOrAdd(Jupiter::ReferenceString::getToken(*value, 2, ','), Jupiter::ReferenceString::getToken(*value, 1, ',').asInt(), RenX::getTeam(Jupiter::ReferenceString::getToken(*value, 0, ',')), false, table.get("STEAM"_jrs, Jupiter::ReferenceString::empty).asUnsignedLongLong(), table.get("IP"_jrs, Jupiter::ReferenceString::empty), table.get("HWID"_jrs, Jupiter::ReferenceString::empty))); else { - Jupiter::ReadableString *name = table.get("Name"_jrs); + Jupiter::ReadableString *name = table.get("NAME"_jrs); value = table.get("ID"_jrs); if (value != nullptr) @@ -1676,7 +1676,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { if (player->name.isEmpty()) { - player->name = table.get("Name"_jrs, Jupiter::ReferenceString::empty); + player->name = table.get("NAME"_jrs, Jupiter::ReferenceString::empty); player->name.processEscapeSequences(); } if (player->ip.isEmpty()) @@ -1693,12 +1693,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) } } - value = table.get("TeamNum"_jrs); + value = table.get("TEAMNUM"_jrs); if (value != nullptr) player->team = RenX::getTeam(value->asInt()); else { - value = table.get("Team"_jrs); + value = table.get("TEAM"_jrs); if (value != nullptr) player->team = RenX::getTeam(*value); } @@ -1727,12 +1727,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) } } - value = table.get("TeamNum"_jrs); + value = table.get("TEAMNUM"_jrs); if (value != nullptr) player->team = RenX::getTeam(value->asInt()); else { - value = table.get("Team"_jrs); + value = table.get("TEAM"_jrs); if (value != nullptr) player->team = RenX::getTeam(*value); } @@ -1771,36 +1771,36 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { Jupiter::ReadableString *value; - value = table.get("Kills"_jrs); + value = table.get("KILLS"_jrs); if (value != nullptr) player->kills = value->asUnsignedInt(); - value = table.get("Deaths"_jrs); + value = table.get("DEATHS"_jrs); if (value != nullptr) player->deaths = value->asUnsignedInt(); - value = table.get("Score"_jrs); + value = table.get("SCORE"_jrs); if (value != nullptr) player->score = value->asDouble(); - value = table.get("Credits"_jrs); + value = table.get("CREDITS"_jrs); if (value != nullptr) player->credits = value->asDouble(); - value = table.get("Character"_jrs); + value = table.get("CHARACTER"_jrs); if (value != nullptr) player->character = *value; - value = table.get("Vehicle"_jrs); + value = table.get("VEHICLE"_jrs); if (value != nullptr) player->vehicle = *value; }; - Jupiter::ReadableString *value = table.get("PlayerLog"_jrs); + Jupiter::ReadableString *value = table.get("PLAYERLOG"_jrs); if (value != nullptr) parse(getPlayerOrAdd(Jupiter::ReferenceString::getToken(*value, 2, ','), Jupiter::ReferenceString::getToken(*value, 1, ',').substring(1).asInt(), RenX::getTeam(Jupiter::ReferenceString::getToken(*value, 0, ',')), true, 0ULL, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty)); else { - Jupiter::ReadableString *name = table.get("Name"_jrs); + Jupiter::ReadableString *name = table.get("NAME"_jrs); value = table.get("ID"_jrs); if (value != nullptr) @@ -1810,16 +1810,16 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { if (player->name.isEmpty()) { - player->name = table.get("Name"_jrs, Jupiter::ReferenceString::empty); + player->name = table.get("NAME"_jrs, Jupiter::ReferenceString::empty); player->name.processEscapeSequences(); } - value = table.get("TeamNum"_jrs); + value = table.get("TEAMNUM"_jrs); if (value != nullptr) player->team = RenX::getTeam(value->asInt()); else { - value = table.get("Team"_jrs); + value = table.get("TEAM"_jrs); if (value != nullptr) player->team = RenX::getTeam(*value); } @@ -1832,12 +1832,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = getPlayerByName(*name); if (player != nullptr) { - value = table.get("TeamNum"_jrs); + value = table.get("TEAMNUM"_jrs); if (value != nullptr) player->team = RenX::getTeam(value->asInt()); else { - value = table.get("Team"_jrs); + value = table.get("TEAM"_jrs); if (value != nullptr) player->team = RenX::getTeam(*value); } diff --git a/RenX.ModSystem/RenX_ModSystem.cpp b/RenX.ModSystem/RenX_ModSystem.cpp index 5e0f2ca..d892371 100644 --- a/RenX.ModSystem/RenX_ModSystem.cpp +++ b/RenX.ModSystem/RenX_ModSystem.cpp @@ -122,6 +122,7 @@ unsigned int RenX_ModSystemPlugin::logoutAllMods(const RenX::Server *server) for (Jupiter::DLList::Node *n = server->players.getNode(0); n != nullptr; n = n->next) if (RenX_ModSystemPlugin::resetAccess(n->data)) total++; + return total; } @@ -148,6 +149,7 @@ bool RenX_ModSystemPlugin::resetAccess(RenX::PlayerInfo *player) player->access = groups.get(0)->access; else player->access = 0; + return player->access != oAccess; } @@ -163,6 +165,7 @@ int RenX_ModSystemPlugin::auth(RenX::Server *server, const RenX::PlayerInfo *pla if (section != nullptr) { const Jupiter::ReadableString &groupName = section->get("Group"_jrs); + if (groupName.isEmpty()) group = RenX_ModSystemPlugin::groups.get(0); else @@ -232,10 +235,12 @@ void RenX_ModSystemPlugin::tempAuth(RenX::Server *server, const RenX::PlayerInfo { if (group == nullptr) group = this->getDefaultGroup(); + player->varData[name].set("Group"_jrs, group->name); player->formatNamePrefix = group->prefix; player->gamePrefix = group->gamePrefix; player->access = group->access; + if (notify) server->sendMessage(player, Jupiter::StringS::Format("You have been authorized into group \"%.*s\", with access level %u.", group->name.size(), group->name.ptr(), player->access)); } @@ -247,6 +252,7 @@ bool RenX_ModSystemPlugin::set(RenX::PlayerInfo *player, RenX_ModSystemPlugin::M this->config[player->uuid].set("LastIP"_jrs, player->ip); this->config[player->uuid].set("Name"_jrs, player->name); this->config.write(); + return r; } @@ -256,6 +262,7 @@ RenX_ModSystemPlugin::ModGroup *RenX_ModSystemPlugin::getGroupByName(const Jupit for (Jupiter::DLList::Node *n = groups.getNode(0); n != nullptr; n = n->next) if (n->data->name.equalsi(name)) return n->data; + return defaultGroup; } @@ -265,6 +272,7 @@ RenX_ModSystemPlugin::ModGroup *RenX_ModSystemPlugin::getGroupByAccess(int acces for (Jupiter::DLList::Node *n = groups.getNode(0); n != nullptr; n = n->next) if (n->data->access == access) return n->data; + return defaultGroup; } @@ -274,14 +282,17 @@ RenX_ModSystemPlugin::ModGroup *RenX_ModSystemPlugin::getGroupByIndex(size_t ind for (Jupiter::DLList::Node *n = groups.getNode(0); n != nullptr; n = n->next) if (index-- == 0) return n->data; + return nullptr; } int RenX_ModSystemPlugin::getConfigAccess(const Jupiter::ReadableString &uuid) const { Jupiter::Config *section = this->config.getSection(uuid); + if (section == nullptr) return RenX_ModSystemPlugin::groups.get(0)->access; + RenX_ModSystemPlugin::ModGroup *group = RenX_ModSystemPlugin::getGroupByName(section->get("Group"_jrs), groups.get(0)); return section->get("Access"_jrs, group->access); } @@ -889,8 +900,6 @@ void ModListIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString & msg += group->name; msg.aformat(IRCNORMAL " (Access: %d): ", group->access); msgBaseSize = msg.size(); - auto bucket_itr = pluginInstance.modsFile.getSections().begin(); - auto bucket_end = pluginInstance.modsFile.getSections().end(); auto entry_callback = [&msg, group](Jupiter::Config::SectionHashTable::Bucket::Entry &in_entry) {