Browse Source

Commands is now a subsection of server sections

Updated Jupiter; refactored as necessary
Various bug fixes
pull/4/head
Jessica James 8 years ago
parent
commit
dc4f891a99
  1. 28
      Bot/IRC_Bot.cpp
  2. 2
      Bot/IRC_Bot.h
  3. 54
      Configs/IRC.Core.ini
  4. 2
      Jupiter
  5. 2
      RenX.Core/RenX_Functions.cpp
  6. 56
      RenX.Core/RenX_Server.cpp
  7. 13
      RenX.ModSystem/RenX_ModSystem.cpp

28
Bot/IRC_Bot.cpp

@ -27,7 +27,7 @@
using namespace Jupiter::literals; 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); IRC_Bot::commandPrefix = this->readConfigValue("Prefix"_jrs);
@ -106,12 +106,16 @@ Jupiter::StringL IRC_Bot::getTriggers(Jupiter::ArrayList<IRCCommand> &cmds)
void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command)
{ {
auto set_command_access_levels = [this, in_command](const Jupiter::ReadableString &section_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;
Jupiter::Config *section = in_section->getSection("Commands"_jrs);
if (section == nullptr)
return;
if (section != nullptr)
{
auto read_section = [this, section, in_command](Jupiter::HashTable::Bucket::Entry &in_entry) auto read_section = [this, section, in_command](Jupiter::HashTable::Bucket::Entry &in_entry)
{ {
size_t tmp_index; size_t tmp_index;
@ -154,18 +158,12 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command)
command->setAccessLevel(in_entry.value.asInt()); command->setAccessLevel(in_entry.value.asInt());
} }
}; };
}
};
const Jupiter::Config *section;
section = this->getSecondaryConfigSection(); section->getTable().callback(read_section);
if (section != nullptr) };
set_command_access_levels(section->getName() + "Commands"_jrs);
section = this->getPrimaryConfigSection(); set_command_access_levels(this->getSecondaryConfigSection());
if (section != nullptr) set_command_access_levels(this->getPrimaryConfigSection());
set_command_access_levels(section->getName() + "Commands"_jrs);
} }
void IRC_Bot::OnChat(const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message) void IRC_Bot::OnChat(const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message)

2
Bot/IRC_Bot.h

@ -110,7 +110,7 @@ public:
bool OnBadRehash(bool removed) { return removed; }; bool OnBadRehash(bool removed) { return removed; };
/** Constructor for IRC_Bot */ /** 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 */ /** Destructor for IRC_Bot */
~IRC_Bot(); ~IRC_Bot();

54
Configs/IRC.Core.ini

@ -72,31 +72,7 @@ PrintOutput=1
Channel.Type=-1 Channel.Type=-1
Prefix=! Prefix=!
; [(ServerName)] ; [[Commands]]
;
; 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]
; You can modify the access requirements for any command here. ; You can modify the access requirements for any command here.
; Values set here will be set across all servers that do not have ; Values set here will be set across all servers that do not have
; server-specific values set. ; server-specific values set.
@ -106,7 +82,7 @@ RawData.1=PRIVMSG NickServ :IDENTIFY your_NickServ_Password
; Syntax: CommandTrigger=AccessLevel ; Syntax: CommandTrigger=AccessLevel
; ;
[DefaultCommands] [[Commands]]
rehash=4 rehash=4
select=4 select=4
deselect=4 deselect=4
@ -120,12 +96,28 @@ ircconnect=5
ircdisconnect=5 ircdisconnect=5
plugin=5 plugin=5
; [(ServerName)Commands] ; [(ServerName)]
; You can modify the access requirements for any command here, on a ;
; per-server basis. Values specified here supercede those which are set ; Anything which can be set within the Default block can
; in the DefaultCommands block. ; 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 ;EOF

2
Jupiter

@ -1 +1 @@
Subproject commit d52d8cbbfbe8f8c1b74d01096d7d90c0c46d9518 Subproject commit 8fbb12310ea9be59420f59406e3d3054686d2a2c

2
RenX.Core/RenX_Functions.cpp

@ -490,7 +490,7 @@ const Jupiter::ReferenceString RenX::translateName(const Jupiter::ReadableString
if (obj.isEmpty()) if (obj.isEmpty())
return Jupiter::ReferenceString::empty; 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()) if (iniTranslation.isNotEmpty())
return iniTranslation; return iniTranslation;

56
RenX.Core/RenX_Server.cpp

@ -1624,35 +1624,35 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
{ {
Jupiter::ReadableString *value; Jupiter::ReadableString *value;
value = table.get("Kills"_jrs); value = table.get("KILLS"_jrs);
if (value != nullptr) if (value != nullptr)
player->kills = value->asUnsignedInt(); player->kills = value->asUnsignedInt();
value = table.get("Deaths"_jrs); value = table.get("DEATHS"_jrs);
if (value != nullptr) if (value != nullptr)
player->deaths = value->asUnsignedInt(); player->deaths = value->asUnsignedInt();
value = table.get("Score"_jrs); value = table.get("SCORE"_jrs);
if (value != nullptr) if (value != nullptr)
player->score = value->asDouble(); player->score = value->asDouble();
value = table.get("Credits"_jrs); value = table.get("CREDITS"_jrs);
if (value != nullptr) if (value != nullptr)
player->credits = value->asDouble(); player->credits = value->asDouble();
value = table.get("Character"_jrs); value = table.get("CHARACTER"_jrs);
if (value != nullptr) if (value != nullptr)
player->character = *value; player->character = *value;
value = table.get("Vehicle"_jrs); value = table.get("VEHICLE"_jrs);
if (value != nullptr) if (value != nullptr)
player->vehicle = *value; player->vehicle = *value;
value = table.get("Ping"_jrs); value = table.get("PING"_jrs);
if (value != nullptr) if (value != nullptr)
player->ping = value->asUnsignedInt(); player->ping = value->asUnsignedInt();
value = table.get("Admin"_jrs); value = table.get("ADMIN"_jrs);
if (value != nullptr) if (value != nullptr)
{ {
if (value->equals("None"_jrs)) if (value->equals("None"_jrs))
@ -1661,12 +1661,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
player->adminType = *value; player->adminType = *value;
} }
}; };
Jupiter::ReadableString *value = table.get("PlayerLog"_jrs); Jupiter::ReadableString *value = table.get("PLAYERLOG"_jrs);
if (value != nullptr) 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))); 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 else
{ {
Jupiter::ReadableString *name = table.get("Name"_jrs); Jupiter::ReadableString *name = table.get("NAME"_jrs);
value = table.get("ID"_jrs); value = table.get("ID"_jrs);
if (value != nullptr) if (value != nullptr)
@ -1676,7 +1676,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
{ {
if (player->name.isEmpty()) 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(); player->name.processEscapeSequences();
} }
if (player->ip.isEmpty()) 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) if (value != nullptr)
player->team = RenX::getTeam(value->asInt()); player->team = RenX::getTeam(value->asInt());
else else
{ {
value = table.get("Team"_jrs); value = table.get("TEAM"_jrs);
if (value != nullptr) if (value != nullptr)
player->team = RenX::getTeam(*value); 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) if (value != nullptr)
player->team = RenX::getTeam(value->asInt()); player->team = RenX::getTeam(value->asInt());
else else
{ {
value = table.get("Team"_jrs); value = table.get("TEAM"_jrs);
if (value != nullptr) if (value != nullptr)
player->team = RenX::getTeam(*value); player->team = RenX::getTeam(*value);
} }
@ -1771,36 +1771,36 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
{ {
Jupiter::ReadableString *value; Jupiter::ReadableString *value;
value = table.get("Kills"_jrs); value = table.get("KILLS"_jrs);
if (value != nullptr) if (value != nullptr)
player->kills = value->asUnsignedInt(); player->kills = value->asUnsignedInt();
value = table.get("Deaths"_jrs); value = table.get("DEATHS"_jrs);
if (value != nullptr) if (value != nullptr)
player->deaths = value->asUnsignedInt(); player->deaths = value->asUnsignedInt();
value = table.get("Score"_jrs); value = table.get("SCORE"_jrs);
if (value != nullptr) if (value != nullptr)
player->score = value->asDouble(); player->score = value->asDouble();
value = table.get("Credits"_jrs); value = table.get("CREDITS"_jrs);
if (value != nullptr) if (value != nullptr)
player->credits = value->asDouble(); player->credits = value->asDouble();
value = table.get("Character"_jrs); value = table.get("CHARACTER"_jrs);
if (value != nullptr) if (value != nullptr)
player->character = *value; player->character = *value;
value = table.get("Vehicle"_jrs); value = table.get("VEHICLE"_jrs);
if (value != nullptr) if (value != nullptr)
player->vehicle = *value; player->vehicle = *value;
}; };
Jupiter::ReadableString *value = table.get("PlayerLog"_jrs); Jupiter::ReadableString *value = table.get("PLAYERLOG"_jrs);
if (value != nullptr) 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)); 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 else
{ {
Jupiter::ReadableString *name = table.get("Name"_jrs); Jupiter::ReadableString *name = table.get("NAME"_jrs);
value = table.get("ID"_jrs); value = table.get("ID"_jrs);
if (value != nullptr) if (value != nullptr)
@ -1810,16 +1810,16 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
{ {
if (player->name.isEmpty()) 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(); player->name.processEscapeSequences();
} }
value = table.get("TeamNum"_jrs); value = table.get("TEAMNUM"_jrs);
if (value != nullptr) if (value != nullptr)
player->team = RenX::getTeam(value->asInt()); player->team = RenX::getTeam(value->asInt());
else else
{ {
value = table.get("Team"_jrs); value = table.get("TEAM"_jrs);
if (value != nullptr) if (value != nullptr)
player->team = RenX::getTeam(*value); player->team = RenX::getTeam(*value);
} }
@ -1832,12 +1832,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
RenX::PlayerInfo *player = getPlayerByName(*name); RenX::PlayerInfo *player = getPlayerByName(*name);
if (player != nullptr) if (player != nullptr)
{ {
value = table.get("TeamNum"_jrs); value = table.get("TEAMNUM"_jrs);
if (value != nullptr) if (value != nullptr)
player->team = RenX::getTeam(value->asInt()); player->team = RenX::getTeam(value->asInt());
else else
{ {
value = table.get("Team"_jrs); value = table.get("TEAM"_jrs);
if (value != nullptr) if (value != nullptr)
player->team = RenX::getTeam(*value); player->team = RenX::getTeam(*value);
} }

13
RenX.ModSystem/RenX_ModSystem.cpp

@ -122,6 +122,7 @@ unsigned int RenX_ModSystemPlugin::logoutAllMods(const RenX::Server *server)
for (Jupiter::DLList<RenX::PlayerInfo>::Node *n = server->players.getNode(0); n != nullptr; n = n->next) for (Jupiter::DLList<RenX::PlayerInfo>::Node *n = server->players.getNode(0); n != nullptr; n = n->next)
if (RenX_ModSystemPlugin::resetAccess(n->data)) if (RenX_ModSystemPlugin::resetAccess(n->data))
total++; total++;
return total; return total;
} }
@ -148,6 +149,7 @@ bool RenX_ModSystemPlugin::resetAccess(RenX::PlayerInfo *player)
player->access = groups.get(0)->access; player->access = groups.get(0)->access;
else else
player->access = 0; player->access = 0;
return player->access != oAccess; return player->access != oAccess;
} }
@ -163,6 +165,7 @@ int RenX_ModSystemPlugin::auth(RenX::Server *server, const RenX::PlayerInfo *pla
if (section != nullptr) if (section != nullptr)
{ {
const Jupiter::ReadableString &groupName = section->get("Group"_jrs); const Jupiter::ReadableString &groupName = section->get("Group"_jrs);
if (groupName.isEmpty()) if (groupName.isEmpty())
group = RenX_ModSystemPlugin::groups.get(0); group = RenX_ModSystemPlugin::groups.get(0);
else else
@ -232,10 +235,12 @@ void RenX_ModSystemPlugin::tempAuth(RenX::Server *server, const RenX::PlayerInfo
{ {
if (group == nullptr) if (group == nullptr)
group = this->getDefaultGroup(); group = this->getDefaultGroup();
player->varData[name].set("Group"_jrs, group->name); player->varData[name].set("Group"_jrs, group->name);
player->formatNamePrefix = group->prefix; player->formatNamePrefix = group->prefix;
player->gamePrefix = group->gamePrefix; player->gamePrefix = group->gamePrefix;
player->access = group->access; player->access = group->access;
if (notify) 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)); 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("LastIP"_jrs, player->ip);
this->config[player->uuid].set("Name"_jrs, player->name); this->config[player->uuid].set("Name"_jrs, player->name);
this->config.write(); this->config.write();
return r; return r;
} }
@ -256,6 +262,7 @@ RenX_ModSystemPlugin::ModGroup *RenX_ModSystemPlugin::getGroupByName(const Jupit
for (Jupiter::DLList<ModGroup>::Node *n = groups.getNode(0); n != nullptr; n = n->next) for (Jupiter::DLList<ModGroup>::Node *n = groups.getNode(0); n != nullptr; n = n->next)
if (n->data->name.equalsi(name)) if (n->data->name.equalsi(name))
return n->data; return n->data;
return defaultGroup; return defaultGroup;
} }
@ -265,6 +272,7 @@ RenX_ModSystemPlugin::ModGroup *RenX_ModSystemPlugin::getGroupByAccess(int acces
for (Jupiter::DLList<ModGroup>::Node *n = groups.getNode(0); n != nullptr; n = n->next) for (Jupiter::DLList<ModGroup>::Node *n = groups.getNode(0); n != nullptr; n = n->next)
if (n->data->access == access) if (n->data->access == access)
return n->data; return n->data;
return defaultGroup; return defaultGroup;
} }
@ -274,14 +282,17 @@ RenX_ModSystemPlugin::ModGroup *RenX_ModSystemPlugin::getGroupByIndex(size_t ind
for (Jupiter::DLList<ModGroup>::Node *n = groups.getNode(0); n != nullptr; n = n->next) for (Jupiter::DLList<ModGroup>::Node *n = groups.getNode(0); n != nullptr; n = n->next)
if (index-- == 0) if (index-- == 0)
return n->data; return n->data;
return nullptr; return nullptr;
} }
int RenX_ModSystemPlugin::getConfigAccess(const Jupiter::ReadableString &uuid) const int RenX_ModSystemPlugin::getConfigAccess(const Jupiter::ReadableString &uuid) const
{ {
Jupiter::Config *section = this->config.getSection(uuid); Jupiter::Config *section = this->config.getSection(uuid);
if (section == nullptr) if (section == nullptr)
return RenX_ModSystemPlugin::groups.get(0)->access; return RenX_ModSystemPlugin::groups.get(0)->access;
RenX_ModSystemPlugin::ModGroup *group = RenX_ModSystemPlugin::getGroupByName(section->get("Group"_jrs), groups.get(0)); RenX_ModSystemPlugin::ModGroup *group = RenX_ModSystemPlugin::getGroupByName(section->get("Group"_jrs), groups.get(0));
return section->get<int>("Access"_jrs, group->access); return section->get<int>("Access"_jrs, group->access);
} }
@ -889,8 +900,6 @@ void ModListIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &
msg += group->name; msg += group->name;
msg.aformat(IRCNORMAL " (Access: %d): ", group->access); msg.aformat(IRCNORMAL " (Access: %d): ", group->access);
msgBaseSize = msg.size(); 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) auto entry_callback = [&msg, group](Jupiter::Config::SectionHashTable::Bucket::Entry &in_entry)
{ {

Loading…
Cancel
Save