From 3b4d7ac12a51bfa1ad80d358733032ec538015b2 Mon Sep 17 00:00:00 2001 From: Jessica James Date: Sun, 7 Nov 2021 13:03:17 -0600 Subject: [PATCH] Remove ArrayList; update Jupiter submodule; various stylistic cleanups --- src/Bot/include/Console_Command.h | 7 +- src/Bot/include/IRC_Bot.h | 28 +- src/Bot/include/IRC_Command.h | 18 +- src/Bot/include/ServerManager.h | 14 +- src/Bot/src/Console_Command.cpp | 35 +- src/Bot/src/IRC_Bot.cpp | 166 +- src/Bot/src/IRC_Command.cpp | 164 +- src/Bot/src/Main.cpp | 121 +- src/Bot/src/ServerManager.cpp | 163 +- src/Jupiter | 2 +- src/Plugins/CoreCommands/CoreCommands.cpp | 69 +- src/Plugins/IRC.Core/IRC_Core.cpp | 39 +- src/Plugins/IRC.Core/IRC_Core.h | 4 +- src/Plugins/PluginManager/PluginManager.cpp | 63 +- .../RenX/RenX.Commands/RenX_Commands.cpp | 1284 ++++---- .../RenX/RenX.Commands/RenX_Commands.h | 10 +- .../RenX/RenX.Core/RenX_BanDatabase.cpp | 152 +- src/Plugins/RenX/RenX.Core/RenX_BanDatabase.h | 16 +- src/Plugins/RenX/RenX.Core/RenX_Core.cpp | 185 +- src/Plugins/RenX/RenX.Core/RenX_Core.h | 25 +- .../RenX/RenX.Core/RenX_ExemptionDatabase.cpp | 139 +- .../RenX/RenX.Core/RenX_ExemptionDatabase.h | 15 +- .../RenX/RenX.Core/RenX_GameCommand.cpp | 82 +- src/Plugins/RenX/RenX.Core/RenX_GameCommand.h | 6 +- .../RenX/RenX.Core/RenX_LadderDatabase.cpp | 398 ++- .../RenX/RenX.Core/RenX_LadderDatabase.h | 29 +- src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp | 397 +-- src/Plugins/RenX/RenX.Core/RenX_Server.cpp | 2682 ++++++++--------- src/Plugins/RenX/RenX.Core/RenX_Server.h | 166 +- src/Plugins/RenX/RenX.Core/RenX_Tags.cpp | 14 +- .../RenX/RenX.Greetings/RenX_Greetings.cpp | 56 +- .../RenX/RenX.Greetings/RenX_Greetings.h | 10 +- .../RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp | 201 +- src/Plugins/RenX/RenX.Ladder/RenX_Ladder.cpp | 88 +- src/Plugins/RenX/RenX.Listen/RenX_Listen.cpp | 24 +- src/Plugins/RenX/RenX.Medals/RenX_Medals.cpp | 15 +- .../RenX/RenX.ModSystem/RenX_ModSystem.cpp | 168 +- .../RenX/RenX.ModSystem/RenX_ModSystem.h | 20 +- .../RenX/RenX.ServerList/RenX_ServerList.cpp | 344 +-- .../RenX/RenX.ServerList/RenX_ServerList.h | 8 +- src/Plugins/RenX/RenX.Warn/RenX_Warn.cpp | 213 +- src/Plugins/RenX/RenX.Warn/RenX_Warn.h | 6 +- 42 files changed, 3475 insertions(+), 4171 deletions(-) diff --git a/src/Bot/include/Console_Command.h b/src/Bot/include/Console_Command.h index 7d79d6b..f2ff93e 100644 --- a/src/Bot/include/Console_Command.h +++ b/src/Bot/include/Console_Command.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2015 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -25,7 +25,6 @@ */ #include "Jupiter/GenericCommand.h" -#include "Jupiter/ArrayList.h" #include "Jupiter_Bot.h" class ConsoleCommand; @@ -36,8 +35,8 @@ class ConsoleCommand; #pragma warning(disable: 4251) #endif -/** Console command list */ -JUPITER_BOT_API extern Jupiter::ArrayList *consoleCommands; +/** Console command list; weak pointers */ +JUPITER_BOT_API extern std::vector& consoleCommands; /** * @brief Provides the basis for console commands. diff --git a/src/Bot/include/IRC_Bot.h b/src/Bot/include/IRC_Bot.h index e8b12a9..cd94cb7 100644 --- a/src/Bot/include/IRC_Bot.h +++ b/src/Bot/include/IRC_Bot.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2016 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -26,7 +26,6 @@ #include "Jupiter_Bot.h" #include "Jupiter/IRC_Client.h" -#include "Jupiter/ArrayList.h" #include "Jupiter/Rehash.h" #include "Jupiter/String.hpp" @@ -64,14 +63,6 @@ public: */ bool freeCommand(const Jupiter::ReadableString &trigger); - /** - * @brief Gets the index of a command. - * - * @param trigger Trigger of the command to find. - * @return Index of the first match for the trigger if found, -1 otherwise. - */ - int getCommandIndex(const Jupiter::ReadableString &trigger) const; - /** * @return Gets a command. * @@ -81,21 +72,21 @@ public: IRCCommand *getCommand(const Jupiter::ReadableString &trigger) const; /** - * @brief Creates and returns an ArrayList of IRC Commands with a specified access level. + * @brief Creates and returns a vector of IRC Commands with a specified access level. * * @param chan Channel which access levels are set. * @param access Access level to match. - * @return An ArrayList containing pointers to all of the matching commands. + * @return Vector containing pointers to all of the matching commands. */ - Jupiter::ArrayList getAccessCommands(Jupiter::IRC::Client::Channel *chan, int access); + std::vector getAccessCommands(Jupiter::IRC::Client::Channel *chan, int access); /** - * @brief Gets the triggers of all the commands in an ArrayList, and adds them to a space-deliminated string. + * @brief Gets the triggers of all the commands in a vector, and adds them to a space-deliminated string. * * @param cmds Commands to construct the string with. * @return A string containing the triggers of the commands in a space-deliminated list. */ - static Jupiter::StringL getTriggers(Jupiter::ArrayList &cmds); + static Jupiter::StringL getTriggers(std::vector &cmds); /** * @brief Reloads some settings. @@ -115,6 +106,9 @@ public: /** Destructor for IRC_Bot */ ~IRC_Bot(); + IRC_Bot& operator=(const IRC_Bot&) = delete; + IRC_Bot(const IRC_Bot&) = delete; + /** Overloaded events from Jupiter::IRC::Client */ protected: @@ -122,8 +116,8 @@ protected: /** Private members for internal usage */ private: - Jupiter::ArrayList commands; - Jupiter::StringS commandPrefix; + std::vector> m_commands; + Jupiter::StringS m_commandPrefix; }; /** Re-enable warnings */ diff --git a/src/Bot/include/IRC_Command.h b/src/Bot/include/IRC_Command.h index 4d2f19e..d3f025a 100644 --- a/src/Bot/include/IRC_Command.h +++ b/src/Bot/include/IRC_Command.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2016 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -26,7 +26,6 @@ #include "Jupiter/GenericCommand.h" #include "Jupiter/IRC_Client.h" -#include "Jupiter/ArrayList.h" #include "Jupiter/String.hpp" #include "Jupiter_Bot.h" #include "ServerManager.h" @@ -41,7 +40,7 @@ class IRCCommand; #endif /** IRC Master Command List */ -JUPITER_BOT_API extern Jupiter::ArrayList *IRCMasterCommandList; +JUPITER_BOT_API extern std::vector& IRCMasterCommandList; /** * @brief Provides the basis for IRC commands. @@ -152,21 +151,20 @@ public: /** Private members */ private: - int access; /** Default access level */ + int m_access; /** Default access level */ - struct TypeAccessPair - { + // Both of these vector sets could just be maps + struct TypeAccessPair { int type; int access; }; - Jupiter::ArrayList types; /** Access levels for channel types */ + std::vector m_types; /** Access levels for channel types */ - struct ChannelAccessPair - { + struct ChannelAccessPair { Jupiter::StringS channel; int access; }; - Jupiter::ArrayList channels; /** Access levels for specific channels */ + std::vector m_channels; /** Access levels for specific channels */ }; class JUPITER_BOT_API GenericCommandWrapperIRCCommand : public IRCCommand diff --git a/src/Bot/include/ServerManager.h b/src/Bot/include/ServerManager.h index 2abfecd..6605434 100644 --- a/src/Bot/include/ServerManager.h +++ b/src/Bot/include/ServerManager.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,9 +24,9 @@ * @brief Provides a system for controlling and affecting multiple IRC connections simultaneously. */ +#include #include "Jupiter_Bot.h" #include "Jupiter/Thinker.h" -#include "Jupiter/ArrayList.h" #include "Jupiter/Readable_String.h" /** Forward declarations */ @@ -161,12 +161,16 @@ public: */ virtual ~ServerManager(); + ServerManager() = default; + ServerManager& operator=(const ServerManager&) = delete; + ServerManager(const ServerManager&) = delete; + private: - /** Underlying ArrayList of servers */ - Jupiter::ArrayList servers; + /** Underlying vector of servers */ + std::vector> m_servers; /** Config to read data from */ - Jupiter::Config *m_config = Jupiter::g_config; + Jupiter::Config* m_config = Jupiter::g_config; }; /** Pointer to an instance of the server manager. Note: DO NOT DELETE OR FREE THIS POINTER. */ diff --git a/src/Bot/src/Console_Command.cpp b/src/Bot/src/Console_Command.cpp index 62debfd..c472ede 100644 --- a/src/Bot/src/Console_Command.cpp +++ b/src/Bot/src/Console_Command.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2015 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,33 +18,28 @@ #include "Console_Command.h" -Jupiter::ArrayList _consoleCommands; -Jupiter::ArrayList *consoleCommands = &_consoleCommands; +std::vector g_consoleCommands; +std::vector& consoleCommands = g_consoleCommands; -ConsoleCommand::ConsoleCommand() -{ - consoleCommands->add(this); +ConsoleCommand::ConsoleCommand() { + consoleCommands.push_back(this); } -ConsoleCommand::~ConsoleCommand() -{ - for (size_t i = 0; i != consoleCommands->size(); i++) - { - if (consoleCommands->get(i) == this) - { - consoleCommands->remove(i); +ConsoleCommand::~ConsoleCommand() { + for (auto itr = consoleCommands.begin(); itr != consoleCommands.end(); ++itr) { + if (*itr == this) { + consoleCommands.erase(itr); break; } } } -ConsoleCommand *getConsoleCommand(const Jupiter::ReadableString &trigger) -{ - for (size_t i = 0; i != consoleCommands->size(); i++) - { - ConsoleCommand *cmd = consoleCommands->get(i); - if (cmd->matches(trigger)) - return cmd; +ConsoleCommand* getConsoleCommand(const Jupiter::ReadableString &trigger) { + for (const auto& command : consoleCommands) { + if (command->matches(trigger)) { + return command; + } } + return nullptr; } \ No newline at end of file diff --git a/src/Bot/src/IRC_Bot.cpp b/src/Bot/src/IRC_Bot.cpp index 51a391f..cfe0a56 100644 --- a/src/Bot/src/IRC_Bot.cpp +++ b/src/Bot/src/IRC_Bot.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2017 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -27,94 +27,85 @@ using namespace Jupiter::literals; -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::IRC_Bot(Jupiter::Config *in_primary_section, Jupiter::Config *in_secondary_section) + : Client(in_primary_section, in_secondary_section) { + m_commandPrefix = this->readConfigValue("Prefix"_jrs); - for (size_t i = 0; i != IRCMasterCommandList->size(); i++) - IRC_Bot::commands.add(IRCMasterCommandList->get(i)->copy()); + for (const auto& command : IRCMasterCommandList) { + m_commands.emplace_back(command->copy()); + } - IRC_Bot::setCommandAccessLevels(); + setCommandAccessLevels(); } -IRC_Bot::~IRC_Bot() -{ - if (IRCCommand::selected_server == this) +IRC_Bot::~IRC_Bot() { + if (IRCCommand::selected_server == this) { IRCCommand::selected_server = nullptr; - if (IRCCommand::active_server == this) - IRCCommand::active_server = IRCCommand::selected_server; + } - IRC_Bot::commands.emptyAndDelete(); + if (IRCCommand::active_server == this) { + IRCCommand::active_server = IRCCommand::selected_server; + } } -void IRC_Bot::addCommand(IRCCommand *in_command) -{ - IRC_Bot::commands.add(in_command); - IRC_Bot::setCommandAccessLevels(in_command); +void IRC_Bot::addCommand(IRCCommand *in_command) { + m_commands.emplace_back(in_command); + setCommandAccessLevels(in_command); } -bool IRC_Bot::freeCommand(const Jupiter::ReadableString &trigger) -{ - for (size_t i = 0; i != IRC_Bot::commands.size(); i++) - { - if (IRC_Bot::commands.get(i)->matches(trigger)) - { - delete IRC_Bot::commands.remove(i); +bool IRC_Bot::freeCommand(const Jupiter::ReadableString &trigger) { + for (auto itr = m_commands.begin(); itr != m_commands.end(); ++itr) { + if ((*itr)->matches(trigger)) { + m_commands.erase(itr); return true; } } + return false; } -int IRC_Bot::getCommandIndex(const Jupiter::ReadableString &trigger) const -{ - for (size_t i = 0; i != IRC_Bot::commands.size(); i++) - if (IRC_Bot::commands.get(i)->matches(trigger)) - return i; - return -1; -} +IRCCommand* IRC_Bot::getCommand(const Jupiter::ReadableString &trigger) const { + for (const auto& command : m_commands) { + if (command->matches(trigger)) { + return command.get(); + } + } -IRCCommand *IRC_Bot::getCommand(const Jupiter::ReadableString &trigger) const -{ - int i = IRC_Bot::getCommandIndex(trigger); - if (i < 0) return nullptr; - return IRC_Bot::commands.get(i); + return nullptr; } -Jupiter::ArrayList IRC_Bot::getAccessCommands(Jupiter::IRC::Client::Channel *chan, int access) -{ - Jupiter::ArrayList r; - for (size_t i = 0; i != IRC_Bot::commands.size(); i++) - { - IRCCommand *cmd = IRC_Bot::commands.get(i); - if (cmd->getAccessLevel(chan) == access) - r.add(cmd); +std::vector IRC_Bot::getAccessCommands(Jupiter::IRC::Client::Channel *chan, int access) { + std::vector result; + for (const auto& command : m_commands) { + if (command->getAccessLevel(chan) == access) { + result.push_back(command.get()); + } } - return r; + + return result; } -Jupiter::StringL IRC_Bot::getTriggers(Jupiter::ArrayList &cmds) -{ - Jupiter::StringL r; - for (size_t i = 0; i < cmds.size(); i++) - { - r += cmds[i]->getTrigger(); - r += ' '; +// TODO: This isn't really needed on here +Jupiter::StringL IRC_Bot::getTriggers(std::vector &commands) { + Jupiter::StringL result; + for (const auto& command : commands) { + result += command->getTrigger(); + result += ' '; } - return r; + + return result; } -void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) -{ - auto set_command_access_levels = [this, in_command](Jupiter::Config *in_section) - { - if (in_section == nullptr) +void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) { + auto set_command_access_levels = [this, in_command](Jupiter::Config *in_section) { + if (in_section == nullptr) { return; + } Jupiter::Config *section = in_section->getSection("Commands"_jrs); - - if (section == nullptr) + if (section == nullptr) { return; + } for (auto& entry : section->getTable()) { size_t tmp_index; @@ -122,8 +113,7 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) IRCCommand *command; tmp_index = entry.first.find('.'); - if (tmp_index != Jupiter::INVALID_INDEX) - { + if (tmp_index != Jupiter::INVALID_INDEX) { // non-default access assignment tmp_key.set(entry.first.ptr(), tmp_index); @@ -131,16 +121,15 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) tmp_sub_key = entry.first; tmp_sub_key.shiftRight(tmp_index + 1); - if (tmp_sub_key.findi("Type."_jrs) == 0) - { + 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)) + if (command != nullptr && (in_command == nullptr || in_command == command)) { command->setAccessLevel(tmp_sub_key.asInt(), entry.second.asInt()); + } } - else if (tmp_sub_key.findi("Channel."_jrs) == 0) - { + 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) @@ -149,8 +138,7 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) command->setAccessLevel(tmp_sub_key, entry.second.asInt()); } } - else - { + else { // Assign access level to command (if command exists) command = this->getCommand(entry.first); if (command != nullptr && (in_command == nullptr || in_command == command)) @@ -159,48 +147,46 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command) }; }; - set_command_access_levels(this->getSecondaryConfigSection()); - set_command_access_levels(this->getPrimaryConfigSection()); + set_command_access_levels(getSecondaryConfigSection()); + set_command_access_levels(getPrimaryConfigSection()); } -void IRC_Bot::OnChat(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message) -{ +void IRC_Bot::OnChat(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message) { Channel *channel = this->getChannel(in_channel); - if (channel != nullptr && channel->getType() >= 0) - { + if (channel != nullptr && channel->getType() >= 0) { Jupiter::ReferenceString msg = message; - while (msg.isNotEmpty() && isspace(msg[0])) + while (msg.isNotEmpty() && isspace(msg[0])) { msg.shiftRight(1); + } - if (IRC_Bot::commandPrefix.size() <= msg.size()) - { + if (m_commandPrefix.size() <= msg.size()) { bool matchesPrefix = true; size_t i; - for (i = 0; i != IRC_Bot::commandPrefix.size(); i++) - { - if (toupper(msg.get(0)) != toupper(IRC_Bot::commandPrefix[i])) - { + for (i = 0; i != m_commandPrefix.size(); i++) { + if (toupper(msg.get(0)) != toupper(m_commandPrefix[i])) { matchesPrefix = false; break; } msg.shiftRight(1); } - if (matchesPrefix) - { + if (matchesPrefix) { Jupiter::ReferenceString command = Jupiter::ReferenceString::getWord(msg, 0, WHITESPACE);; Jupiter::ReferenceString parameters = Jupiter::ReferenceString::gotoWord(msg, 1, WHITESPACE); - IRCCommand *cmd = IRC_Bot::getCommand(command); - if (cmd != nullptr) - { + IRCCommand *cmd = getCommand(command); + if (cmd != nullptr) { IRCCommand::active_server = this; int command_access = cmd->getAccessLevel(channel); - if (command_access < 0) + if (command_access < 0) { this->sendNotice(nick, "Error: Command disabled."_jrs); - else if (Jupiter::IRC::Client::getAccessLevel(*channel, nick) < command_access) + } + else if (Jupiter::IRC::Client::getAccessLevel(*channel, nick) < command_access) { this->sendNotice(nick, "Access Denied."_jrs); - else + } + else { cmd->trigger(this, in_channel, nick, parameters); + } + IRCCommand::active_server = IRCCommand::selected_server; } } diff --git a/src/Bot/src/IRC_Command.cpp b/src/Bot/src/IRC_Command.cpp index e9cd602..74572fb 100644 --- a/src/Bot/src/IRC_Command.cpp +++ b/src/Bot/src/IRC_Command.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2016 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,42 +18,37 @@ #include "IRC_Command.h" -Jupiter::ArrayList _IRCMasterCommandList; -Jupiter::ArrayList *IRCMasterCommandList = &_IRCMasterCommandList; +std::vector g_IRCMasterCommandList; +std::vector& IRCMasterCommandList = g_IRCMasterCommandList; /** IRCCommand */ -IRCCommand::IRCCommand() -{ - IRCCommand::access = 0; - IRCMasterCommandList->add(this); +IRCCommand::IRCCommand() { + m_access = 0; + IRCMasterCommandList.push_back(this); } -IRCCommand::IRCCommand(const IRCCommand &command) -{ - IRCCommand::access = command.access; - size_t i; +IRCCommand::IRCCommand(const IRCCommand &command) { + m_access = command.m_access; - for (i = 0; i < command.channels.size(); i++) - IRCCommand::channels.add(new IRCCommand::ChannelAccessPair(*command.channels.get(i))); + for (const auto& channel : command.m_channels) { + m_channels.emplace_back(channel); + } - for (i = 0; i < command.types.size(); i++) - IRCCommand::types.add(new IRCCommand::TypeAccessPair(*command.types.get(i))); + for (const auto& type : command.m_types) { + m_types.emplace_back(type); + } } -IRCCommand::~IRCCommand() -{ - for (size_t i = 0; i != IRCMasterCommandList->size(); i++) - { - if (IRCMasterCommandList->get(i) == this) - { +IRCCommand::~IRCCommand() { + // Remove any weak references to this + for (auto itr = IRCMasterCommandList.begin(); itr != IRCMasterCommandList.end(); ++itr) { + if (*itr == this) { serverManager->removeCommand(this); - IRCMasterCommandList->remove(i); + IRCMasterCommandList.erase(itr); break; } } - IRCCommand::channels.emptyAndDelete(); - IRCCommand::types.emptyAndDelete(); } IRC_Bot *IRCCommand::active_server = nullptr; @@ -61,102 +56,92 @@ IRC_Bot *IRCCommand::selected_server = nullptr; // IRC Command Functions -int IRCCommand::getAccessLevel() -{ - return IRCCommand::access; +int IRCCommand::getAccessLevel() { + return m_access; } -int IRCCommand::getAccessLevel(int type) -{ - for (size_t i = 0; i != IRCCommand::types.size(); i++) - if (IRCCommand::types.get(i)->type == type) - return IRCCommand::types.get(i)->access; - return IRCCommand::access; +int IRCCommand::getAccessLevel(int type) { + for (const auto& pair : m_types) { + if (pair.type == type) { + return pair.access; + } + } + + return m_access; } -int IRCCommand::getAccessLevel(const Jupiter::ReadableString &channel) -{ - IRCCommand::ChannelAccessPair *pair; - for (size_t i = 0; i != IRCCommand::channels.size(); i++) - { - pair = IRCCommand::channels.get(i); - if (pair->channel.equalsi(channel)) - return pair->access; +int IRCCommand::getAccessLevel(const Jupiter::ReadableString &channel) { + for (const auto& pair : m_channels) { + if (pair.channel.equalsi(channel)) { + return pair.access; + } } - return IRCCommand::access; + + return m_access; } -int IRCCommand::getAccessLevel(Jupiter::IRC::Client::Channel *channel) -{ - IRCCommand::ChannelAccessPair *pair; - for (size_t i = 0; i != IRCCommand::channels.size(); i++) - { - pair = IRCCommand::channels.get(i); - if (pair->channel.equalsi(channel->getName())) - return pair->access; +int IRCCommand::getAccessLevel(Jupiter::IRC::Client::Channel *channel) { + for (const auto& pair : m_channels) { + if (pair.channel.equalsi(channel->getName())) { + return pair.access; + } } - for (size_t i = 0; i != IRCCommand::types.size(); i++) - if (IRCCommand::types.get(i)->type == channel->getType()) - return IRCCommand::types.get(i)->access; + for (const auto& pair : m_types) { + if (pair.type == channel->getType()) { + return pair.access; + } + } - return IRCCommand::access; + return m_access; } -void IRCCommand::setAccessLevel(int accessLevel) -{ - IRCCommand::access = accessLevel; +void IRCCommand::setAccessLevel(int accessLevel) { + m_access = accessLevel; } -void IRCCommand::setAccessLevel(int type, int accessLevel) -{ - IRCCommand::TypeAccessPair *pair = new IRCCommand::TypeAccessPair(); - pair->type = type; - pair->access = accessLevel; - IRCCommand::types.add(pair); +void IRCCommand::setAccessLevel(int type, int accessLevel) { + m_types.push_back({type, accessLevel}); } -void IRCCommand::setAccessLevel(const Jupiter::ReadableString &channel, int accessLevel) -{ - IRCCommand::ChannelAccessPair *pair = new IRCCommand::ChannelAccessPair(); - pair->channel = channel; - pair->access = accessLevel; - IRCCommand::channels.add(pair); +void IRCCommand::setAccessLevel(const Jupiter::ReadableString &channel, int accessLevel) { + m_channels.push_back({ channel, accessLevel }); } -void IRCCommand::create() -{ +void IRCCommand::create() { } /** GenericCommandWrapperIRCCommand */ -GenericCommandWrapperIRCCommand::GenericCommandWrapperIRCCommand(const GenericCommandWrapperIRCCommand &in_command) : IRCCommand(in_command) -{ - GenericCommandWrapperIRCCommand::m_command = in_command.m_command; +GenericCommandWrapperIRCCommand::GenericCommandWrapperIRCCommand(const GenericCommandWrapperIRCCommand &in_command) + : IRCCommand(in_command) { + m_command = in_command.m_command; // Copy triggers - for (size_t index = 0; index != GenericCommandWrapperIRCCommand::m_command->getTriggerCount(); ++index) - this->addTrigger(GenericCommandWrapperIRCCommand::m_command->getTrigger(index)); + for (size_t index = 0; index != m_command->getTriggerCount(); ++index) { + this->addTrigger(m_command->getTrigger(index)); + } } -GenericCommandWrapperIRCCommand::GenericCommandWrapperIRCCommand(Jupiter::GenericCommand &in_command) : IRCCommand() -{ - GenericCommandWrapperIRCCommand::m_command = &in_command; +GenericCommandWrapperIRCCommand::GenericCommandWrapperIRCCommand(Jupiter::GenericCommand &in_command) + : IRCCommand() { + m_command = &in_command; // Copy triggers - for (size_t index = 0; index != GenericCommandWrapperIRCCommand::m_command->getTriggerCount(); ++index) - this->addTrigger(GenericCommandWrapperIRCCommand::m_command->getTrigger(index)); + for (size_t index = 0; index != m_command->getTriggerCount(); ++index) { + this->addTrigger(m_command->getTrigger(index)); + } - if (serverManager != nullptr) + if (serverManager != nullptr) { serverManager->addCommand(this); + } } // GenericCommandWrapperIRCCommand functions -void GenericCommandWrapperIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nick, const Jupiter::ReadableString &in_parameters) -{ +void GenericCommandWrapperIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nick, const Jupiter::ReadableString &in_parameters) { Jupiter::GenericCommand::ResponseLine *del; - Jupiter::GenericCommand::ResponseLine *result = GenericCommandWrapperIRCCommand::m_command->trigger(in_parameters); + Jupiter::GenericCommand::ResponseLine *result = m_command->trigger(in_parameters); while (result != nullptr) { @@ -181,17 +166,14 @@ void GenericCommandWrapperIRCCommand::trigger(IRC_Bot *source, const Jupiter::Re } } -const Jupiter::ReadableString &GenericCommandWrapperIRCCommand::getHelp(const Jupiter::ReadableString ¶meters) -{ +const Jupiter::ReadableString &GenericCommandWrapperIRCCommand::getHelp(const Jupiter::ReadableString ¶meters) { return GenericCommandWrapperIRCCommand::m_command->getHelp(parameters); } -IRCCommand *GenericCommandWrapperIRCCommand::copy() -{ +IRCCommand *GenericCommandWrapperIRCCommand::copy() { return new GenericCommandWrapperIRCCommand(*this); } -const Jupiter::GenericCommand &GenericCommandWrapperIRCCommand::getGenericCommand() const -{ +const Jupiter::GenericCommand &GenericCommandWrapperIRCCommand::getGenericCommand() const { return *GenericCommandWrapperIRCCommand::m_command; } diff --git a/src/Bot/src/Main.cpp b/src/Bot/src/Main.cpp index 6c08ac3..1793547 100644 --- a/src/Bot/src/Main.cpp +++ b/src/Bot/src/Main.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2017 Jessica James. + * Copyright (C) 2013-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -44,8 +44,7 @@ std::chrono::steady_clock::time_point Jupiter::g_start_time = std::chrono::stead #define INPUT_BUFFER_SIZE 2048 -struct ConsoleInput -{ +struct ConsoleInput { Jupiter::String input; std::mutex input_mutex; bool awaiting_processing = false; @@ -53,23 +52,19 @@ struct ConsoleInput ConsoleInput() : input(INPUT_BUFFER_SIZE) {} } console_input; -void onTerminate() -{ +void onTerminate() { puts("Terminate signal received..."); } -void onExit() -{ +void onExit() { puts("Exit signal received; Cleaning up..."); Jupiter::Socket::cleanup(); puts("Clean-up complete. Closing..."); } -void inputLoop() -{ +void inputLoop() { std::string input; - while (ftell(stdin) != -1 || errno != EBADF) - { + while (ftell(stdin) != -1 || errno != EBADF) { std::getline(std::cin, input); check_input_processing: @@ -88,13 +83,45 @@ void inputLoop() } } -int main(int argc, const char **args) -{ +[[noreturn]] void main_loop() { + Jupiter::ReferenceString command; + size_t index; + while (1) { + index = 0; + while (index < Jupiter::plugins.size()) { + if (Jupiter::plugins[index]->shouldRemove() || Jupiter::plugins[index]->think() != 0) { + Jupiter::Plugin::free(index); + } + else { + ++index; + } + } + Jupiter::Timer::check(); + + if (console_input.input_mutex.try_lock()) { + if (console_input.awaiting_processing) { + console_input.awaiting_processing = false; + command = Jupiter::ReferenceString::getWord(console_input.input, 0, WHITESPACE); + + ConsoleCommand *cmd = getConsoleCommand(command); + if (cmd != nullptr) { + cmd->trigger(Jupiter::ReferenceString::gotoWord(console_input.input, 1, WHITESPACE)); + } + else { + printf("Error: Command \"%.*s\" not found." ENDL, command.size(), command.ptr()); + } + } + console_input.input_mutex.unlock(); + } + std::this_thread::sleep_for((std::chrono::milliseconds(1))); + } +} + +int main(int argc, const char **args) { atexit(onExit); std::set_terminate(onTerminate); std::thread inputThread(inputLoop); - Jupiter::ReferenceString command, plugins_directory, configs_directory; - size_t index; + Jupiter::ReferenceString plugins_directory, configs_directory; #if defined SIGPIPE std::signal(SIGPIPE, SIG_IGN); @@ -110,10 +137,8 @@ int main(int argc, const char **args) puts(Jupiter::copyright); const char *configFileName = "Config.ini"; - for (int i = 1; i < argc; i++) - { - if ("-help"_jrs.equalsi(args[i])) - { + for (int i = 1; i < argc; i++) { + if ("-help"_jrs.equalsi(args[i])) { puts("Help coming soon, to a theatre near you!"); return 0; } @@ -132,8 +157,7 @@ int main(int argc, const char **args) std::chrono::steady_clock::time_point load_start = std::chrono::steady_clock::now(); puts("Loading config file..."); - if (!o_config.read(configFileName)) - { + if (!o_config.read(configFileName)) { puts("Unable to read config file. Closing..."); exit(0); } @@ -148,14 +172,12 @@ int main(int argc, const char **args) if (configs_directory.isEmpty()) configs_directory = o_config.get("ConfigsDirectory"_jrs); - if (plugins_directory.isNotEmpty()) - { + if (plugins_directory.isNotEmpty()) { Jupiter::Plugin::setDirectory(plugins_directory); printf("Plugins will be loaded from \"%.*s\"." ENDL, plugins_directory.size(), plugins_directory.ptr()); } - if (configs_directory.isNotEmpty()) - { + if (configs_directory.isNotEmpty()) { Jupiter::Plugin::setConfigDirectory(configs_directory); printf("Plugin configs will be loaded from \"%.*s\"." ENDL, configs_directory.size(), configs_directory.ptr()); } @@ -164,16 +186,14 @@ int main(int argc, const char **args) const Jupiter::ReadableString &pluginList = o_config.get("Plugins"_jrs); if (pluginList.isEmpty()) puts("No plugins to load!"); - else - { + else { // initialize plugins unsigned int nPlugins = pluginList.wordCount(WHITESPACE); printf("Attempting to load %u plugins..." ENDL, nPlugins); bool load_success; - for (unsigned int i = 0; i < nPlugins; i++) - { + for (unsigned int i = 0; i < nPlugins; i++) { Jupiter::ReferenceString plugin = Jupiter::ReferenceString::getWord(pluginList, i, WHITESPACE); load_start = std::chrono::steady_clock::now(); @@ -187,43 +207,20 @@ int main(int argc, const char **args) } // OnPostInitialize - for (index = 0; index != Jupiter::plugins->size(); ++index) - Jupiter::plugins->get(index)->OnPostInitialize(); + for (const auto& plugin : Jupiter::plugins) { + plugin->OnPostInitialize(); + } } printf("Initialization completed in %f milliseconds." ENDL, static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - Jupiter::g_start_time).count()) / 1000.0 ); - if (consoleCommands->size() > 0) - printf("%zu Console Commands have been initialized%s" ENDL, consoleCommands->size(), getConsoleCommand("help"_jrs) == nullptr ? "." : "; type \"help\" for more information."); - if (IRCMasterCommandList->size() > 0) - printf("%zu IRC Commands have been loaded into the master list." ENDL, IRCMasterCommandList->size()); - - while (1) - { - index = 0; - while (index < Jupiter::plugins->size()) - if (Jupiter::plugins->get(index)->shouldRemove() || Jupiter::plugins->get(index)->think() != 0) - Jupiter::Plugin::free(index); - else - ++index; - Jupiter::Timer::check(); - - if (console_input.input_mutex.try_lock()) - { - if (console_input.awaiting_processing) - { - console_input.awaiting_processing = false; - command = Jupiter::ReferenceString::getWord(console_input.input, 0, WHITESPACE); - - ConsoleCommand *cmd = getConsoleCommand(command); - if (cmd != nullptr) - cmd->trigger(Jupiter::ReferenceString::gotoWord(console_input.input, 1, WHITESPACE)); - else - printf("Error: Command \"%.*s\" not found." ENDL, command.size(), command.ptr()); - } - console_input.input_mutex.unlock(); - } - std::this_thread::sleep_for((std::chrono::milliseconds(1))); + if (!consoleCommands.empty()) { + printf("%zu Console Commands have been initialized%s" ENDL, consoleCommands.size(), getConsoleCommand("help"_jrs) == nullptr ? "." : "; type \"help\" for more information."); } + if (!IRCMasterCommandList.empty()) { + printf("%zu IRC Commands have been loaded into the master list." ENDL, IRCMasterCommandList.size()); + } + + main_loop(); return 0; } \ No newline at end of file diff --git a/src/Bot/src/ServerManager.cpp b/src/Bot/src/ServerManager.cpp index f62e042..2df352c 100644 --- a/src/Bot/src/ServerManager.cpp +++ b/src/Bot/src/ServerManager.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2016 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,148 +23,129 @@ using namespace Jupiter::literals; -ServerManager _serverManager; -ServerManager *serverManager = &_serverManager; +ServerManager g_serverManager; +ServerManager *serverManager = &g_serverManager; -int ServerManager::think() -{ - for (size_t i = 0; i < ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); - if (server->think() != 0) delete ServerManager::servers.remove(i); +int ServerManager::think() { + for (auto itr = m_servers.begin(); itr != m_servers.end();) { + if ((*itr)->think() != 0) { + itr = m_servers.erase(itr + 1); + continue; + } + ++itr; } - return ServerManager::servers.size() != 0; + + return m_servers.size() != 0; } -size_t ServerManager::addCommand(IRCCommand *command) -{ - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); +size_t ServerManager::addCommand(IRCCommand *command) { + for (const auto& server : m_servers) { server->addCommand(command->copy()); } - return ServerManager::servers.size(); + + return m_servers.size(); } -size_t ServerManager::removeCommand(IRCCommand *command) -{ - size_t r = 0; - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); - if (server->freeCommand(command->getTrigger())) r++; +size_t ServerManager::removeCommand(IRCCommand *command) { + size_t result = 0; + for (const auto& server : m_servers) { + if (server->freeCommand(command->getTrigger())) { + ++result; + } } - return r; + + return result; } -size_t ServerManager::removeCommand(const Jupiter::ReadableString &command) -{ - size_t r = 0; - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); - if (server->freeCommand(command)) r++; +size_t ServerManager::removeCommand(const Jupiter::ReadableString &command) { + size_t result = 0; + for (const auto& server : m_servers) { + if (server->freeCommand(command)) { + ++result; + } } - return r; -} -void ServerManager::OnConfigRehash() -{ - IRC_Bot *server; - for (size_t index = 0; index != ServerManager::servers.size(); ++index) - { - server = ServerManager::servers.get(index); + return result; +} +void ServerManager::OnConfigRehash() { + for (const auto& server : m_servers) { server->setPrimaryConfigSection(m_config->getSection(server->getConfigSection())); server->setSecondaryConfigSection(m_config->getSection("Defualt"_jrs)); server->setCommandAccessLevels(); } } -size_t ServerManager::syncCommands() -{ - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); +size_t ServerManager::syncCommands() { + for (const auto& server : m_servers) { server->setCommandAccessLevels(); } - return ServerManager::servers.size(); + + return m_servers.size(); } -IRC_Bot *ServerManager::getServer(const Jupiter::ReadableString &serverConfig) -{ - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); - if (server->getConfigSection().equalsi(serverConfig)) return server; +IRC_Bot *ServerManager::getServer(const Jupiter::ReadableString &serverConfig) { + for (const auto& server : m_servers) { + if (server->getConfigSection().equalsi(serverConfig)) { + return server.get(); + } } + return nullptr; } -IRC_Bot *ServerManager::getServer(size_t serverIndex) -{ - if (serverIndex < ServerManager::servers.size()) return ServerManager::servers.get(serverIndex); +IRC_Bot *ServerManager::getServer(size_t serverIndex) { + if (serverIndex < m_servers.size()) { + return m_servers[serverIndex].get(); + } + return nullptr; } -bool ServerManager::addServer(const Jupiter::ReadableString &serverConfig) -{ - IRC_Bot *server = new IRC_Bot(m_config->getSection(serverConfig), m_config->getSection("Default"_jrs)); - if (server->connect()) - { - ServerManager::servers.add(server); +bool ServerManager::addServer(const Jupiter::ReadableString &serverConfig) { + auto server = std::make_unique(m_config->getSection(serverConfig), m_config->getSection("Default"_jrs)); + if (server->connect()) { + m_servers.push_back(std::move(server)); return true; } - else - { - delete server; - return false; - } + + return false; } -bool ServerManager::freeServer(size_t serverIndex) -{ - if (serverIndex < ServerManager::servers.size()) - { - delete ServerManager::servers.remove(serverIndex); +bool ServerManager::freeServer(size_t serverIndex) { + if (serverIndex < m_servers.size()) { + m_servers.erase(m_servers.begin() + serverIndex); return true; } + return false; } -bool ServerManager::freeServer(IRC_Bot *server) -{ - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - if (ServerManager::servers.get(i) == server) - { - delete ServerManager::servers.remove(i); +bool ServerManager::freeServer(IRC_Bot *server) { + for (auto itr = m_servers.begin(); itr != m_servers.end(); ++itr) { + if (itr->get() == server) { + m_servers.erase(itr); return true; } } + return false; } -bool ServerManager::freeServer(const Jupiter::ReadableString &serverConfig) -{ - for (size_t i = 0; i != ServerManager::servers.size(); i++) - { - IRC_Bot *server = ServerManager::servers.get(i); - if (server->getConfigSection().equalsi(serverConfig)) - { - delete ServerManager::servers.remove(i); +bool ServerManager::freeServer(const Jupiter::ReadableString &serverConfig) { + for (auto itr = m_servers.begin(); itr != m_servers.end(); ++itr) { + if ((*itr)->getConfigSection().equalsi(serverConfig)) { + m_servers.erase(itr); return true; } } + return false; } -size_t ServerManager::size() -{ - return ServerManager::servers.size(); +size_t ServerManager::size() { + return m_servers.size(); } -ServerManager::~ServerManager() -{ - ServerManager::servers.emptyAndDelete(); +ServerManager::~ServerManager() { } \ No newline at end of file diff --git a/src/Jupiter b/src/Jupiter index 22d6097..3a11bda 160000 --- a/src/Jupiter +++ b/src/Jupiter @@ -1 +1 @@ -Subproject commit 22d6097d595330b5dccd6d322d4f09bf8dd4ca41 +Subproject commit 3a11bda36d30ce285604928ece72418af7fb921d diff --git a/src/Plugins/CoreCommands/CoreCommands.cpp b/src/Plugins/CoreCommands/CoreCommands.cpp index db0b318..7f880ba 100644 --- a/src/Plugins/CoreCommands/CoreCommands.cpp +++ b/src/Plugins/CoreCommands/CoreCommands.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,7 +18,6 @@ #include #include "Jupiter/Functions.h" -#include "Jupiter/ArrayList.h" #include "CoreCommands.h" #include "IRC_Bot.h" @@ -26,37 +25,33 @@ using namespace Jupiter::literals; // Help Console Command -HelpConsoleCommand::HelpConsoleCommand() -{ +HelpConsoleCommand::HelpConsoleCommand() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("help")); } -void HelpConsoleCommand::trigger(const Jupiter::ReadableString ¶meters) -{ - if (parameters.isEmpty()) - { +void HelpConsoleCommand::trigger(const Jupiter::ReadableString ¶meters) { + if (parameters.isEmpty()) { fputs("Supported commands:", stdout); - for (size_t i = 0; i != consoleCommands->size(); i++) - { + for (const auto& command : consoleCommands) { fputc(' ', stdout); - consoleCommands->get(i)->getTrigger().print(stdout); + command->getTrigger().print(stdout); } printf(ENDL "%s - %s" ENDL, Jupiter::version, Jupiter::copyright); puts("For command-specific help, use: help "); + return; } - else - { - Jupiter::ReferenceString command = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE); - ConsoleCommand *cmd = getConsoleCommand(command); - if (cmd != nullptr) - cmd->getHelp(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)).println(stdout); - else - printf("Error: Command \"%.*s\" not found." ENDL, command.size(), command.ptr()); + + Jupiter::ReferenceString command = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE); + ConsoleCommand *cmd = getConsoleCommand(command); + if (cmd == nullptr) { + printf("Error: Command \"%.*s\" not found." ENDL, command.size(), command.ptr()); + return; } + + cmd->getHelp(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)).println(stdout); } -const Jupiter::ReadableString &HelpConsoleCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &HelpConsoleCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Lists commands, or sends command-specific help. Syntax: help [command]"); return defaultHelp; } @@ -65,13 +60,11 @@ CONSOLE_COMMAND_INIT(HelpConsoleCommand) // Help IRC Command. -void HelpIRCCommand::create() -{ +void HelpIRCCommand::create() { this->addTrigger("help"_jrs); } -void HelpIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void HelpIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *channel = source->getChannel(in_channel); if (channel != nullptr) { @@ -80,7 +73,7 @@ void HelpIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &in_ { for (int i = 0; i <= access; i++) { - Jupiter::ArrayList cmds = source->getAccessCommands(channel, i); + auto cmds = source->getAccessCommands(channel, i); if (cmds.size() != 0) { Jupiter::StringL triggers = source->getTriggers(cmds); @@ -109,8 +102,7 @@ void HelpIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &in_ } } -const Jupiter::ReadableString &HelpIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &HelpIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Syntax: help [command]"); return defaultHelp; } @@ -119,8 +111,7 @@ IRC_COMMAND_INIT(HelpIRCCommand) // Version Command -VersionGenericCommand::VersionGenericCommand() -{ +VersionGenericCommand::VersionGenericCommand() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("version")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("versioninfo")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("copyright")); @@ -129,15 +120,13 @@ VersionGenericCommand::VersionGenericCommand() this->addTrigger(STRING_LITERAL_AS_REFERENCE("clientinfo")); } -Jupiter::GenericCommand::ResponseLine *VersionGenericCommand::trigger(const Jupiter::ReadableString ¶meters) -{ +Jupiter::GenericCommand::ResponseLine *VersionGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { Jupiter::GenericCommand::ResponseLine *ret = new Jupiter::GenericCommand::ResponseLine("Version: "_jrs + Jupiter::ReferenceString(Jupiter::version), GenericCommand::DisplayType::PublicSuccess); ret->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::ReferenceString(Jupiter::copyright), GenericCommand::DisplayType::PublicSuccess); return ret; } -const Jupiter::ReadableString &VersionGenericCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &VersionGenericCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Displays version and copyright information"); return defaultHelp; } @@ -147,13 +136,11 @@ GENERIC_COMMAND_AS_CONSOLE_COMMAND(VersionGenericCommand) // Rehash Command -RehashGenericCommand::RehashGenericCommand() -{ +RehashGenericCommand::RehashGenericCommand() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("rehash")); } -Jupiter::GenericCommand::ResponseLine *RehashGenericCommand::trigger(const Jupiter::ReadableString ¶meters) -{ +Jupiter::GenericCommand::ResponseLine *RehashGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { unsigned int r = Jupiter::rehash(); if (r == 0) @@ -162,8 +149,7 @@ Jupiter::GenericCommand::ResponseLine *RehashGenericCommand::trigger(const Jupit return new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("%u of %u objects failed to successfully rehash.", r, Jupiter::getRehashableCount()), GenericCommand::DisplayType::PublicError); } -const Jupiter::ReadableString &RehashGenericCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RehashGenericCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Rehashes configuration data from a file. Syntax: rehash [file]"); return defaultHelp; } @@ -174,7 +160,6 @@ GENERIC_COMMAND_AS_CONSOLE_COMMAND(RehashGenericCommand) // Plugin instantiation and entry point. CoreCommandsPlugin pluginInstance; -extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() -{ +extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() { return &pluginInstance; } diff --git a/src/Plugins/IRC.Core/IRC_Core.cpp b/src/Plugins/IRC.Core/IRC_Core.cpp index 27609bf..20707ef 100644 --- a/src/Plugins/IRC.Core/IRC_Core.cpp +++ b/src/Plugins/IRC.Core/IRC_Core.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2016 Jessica James. + * Copyright (C) 2016-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,57 +23,48 @@ using namespace Jupiter::literals; -IRCCorePlugin::~IRCCorePlugin() -{ - IRCCorePlugin::m_wrapped_commands.emptyAndDelete(); +IRCCorePlugin::~IRCCorePlugin() { } -bool IRCCorePlugin::initialize() -{ +bool IRCCorePlugin::initialize() { const Jupiter::ReadableString &serverList = this->config.get("Servers"_jrs); - if (serverList != nullptr) - { + if (serverList != nullptr) { serverManager->setConfig(this->config); unsigned int server_count = serverList.wordCount(WHITESPACE); - for (unsigned int index = 0; index != server_count; ++index) + for (unsigned int index = 0; index != server_count; ++index) { serverManager->addServer(Jupiter::ReferenceString::getWord(serverList, index, WHITESPACE)); + } } return true; } -int IRCCorePlugin::OnRehash() -{ +int IRCCorePlugin::OnRehash() { Jupiter::Plugin::OnRehash(); serverManager->OnConfigRehash(); return 0; } -int IRCCorePlugin::think() -{ +int IRCCorePlugin::think() { serverManager->think(); return 0; } -void IRCCorePlugin::OnGenericCommandAdd(Jupiter::GenericCommand &in_command) -{ - IRCCorePlugin::m_wrapped_commands.add(new GenericCommandWrapperIRCCommand(in_command)); +void IRCCorePlugin::OnGenericCommandAdd(Jupiter::GenericCommand &in_command) { + m_wrapped_commands.emplace_back(in_command); } -void IRCCorePlugin::OnGenericCommandRemove(Jupiter::GenericCommand &in_command) -{ - for (size_t index = 0; index != IRCCorePlugin::m_wrapped_commands.size(); ++index) - if (&IRCCorePlugin::m_wrapped_commands.get(index)->getGenericCommand() == &in_command) - { - delete IRCCorePlugin::m_wrapped_commands.remove(index); +void IRCCorePlugin::OnGenericCommandRemove(Jupiter::GenericCommand &in_command) { + for (auto itr = m_wrapped_commands.begin(); itr != m_wrapped_commands.end(); ++itr) { + if (&itr->getGenericCommand() == &in_command) { + m_wrapped_commands.erase(itr); return; } + } } - - // Plugin instantiation and entry point. IRCCorePlugin pluginInstance; diff --git a/src/Plugins/IRC.Core/IRC_Core.h b/src/Plugins/IRC.Core/IRC_Core.h index 935c725..bf2192e 100644 --- a/src/Plugins/IRC.Core/IRC_Core.h +++ b/src/Plugins/IRC.Core/IRC_Core.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2016 Jessica James. + * Copyright (C) 2016-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -58,7 +58,7 @@ public: ~IRCCorePlugin(); private: - Jupiter::ArrayList m_wrapped_commands; + std::vector m_wrapped_commands; }; #endif // _IRC_CORE_H_HEADER \ No newline at end of file diff --git a/src/Plugins/PluginManager/PluginManager.cpp b/src/Plugins/PluginManager/PluginManager.cpp index 0c6c292..809304e 100644 --- a/src/Plugins/PluginManager/PluginManager.cpp +++ b/src/Plugins/PluginManager/PluginManager.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2016 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,45 +23,47 @@ using namespace Jupiter::literals; // Plugin Generic Command -PluginGenericCommand::PluginGenericCommand() -{ +PluginGenericCommand::PluginGenericCommand() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("plugin")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("plugins")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("module")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("modules")); } -Jupiter::GenericCommand::ResponseLine *PluginGenericCommand::trigger(const Jupiter::ReadableString ¶meters) -{ - Jupiter::GenericCommand::ResponseLine *ret = new Jupiter::GenericCommand::ResponseLine(); - if (parameters.isEmpty() || parameters.matchi("list*")) - { - Jupiter::GenericCommand::ResponseLine *line = ret->set(Jupiter::String::Format("There are %u plugins loaded:", Jupiter::plugins->size()), GenericCommand::DisplayType::PublicSuccess); - for (size_t i = 0; i != Jupiter::plugins->size(); i++) - { - line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::plugins->get(i)->getName(), GenericCommand::DisplayType::PublicSuccess); +Jupiter::GenericCommand::ResponseLine *PluginGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { + Jupiter::GenericCommand::ResponseLine *result = new Jupiter::GenericCommand::ResponseLine(); + if (parameters.isEmpty() || parameters.matchi("list*")) { + Jupiter::GenericCommand::ResponseLine *line = result->set(Jupiter::String::Format("There are %u plugins loaded:", Jupiter::plugins.size()), GenericCommand::DisplayType::PublicSuccess); + for (auto& plugin : Jupiter::plugins) { + line->next = new Jupiter::GenericCommand::ResponseLine(plugin->getName(), GenericCommand::DisplayType::PublicSuccess); line = line->next; } - return ret; + + return result; } - if (parameters.matchi("load *")) - { - if (Jupiter::Plugin::load(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)) == nullptr) - return ret->set("Error: Failed to load plugin."_jrs, GenericCommand::DisplayType::PublicError); - else - return ret->set("Plugin successfully loaded."_jrs, GenericCommand::DisplayType::PublicSuccess); + if (parameters.matchi("load *")) { + if (Jupiter::Plugin::load(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)) == nullptr) { + return result->set("Error: Failed to load plugin."_jrs, GenericCommand::DisplayType::PublicError); + } + + return result->set("Plugin successfully loaded."_jrs, GenericCommand::DisplayType::PublicSuccess); } + if (parameters.matchi("unload *")) { Jupiter::ReferenceString pluginName = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE); - if (Jupiter::Plugin::get(pluginName) == nullptr) - return ret->set("Error: Plugin does not exist."_jrs, GenericCommand::DisplayType::PublicError); - if (Jupiter::Plugin::free(pluginName) == false) - return ret->set("Error: Failed to unload plugin."_jrs, GenericCommand::DisplayType::PublicError); - return ret->set("Plugin successfully unloaded."_jrs, GenericCommand::DisplayType::PublicSuccess); + if (Jupiter::Plugin::get(pluginName) == nullptr) { + return result->set("Error: Plugin does not exist."_jrs, GenericCommand::DisplayType::PublicError); + } + + if (Jupiter::Plugin::free(pluginName) == false) { + return result->set("Error: Failed to unload plugin."_jrs, GenericCommand::DisplayType::PublicError); + } + + return result->set("Plugin successfully unloaded."_jrs, GenericCommand::DisplayType::PublicSuccess); } - return ret->set("Error: Invalid Syntax. Syntax: plugin {[list], , }"_jrs, GenericCommand::DisplayType::PrivateError); + return result->set("Error: Invalid Syntax. Syntax: plugin {[list], , }"_jrs, GenericCommand::DisplayType::PrivateError); } const Jupiter::ReadableString &PluginGenericCommand::getHelp(const Jupiter::ReadableString ¶meters) @@ -71,12 +73,17 @@ const Jupiter::ReadableString &PluginGenericCommand::getHelp(const Jupiter::Read static STRING_LITERAL_AS_NAMED_REFERENCE(listHelp, "Lists all of the plugins currently loaded. Syntax: plugin [list]"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Manages plugins. Syntax: plugin {[list], , }"); - if (parameters.equalsi(STRING_LITERAL_AS_REFERENCE("load"))) + if (parameters.equalsi(STRING_LITERAL_AS_REFERENCE("load"))) { return loadHelp; - if (parameters.equalsi(STRING_LITERAL_AS_REFERENCE("unload"))) + } + + if (parameters.equalsi(STRING_LITERAL_AS_REFERENCE("unload"))) { return unloadHelp; - if (parameters.equalsi(STRING_LITERAL_AS_REFERENCE("list"))) + } + + if (parameters.equalsi(STRING_LITERAL_AS_REFERENCE("list"))) { return listHelp; + } return defaultHelp; } diff --git a/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp b/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp index ef57535..e65e419 100644 --- a/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp +++ b/src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -36,87 +36,76 @@ using namespace jessilib::literals; const Jupiter::ReferenceString RxCommandsSection = "RenX.Commands"_jrs; -inline bool togglePhasing(RenX::Server *server, bool newState) -{ +bool togglePhasing(RenX::Server *server, bool newState) { server->varData[RxCommandsSection].set("phasing"_jrs, newState ? "true"_jrs : "false"_jrs); return newState; } -inline bool togglePhasing(RenX::Server *server) -{ +bool togglePhasing(RenX::Server *server) { return togglePhasing(server, !server->varData[RxCommandsSection].get("phasing"_jrs, false)); } -inline void onDie(RenX::Server &server, const RenX::PlayerInfo &player) -{ - if (player.isBot && server.varData[RxCommandsSection].get("phasing"_jrs, false)) +void onDie(RenX::Server &server, const RenX::PlayerInfo &player) { + if (player.isBot && server.varData[RxCommandsSection].get("phasing"_jrs, false)) { server.kickPlayer(player, Jupiter::StringS::empty); + } } -void RenX_CommandsPlugin::RenX_OnSuicide(RenX::Server &server, const RenX::PlayerInfo &player, const Jupiter::ReadableString &) -{ +void RenX_CommandsPlugin::RenX_OnSuicide(RenX::Server &server, const RenX::PlayerInfo &player, const Jupiter::ReadableString &) { onDie(server, player); } -void RenX_CommandsPlugin::RenX_OnKill(RenX::Server &server, const RenX::PlayerInfo &, const RenX::PlayerInfo &victim, const Jupiter::ReadableString &) -{ +void RenX_CommandsPlugin::RenX_OnKill(RenX::Server &server, const RenX::PlayerInfo &, const RenX::PlayerInfo &victim, const Jupiter::ReadableString &) { onDie(server, victim); } -void RenX_CommandsPlugin::RenX_OnDie(RenX::Server &server, const RenX::PlayerInfo &player, const Jupiter::ReadableString &) -{ +void RenX_CommandsPlugin::RenX_OnDie(RenX::Server &server, const RenX::PlayerInfo &player, const Jupiter::ReadableString &) { onDie(server, player); } -bool RenX_CommandsPlugin::initialize() -{ +bool RenX_CommandsPlugin::initialize() { auto default_tban_time = this->config.get("DefaultTBanTime"_jrs, "1d"_jrs); auto max_tban_time = this->config.get("MaxTBanTime"_jrs, "1w"_jrs); - RenX_CommandsPlugin::m_defaultTempBanTime = jessilib::duration_from_string(default_tban_time.ptr(), default_tban_time.ptr() + default_tban_time.size()).duration; - RenX_CommandsPlugin::m_maxTempBanTime = std::max(jessilib::duration_from_string(max_tban_time.ptr(), max_tban_time.ptr() + max_tban_time.size()).duration, m_defaultTempBanTime); - RenX_CommandsPlugin::playerInfoFormat = this->config.get("PlayerInfoFormat"_jrs, IRCCOLOR "03[Player Info]" IRCCOLOR "{TCOLOR} Name: " IRCBOLD "{RNAME}" IRCBOLD " - ID: {ID} - Team: " IRCBOLD "{TEAML}" IRCBOLD " - Vehicle Kills: {VEHICLEKILLS} - Building Kills {BUILDINGKILLS} - Kills {KILLS} - Deaths: {DEATHS} - KDR: {KDR} - Access: {ACCESS}"_jrs); - RenX_CommandsPlugin::adminPlayerInfoFormat = this->config.get("AdminPlayerInfoFormat"_jrs, Jupiter::StringS::Format("%.*s - IP: " IRCBOLD "{IP}" IRCBOLD " - HWID: " IRCBOLD "{HWID}" IRCBOLD " - RDNS: " IRCBOLD "{RDNS}" IRCBOLD " - Steam ID: " IRCBOLD "{STEAM}", RenX_CommandsPlugin::playerInfoFormat.size(), RenX_CommandsPlugin::playerInfoFormat.ptr())); - RenX_CommandsPlugin::buildingInfoFormat = this->config.get("BuildingInfoFormat"_jrs, ""_jrs IRCCOLOR + RenX::tags->buildingTeamColorTag + RenX::tags->buildingNameTag + IRCCOLOR " - " IRCCOLOR "07"_jrs + RenX::tags->buildingHealthPercentageTag + "%"_jrs); - RenX_CommandsPlugin::staffTitle = this->config.get("StaffTitle"_jrs, "Moderator"_jrs); - - RenX::sanitizeTags(RenX_CommandsPlugin::playerInfoFormat); - RenX::sanitizeTags(RenX_CommandsPlugin::adminPlayerInfoFormat); - RenX::sanitizeTags(RenX_CommandsPlugin::buildingInfoFormat); + m_defaultTempBanTime = jessilib::duration_from_string(default_tban_time.ptr(), default_tban_time.ptr() + default_tban_time.size()).duration; + m_maxTempBanTime = std::max(jessilib::duration_from_string(max_tban_time.ptr(), max_tban_time.ptr() + max_tban_time.size()).duration, m_defaultTempBanTime); + m_playerInfoFormat = this->config.get("PlayerInfoFormat"_jrs, IRCCOLOR "03[Player Info]" IRCCOLOR "{TCOLOR} Name: " IRCBOLD "{RNAME}" IRCBOLD " - ID: {ID} - Team: " IRCBOLD "{TEAML}" IRCBOLD " - Vehicle Kills: {VEHICLEKILLS} - Building Kills {BUILDINGKILLS} - Kills {KILLS} - Deaths: {DEATHS} - KDR: {KDR} - Access: {ACCESS}"_jrs); + m_adminPlayerInfoFormat = this->config.get("AdminPlayerInfoFormat"_jrs, Jupiter::StringS::Format("%.*s - IP: " IRCBOLD "{IP}" IRCBOLD " - HWID: " IRCBOLD "{HWID}" IRCBOLD " - RDNS: " IRCBOLD "{RDNS}" IRCBOLD " - Steam ID: " IRCBOLD "{STEAM}", m_playerInfoFormat.size(), m_playerInfoFormat.ptr())); + m_buildingInfoFormat = this->config.get("BuildingInfoFormat"_jrs, ""_jrs IRCCOLOR + RenX::tags->buildingTeamColorTag + RenX::tags->buildingNameTag + IRCCOLOR " - " IRCCOLOR "07"_jrs + RenX::tags->buildingHealthPercentageTag + "%"_jrs); + m_staffTitle = this->config.get("StaffTitle"_jrs, "Moderator"_jrs); + + RenX::sanitizeTags(m_playerInfoFormat); + RenX::sanitizeTags(m_adminPlayerInfoFormat); + RenX::sanitizeTags(m_buildingInfoFormat); return true; } -int RenX_CommandsPlugin::OnRehash() -{ +int RenX_CommandsPlugin::OnRehash() { RenX::Plugin::OnRehash(); return this->initialize() ? 0 : -1; } std::chrono::seconds RenX_CommandsPlugin::getDefaultTBanTime() const { - return RenX_CommandsPlugin::m_defaultTempBanTime; + return m_defaultTempBanTime; } std::chrono::seconds RenX_CommandsPlugin::getMaxTBanTime() const { - return RenX_CommandsPlugin::m_maxTempBanTime; + return m_maxTempBanTime; } -const Jupiter::ReadableString &RenX_CommandsPlugin::getPlayerInfoFormat() const -{ - return RenX_CommandsPlugin::playerInfoFormat; +const Jupiter::ReadableString &RenX_CommandsPlugin::getPlayerInfoFormat() const { + return m_playerInfoFormat; } -const Jupiter::ReadableString &RenX_CommandsPlugin::getAdminPlayerInfoFormat() const -{ - return RenX_CommandsPlugin::adminPlayerInfoFormat; +const Jupiter::ReadableString &RenX_CommandsPlugin::getAdminPlayerInfoFormat() const { + return m_adminPlayerInfoFormat; } -const Jupiter::ReadableString &RenX_CommandsPlugin::getBuildingInfoFormat() const -{ - return RenX_CommandsPlugin::buildingInfoFormat; +const Jupiter::ReadableString &RenX_CommandsPlugin::getBuildingInfoFormat() const { + return m_buildingInfoFormat; } -const Jupiter::ReadableString &RenX_CommandsPlugin::getStaffTitle() const -{ - return RenX_CommandsPlugin::staffTitle; +const Jupiter::ReadableString &RenX_CommandsPlugin::getStaffTitle() const { + return m_staffTitle; } // Plugin instantiation and entry point. @@ -126,28 +115,31 @@ RenX_CommandsPlugin pluginInstance; // RawRCON Console Command -RawRCONConsoleCommand::RawRCONConsoleCommand() -{ +RawRCONConsoleCommand::RawRCONConsoleCommand() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("rrcon")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("rawrcon")); } -void RawRCONConsoleCommand::trigger(const Jupiter::ReadableString ¶meters) -{ +void RawRCONConsoleCommand::trigger(const Jupiter::ReadableString ¶meters) { + if (parameters.isEmpty()) { + puts("Error: Too Few Parameters. Syntax: rrcon "); + return; + } + + const auto& servers = RenX::getCore()->getServers(); + if (servers.empty()) { + puts("Error: Not connected to any Renegade X servers."); + return; + } + Jupiter::StringS msg = parameters; msg += '\n'; - int i = RenX::getCore()->getServerCount(); - if (i == 0) - puts("Error: Not connected to any Renegade X servers."); - else if (parameters.isNotEmpty()) - while (--i >= 0) - RenX::getCore()->getServer(i)->sendData(msg); - else - puts("Error: Too Few Parameters. Syntax: rrcon "); + for (const auto& server : servers) { + server->sendData(msg); + } } -const Jupiter::ReadableString &RawRCONConsoleCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RawRCONConsoleCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends data over the Renegade X server's rcon connection. Syntax: rrcon "); return defaultHelp; } @@ -156,26 +148,28 @@ CONSOLE_COMMAND_INIT(RawRCONConsoleCommand) // RCON Console Command -RCONConsoleCommand::RCONConsoleCommand() -{ +RCONConsoleCommand::RCONConsoleCommand() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("rcon")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("renx")); } -void RCONConsoleCommand::trigger(const Jupiter::ReadableString ¶meters) -{ - int i = RenX::getCore()->getServerCount(); - if (i == 0) - puts("Error: Not connected to any Renegade X servers."); - else if (parameters != nullptr) - while (--i >= 0) - RenX::getCore()->getServer(i)->send(parameters); - else +void RCONConsoleCommand::trigger(const Jupiter::ReadableString ¶meters) { + if (parameters.isEmpty()) { puts("Error: Too Few Parameters. Syntax: rcon "); + } + + const auto& servers = RenX::getCore()->getServers(); + if (servers.empty()) { + puts("Error: Not connected to any Renegade X servers."); + return; + } + + for (const auto& server : servers) { + server->send(parameters); + } } -const Jupiter::ReadableString &RCONConsoleCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RCONConsoleCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Executes a command over the Renegade X server's rcon connection. Syntax: rcon "); return defaultHelp; } @@ -687,8 +681,7 @@ void PlayerTableIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStri source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); } -const Jupiter::ReadableString &PlayerTableIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &PlayerTableIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Generates a table of all the players in-game. Syntax: PT"); return defaultHelp; } @@ -697,49 +690,40 @@ IRC_COMMAND_INIT(PlayerTableIRCCommand) // PlayerInfo IRC Command -void PlayerInfoIRCCommand::create() -{ +void PlayerInfoIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("playerinfo")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("pi")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("player")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("pinfo")); } -void PlayerInfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void PlayerInfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { + if (chan != nullptr) { int type = chan->getType(); Jupiter::StringL msg; RenX::Server *server; const Jupiter::ReadableString &player_info_format = source->getAccessLevel(channel, nick) > 1 ? pluginInstance.getAdminPlayerInfoFormat() : pluginInstance.getPlayerInfoFormat(); size_t index = 0; - if (parameters.isEmpty()) // List all players - while (index != RenX::getCore()->getServerCount()) - { + if (parameters.isEmpty()) { // List all players + while (index != RenX::getCore()->getServerCount()) { server = RenX::getCore()->getServer(index++); - if (server->isLogChanType(type) && server->players.size() != 0) - { - for (auto node = server->players.begin(); node != server->players.end(); ++node) - { + if (server->isLogChanType(type) && server->players.size() != 0) { + for (auto node = server->players.begin(); node != server->players.end(); ++node) { msg = player_info_format; RenX::processTags(msg, server, &*node); source->sendMessage(channel, msg); } } } - else // List all partial matches - while (index != RenX::getCore()->getServerCount()) - { + } + else { // List all partial matches + while (index != RenX::getCore()->getServerCount()) { server = RenX::getCore()->getServer(index++); - if (server->isLogChanType(type) && server->players.size() != 0) - { - for (auto node = server->players.begin(); node != server->players.end(); ++node) - { - if (node->name.findi(parameters) != Jupiter::INVALID_INDEX) - { + if (server->isLogChanType(type) && server->players.size() != 0) { + for (auto node = server->players.begin(); node != server->players.end(); ++node) { + if (node->name.findi(parameters) != Jupiter::INVALID_INDEX) { msg = player_info_format; RenX::processTags(msg, server, &*node); source->sendMessage(channel, msg); @@ -747,14 +731,15 @@ void PlayerInfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStrin } } } + } - if (msg.isEmpty()) + if (msg.isEmpty()) { source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Player not found.")); + } } } -const Jupiter::ReadableString &PlayerInfoIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &PlayerInfoIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Gets information about a player. Syntax: PlayerInfo [Player]"); return defaultHelp; } @@ -763,93 +748,81 @@ IRC_COMMAND_INIT(PlayerInfoIRCCommand) // BuildingInfo IRC Command -void BuildingInfoIRCCommand::create() -{ +void BuildingInfoIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("binfo")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("bi")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("buildinginfo")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("building")); } -void BuildingInfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void BuildingInfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - int type = chan->getType(); - bool seenStrip; - std::forward_list gStrings; - std::forward_list nStrings; - std::forward_list oStrings; - std::forward_list cStrings; - Jupiter::String *str = nullptr; - RenX::BuildingInfo *building; - for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) - { - RenX::Server *server = RenX::getCore()->getServer(i); - if (server->isLogChanType(type)) - { - seenStrip = false; - for (size_t index = 0; index != server->buildings.size(); ++index) - { - building = server->buildings.get(index); - if (building->name.find("Rx_Building_Air"_jrs) == 0) - { - if (seenStrip) - continue; + if (chan == nullptr) { + return; + } - seenStrip = true; + int type = chan->getType(); + bool seenStrip; + std::forward_list gStrings; + std::forward_list nStrings; + std::forward_list oStrings; + std::forward_list cStrings; + Jupiter::String *str = nullptr; + for (const auto& server : RenX::getCore()->getServers()) { + if (server->isLogChanType(type)) { + seenStrip = false; + for (const auto& building : server->buildings){ + if (building->name.find("Rx_Building_Air"_jrs) == 0) { + if (seenStrip) { + continue; } - str = new Jupiter::String(pluginInstance.getBuildingInfoFormat()); - RenX::processTags(*str, server, nullptr, nullptr, building); - - if (building->capturable) - cStrings.push_front(str); - else if (building->team == RenX::TeamType::GDI) - gStrings.push_front(str); - else if (building->team == RenX::TeamType::Nod) - nStrings.push_front(str); - else - oStrings.push_front(str); - } - while (gStrings.empty() == false) - { - str = gStrings.front(); - gStrings.pop_front(); - source->sendMessage(channel, *str); - delete str; - } - while (nStrings.empty() == false) - { - str = nStrings.front(); - nStrings.pop_front(); - source->sendMessage(channel, *str); - delete str; - } - while (oStrings.empty() == false) - { - str = oStrings.front(); - oStrings.pop_front(); - source->sendMessage(channel, *str); - delete str; - } - while (cStrings.empty() == false) - { - str = cStrings.front(); - cStrings.pop_front(); - source->sendMessage(channel, *str); - delete str; + seenStrip = true; } + str = new Jupiter::String(pluginInstance.getBuildingInfoFormat()); + RenX::processTags(*str, server, nullptr, nullptr, building.get()); + + if (building->capturable) + cStrings.push_front(str); + else if (building->team == RenX::TeamType::GDI) + gStrings.push_front(str); + else if (building->team == RenX::TeamType::Nod) + nStrings.push_front(str); + else + oStrings.push_front(str); + } + + while (gStrings.empty() == false) { + str = gStrings.front(); + gStrings.pop_front(); + source->sendMessage(channel, *str); + delete str; + } + while (nStrings.empty() == false) { + str = nStrings.front(); + nStrings.pop_front(); + source->sendMessage(channel, *str); + delete str; + } + while (oStrings.empty() == false) { + str = oStrings.front(); + oStrings.pop_front(); + source->sendMessage(channel, *str); + delete str; + } + while (cStrings.empty() == false) { + str = cStrings.front(); + cStrings.pop_front(); + source->sendMessage(channel, *str); + delete str; } } - if (str == nullptr) - source->sendMessage(channel, "Error: Channel not attached to any connected Renegade X servers."_jrs); } + if (str == nullptr) + source->sendMessage(channel, "Error: Channel not attached to any connected Renegade X servers."_jrs); } -const Jupiter::ReadableString &BuildingInfoIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &BuildingInfoIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Provides a list of buildings, and the status of each one. Syntax: BuildingInfo"); return defaultHelp; } @@ -858,8 +831,7 @@ IRC_COMMAND_INIT(BuildingInfoIRCCommand) // Mutators IRC Command -void MutatorsIRCCommand::create() -{ +void MutatorsIRCCommand::create() { this->addTrigger("mutators"_jrs); this->addTrigger("mutator"_jrs); } @@ -878,12 +850,16 @@ void MutatorsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString if (server->isLogChanType(type)) { list = STRING_LITERAL_AS_REFERENCE(IRCCOLOR "03[Mutators]" IRCNORMAL); - for (index = 0; index != server->mutators.size(); ++index) - list += " "_jrs + *server->mutators.get(index); - if (index == 0) + for (const auto& mutator : server->mutators) { + list += " "_jrs + mutator; + } + + if (server->mutators.empty()) { source->sendMessage(channel, "No mutators loaded"_jrs); - else + } + else { source->sendMessage(channel, list); + } } } if (list.isEmpty()) @@ -909,42 +885,39 @@ void RotationIRCCommand::create() this->addTrigger("rot"_jrs); } -void RotationIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void RotationIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - const RenX::Map *map; + if (chan != nullptr) { int type = chan->getType(); Jupiter::String list; - size_t index = 0; - for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) - { + for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) { RenX::Server *server = RenX::getCore()->getServer(i); - if (server->isLogChanType(type)) - { + if (server->isLogChanType(type)) { list = STRING_LITERAL_AS_REFERENCE(IRCCOLOR "03[Rotation]" IRCNORMAL); - for (index = 0; index != server->maps.size(); ++index) - { - map = server->maps.get(index); - if (server->getMap().name.equalsi(map->name)) - list += STRING_LITERAL_AS_REFERENCE(" " IRCBOLD "[") + server->maps.get(index)->name + STRING_LITERAL_AS_REFERENCE("]" IRCBOLD); - else - list += " "_jrs + server->maps.get(index)->name; + for (const auto& map : server->maps) { + if (server->getMap().name.equalsi(map.name)) { + list += STRING_LITERAL_AS_REFERENCE(" " IRCBOLD "[") + map.name + STRING_LITERAL_AS_REFERENCE("]" IRCBOLD); + } + else { + list += " "_jrs + map.name; + } } - if (index == 0) + + if (server->maps.empty()) { source->sendMessage(channel, "No maps in rotation"_jrs); - else + } + else { source->sendMessage(channel, list); + } } } - if (list.isEmpty()) + if (list.isEmpty()) { source->sendMessage(channel, "Error: Channel not attached to any connected Renegade X servers."_jrs); + } } } -const Jupiter::ReadableString &RotationIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RotationIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Provides a list of maps in the server rotation. Syntax: Rotation"); return defaultHelp; } @@ -953,30 +926,25 @@ IRC_COMMAND_INIT(RotationIRCCommand) // Map IRC Command -void MapIRCCommand::create() -{ +void MapIRCCommand::create() { this->addTrigger("map"_jrs); } -void MapIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void MapIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { + if (chan != nullptr) { int type = chan->getType(); bool match = false; - for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) - { - RenX::Server *server = RenX::getCore()->getServer(i); - if (server->isLogChanType(type)) - { + for (const auto& server : RenX::getCore()->getServers()) { + if (server->isLogChanType(type)) { match = true; const RenX::Map &map = server->getMap(); source->sendMessage(channel, "Current Map: "_jrs + map.name + "; GUID: "_jrs + RenX::formatGUID(map)); } } - if (match == false) + if (match == false) { source->sendMessage(channel, "Error: Channel not attached to any connected Renegade X servers."_jrs); + } } } @@ -1853,48 +1821,46 @@ void KickIRCCommand::create() void KickIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { - if (parameters.isNotEmpty()) - { - Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() != 0) - { - RenX::PlayerInfo *player; - RenX::Server *server; - unsigned int kicks = 0; - Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); - Jupiter::StringS reason; - if (parameters.wordCount(WHITESPACE) > 1) { - reason = Jupiter::StringS::gotoWord(parameters, 1, WHITESPACE); - } - else { - reason = STRING_LITERAL_AS_REFERENCE("No reason"); - }; - for (size_t i = 0; i != servers.size(); i++) - { - server = servers.get(i); - if (server != nullptr) - { - player = server->getPlayerByPartName(name); - if (player != nullptr) - { - server->kickPlayer(*player, reason); - ++kicks; - } - } - } - source->sendMessage(channel, Jupiter::StringS::Format("%u players kicked.", kicks)); + if (parameters.isEmpty()) { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: Kick [Reason]")); + return; + } + + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan == nullptr) { + return; + } + + auto servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } + + RenX::PlayerInfo *player; + unsigned int kicks = 0; + Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); + Jupiter::StringS reason; + if (parameters.wordCount(WHITESPACE) > 1) { + reason = Jupiter::StringS::gotoWord(parameters, 1, WHITESPACE); + } + else { + reason = STRING_LITERAL_AS_REFERENCE("No reason"); + } + + for (const auto& server : servers) { + if (server != nullptr) { + player = server->getPlayerByPartName(name); + if (player != nullptr) { + server->kickPlayer(*player, reason); + ++kicks; } - else 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: Kick [Reason]")); + source->sendMessage(channel, Jupiter::StringS::Format("%u players kicked.", kicks)); } -const Jupiter::ReadableString &KickIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KickIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Kicks a player from the game. Syntax: Kick [Reason]"); return defaultHelp; } @@ -1905,8 +1871,7 @@ IRC_COMMAND_INIT(KickIRCCommand) // BanSearch IRC Command -void BanSearchIRCCommand::create() -{ +void BanSearchIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("bansearch")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("bsearch")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("banfind")); @@ -1916,9 +1881,8 @@ void BanSearchIRCCommand::create() 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(); +void BanSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + const auto& entries = RenX::banDatabase->getEntries(); if (parameters.isNotEmpty()) { if (entries.size() == 0) @@ -1981,11 +1945,9 @@ void BanSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString Jupiter::String types(64); char dateStr[256]; char expireStr[256]; - for (size_t i = 0; i != entries.size(); i++) - { - entry = entries.get(i); - if (isMatch(type)) - { + for (size_t i = 0; i != entries.size(); i++) { + entry = entries[i].get(); + if (isMatch(type)) { Jupiter::StringS ip_str = Jupiter::Socket::ntop4(entry->ip); time_t added_time = std::chrono::system_clock::to_time_t(entry->timestamp); @@ -2062,14 +2024,13 @@ struct player_search_result { RenX::PlayerInfo* player{}; // Set if a player is found }; -player_search_result findPlayerByPartName(Jupiter::ArrayList& servers, const Jupiter::ReadableString& name) { +player_search_result findPlayerByPartName(const std::vector& servers, const Jupiter::ReadableString& name) { if (servers.size() == 0) { return {}; } player_search_result result; - for (size_t index = 0; index != servers.size(); ++index) { - auto server = servers.get(index); + for (const auto& server : servers) { if (server != nullptr) { result.server = server; result.player = server->getPlayerByPartName(name); @@ -2088,20 +2049,18 @@ player_search_result findPlayerByPartName(IRC_Bot* source, const Jupiter::Readab return {}; } - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); + const auto& servers = RenX::getCore()->getServers(chan->getType()); return findPlayerByPartName(servers, name); } -void TempBanIRCCommand::create() -{ +void TempBanIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("tban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tb")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tempban")); this->setAccessLevel(3); } -void TempBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void TempBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: TempBan [Duration] [Reason]")); return; @@ -2146,8 +2105,7 @@ void TempBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString & source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Player banned.")); } -const Jupiter::ReadableString &TempBanIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &TempBanIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Kicks and temporarily bans a player from the game. Syntax: TempBan [Duration] [Reason]"); return defaultHelp; } @@ -2156,8 +2114,7 @@ IRC_COMMAND_INIT(TempBanIRCCommand) // TempChatBan IRC Command -void TempChatBanIRCCommand::create() -{ +void TempChatBanIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("tchatban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tcban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tempchatban")); @@ -2165,8 +2122,7 @@ void TempChatBanIRCCommand::create() this->setAccessLevel(3); } -void TempChatBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void TempChatBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: TempChatBan [Duration] [Reason]")); return; @@ -2211,8 +2167,7 @@ void TempChatBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStri source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Player chat banned.")); } -const Jupiter::ReadableString &TempChatBanIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &TempChatBanIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Mutes and temporarily chat bans a player from the game. Syntax: TempChatBan [Duration] [Reason]"); return defaultHelp; } @@ -2221,26 +2176,21 @@ IRC_COMMAND_INIT(TempChatBanIRCCommand) // KickBan IRC Command -void KickBanIRCCommand::create() -{ +void KickBanIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("kickban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("kb")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("ban")); this->setAccessLevel(4); } -void KickBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void KickBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); + if (chan != nullptr) { + const auto& servers = RenX::getCore()->getServers(chan->getType()); if (servers.size() != 0) { RenX::PlayerInfo *player; - RenX::Server *server; unsigned int kicks = 0; Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); Jupiter::StringS reason; @@ -2253,14 +2203,10 @@ void KickBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString & Jupiter::String banner(nick.size() + 4); banner += nick; banner += "@IRC"; - for (size_t i = 0; i != servers.size(); i++) - { - server = servers.get(i); - if (server != nullptr) - { + for (const auto& server : servers) { + if (server != nullptr) { player = server->getPlayerByPartName(name); - if (player != nullptr) - { + if (player != nullptr) { server->banPlayer(*player, banner, reason); kicks++; } @@ -2505,8 +2451,7 @@ IRC_COMMAND_INIT(UnBanIRCCommand) // ExemptionSearch IRC Command -void ExemptionSearchIRCCommand::create() -{ +void ExemptionSearchIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("exemptionsearch")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("esearch")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("exemptionfind")); @@ -2516,19 +2461,17 @@ void ExemptionSearchIRCCommand::create() this->setAccessLevel(2); } -void ExemptionSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - auto entries = RenX::exemptionDatabase->getEntries(); +void ExemptionSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + const auto& entries = RenX::exemptionDatabase->getEntries(); if (parameters.isNotEmpty()) { - if (entries.size() == 0) + if (entries.size() == 0) { source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("The exemption database is empty!")); - else - { + } + else { RenX::ExemptionDatabase::Entry *entry; Jupiter::ReferenceString params = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE); - std::function isMatch = [&](unsigned int type_l) -> bool - { + std::function isMatch = [&](unsigned int type_l) -> bool { switch (type_l) { default: @@ -2559,8 +2502,7 @@ void ExemptionSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::Readable type = 4; else if (type_str.equalsi(STRING_LITERAL_AS_REFERENCE("active"))) type = 5; - else - { + else { type = 0; params = parameters; } @@ -2570,7 +2512,7 @@ void ExemptionSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::Readable char timeStr[256]; for (size_t i = 0; i != entries.size(); i++) { - entry = entries.get(i); + entry = entries[i].get(); if (isMatch(type)) { time_t current_time = std::chrono::system_clock::to_time_t(entry->timestamp); @@ -2606,8 +2548,7 @@ void ExemptionSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::Readable source->sendNotice(nick, Jupiter::StringS::Format("There are a total of %u entries in the exemption database.", entries.size())); } -const Jupiter::ReadableString &ExemptionSearchIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &ExemptionSearchIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Searches the exemption database for an entry. Syntax: esearch [ip/steam/setter/active/any/all = any] "); return defaultHelp; } @@ -2616,57 +2557,54 @@ IRC_COMMAND_INIT(ExemptionSearchIRCCommand) // BanExempt IRC Command -void BanExemptIRCCommand::create() -{ +void BanExemptIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("banexempt")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("bexempt")); this->setAccessLevel(4); } -void BanExemptIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { - Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() != 0) - { - RenX::PlayerInfo *player; - RenX::Server *server; - unsigned int exemptions = 0; - Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); - Jupiter::String setter(nick.size() + 4); - setter += nick; - setter += "@IRC"; - for (size_t i = 0; i != servers.size(); i++) - { - server = servers.get(i); - if (server != nullptr) - { - player = server->getPlayerByPartName(name); - if (player != nullptr) - { - if (player->steamid != 0LL) - RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN); - else - RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_USE_IP); - ++exemptions; - } - } +void BanExemptIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + if (parameters.isEmpty()) { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: BanExempt [Reason]")); + return; + } + + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan == nullptr) { + return; + } + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } + + RenX::PlayerInfo *player; + unsigned int exemptions = 0; + Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); + Jupiter::String setter(nick.size() + 4); + setter += nick; + setter += "@IRC"; + for (const auto& server : servers) { + if (server != nullptr) { + player = server->getPlayerByPartName(name); + if (player != nullptr) { + if (player->steamid != 0LL) { + RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN); } - if (exemptions == 0) - source->sendMessage(channel, "Player \""_jrs + name + "\" not found."_jrs); - else - { - source->sendMessage(channel, Jupiter::StringS::Format("%u players added.", exemptions)); + else { + RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_USE_IP); } + ++exemptions; } - else 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: BanExempt [Reason]")); + + if (exemptions == 0) + source->sendMessage(channel, "Player \""_jrs + name + "\" not found."_jrs); + else { + source->sendMessage(channel, Jupiter::StringS::Format("%u players added.", exemptions)); + } } const Jupiter::ReadableString &BanExemptIRCCommand::getHelp(const Jupiter::ReadableString &) @@ -2679,61 +2617,57 @@ IRC_COMMAND_INIT(BanExemptIRCCommand) // KickExempt IRC Command -void KickExemptIRCCommand::create() -{ +void KickExemptIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("kickexempt")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("kexempt")); this->setAccessLevel(4); } -void KickExemptIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { - Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() != 0) - { - RenX::PlayerInfo *player; - RenX::Server *server; - unsigned int exemptions = 0; - Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); - Jupiter::String setter(nick.size() + 4); - setter += nick; - setter += "@IRC"; - for (size_t i = 0; i != servers.size(); i++) - { - server = servers.get(i); - if (server != nullptr) - { - player = server->getPlayerByPartName(name); - if (player != nullptr) - { - if (player->steamid != 0LL) - RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK); - else - RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK | RenX::ExemptionDatabase::Entry::FLAG_USE_IP); - ++exemptions; - } - } +void KickExemptIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + if (parameters.isEmpty()) { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: KickExempt [Reason]")); + } + + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan == nullptr) { + return; + } + + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } + + RenX::PlayerInfo *player; + unsigned int exemptions = 0; + Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); + Jupiter::String setter(nick.size() + 4); + setter += nick; + setter += "@IRC"; + for (const auto& server : servers) { + if (server != nullptr) { + player = server->getPlayerByPartName(name); + if (player != nullptr) { + if (player->steamid != 0LL) { + RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK); } - if (exemptions == 0) - source->sendMessage(channel, "Player \""_jrs + name + "\" not found."_jrs); - else - { - source->sendMessage(channel, Jupiter::StringS::Format("%u players added.", exemptions)); + else { + RenX::exemptionDatabase->add(*server, *player, setter, std::chrono::seconds::zero(), RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK | RenX::ExemptionDatabase::Entry::FLAG_USE_IP); } + ++exemptions; } - else 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: KickExempt [Reason]")); + if (exemptions == 0) { + source->sendMessage(channel, "Player \""_jrs + name + "\" not found."_jrs); + } + else { + source->sendMessage(channel, Jupiter::StringS::Format("%u players added.", exemptions)); + } } -const Jupiter::ReadableString &KickExemptIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KickExemptIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Exempts a player from kicks and bans using their SteamID, or their IP address if they have none. Syntax: KickExempt [Reason]"); return defaultHelp; } @@ -2906,64 +2840,60 @@ IRC_COMMAND_INIT(UnExemptIRCCommand) // AddBots IRC Command -void AddBotsIRCCommand::create() -{ +void AddBotsIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("addbots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("addbot")); this->setAccessLevel(2); } -void AddBotsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(source->getChannel(channel)->getType()); - if (servers.size() != 0) - { - int amount = 1; - if (parameters.isNotEmpty()) - amount = parameters.asInt(); - if (amount != 0) - { - RenX::Server *server; - Jupiter::StringL cmd; - RenX::TeamType team = RenX::getTeam(Jupiter::ReferenceString::getWord(parameters, 1, WHITESPACE)); +void AddBotsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan == nullptr) { + return; + } - switch (team) - { - case RenX::TeamType::GDI: - cmd = "addredbots "; - break; - case RenX::TeamType::Nod: - cmd = "addbluebots "; - break; - case RenX::TeamType::None: - case RenX::TeamType::Other: - cmd = "addbots "; - break; - } + const auto& servers = RenX::getCore()->getServers(source->getChannel(channel)->getType()); + if (servers.empty()) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } - for (size_t i = 0, extra; i != servers.size(); i++) - { - server = servers.get(i); - if (server != nullptr) - { - extra = cmd.aformat("%u", amount); - server->send(cmd); - cmd -= extra; - } - server->sendMessage(Jupiter::StringS::Format("%u bots have been added to the server.", amount)); - } - } - else source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Invalid amount entered. Amount must be a positive integer.")); - } - else source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + int amount = 1; + if (parameters.isNotEmpty()) { + amount = parameters.asInt(); + if (amount == 0) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Invalid amount entered. Amount must be a positive integer.")); + return; } + } + + Jupiter::StringL cmd; + RenX::TeamType team = RenX::getTeam(Jupiter::ReferenceString::getWord(parameters, 1, WHITESPACE)); + + switch (team) { + case RenX::TeamType::GDI: + cmd = "addredbots "; + break; + case RenX::TeamType::Nod: + cmd = "addbluebots "; + break; + case RenX::TeamType::None: + case RenX::TeamType::Other: + cmd = "addbots "; + break; + } + + for (const auto& server : servers) { + if (server != nullptr) { + size_t extra = cmd.aformat("%u", amount); + server->send(cmd); + cmd -= extra; + } + server->sendMessage(Jupiter::StringS::Format("%u bots have been added to the server.", amount)); + } } -const Jupiter::ReadableString &AddBotsIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &AddBotsIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Adds bots to the game. Syntax: AddBots [Amount=1] [Team]"); return defaultHelp; } @@ -2972,36 +2902,31 @@ IRC_COMMAND_INIT(AddBotsIRCCommand) // KillBots IRC Command -void KillBotsIRCCommand::create() -{ +void KillBotsIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("killbots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("killbot")); this->setAccessLevel(2); } -void KillBotsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void KillBotsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() != 0) - { - RenX::Server *server; + if (chan == nullptr) { + return; + } - for (size_t i = 0; i != servers.size(); i++) - { - server = servers.get(i); - server->send(STRING_LITERAL_AS_REFERENCE("killbots")); - server->sendMessage(STRING_LITERAL_AS_REFERENCE("All bots have been removed from the server.")); - } - } - else source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } + + for (const auto& server : servers) { + server->send(STRING_LITERAL_AS_REFERENCE("killbots")); + server->sendMessage(STRING_LITERAL_AS_REFERENCE("All bots have been removed from the server.")); } } -const Jupiter::ReadableString &KillBotsIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KillBotsIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Removes all bots from the game. Syntax: KillBots"); return defaultHelp; } @@ -3010,50 +2935,45 @@ IRC_COMMAND_INIT(KillBotsIRCCommand) // PhaseBots IRC Command -void PhaseBotsIRCCommand::create() -{ +void PhaseBotsIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("phasebots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("phasebot")); this->setAccessLevel(2); } -void PhaseBotsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void PhaseBotsIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() != 0) - { - RenX::Server *server; + if (chan == nullptr) { + return; + } - for (size_t i = 0; i != servers.size(); i++) - { - server = servers.get(i); - if (parameters.isEmpty()) - { - if (togglePhasing(server)) - server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been enabled.")); - else server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been disabled.")); - } - else if (parameters.equalsi("true") || parameters.equalsi("on") || parameters.equalsi("start") || parameters.equalsi("1")) - { - togglePhasing(server, true); - server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been enabled.")); - } - else - { - togglePhasing(server, false); - server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been disabled.")); - } + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { + source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); + return; + } + + for (const auto& server : servers) { + if (parameters.isEmpty()) { + if (togglePhasing(server)) { + server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been enabled.")); } + else { + server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been disabled.")); + } + } + else if (parameters.equalsi("true") || parameters.equalsi("on") || parameters.equalsi("start") || parameters.equalsi("1")) { + togglePhasing(server, true); + server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been enabled.")); + } + else { + togglePhasing(server, false); + server->sendMessage(STRING_LITERAL_AS_REFERENCE("Bot phasing has been disabled.")); } - else source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); } } -const Jupiter::ReadableString &PhaseBotsIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &PhaseBotsIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Toggles the phasing of bots from the game by kicking them after death. Syntax: PhaseBots [on/off]"); return defaultHelp; } @@ -3062,31 +2982,33 @@ IRC_COMMAND_INIT(PhaseBotsIRCCommand) // RCON IRC Command -void RCONIRCCommand::create() -{ +void RCONIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("rcon")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("renx")); this->setAccessLevel(5); } -void RCONIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - if (parameters != nullptr) - { - Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { - unsigned int r = RenX::getCore()->send(chan->getType(), parameters); - if (r > 0) - source->sendMessage(channel, Jupiter::StringS::Format("Command sent to %u servers.", r)); - else source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); - } +void RCONIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + if (parameters.isEmpty()) { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: rcon ")); + return; + } + + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan == nullptr) { + return; + } + + size_t server_count = RenX::getCore()->send(chan->getType(), parameters); + if (server_count > 0) { + source->sendMessage(channel, Jupiter::StringS::Format("Command sent to %u servers.", server_count)); + } + else { + 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: rcon ")); } -const Jupiter::ReadableString &RCONIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RCONIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends data to the Renegade X server's rcon. Syntax: rcon "); return defaultHelp; } @@ -3095,8 +3017,7 @@ IRC_COMMAND_INIT(RCONIRCCommand) // Refund IRC Command -void RefundIRCCommand::create() -{ +void RefundIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("refund")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("givecredits")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("gc")); @@ -3105,46 +3026,43 @@ void RefundIRCCommand::create() this->setAccessLevel(3); } -void RefundIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ - if (parameters.wordCount(WHITESPACE) >= 2) - { +void RefundIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { + if (parameters.wordCount(WHITESPACE) >= 2) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); - if (chan != nullptr) - { + if (chan != nullptr) { int type = chan->getType(); Jupiter::ReferenceString playerName = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE); double credits = Jupiter::ReferenceString::getWord(parameters, 1, WHITESPACE).asDouble(); RenX::PlayerInfo *player; Jupiter::StringL msg; - for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) - { + for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) { RenX::Server *server = RenX::getCore()->getServer(i); - if (server->isLogChanType(type) && server->players.size() != 0) - { + if (server->isLogChanType(type) && server->players.size() != 0) { player = server->getPlayerByPartName(playerName); - if (player != nullptr) - { - if (server->giveCredits(*player, credits)) - { + if (player != nullptr) { + if (server->giveCredits(*player, credits)) { msg.format("You have been refunded %.0f credits by %.*s.", credits, nick.size(), nick.ptr()); server->sendMessage(*player, msg); msg.format("%.*s has been refunded %.0f credits.", player->name.size(), player->name.ptr(), credits); } - else + else { msg.set("Error: Server does not support refunds."); + } source->sendMessage(channel, msg); } } } - if (msg.isEmpty()) source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Player not found.")); + if (msg.isEmpty()) { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Player not found.")); + } } } - else source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: refund ")); + else { + source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: refund ")); + } } -const Jupiter::ReadableString &RefundIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RefundIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Refunds a player's credits. Syntax: refund "); return defaultHelp; } @@ -3153,8 +3071,7 @@ IRC_COMMAND_INIT(RefundIRCCommand) // Team-Change IRC Command -void TeamChangeIRCCommand::create() -{ +void TeamChangeIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("team")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tc")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("ftc")); @@ -3277,17 +3194,15 @@ void NModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &ch return; } - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() == 0) { + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); return; } RenX::PlayerInfo *player; - RenX::Server *server; unsigned int nmodes = 0; - for (size_t i = 0; i != servers.size(); i++) { - server = servers.get(i); + for (const auto& server : servers) { if (server != nullptr) { player = server->getPlayerByPartName(parameters); if (player != nullptr) { @@ -3296,11 +3211,11 @@ void NModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &ch } } } + source->sendMessage(channel, Jupiter::StringS::Format("%u players nmoded.", nmodes)); } -const Jupiter::ReadableString &NModeIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &NModeIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: nmode "); return defaultHelp; } @@ -3309,14 +3224,12 @@ IRC_COMMAND_INIT(NModeIRCCommand) // SMode IRC Command -void SModeIRCCommand::create() -{ +void SModeIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("smode")); this->setAccessLevel(2); } -void SModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void SModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: smode ")); return; @@ -3327,17 +3240,15 @@ void SModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &ch return; } - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() == 0) { + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); return; } RenX::PlayerInfo *player; - RenX::Server *server; unsigned int smodes = 0; - for (size_t i = 0; i != servers.size(); i++) { - server = servers.get(i); + for (const auto& server : servers) { if (server != nullptr) { player = server->getPlayerByPartName(parameters); if (player != nullptr) { @@ -3349,8 +3260,7 @@ void SModeIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &ch source->sendMessage(channel, Jupiter::StringS::Format("%u players smoded.", smodes)); } -const Jupiter::ReadableString &SModeIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &SModeIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: smode "); return defaultHelp; } @@ -3359,23 +3269,21 @@ IRC_COMMAND_INIT(SModeIRCCommand) // CancelVote IRC Command -void CancelVoteIRCCommand::create() -{ +void CancelVoteIRCCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvote")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvotes")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("cv")); this->setAccessLevel(2); } -void CancelVoteIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) -{ +void CancelVoteIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); if (chan == nullptr) { return; } - Jupiter::ArrayList servers = RenX::getCore()->getServers(chan->getType()); - if (servers.size() == 0) { + const auto& servers = RenX::getCore()->getServers(chan->getType()); + if (servers.empty()) { source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Channel not attached to any connected Renegade X servers.")); return; } @@ -3403,8 +3311,7 @@ void CancelVoteIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStrin } if (cancel_all) { - for (size_t i = 0; i != servers.size(); i++) { - RenX::Server *server = servers.get(i); + for (const auto& server : servers) { if (server == nullptr) { continue; } @@ -3414,8 +3321,7 @@ void CancelVoteIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStrin server->cancelVote(RenX::TeamType::Nod); } } else { - for (size_t i = 0; i != servers.size(); i++) { - RenX::Server *server = servers.get(i); + for (const auto& server : servers) { if (server == nullptr) { continue; } @@ -3425,8 +3331,7 @@ void CancelVoteIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStrin } } -const Jupiter::ReadableString &CancelVoteIRCCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &CancelVoteIRCCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Cancels active votes. Syntax: cancelvote [all|public|gdi|nod|blackhand]"); return defaultHelp; } @@ -3437,13 +3342,11 @@ IRC_COMMAND_INIT(CancelVoteIRCCommand) // Help Game Command -void HelpGameCommand::create() -{ +void HelpGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("help")); } -void HelpGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void HelpGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { RenX::GameCommand *cmd; unsigned int cmdCount = 0; auto getAccessCommands = [&](int accessLevel) @@ -3499,8 +3402,7 @@ void HelpGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, co } } -const Jupiter::ReadableString &HelpGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &HelpGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Lists commands, or sends command-specific help. Syntax: help [command]"); return defaultHelp; } @@ -3509,21 +3411,17 @@ GAME_COMMAND_INIT(HelpGameCommand) // Mods Game Command -void ModsGameCommand::create() -{ +void ModsGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("staff")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("mods")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("showmods")); } -void ModsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *, const Jupiter::ReadableString &) -{ +void ModsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *, const Jupiter::ReadableString &) { Jupiter::StringL msg; const Jupiter::ReadableString &staff_word = pluginInstance.getStaffTitle(); - for (auto node = source->players.begin(); node != source->players.end(); ++node) - { - if (node->isBot == false && (node->adminType.isNotEmpty() || (node->access != 0 && (node->gamePrefix.isNotEmpty() || node->formatNamePrefix.isNotEmpty())))) - { + for (auto node = source->players.begin(); node != source->players.end(); ++node) { + if (node->isBot == false && (node->adminType.isNotEmpty() || (node->access != 0 && (node->gamePrefix.isNotEmpty() || node->formatNamePrefix.isNotEmpty())))) { if (msg.isEmpty()) msg = staff_word + "s in-game: "_jrs; else @@ -3533,8 +3431,7 @@ void ModsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *, const Ju msg += node->name; } } - if (msg.isEmpty()) - { + if (msg.isEmpty()) { msg += "No "_jrs + staff_word + "s are in-game"_jrs; RenX::GameCommand *cmd = source->getCommand(STRING_LITERAL_AS_REFERENCE("modrequest")); if (cmd != nullptr) @@ -3544,8 +3441,7 @@ void ModsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *, const Ju source->sendMessage(msg); } -const Jupiter::ReadableString &ModsGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &ModsGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Displays in-game staff. Syntax: staff"); return defaultHelp; } @@ -3554,21 +3450,18 @@ GAME_COMMAND_INIT(ModsGameCommand) // Rules Game Command -void RulesGameCommand::create() -{ +void RulesGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("rules")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("rule")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("showrules")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("showrule")); } -void RulesGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void RulesGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { source->sendMessage(Jupiter::StringS::Format("Rules: %.*s", source->getRules().size(), source->getRules().ptr())); } -const Jupiter::ReadableString &RulesGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RulesGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Displays the rules for this server. Syntax: rules"); return defaultHelp; } @@ -3577,15 +3470,13 @@ GAME_COMMAND_INIT(RulesGameCommand) // Mod Request Game Command -void ModRequestGameCommand::create() -{ +void ModRequestGameCommand::create() { this->addTrigger("modrequest"_jrs); this->addTrigger("requestmod"_jrs); this->addTrigger("mod"_jrs); } -void ModRequestGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void ModRequestGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { source->sendMessage(*player, "Please specify a reason for requesting moderator assistance."_jrs); return; @@ -3637,8 +3528,7 @@ void ModRequestGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *play source->sendMessage(*player, Jupiter::StringS::Format("A total of %u %.*ss have been notified of your assistance request.", total_user_alerts, staff_word.size(), staff_word.ptr())); } -const Jupiter::ReadableString &ModRequestGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &ModRequestGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Notifies staff on IRC that assistance is required. Syntax: modRequest "); return defaultHelp; } @@ -3647,8 +3537,7 @@ GAME_COMMAND_INIT(ModRequestGameCommand) // AdminMessage Game Command -void AdminMessageGameCommand::create() -{ +void AdminMessageGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("amsg")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("adminmsg")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("amessage")); @@ -3656,19 +3545,17 @@ void AdminMessageGameCommand::create() this->setAccessLevel(1); } -void AdminMessageGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void AdminMessageGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::StringS msg = player->gamePrefix + player->name + ": "_jrs + parameters; source->sendAdminMessage(msg); } - else + else { source->sendMessage(*player, "Error: Too few parameters. Syntax: amsg "_jrs); + } } -const Jupiter::ReadableString &AdminMessageGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &AdminMessageGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends an admin message in-game. Syntax: amsg "); return defaultHelp; } @@ -3677,8 +3564,7 @@ GAME_COMMAND_INIT(AdminMessageGameCommand) // PAdminMessage Game Command -void PAdminMessageGameCommand::create() -{ +void PAdminMessageGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("pamsg")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("padminmsg")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("pamessage")); @@ -3686,28 +3572,27 @@ void PAdminMessageGameCommand::create() this->setAccessLevel(1); } -void PAdminMessageGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.wordCount(WHITESPACE) >= 2) - { +void PAdminMessageGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.wordCount(WHITESPACE) >= 2) { Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); Jupiter::StringS msg = player->gamePrefix + player->name + ": "_jrs + Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE); RenX::PlayerInfo *target = source->getPlayerByPartName(name); - if (target == nullptr) + if (target == nullptr) { source->sendMessage(*player, "Error: Player not found."_jrs); + } else { source->sendAdminMessage(*target, msg); source->sendMessage(*player, "Message sent to "_jrs + target->name); } } - else + else { source->sendMessage(*player, "Error: Too few parameters. Syntax: pamsg "_jrs); + } } -const Jupiter::ReadableString &PAdminMessageGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &PAdminMessageGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends an admin message to a player in-game. Syntax: pamsg "); return defaultHelp; } @@ -3716,23 +3601,21 @@ GAME_COMMAND_INIT(PAdminMessageGameCommand) // Kill Game Command -void KillGameCommand::create() -{ +void KillGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("kill")); this->setAccessLevel(1); } -void KillGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void KillGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { RenX::PlayerInfo *target = source->getPlayerByPartName(parameters); - if (target == nullptr) + if (target == nullptr) { source->sendMessage(*player, "Error: Player not found."_jrs); - else if (target->access >= player->access) + } + else if (target->access >= player->access) { source->sendMessage(*player, "Error: You can not kill higher level "_jrs + pluginInstance.getStaffTitle() + "s."_jrs); - else - { + } + else { source->kill(*target); source->sendMessage(*player, "Player has been killed."_jrs); } @@ -3741,8 +3624,7 @@ void KillGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, co source->sendMessage(*player, "Error: Too few parameters. Syntax: kill "_jrs); } -const Jupiter::ReadableString &KillGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KillGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Kills a player in the game. Syntax: kill "); return defaultHelp; } @@ -3751,16 +3633,13 @@ GAME_COMMAND_INIT(KillGameCommand) // Disarm Game Command -void DisarmGameCommand::create() -{ +void DisarmGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("disarm")); this->setAccessLevel(1); } -void DisarmGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void DisarmGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { RenX::PlayerInfo *target = source->getPlayerByPartName(parameters); if (target == nullptr) source->sendMessage(*player, "Error: Player not found."_jrs); @@ -3775,8 +3654,7 @@ void DisarmGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, source->sendMessage(*player, "Error: Too few parameters. Syntax: disarm "_jrs); } -const Jupiter::ReadableString &DisarmGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &DisarmGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Disarms all of a player's deployed objects in the game. Syntax: disarm "); return defaultHelp; } @@ -3785,16 +3663,13 @@ GAME_COMMAND_INIT(DisarmGameCommand) // DisarmC4 Game Command -void DisarmC4GameCommand::create() -{ +void DisarmC4GameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("disarmc4")); this->setAccessLevel(1); } -void DisarmC4GameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void DisarmC4GameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { RenX::PlayerInfo *target = source->getPlayerByPartName(parameters); if (target == nullptr) source->sendMessage(*player, "Error: Player not found."_jrs); @@ -3809,8 +3684,7 @@ void DisarmC4GameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player source->sendMessage(*player, "Error: Too few parameters. Syntax: disarmc4 "_jrs); } -const Jupiter::ReadableString &DisarmC4GameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &DisarmC4GameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Disarms all of a player's deployed mines in the game. Syntax: disarmc4 "); return defaultHelp; } @@ -3819,18 +3693,15 @@ GAME_COMMAND_INIT(DisarmC4GameCommand) // DisarmBeacon Game Command -void DisarmBeaconGameCommand::create() -{ +void DisarmBeaconGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("disarmb")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("disarmbeacon")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("disarmbeacons")); this->setAccessLevel(1); } -void DisarmBeaconGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void DisarmBeaconGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { RenX::PlayerInfo *target = source->getPlayerByPartName(parameters); if (target == nullptr) source->sendMessage(*player, "Error: Player not found."_jrs); @@ -3845,8 +3716,7 @@ void DisarmBeaconGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *pl source->sendMessage(*player, "Error: Too few parameters. Syntax: disarmb "_jrs); } -const Jupiter::ReadableString &DisarmBeaconGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &DisarmBeaconGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Disarms all of a player's deployed beacons in the game. Syntax: disarmb "); return defaultHelp; } @@ -3855,14 +3725,12 @@ GAME_COMMAND_INIT(DisarmBeaconGameCommand) // MineBan Game Command -void MineBanGameCommand::create() -{ +void MineBanGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("mineban")); this->setAccessLevel(1); } -void MineBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void MineBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { if (parameters.isNotEmpty()) { RenX::PlayerInfo *target = source->getPlayerByPartName(parameters); @@ -3880,8 +3748,7 @@ void MineBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, source->sendMessage(*player, "Error: Too few parameters. Syntax: mineban "_jrs); } -const Jupiter::ReadableString &MineBanGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &MineBanGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Bans a player from mining for 1 game (or until they leave). Syntax: mineban "); return defaultHelp; } @@ -3890,18 +3757,15 @@ GAME_COMMAND_INIT(MineBanGameCommand) // Kick Game Command -void KickGameCommand::create() -{ +void KickGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("kick")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("qkick")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("k")); this->setAccessLevel(1); } -void KickGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void KickGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); Jupiter::StringS reason; if (parameters.wordCount(WHITESPACE) > 1) { @@ -3927,8 +3791,7 @@ void KickGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, co source->sendMessage(*player, "Error: Too few parameters. Syntax: kick [Reason]"_jrs); } -const Jupiter::ReadableString &KickGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KickGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Kicks a player from the game. Syntax: kick [Reason]"); return defaultHelp; } @@ -3937,16 +3800,13 @@ GAME_COMMAND_INIT(KickGameCommand) // Mute Game Command -void MuteGameCommand::create() -{ +void MuteGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("mute")); this->setAccessLevel(1); } -void MuteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void MuteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); Jupiter::StringS reason; if (parameters.wordCount(WHITESPACE) > 1) { @@ -3973,8 +3833,7 @@ void MuteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, co source->sendMessage(*player, "Error: Too few parameters. Syntax: mute [Reason]"_jrs); } -const Jupiter::ReadableString &MuteGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &MuteGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Mutes a player from chat. Syntax: mute [Reason]"); return defaultHelp; } @@ -3983,18 +3842,15 @@ GAME_COMMAND_INIT(MuteGameCommand) // TempBan Game Command -void TempBanGameCommand::create() -{ +void TempBanGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("tban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tempban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tb")); this->setAccessLevel(1); } -void TempBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void TempBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); std::chrono::seconds duration = pluginInstance.getDefaultTBanTime(); Jupiter::StringS reason; @@ -4037,8 +3893,7 @@ void TempBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, source->sendMessage(*player, "Error: Too few parameters. Syntax: tban [Reason]"_jrs); } -const Jupiter::ReadableString &TempBanGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &TempBanGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Kicks and temporarily bans a player from the game. Syntax: tban [Reason]"); return defaultHelp; } @@ -4047,8 +3902,7 @@ GAME_COMMAND_INIT(TempBanGameCommand) // TempChatBan Game Command -void TempChatBanGameCommand::create() -{ +void TempChatBanGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("tchatban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tcban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("tempchatban")); @@ -4056,10 +3910,8 @@ void TempChatBanGameCommand::create() this->setAccessLevel(1); } -void TempChatBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void TempChatBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); std::chrono::seconds duration = pluginInstance.getDefaultTBanTime(); Jupiter::StringS reason; @@ -4092,8 +3944,7 @@ void TempChatBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *pla source->sendMessage(*player, "Error: You can not ban yourself."_jrs); else if (target->access >= player->access) source->sendMessage(*player, "Error: You can not ban higher level "_jrs + pluginInstance.getStaffTitle() + "s."_jrs); - else - { + else { source->mute(*target); RenX::banDatabase->add(source, *target, player->name, reason, duration, RenX::BanDatabase::Entry::FLAG_TYPE_CHAT); source->sendMessage(*player, "Player has been temporarily muted and chat banned from the game."_jrs); @@ -4103,8 +3954,7 @@ void TempChatBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *pla source->sendMessage(*player, "Error: Too few parameters. Syntax: tchatban [Duration] [Reason]"_jrs); } -const Jupiter::ReadableString &TempChatBanGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &TempChatBanGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Mutes and temporarily chat bans a player from the game. Syntax: tchatban [Duration] [Reason]"); return defaultHelp; } @@ -4113,8 +3963,7 @@ GAME_COMMAND_INIT(TempChatBanGameCommand) // KickBan Game Command -void KickBanGameCommand::create() -{ +void KickBanGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("ban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("kickban")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("kb")); @@ -4122,10 +3971,8 @@ void KickBanGameCommand::create() this->setAccessLevel(2); } -void KickBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - if (parameters.isNotEmpty()) - { +void KickBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + if (parameters.isNotEmpty()) { Jupiter::StringS name = Jupiter::StringS::getWord(parameters, 0, WHITESPACE); Jupiter::StringS reason; if (parameters.wordCount(WHITESPACE) > 1) { @@ -4152,8 +3999,7 @@ void KickBanGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, source->sendMessage(*player, "Error: Too few parameters. Syntax: ban [Duration] [reason]"_jrs); } -const Jupiter::ReadableString &KickBanGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KickBanGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Kicks and bans a player from the game. Syntax: ban [Duration] [reason]"); return defaultHelp; } @@ -4162,8 +4008,7 @@ GAME_COMMAND_INIT(KickBanGameCommand) // AddBots Game Command -void AddBotsGameCommand::create() -{ +void AddBotsGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("addbots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("abots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("addbot")); @@ -4171,8 +4016,7 @@ void AddBotsGameCommand::create() this->setAccessLevel(1); } -void AddBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void AddBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { RenX::TeamType team = RenX::getTeam(Jupiter::ReferenceString::getWord(parameters, 1, WHITESPACE)); Jupiter::StringS cmd; @@ -4202,8 +4046,7 @@ void AddBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, source->sendMessage(*player, Jupiter::StringS::Format("%u bots have been added to the server.", amount)); } -const Jupiter::ReadableString &AddBotsGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &AddBotsGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Adds bots to the game. Syntax: addbots [amount=1] [team]"); return defaultHelp; } @@ -4212,8 +4055,7 @@ GAME_COMMAND_INIT(AddBotsGameCommand) // KillBots Game Command -void KillBotsGameCommand::create() -{ +void KillBotsGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("killbots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("kbots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("rembots")); @@ -4221,14 +4063,12 @@ void KillBotsGameCommand::create() this->setAccessLevel(2); } -void KillBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void KillBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { source->send(STRING_LITERAL_AS_REFERENCE("killbots")); source->sendMessage(*player, STRING_LITERAL_AS_REFERENCE("All bots have been removed from the server.")); } -const Jupiter::ReadableString &KillBotsGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &KillBotsGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Removes all bots from the game. Syntax: killbots"); return defaultHelp; } @@ -4237,15 +4077,13 @@ GAME_COMMAND_INIT(KillBotsGameCommand) // PhaseBots Game Command -void PhaseBotsGameCommand::create() -{ +void PhaseBotsGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("phasebots")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("pbots")); this->setAccessLevel(1); } -void PhaseBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void PhaseBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { if (togglePhasing(source)) @@ -4264,8 +4102,7 @@ void PhaseBotsGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *playe } } -const Jupiter::ReadableString &PhaseBotsGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &PhaseBotsGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Removes all bots from the game. Syntax: phasebots"); return defaultHelp; } @@ -4274,14 +4111,12 @@ GAME_COMMAND_INIT(PhaseBotsGameCommand) // NMode Game Command -void NModeGameCommand::create() -{ +void NModeGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("nmode")); this->setAccessLevel(1); } -void NModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void NModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { source->sendMessage(*player, "Error: Too few parameters. Syntax: nmode "_jrs); return; @@ -4301,8 +4136,7 @@ void NModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, c source->sendMessage(*player, "Player's mode has been reset."_jrs); } -const Jupiter::ReadableString &NModeGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &NModeGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: nmode "); return defaultHelp; } @@ -4311,14 +4145,12 @@ GAME_COMMAND_INIT(NModeGameCommand) // SMode Game Command -void SModeGameCommand::create() -{ +void SModeGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("smode")); this->setAccessLevel(1); } -void SModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void SModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { source->sendMessage(*player, "Error: Too few parameters. Syntax: smode "_jrs); return; @@ -4338,8 +4170,7 @@ void SModeGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, c source->sendMessage(*player, "Player's mode has been reset."_jrs); } -const Jupiter::ReadableString &SModeGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &SModeGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resets a player's mode from spectator to normal. Syntax: smode "); return defaultHelp; } @@ -4348,22 +4179,21 @@ GAME_COMMAND_INIT(SModeGameCommand) // CancelVote Game Command -void CancelVoteGameCommand::create() -{ +void CancelVoteGameCommand::create() { this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvote")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("cancelvotes")); this->addTrigger(STRING_LITERAL_AS_REFERENCE("cv")); this->setAccessLevel(1); } -void CancelVoteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ +void CancelVoteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { bool cancel_all = false; RenX::TeamType target = RenX::TeamType::None; if (parameters.isEmpty()) { cancel_all = true; - } else { + } + else { if (parameters.equalsi("all") || parameters.equalsi("a")) { cancel_all = true; } else if (parameters.equalsi("public") || parameters.equalsi("p")) { @@ -4384,13 +4214,13 @@ void CancelVoteGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *play source->cancelVote(RenX::TeamType::None); source->cancelVote(RenX::TeamType::GDI); source->cancelVote(RenX::TeamType::Nod); - } else { + } + else { source->cancelVote(target); } } -const Jupiter::ReadableString &CancelVoteGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &CancelVoteGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Cancels active votes. Syntax: cancelvote [all|public|gdi|nod|blackhand]"); return defaultHelp; } diff --git a/src/Plugins/RenX/RenX.Commands/RenX_Commands.h b/src/Plugins/RenX/RenX.Commands/RenX_Commands.h index d7a6871..a01d755 100644 --- a/src/Plugins/RenX/RenX.Commands/RenX_Commands.h +++ b/src/Plugins/RenX/RenX.Commands/RenX_Commands.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -47,10 +47,10 @@ public: private: std::chrono::seconds m_defaultTempBanTime; std::chrono::seconds m_maxTempBanTime; - Jupiter::StringS playerInfoFormat; - Jupiter::StringS adminPlayerInfoFormat; - Jupiter::StringS buildingInfoFormat; - Jupiter::StringS staffTitle; + Jupiter::StringS m_playerInfoFormat; + Jupiter::StringS m_adminPlayerInfoFormat; + Jupiter::StringS m_buildingInfoFormat; + Jupiter::StringS m_staffTitle; }; GENERIC_CONSOLE_COMMAND(RawRCONConsoleCommand) diff --git a/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.cpp b/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.cpp index 6832b6c..a849ff5 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -32,15 +32,15 @@ RenX::BanDatabase &RenX::defaultBanDatabase = _banDatabase; void RenX::BanDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) { - if (RenX::BanDatabase::read_version < 3U) + if (m_read_version < 3U) return; // incompatible database version - RenX::BanDatabase::Entry *entry = new RenX::BanDatabase::Entry(); + std::unique_ptr entry = std::make_unique(); entry->pos = pos; // Read data from buffer to entry entry->flags = buffer.pop(); - if (RenX::BanDatabase::read_version >= 4U) + if (m_read_version >= 4U) { entry->timestamp = std::chrono::system_clock::time_point(std::chrono::seconds(buffer.pop())); entry->length = std::chrono::seconds(buffer.pop()); @@ -53,7 +53,7 @@ void RenX::BanDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fp entry->steamid = buffer.pop(); entry->ip = buffer.pop(); entry->prefix_length = buffer.pop(); - if (this->read_version >= 5U) + if (m_read_version >= 5U) entry->hwid = buffer.pop(); entry->rdns = buffer.pop(); entry->name = buffer.pop(); @@ -61,78 +61,72 @@ void RenX::BanDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fp entry->reason = buffer.pop(); // Read varData from buffer to entry - for (size_t varData_entries = buffer.pop(); varData_entries != 0; --varData_entries) + for (size_t varData_entries = buffer.pop(); varData_entries != 0; --varData_entries) { entry->varData[buffer.pop()] = buffer.pop(); + } - RenX::BanDatabase::entries.add(entry); + m_entries.push_back(std::move(entry)); } void RenX::BanDatabase::process_header(FILE *file) { int chr = fgetc(file); if (chr != EOF) - RenX::BanDatabase::read_version = chr; + m_read_version = chr; } void RenX::BanDatabase::create_header(FILE *file) { - fputc(RenX::BanDatabase::write_version, file); + fputc(m_write_version, file); } -void RenX::BanDatabase::process_file_finish(FILE *file) -{ - if (RenX::BanDatabase::read_version < 3) - { - if (freopen(RenX::BanDatabase::filename.c_str(), "wb", file) == nullptr) +void RenX::BanDatabase::process_file_finish(FILE *file) { + if (m_read_version < 3) { + if (freopen(m_filename.c_str(), "wb", file) == nullptr) { puts("FATAL ERROR: UNABLE TO REMOVE UNSUPPORTED BAN DATABASE FILE VERSION"); - else - { - puts("Warning: Unsupported ban database file version. The database will be removed and rewritten."); - this->create_header(file); - fgetpos(file, std::addressof(RenX::BanDatabase::eof)); - RenX::BanDatabase::read_version = RenX::BanDatabase::write_version; + return; } + + puts("Warning: Unsupported ban database file version. The database will be removed and rewritten."); + create_header(file); + fgetpos(file, std::addressof(m_eof)); + m_read_version = m_write_version; return; } - else if (RenX::BanDatabase::read_version < RenX::BanDatabase::write_version) - { - if (freopen(RenX::BanDatabase::filename.c_str(), "wb", file) != nullptr) - { + else if (m_read_version < m_write_version) { + if (freopen(m_filename.c_str(), "wb", file) != nullptr) { this->create_header(file); - for (size_t index = 0; index != RenX::BanDatabase::entries.size(); ++index) - RenX::BanDatabase::write(RenX::BanDatabase::entries.get(index), file); + for (const auto& entry : m_entries) { + write(entry.get(), file); + } } } - fgetpos(file, std::addressof(RenX::BanDatabase::eof)); + fgetpos(file, std::addressof(m_eof)); } -void RenX::BanDatabase::upgrade_database() -{ - FILE *file = fopen(RenX::BanDatabase::filename.c_str(), "wb"); - if (file != nullptr) - { +void RenX::BanDatabase::upgrade_database() { + FILE *file = fopen(m_filename.c_str(), "wb"); + if (file != nullptr) { this->create_header(file); - for (size_t index = 0; index != RenX::BanDatabase::entries.size(); ++index) - RenX::BanDatabase::write(RenX::BanDatabase::entries.get(index), file); + for (const auto& entry : m_entries) { + write(entry.get(), file); + } fclose(file); } } -void RenX::BanDatabase::write(RenX::BanDatabase::Entry *entry) -{ - FILE *file = fopen(filename.c_str(), "r+b"); - fsetpos(file, std::addressof(RenX::BanDatabase::eof)); - if (file != nullptr) - { - RenX::BanDatabase::write(entry, file); +void RenX::BanDatabase::write(Entry* entry) { + FILE *file = fopen(m_filename.c_str(), "r+b"); + fsetpos(file, std::addressof(m_eof)); + if (file != nullptr) { + write(entry, file); fclose(file); } } -void RenX::BanDatabase::write(RenX::BanDatabase::Entry *entry, FILE *file) -{ +void RenX::BanDatabase::write(Entry* entry, FILE *file) { Jupiter::DataBuffer buffer; fgetpos(file, &entry->pos); @@ -160,12 +154,11 @@ void RenX::BanDatabase::write(RenX::BanDatabase::Entry *entry, FILE *file) // push buffer to file buffer.push_to(file); - fgetpos(file, std::addressof(RenX::BanDatabase::eof)); + fgetpos(file, std::addressof(m_eof)); } -void RenX::BanDatabase::add(RenX::Server *server, const RenX::PlayerInfo &player, const Jupiter::ReadableString &banner, const Jupiter::ReadableString &reason, std::chrono::seconds length, uint16_t flags) -{ - Entry *entry = new Entry(); +void RenX::BanDatabase::add(RenX::Server *server, const RenX::PlayerInfo &player, const Jupiter::ReadableString &banner, const Jupiter::ReadableString &reason, std::chrono::seconds length, uint16_t flags) { + std::unique_ptr entry = std::make_unique(); if (flags != 0) { entry->set_active(); entry->flags |= flags; @@ -187,18 +180,18 @@ void RenX::BanDatabase::add(RenX::Server *server, const RenX::PlayerInfo &player // add plugin data Jupiter::String pluginData; - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (size_t i = 0; i < xPlugins.size(); i++) - if (xPlugins.get(i)->RenX_OnBan(*server, player, pluginData)) - entry->varData[xPlugins.get(i)->getName()] = pluginData; + for (Plugin* plugin : RenX::getCore()->getPlugins()) { + if (plugin->RenX_OnBan(*server, player, pluginData)) { + entry->varData[plugin->getName()] = pluginData; + } + } - entries.add(entry); - RenX::BanDatabase::write(entry); + m_entries.push_back(std::move(entry)); + write(m_entries.back().get()); } -void RenX::BanDatabase::add(const Jupiter::ReadableString &name, uint32_t ip, uint8_t prefix_length, uint64_t steamid, const Jupiter::ReadableString &hwid, const Jupiter::ReadableString &rdns, const Jupiter::ReadableString &banner, Jupiter::ReadableString &reason, std::chrono::seconds length, uint16_t flags) -{ - Entry *entry = new Entry(); +void RenX::BanDatabase::add(const Jupiter::ReadableString &name, uint32_t ip, uint8_t prefix_length, uint64_t steamid, const Jupiter::ReadableString &hwid, const Jupiter::ReadableString &rdns, const Jupiter::ReadableString &banner, Jupiter::ReadableString &reason, std::chrono::seconds length, uint16_t flags) { + std::unique_ptr entry = std::make_unique(); entry->set_active(); entry->flags |= flags; entry->timestamp = std::chrono::system_clock::now(); @@ -212,19 +205,20 @@ void RenX::BanDatabase::add(const Jupiter::ReadableString &name, uint32_t ip, ui entry->banner = banner; entry->reason = reason; - entries.add(entry); - RenX::BanDatabase::write(entry); + m_entries.push_back(std::move(entry)); + write(m_entries.back().get()); } -bool RenX::BanDatabase::deactivate(size_t index) -{ - RenX::BanDatabase::Entry *entry = RenX::BanDatabase::entries.get(index); - if (entry->is_active()) - { +bool RenX::BanDatabase::deactivate(size_t index) { + const auto& entry = m_entries[index]; + return deactivate(entry.get()); +} + +bool RenX::BanDatabase::deactivate(Entry* entry) { + if (entry->is_active()) { entry->unset_active(); - FILE *file = fopen(RenX::BanDatabase::filename.c_str(), "r+b"); - if (file != nullptr) - { + FILE *file = fopen(m_filename.c_str(), "r+b"); + if (file != nullptr) { fsetpos(file, &entry->pos); fseek(file, sizeof(size_t), SEEK_CUR); fwrite(std::addressof(entry->flags), sizeof(entry->flags), 1, file); @@ -235,28 +229,22 @@ bool RenX::BanDatabase::deactivate(size_t index) return false; } -uint8_t RenX::BanDatabase::getVersion() const -{ - return RenX::BanDatabase::write_version; +uint8_t RenX::BanDatabase::getVersion() const { + return m_write_version; } -const std::string &RenX::BanDatabase::getFileName() const -{ - return RenX::BanDatabase::filename; +const std::string &RenX::BanDatabase::getFileName() const { + return m_filename; } -const Jupiter::ArrayList &RenX::BanDatabase::getEntries() const -{ - return RenX::BanDatabase::entries; +const std::vector>& RenX::BanDatabase::getEntries() const { + return m_entries; } -bool RenX::BanDatabase::initialize() -{ - RenX::BanDatabase::filename = static_cast(RenX::getCore()->getConfig().get("BanDB"_jrs, "Bans.db"_jrs)); - return this->process_file(filename); +bool RenX::BanDatabase::initialize() { + m_filename = static_cast(RenX::getCore()->getConfig().get("BanDB"_jrs, "Bans.db"_jrs)); + return this->process_file(m_filename); } -RenX::BanDatabase::~BanDatabase() -{ - RenX::BanDatabase::entries.emptyAndDelete(); +RenX::BanDatabase::~BanDatabase() { } \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.h b/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.h index 45ebb9b..7e26616 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.h +++ b/src/Plugins/RenX/RenX.Core/RenX_BanDatabase.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,7 +23,6 @@ #include #include "Jupiter/Database.h" #include "Jupiter/String.hpp" -#include "Jupiter/ArrayList.h" #include "RenX.h" /** DLL Linkage Nagging */ @@ -188,6 +187,7 @@ namespace RenX * @param True if the entry was active and is now inactive, false otherwise. */ bool deactivate(size_t index); + bool deactivate(Entry* entry); /** * @brief Fetches the version of the database file. @@ -208,19 +208,19 @@ namespace RenX * * @return List of entries */ - const Jupiter::ArrayList &getEntries() const; + const std::vector>& getEntries() const; virtual bool initialize(); ~BanDatabase(); private: /** Database version */ - const uint8_t write_version = 5U; - uint8_t read_version = write_version; - fpos_t eof; + const uint8_t m_write_version = 5U; + uint8_t m_read_version = m_write_version; + fpos_t m_eof; - std::string filename; - Jupiter::ArrayList entries; + std::string m_filename; + std::vector> m_entries; }; RENX_API extern RenX::BanDatabase *banDatabase; diff --git a/src/Plugins/RenX/RenX.Core/RenX_Core.cpp b/src/Plugins/RenX/RenX.Core/RenX_Core.cpp index f4d56f9..38dd0c2 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Core.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Core.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -34,158 +34,157 @@ using namespace Jupiter::literals; RenX::Core pluginInstance; RenX::Core *RenXInstance = &pluginInstance; -RenX::Core *RenX::getCore() -{ +RenX::Core *RenX::getCore() { return &pluginInstance; } -bool RenX::Core::initialize() -{ +bool RenX::Core::initialize() { RenX::banDatabase->initialize(); RenX::exemptionDatabase->initialize(); RenX::tags->initialize(); RenX::initTranslations(this->config); const Jupiter::ReadableString &serverList = this->config.get("Servers"_jrs); - RenX::Core::commandsFile.read(this->config.get("CommandsFile"_jrs, "RenXGameCommands.ini"_jrs)); + m_commandsFile.read(this->config.get("CommandsFile"_jrs, "RenXGameCommands.ini"_jrs)); unsigned int wc = serverList.wordCount(WHITESPACE); - RenX::Server *server; - for (unsigned int i = 0; i != wc; i++) - { - server = new RenX::Server(Jupiter::ReferenceString::getWord(serverList, i, WHITESPACE)); + std::unique_ptr server; + for (unsigned int i = 0; i != wc; i++) { + server = std::make_unique(Jupiter::ReferenceString::getWord(serverList, i, WHITESPACE)); - if (server->connect() == false) - { + if (server->connect() == false) { fprintf(stderr, "[RenX] ERROR: Failed to connect to %.*s on port %u. Error code: %d" ENDL, server->getHostname().size(), server->getHostname().c_str(), server->getPort(), Jupiter::Socket::getLastError()); - delete server; + continue; } - else RenX::Core::addServer(server); + + addServer(std::move(server)); } return true; } -RenX::Core::~Core() -{ - RenX::Core::servers.emptyAndDelete(); +RenX::Core::~Core() { } -size_t RenX::Core::send(int type, const Jupiter::ReadableString &msg) -{ +size_t RenX::Core::send(int type, const Jupiter::ReadableString &msg) { size_t result = 0; - RenX::Server *server; - for (size_t i = 0; i != RenX::Core::servers.size(); i++) - { - server = RenX::Core::getServer(i); - if (server->isLogChanType(type) && server->send(msg) > 0) + for (auto& server : m_servers) { + if (server->isLogChanType(type) && server->send(msg) > 0) { ++result; + } } return result; } -void RenX::Core::addServer(RenX::Server *server) -{ - RenX::Core::servers.add(server); +void RenX::Core::addServer(std::unique_ptr server) { + m_servers.push_back(std::move(server)); } -size_t RenX::Core::getServerIndex(RenX::Server *server) -{ - for (size_t index = 0; index != RenX::Core::servers.size(); ++index) - if (server == RenX::Core::servers.get(index)) +size_t RenX::Core::getServerIndex(RenX::Server *server) { + for (size_t index = 0; index != m_servers.size(); ++index) { + if (server == m_servers[index].get()) { return index; + } + } return Jupiter::INVALID_INDEX; } -RenX::Server *RenX::Core::getServer(size_t index) -{ - return RenX::Core::servers.get(index); +RenX::Server* RenX::Core::getServer(size_t index) { + if (index > m_servers.size()) { + return nullptr; + } + + return m_servers[index].get(); } -Jupiter::ArrayList RenX::Core::getServers() -{ - return RenX::Core::servers; +std::vector RenX::Core::getServers() { + std::vector result; + + for (const auto& server : m_servers) { + result.push_back(server.get()); + } + + return result; } -Jupiter::ArrayList RenX::Core::getServers(int type) -{ - Jupiter::ArrayList r; - RenX::Server *server; - for (size_t i = 0; i != RenX::Core::servers.size(); i++) - { - server = RenX::Core::servers.get(i); - if (server != nullptr && server->isLogChanType(type)) - r.add(server); +std::vector RenX::Core::getServers(int type) { + std::vector result; + + for (const auto& server : m_servers) { + if (server->isLogChanType(type)) { + result.push_back(server.get()); + } } - return r; + + return result; } -void RenX::Core::removeServer(unsigned int index) -{ - delete RenX::Core::servers.remove(index); +void RenX::Core::removeServer(unsigned int index) { + if (index < m_servers.size()) { + m_servers.erase(m_servers.begin() + index); + } } -size_t RenX::Core::removeServer(RenX::Server *server) -{ - size_t index = RenX::Core::getServerIndex(server); - - if (index != Jupiter::INVALID_INDEX) - delete RenX::Core::servers.remove(index); +size_t RenX::Core::removeServer(RenX::Server *server) { + for (auto itr = m_servers.begin(); itr != m_servers.end(); ++itr) { + if (itr->get() == server) { + size_t index = m_servers.end() - itr; + m_servers.erase(itr); + return index; + } + } - return index; + return Jupiter::INVALID_INDEX; } -bool RenX::Core::hasServer(RenX::Server *server) -{ - size_t index = RenX::Core::servers.size(); - - while (index != 0) - if (server == RenX::Core::servers.get(--index)) +bool RenX::Core::hasServer(RenX::Server* in_server) { + for (const auto& server : m_servers) { + if (server.get() == in_server) { return true; + } + } return false; } -size_t RenX::Core::getServerCount() -{ - return RenX::Core::servers.size(); +size_t RenX::Core::getServerCount() { + return m_servers.size(); } -Jupiter::ArrayList *RenX::Core::getPlugins() -{ - return &(RenX::Core::plugins); +std::vector& RenX::Core::getPlugins() { + return m_plugins; } -Jupiter::Config &RenX::Core::getCommandsFile() -{ - return RenX::Core::commandsFile; +Jupiter::Config &RenX::Core::getCommandsFile() { + return m_commandsFile; } -size_t RenX::Core::addCommand(RenX::GameCommand *command) -{ - for (size_t index = 0; index != RenX::Core::servers.size(); ++index) - RenX::Core::servers.get(index)->addCommand(command->copy()); +size_t RenX::Core::addCommand(RenX::GameCommand *command) { + for (const auto& server : m_servers) { + server->addCommand(command->copy()); + } - return RenX::Core::servers.size(); + return m_servers.size(); } -void RenX::Core::banCheck() -{ - for (size_t index = 0; index != RenX::Core::servers.size(); ++index) - RenX::Core::servers.get(index)->banCheck(); +void RenX::Core::banCheck() { + for (const auto& server : m_servers) { + server->banCheck(); + } } -int RenX::Core::think() -{ - size_t index = 0; - while (index < RenX::Core::servers.size()) - if (RenX::Core::servers.get(index)->think() != 0) - delete RenX::Core::servers.remove(index); - else ++index; +int RenX::Core::think() { + for (auto itr = m_servers.begin(); itr != m_servers.end();) { + if ((*itr)->think() != 0) { + itr = m_servers.erase(itr + 1); + continue; + } + ++itr; + } return Jupiter::Plugin::think(); } @@ -199,8 +198,10 @@ extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() // Unload -extern "C" JUPITER_EXPORT void unload(void) -{ - while (pluginInstance.getPlugins()->size() > 0) - Jupiter::Plugin::free(pluginInstance.getPlugins()->remove(0)); +extern "C" JUPITER_EXPORT void unload(void) { + auto& plugins = pluginInstance.getPlugins(); + while (!plugins.empty()) { + Jupiter::Plugin::free(plugins.back()); + plugins.pop_back(); + } } diff --git a/src/Plugins/RenX/RenX.Core/RenX_Core.h b/src/Plugins/RenX/RenX.Core/RenX_Core.h index 6ae625f..dc198b4 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Core.h +++ b/src/Plugins/RenX/RenX.Core/RenX_Core.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -27,6 +27,7 @@ #include "Jupiter/Plugin.h" #include "Jupiter/Config.h" #include "RenX.h" +#include "RenX_Server.h" /** DLL Linkage Nagging */ #if defined _MSC_VER @@ -80,7 +81,7 @@ namespace RenX * * @param server Server to add to the list. */ - void addServer(RenX::Server *server); + void addServer(std::unique_ptr server); /** * @brief Fetches a server's index. @@ -103,15 +104,15 @@ namespace RenX * * @return Copy of the list of servers. */ - Jupiter::ArrayList getServers(); + std::vector getServers(); /** * @brief Constructs a list of servers based on their type. * * @param type Type of servers to fetch. - * @return ArrayList of servers with the same type. + * @return vector of servers with the same type. */ - Jupiter::ArrayList getServers(int type); + std::vector getServers(int type); /** * @brief Removes a server based on its index. @@ -146,9 +147,9 @@ namespace RenX /** * @brief Fetches the Renegade-X plugins currently loaded. * - * @return ArrayList containing pointers to the plugins. + * @return vector containing pointers to the plugins. */ - Jupiter::ArrayList *getPlugins(); + std::vector& getPlugins(); /** * @brief Fetches the commands settings file. @@ -175,11 +176,15 @@ namespace RenX */ ~Core(); + Core() = default; + Core(const Core&) = delete; + Core& operator=(const Core&) = delete; + private: /** Inaccessible private members */ - Jupiter::ArrayList servers; - Jupiter::ArrayList plugins; - Jupiter::INIConfig commandsFile; + std::vector> m_servers; + std::vector m_plugins; + Jupiter::INIConfig m_commandsFile; }; RENX_API Core *getCore(); diff --git a/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.cpp b/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.cpp index 999efec..c7868de 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.cpp @@ -1,5 +1,5 @@ /** -* Copyright (C) 2016-2017 Jessica James. +* Copyright (C) 2016-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -25,13 +25,12 @@ using namespace Jupiter::literals; -RenX::ExemptionDatabase _exemptionDatabase; -RenX::ExemptionDatabase *RenX::exemptionDatabase = &_exemptionDatabase; -RenX::ExemptionDatabase &RenX::defaultExemptionDatabase = _exemptionDatabase; +RenX::ExemptionDatabase g_exemptionDatabase; +RenX::ExemptionDatabase *RenX::exemptionDatabase = &g_exemptionDatabase; +RenX::ExemptionDatabase &RenX::defaultExemptionDatabase = g_exemptionDatabase; -void RenX::ExemptionDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) -{ - RenX::ExemptionDatabase::Entry *entry = new RenX::ExemptionDatabase::Entry(); +void RenX::ExemptionDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) { + std::unique_ptr entry = std::make_unique(); entry->pos = pos; // Read data from buffer to entry @@ -43,52 +42,45 @@ void RenX::ExemptionDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *fi entry->prefix_length = buffer.pop(); entry->setter = buffer.pop(); - RenX::ExemptionDatabase::entries.add(entry); + m_entries.push_back(std::move(entry)); } -void RenX::ExemptionDatabase::process_header(FILE *file) -{ +void RenX::ExemptionDatabase::process_header(FILE *file) { int chr = fgetc(file); if (chr != EOF) - RenX::ExemptionDatabase::read_version = chr; + m_read_version = chr; } -void RenX::ExemptionDatabase::create_header(FILE *file) -{ - fputc(RenX::ExemptionDatabase::write_version, file); +void RenX::ExemptionDatabase::create_header(FILE *file) { + fputc(m_write_version, file); } -void RenX::ExemptionDatabase::process_file_finish(FILE *file) -{ - fgetpos(file, std::addressof(RenX::ExemptionDatabase::eof)); +void RenX::ExemptionDatabase::process_file_finish(FILE *file) { + fgetpos(file, std::addressof(m_eof)); } -void RenX::ExemptionDatabase::upgrade_database() -{ - FILE *file = fopen(RenX::ExemptionDatabase::filename.c_str(), "wb"); - if (file != nullptr) - { +void RenX::ExemptionDatabase::upgrade_database() { + FILE *file = fopen(m_filename.c_str(), "wb"); + if (file != nullptr) { this->create_header(file); - for (size_t index = 0; RenX::ExemptionDatabase::entries.size(); ++index) - RenX::ExemptionDatabase::write(RenX::ExemptionDatabase::entries.get(index), file); + for (size_t index = 0; m_entries.size(); ++index) { + write(m_entries[index].get(), file); + } fclose(file); } } -void RenX::ExemptionDatabase::write(RenX::ExemptionDatabase::Entry *entry) -{ - FILE *file = fopen(filename.c_str(), "r+b"); - fsetpos(file, std::addressof(RenX::ExemptionDatabase::eof)); - if (file != nullptr) - { - RenX::ExemptionDatabase::write(entry, file); +void RenX::ExemptionDatabase::write(RenX::ExemptionDatabase::Entry *entry) { + FILE *file = fopen(m_filename.c_str(), "r+b"); + fsetpos(file, std::addressof(m_eof)); + if (file != nullptr) { + write(entry, file); fclose(file); } } -void RenX::ExemptionDatabase::write(RenX::ExemptionDatabase::Entry *entry, FILE *file) -{ +void RenX::ExemptionDatabase::write(RenX::ExemptionDatabase::Entry *entry, FILE *file) { Jupiter::DataBuffer buffer; fgetpos(file, &entry->pos); @@ -103,17 +95,15 @@ void RenX::ExemptionDatabase::write(RenX::ExemptionDatabase::Entry *entry, FILE // push buffer to file buffer.push_to(file); - fgetpos(file, std::addressof(RenX::ExemptionDatabase::eof)); + fgetpos(file, std::addressof(m_eof)); } -void RenX::ExemptionDatabase::add(RenX::Server &, const RenX::PlayerInfo &player, const Jupiter::ReadableString &setter, std::chrono::seconds length, uint8_t flags) -{ - RenX::ExemptionDatabase::add(player.ip32, 32U, player.steamid, setter, length, flags); +void RenX::ExemptionDatabase::add(RenX::Server &, const RenX::PlayerInfo &player, const Jupiter::ReadableString &setter, std::chrono::seconds length, uint8_t flags) { + add(player.ip32, 32U, player.steamid, setter, length, flags); } -void RenX::ExemptionDatabase::add(uint32_t ip, uint8_t prefix_length, uint64_t steamid, const Jupiter::ReadableString &setter, std::chrono::seconds length, uint8_t flags) -{ - Entry *entry = new Entry(); +void RenX::ExemptionDatabase::add(uint32_t ip, uint8_t prefix_length, uint64_t steamid, const Jupiter::ReadableString &setter, std::chrono::seconds length, uint8_t flags) { + std::unique_ptr entry = std::make_unique(); entry->set_active(); entry->flags |= flags; entry->timestamp = std::chrono::system_clock::now(); @@ -123,19 +113,16 @@ void RenX::ExemptionDatabase::add(uint32_t ip, uint8_t prefix_length, uint64_t s entry->prefix_length = prefix_length; entry->setter = setter; - entries.add(entry); - RenX::ExemptionDatabase::write(entry); + m_entries.push_back(std::move(entry)); + write(m_entries.back().get()); } -bool RenX::ExemptionDatabase::deactivate(size_t index) -{ - RenX::ExemptionDatabase::Entry *entry = RenX::ExemptionDatabase::entries.get(index); - if (entry->is_active()) - { +bool RenX::ExemptionDatabase::deactivate(size_t index) { + Entry* entry = m_entries[index].get(); + if (entry->is_active()) { entry->unset_active(); - FILE *file = fopen(RenX::ExemptionDatabase::filename.c_str(), "r+b"); - if (file != nullptr) - { + FILE *file = fopen(m_filename.c_str(), "r+b"); + if (file != nullptr) { fsetpos(file, &entry->pos); fseek(file, sizeof(size_t), SEEK_CUR); fwrite(std::addressof(entry->flags), sizeof(entry->flags), 1, file); @@ -146,51 +133,43 @@ bool RenX::ExemptionDatabase::deactivate(size_t index) return false; } -void RenX::ExemptionDatabase::exemption_check(RenX::PlayerInfo &player) -{ - RenX::ExemptionDatabase::Entry *entry; +void RenX::ExemptionDatabase::exemption_check(RenX::PlayerInfo &player) { + Entry* entry; uint32_t netmask; - size_t index = RenX::ExemptionDatabase::entries.size(); - while (index != 0) - { - entry = RenX::ExemptionDatabase::entries.get(--index); - if (entry->is_active()) - { - if (entry->length == std::chrono::seconds::zero() || entry->timestamp + entry->length < std::chrono::system_clock::now()) - { + size_t index = m_entries.size(); + while (index != 0) { + entry = m_entries[--index].get(); + if (entry->is_active()) { + if (entry->length == std::chrono::seconds::zero() || entry->timestamp + entry->length < std::chrono::system_clock::now()) { netmask = Jupiter_prefix_length_to_netmask(entry->prefix_length); if ((player.steamid != 0 && entry->steamid == player.steamid) // SteamID exemption - || (player.ip32 != 0U && (player.ip32 & netmask) == (entry->ip & netmask))) // IP address exemption + || (player.ip32 != 0U && (player.ip32 & netmask) == (entry->ip & netmask))) { // IP address exemption player.exemption_flags |= entry->flags; + } + } + else { + deactivate(index); } - else - RenX::ExemptionDatabase::deactivate(index); } } } -uint8_t RenX::ExemptionDatabase::getVersion() const -{ - return RenX::ExemptionDatabase::write_version; +uint8_t RenX::ExemptionDatabase::getVersion() const { + return m_write_version; } -const std::string &RenX::ExemptionDatabase::getFileName() const -{ - return RenX::ExemptionDatabase::filename; +const std::string &RenX::ExemptionDatabase::getFileName() const { + return m_filename; } -const Jupiter::ArrayList &RenX::ExemptionDatabase::getEntries() const -{ - return RenX::ExemptionDatabase::entries; +const std::vector>& RenX::ExemptionDatabase::getEntries() const { + return m_entries; } -bool RenX::ExemptionDatabase::initialize() -{ - RenX::ExemptionDatabase::filename = static_cast(RenX::getCore()->getConfig().get("ExemptionDB"_jrs, "Exemptions.db"_jrs)); - return this->process_file(filename); +bool RenX::ExemptionDatabase::initialize() { + m_filename = static_cast(RenX::getCore()->getConfig().get("ExemptionDB"_jrs, "Exemptions.db"_jrs)); + return this->process_file(m_filename); } -RenX::ExemptionDatabase::~ExemptionDatabase() -{ - RenX::ExemptionDatabase::entries.emptyAndDelete(); +RenX::ExemptionDatabase::~ExemptionDatabase() { } diff --git a/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.h b/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.h index e04a0da..113125b 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.h +++ b/src/Plugins/RenX/RenX.Core/RenX_ExemptionDatabase.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2016-2017 Jessica James. + * Copyright (C) 2016-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,7 +23,6 @@ #include #include "Jupiter/Database.h" #include "Jupiter/String.hpp" -#include "Jupiter/ArrayList.h" #include "RenX.h" /** DLL Linkage Nagging */ @@ -179,19 +178,19 @@ namespace RenX * * @return List of entries */ - const Jupiter::ArrayList &getEntries() const; + const std::vector>& getEntries() const; virtual bool initialize(); ~ExemptionDatabase(); private: /** Database version */ - const uint8_t write_version = 0U; - uint8_t read_version = write_version; - fpos_t eof; + const uint8_t m_write_version = 0U; + uint8_t m_read_version = m_write_version; + fpos_t m_eof; - std::string filename; - Jupiter::ArrayList entries; + std::string m_filename; + std::vector> m_entries; }; RENX_API extern RenX::ExemptionDatabase *exemptionDatabase; diff --git a/src/Plugins/RenX/RenX.Core/RenX_GameCommand.cpp b/src/Plugins/RenX/RenX.Core/RenX_GameCommand.cpp index 118ae3d..c6fe7e6 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_GameCommand.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_GameCommand.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,95 +19,83 @@ #include "RenX_GameCommand.h" #include "RenX_Server.h" -Jupiter::ArrayList _GameMasterCommandList; -Jupiter::ArrayList *RenX::GameMasterCommandList = &_GameMasterCommandList; +std::vector g_GameMasterCommandList; +std::vector &RenX::GameMasterCommandList = g_GameMasterCommandList; RenX::Server *RenX::GameCommand::active_server = nullptr; RenX::Server *RenX::GameCommand::selected_server = nullptr; -RenX::GameCommand::GameCommand(std::nullptr_t) -{ +RenX::GameCommand::GameCommand(std::nullptr_t) { } -RenX::GameCommand::GameCommand(const RenX::GameCommand &command) -{ +RenX::GameCommand::GameCommand(const RenX::GameCommand &command) { //RenX::GameMasterCommandList->add(this); } -RenX::GameCommand::GameCommand() -{ - RenX::GameMasterCommandList->add(this); +RenX::GameCommand::GameCommand() { + RenX::GameMasterCommandList.push_back(this); } -RenX::GameCommand::~GameCommand() -{ +RenX::GameCommand::~GameCommand() { RenX::Core *core = RenX::getCore(); - for (size_t command_index = 0; command_index != RenX::GameMasterCommandList->size(); ++command_index) - { - if (RenX::GameMasterCommandList->get(command_index) == this) - { + for (auto itr = RenX::GameMasterCommandList.begin(); itr != RenX::GameMasterCommandList.end(); ++itr) { + if (*itr == this) { RenX::Server *server; - for (size_t server_index = 0; server_index != core->getServerCount(); ++server_index) - { + for (size_t server_index = 0; server_index != core->getServerCount(); ++server_index) { server = core->getServer(server_index); - if (server != nullptr) + if (server != nullptr) { server->removeCommand(this->getTrigger()); + } } - RenX::GameMasterCommandList->remove(command_index); + RenX::GameMasterCommandList.erase(itr); break; } } } -int RenX::GameCommand::getAccessLevel() -{ +int RenX::GameCommand::getAccessLevel() { return RenX::GameCommand::access; } -void RenX::GameCommand::setAccessLevel(int accessLevel) -{ +void RenX::GameCommand::setAccessLevel(int accessLevel) { RenX::GameCommand::access = accessLevel; } // Basic Game Command -RenX::BasicGameCommand::BasicGameCommand() : RenX::GameCommand(nullptr) -{ +RenX::BasicGameCommand::BasicGameCommand() : RenX::GameCommand(nullptr) { } -RenX::BasicGameCommand::BasicGameCommand(BasicGameCommand &c) : RenX::GameCommand(c) -{ +RenX::BasicGameCommand::BasicGameCommand(BasicGameCommand &c) : RenX::GameCommand(c) { } -RenX::BasicGameCommand::BasicGameCommand(const Jupiter::ReadableString &in_trigger, const Jupiter::ReadableString &in_message, const Jupiter::ReadableString &in_help_message) : RenX::GameCommand(nullptr) -{ +RenX::BasicGameCommand::BasicGameCommand(const Jupiter::ReadableString &in_trigger, const Jupiter::ReadableString &in_message, const Jupiter::ReadableString &in_help_message) + : RenX::GameCommand(nullptr) { this->addTrigger(in_trigger); - RenX::BasicGameCommand::message = in_message; - RenX::BasicGameCommand::help_message = in_help_message; + m_message = in_message; + m_help_message = in_help_message; } -void RenX::BasicGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) -{ - source->sendMessage(RenX::BasicGameCommand::message); +void RenX::BasicGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) { + source->sendMessage(m_message); } -const Jupiter::ReadableString &RenX::BasicGameCommand::getHelp(const Jupiter::ReadableString &) -{ +const Jupiter::ReadableString &RenX::BasicGameCommand::getHelp(const Jupiter::ReadableString &) { static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Returns a basic text string."); - if (RenX::BasicGameCommand::help_message.isEmpty()) + if (m_help_message.isEmpty()) { return defaultHelp; - return RenX::BasicGameCommand::help_message; + } + + return m_help_message; } -RenX::BasicGameCommand *RenX::BasicGameCommand::copy() -{ - RenX::BasicGameCommand *r = new RenX::BasicGameCommand(*this); - r->message = RenX::BasicGameCommand::message; - r->help_message = RenX::BasicGameCommand::help_message; - return r; +RenX::BasicGameCommand *RenX::BasicGameCommand::copy() { + RenX::BasicGameCommand* result = new RenX::BasicGameCommand(*this); + result->m_message = m_message; + result->m_help_message = m_help_message; + return result; } -void RenX::BasicGameCommand::create() -{ +void RenX::BasicGameCommand::create() { } \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.Core/RenX_GameCommand.h b/src/Plugins/RenX/RenX.Core/RenX_GameCommand.h index a371a37..10d5757 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_GameCommand.h +++ b/src/Plugins/RenX/RenX.Core/RenX_GameCommand.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2015 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -43,7 +43,7 @@ namespace RenX class GameCommand; /** Master command list */ - RENX_API extern Jupiter::ArrayList *GameMasterCommandList; + RENX_API extern std::vector& GameMasterCommandList; /** * @brief Provides an extendable interface from which in-game commands can be created. @@ -133,7 +133,7 @@ namespace RenX BasicGameCommand(const Jupiter::ReadableString &trigger, const Jupiter::ReadableString &in_message, const Jupiter::ReadableString &in_help_message); private: - Jupiter::StringS message, help_message; + Jupiter::StringS m_message, m_help_message; }; } diff --git a/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.cpp b/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.cpp index aa6c74d..b9ad995 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2015-2017 Jessica James. + * Copyright (C) 2015-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -22,50 +22,47 @@ #include "RenX_BanDatabase.h" RenX::LadderDatabase *RenX::default_ladder_database = nullptr; -Jupiter::ArrayList _ladder_databases; -Jupiter::ArrayList &RenX::ladder_databases = _ladder_databases; +std::vector g_ladder_databases; +std::vector& RenX::ladder_databases = g_ladder_databases; -RenX::LadderDatabase::LadderDatabase() -{ - _ladder_databases.add(this); +RenX::LadderDatabase::LadderDatabase() { + g_ladder_databases.push_back(this); - if (RenX::default_ladder_database == nullptr) + if (RenX::default_ladder_database == nullptr) { RenX::default_ladder_database = this; + } } -RenX::LadderDatabase::LadderDatabase(const Jupiter::ReadableString &in_name) : LadderDatabase() -{ +RenX::LadderDatabase::LadderDatabase(const Jupiter::ReadableString &in_name) : LadderDatabase() { RenX::LadderDatabase::setName(in_name); } -RenX::LadderDatabase::~LadderDatabase() -{ - while (RenX::LadderDatabase::head != nullptr) - { - RenX::LadderDatabase::end = RenX::LadderDatabase::head; - RenX::LadderDatabase::head = RenX::LadderDatabase::head->next; - delete RenX::LadderDatabase::end; +RenX::LadderDatabase::~LadderDatabase() { + while (m_head != nullptr) { + m_end = m_head; + m_head = m_head->next; + delete m_end; } - for (size_t index = 0; index != _ladder_databases.size(); ++index) - if (_ladder_databases.get(index) == this) - { - _ladder_databases.remove(index); + for (auto itr = g_ladder_databases.begin(); itr != g_ladder_databases.end(); ++itr) { + if (*itr == this) { + g_ladder_databases.erase(itr); break; } + } - if (RenX::default_ladder_database == this) - { - if (_ladder_databases.size() == 0) + if (RenX::default_ladder_database == this) { + if (g_ladder_databases.empty()) { RenX::default_ladder_database = nullptr; - else - RenX::default_ladder_database = _ladder_databases.get(0); + } + else { + RenX::default_ladder_database = g_ladder_databases[0]; + } } } -void RenX::LadderDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) -{ - RenX::LadderDatabase::Entry *entry = new RenX::LadderDatabase::Entry(); +void RenX::LadderDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) { + Entry *entry = new Entry(); // read data from buffer to entry entry->steam_id = buffer.pop(); @@ -80,13 +77,13 @@ void RenX::LadderDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, entry->total_captures = buffer.pop(); entry->total_game_time = buffer.pop(); entry->total_games = buffer.pop(); - if (this->read_version == 0) + if (m_read_version == 0) { entry->total_gdi_games = buffer.pop(); entry->total_nod_games = buffer.pop(); } entry->total_wins = buffer.pop(); - if (this->read_version == 0) + if (m_read_version == 0) { entry->total_gdi_wins = buffer.pop(); entry->total_nod_wins = buffer.pop(); @@ -96,7 +93,7 @@ void RenX::LadderDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, entry->total_proxy_placements = buffer.pop(); entry->total_proxy_disarms = buffer.pop(); - if (this->read_version > 0) + if (m_read_version > 0) { entry->total_gdi_games = buffer.pop(); entry->total_gdi_wins = buffer.pop(); @@ -149,194 +146,199 @@ void RenX::LadderDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, entry->most_recent_name = buffer.pop(); // push data to list - if (RenX::LadderDatabase::head == nullptr) - { - RenX::LadderDatabase::head = entry; - RenX::LadderDatabase::end = RenX::LadderDatabase::head; + if (m_head == nullptr) { + m_head = entry; + m_end = m_head; } - else - { - RenX::LadderDatabase::end->next = entry; - entry->prev = end; - end = entry; + else { + m_end->next = entry; + entry->prev = m_end; + m_end = entry; } - entry->rank = ++RenX::LadderDatabase::entries; + entry->rank = ++m_entries; } -void RenX::LadderDatabase::process_header(FILE *file) -{ +void RenX::LadderDatabase::process_header(FILE *file) { int chr = fgetc(file); - if (chr != EOF) - RenX::LadderDatabase::read_version = chr; + if (chr != EOF) { + m_read_version = chr; + } } -void RenX::LadderDatabase::create_header(FILE *file) -{ - fputc(RenX::LadderDatabase::write_version, file); +void RenX::LadderDatabase::create_header(FILE *file) { + fputc(m_write_version, file); } -void RenX::LadderDatabase::process_file_finish(FILE *file) -{ - if (RenX::LadderDatabase::read_version != RenX::LadderDatabase::write_version) - { +void RenX::LadderDatabase::process_file_finish(FILE *file) { + if (m_read_version != m_write_version) { puts("Notice: Ladder database is out of date; upgrading..."); std::chrono::steady_clock::duration write_duration; std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now(); - RenX::LadderDatabase::write(this->getFilename()); + write(this->getFilename()); write_duration = std::chrono::steady_clock::now() - start_time; printf("Ladder database upgrade completed in %f seconds", static_cast(write_duration.count()) * (static_cast(std::chrono::steady_clock::duration::period::num) / static_cast(std::chrono::steady_clock::duration::period::den) * static_cast(std::chrono::seconds::duration::period::den / std::chrono::seconds::duration::period::num))); - RenX::LadderDatabase::read_version = RenX::LadderDatabase::write_version; + m_read_version = m_write_version; } } -RenX::LadderDatabase::Entry *RenX::LadderDatabase::getHead() const -{ - return RenX::LadderDatabase::head; +RenX::LadderDatabase::Entry *RenX::LadderDatabase::getHead() const { + return m_head; } -RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntry(uint64_t steamid) const -{ - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next) - if (itr->steam_id == steamid) +RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntry(uint64_t steamid) const { + for (Entry *itr = m_head; itr != nullptr; itr = itr->next) { + if (itr->steam_id == steamid) { return itr; + } + } + return nullptr; } -std::pair RenX::LadderDatabase::getPlayerEntryAndIndex(uint64_t steamid) const -{ +std::pair RenX::LadderDatabase::getPlayerEntryAndIndex(uint64_t steamid) const { size_t index = 0; - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next, ++index) - if (itr->steam_id == steamid) - return std::pair(itr, index); - return std::pair(nullptr, Jupiter::INVALID_INDEX); + for (Entry *itr = m_head; itr != nullptr; itr = itr->next, ++index) { + if (itr->steam_id == steamid) { + return std::pair(itr, index); + } + } + return std::pair(nullptr, Jupiter::INVALID_INDEX); } -RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntryByName(const Jupiter::ReadableString &name) const -{ - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next) - if (itr->most_recent_name.equalsi(name)) +RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntryByName(const Jupiter::ReadableString &name) const { + for (Entry *itr = m_head; itr != nullptr; itr = itr->next) { + if (itr->most_recent_name.equalsi(name)) { return itr; + } + } + return nullptr; } -std::pair RenX::LadderDatabase::getPlayerEntryAndIndexByName(const Jupiter::ReadableString &name) const -{ +std::pair RenX::LadderDatabase::getPlayerEntryAndIndexByName(const Jupiter::ReadableString &name) const { size_t index = 0; - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next, ++index) - if (itr->most_recent_name.equalsi(name)) - return std::pair(itr, index); - return std::pair(nullptr, Jupiter::INVALID_INDEX); + for (Entry *itr = m_head; itr != nullptr; itr = itr->next, ++index) { + if (itr->most_recent_name.equalsi(name)) { + return std::pair(itr, index); + } + } + + return std::pair(nullptr, Jupiter::INVALID_INDEX); } -RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntryByPartName(const Jupiter::ReadableString &name) const -{ - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next) - if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) +RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntryByPartName(const Jupiter::ReadableString &name) const { + for (Entry *itr = m_head; itr != nullptr; itr = itr->next) { + if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { return itr; + } + } + return nullptr; } -std::pair RenX::LadderDatabase::getPlayerEntryAndIndexByPartName(const Jupiter::ReadableString &name) const -{ +std::pair RenX::LadderDatabase::getPlayerEntryAndIndexByPartName(const Jupiter::ReadableString &name) const { size_t index = 0; - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next, ++index) - if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) - return std::pair(itr, index); - return std::pair(nullptr, Jupiter::INVALID_INDEX); + for (Entry *itr = m_head; itr != nullptr; itr = itr->next, ++index) { + if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { + return std::pair(itr, index); + } + } + + return std::pair(nullptr, Jupiter::INVALID_INDEX); } -std::forward_list RenX::LadderDatabase::getPlayerEntriesByPartName(const Jupiter::ReadableString &name, size_t max) const -{ - std::forward_list list; - if (max == 0) - { - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next) - if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) +std::forward_list RenX::LadderDatabase::getPlayerEntriesByPartName(const Jupiter::ReadableString &name, size_t max) const { + std::forward_list list; + if (max == 0) { + for (Entry *itr = m_head; itr != nullptr; itr = itr->next) { + if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { list.emplace_front(*itr); + } + } } - else - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next) - if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) - { + else { + for (Entry* itr = m_head; itr != nullptr; itr = itr->next) { + if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { list.emplace_front(*itr); - if (--max == 0) + if (--max == 0) { return list; + } } + } + } return list; } -std::forward_list> RenX::LadderDatabase::getPlayerEntriesAndIndexByPartName(const Jupiter::ReadableString &name, size_t max) const -{ - std::forward_list> list; +std::forward_list> RenX::LadderDatabase::getPlayerEntriesAndIndexByPartName(const Jupiter::ReadableString &name, size_t max) const { + std::forward_list> list; size_t index = 0; if (max == 0) { - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next, ++index) - if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) + for (Entry *itr = m_head; itr != nullptr; itr = itr->next, ++index) { + if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { list.emplace_front(*itr, index); + } + } } - else - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next, ++index) - if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) - { + else { + for (Entry* itr = m_head; itr != nullptr; itr = itr->next, ++index) { + if (itr->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { list.emplace_front(*itr, index); - if (--max) + if (--max) { return list; + } } + } + } return list; } -RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntryByIndex(size_t index) const -{ - for (RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; itr != nullptr; itr = itr->next, --index) - if (index == 0) +RenX::LadderDatabase::Entry *RenX::LadderDatabase::getPlayerEntryByIndex(size_t index) const { + for (Entry *itr = m_head; itr != nullptr; itr = itr->next, --index) { + if (index == 0) { return itr; + } + } return nullptr; } -size_t RenX::LadderDatabase::getEntries() const -{ - return RenX::LadderDatabase::entries; +size_t RenX::LadderDatabase::getEntries() const { + return m_entries; } -std::chrono::steady_clock::time_point RenX::LadderDatabase::getLastSortTime() const -{ - return RenX::LadderDatabase::last_sort; +std::chrono::steady_clock::time_point RenX::LadderDatabase::getLastSortTime() const { + return m_last_sort; } -void RenX::LadderDatabase::append(RenX::LadderDatabase::Entry *entry) -{ - ++RenX::LadderDatabase::entries; - if (RenX::LadderDatabase::head == nullptr) - { - RenX::LadderDatabase::head = entry; - RenX::LadderDatabase::end = RenX::LadderDatabase::head; +void RenX::LadderDatabase::append(Entry *entry) { + ++m_entries; + if (m_head == nullptr) { + m_head = entry; + m_end = m_head; return; } - RenX::LadderDatabase::end->next = entry; - entry->prev = RenX::LadderDatabase::end; - RenX::LadderDatabase::end = entry; + m_end->next = entry; + entry->prev = m_end; + m_end = entry; } -void RenX::LadderDatabase::write(const std::string &filename) -{ - return RenX::LadderDatabase::write(filename.c_str()); +void RenX::LadderDatabase::write(const std::string &filename) { + return write(filename.c_str()); } -void RenX::LadderDatabase::write(const char *filename) -{ - if (RenX::LadderDatabase::entries != 0) +void RenX::LadderDatabase::write(const char *filename) { + if (m_entries != 0) { FILE *file = fopen(filename, "wb"); if (file != nullptr) { size_t rank = 0; Jupiter::DataBuffer buffer; - RenX::LadderDatabase::create_header(file); - RenX::LadderDatabase::Entry *entry = RenX::LadderDatabase::head; + create_header(file); + Entry *entry = m_head; while (entry != nullptr) { // update rank @@ -421,42 +423,38 @@ void RenX::LadderDatabase::write(const char *filename) } } -void RenX::LadderDatabase::sort_entries() -{ - if (RenX::LadderDatabase::entries <= 1) +void RenX::LadderDatabase::sort_entries() { + if (m_entries <= 1) { return; + } - RenX::LadderDatabase::Entry *itr = RenX::LadderDatabase::head; - RenX::LadderDatabase::Entry *itr2, *ptr; + Entry *itr = m_head; + Entry *itr2, *ptr; // iterate forward (search for out-of-order content) - while (itr->next != nullptr) - { + while (itr->next != nullptr) { // out-of-order content found - if (itr->next->total_score > itr->total_score) - { + if (itr->next->total_score > itr->total_score) { // pull content out ptr = itr->next; itr->next = ptr->next; - if (itr->next != nullptr) + if (itr->next != nullptr) { itr->next->prev = itr; + } // iterate backwards from our iterator, and insert itr2 = itr; - while (true) - { - if (itr2->prev == nullptr) - { + while (true) { + if (itr2->prev == nullptr) { // push ptr to head ptr->next = itr2; ptr->prev = nullptr; itr2->prev = ptr; - RenX::LadderDatabase::head = ptr; + m_head = ptr; break; } itr2 = itr2->prev; - if (itr2->total_score > ptr->total_score) - { + if (itr2->total_score > ptr->total_score) { // insert ptr after itr2 ptr->next = itr2->next; ptr->next->prev = ptr; @@ -466,33 +464,30 @@ void RenX::LadderDatabase::sort_entries() } } } - else // continue iterating + else { // continue iterating itr = itr->next; + } } - RenX::LadderDatabase::end = itr; - RenX::LadderDatabase::last_sort = std::chrono::steady_clock::now(); + m_end = itr; + m_last_sort = std::chrono::steady_clock::now(); } -void RenX::LadderDatabase::updateLadder(RenX::Server &server, const RenX::TeamType &team) -{ - if (server.players.size() != server.getBotCount()) - { +void RenX::LadderDatabase::updateLadder(RenX::Server &server, const RenX::TeamType &team) { + if (server.players.size() != server.getBotCount()) { // call the PreUpdateLadder event - if (this->OnPreUpdateLadder != nullptr) + if (this->OnPreUpdateLadder != nullptr) { this->OnPreUpdateLadder(*this, server, team); + } // update player stats in memory - RenX::LadderDatabase::Entry *entry; - for (auto player = server.players.begin(); player != server.players.end(); ++player) - { - if (player->steamid != 0 && (player->ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_LADDER) == 0) - { - entry = RenX::LadderDatabase::getPlayerEntry(player->steamid); - if (entry == nullptr) - { - entry = new RenX::LadderDatabase::Entry(); - RenX::LadderDatabase::append(entry); + Entry *entry; + for (auto player = server.players.begin(); player != server.players.end(); ++player) { + if (player->steamid != 0 && (player->ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_LADDER) == 0) { + entry = getPlayerEntry(player->steamid); + if (entry == nullptr) { + entry = new Entry(); + append(entry); entry->steam_id = player->steamid; } @@ -512,8 +507,7 @@ void RenX::LadderDatabase::updateLadder(RenX::Server &server, const RenX::TeamTy entry->total_proxy_disarms += player->proxy_disarms; ++entry->total_games; - switch (player->team) - { + switch (player->team) { case RenX::TeamType::GDI: ++entry->total_gdi_games; if (player->team == team) @@ -560,10 +554,10 @@ void RenX::LadderDatabase::updateLadder(RenX::Server &server, const RenX::TeamTy break; } - auto set_if_greater = [](uint32_t &src, const uint32_t &cmp) - { - if (cmp > src) + auto set_if_greater = [](uint32_t &src, const uint32_t &cmp) { + if (cmp > src) { src = cmp; + } }; set_if_greater(entry->top_score, static_cast(player->score)); @@ -588,18 +582,18 @@ void RenX::LadderDatabase::updateLadder(RenX::Server &server, const RenX::TeamTy // sort new stats std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now(); - RenX::LadderDatabase::sort_entries(); + sort_entries(); std::chrono::steady_clock::duration sort_duration = std::chrono::steady_clock::now() - start_time; // write new stats start_time = std::chrono::steady_clock::now(); - RenX::LadderDatabase::write(this->getFilename()); + write(this->getFilename()); std::chrono::steady_clock::duration write_duration = std::chrono::steady_clock::now() - start_time; - if (RenX::LadderDatabase::output_times) + if (m_output_times) { Jupiter::StringS str = Jupiter::StringS::Format("Ladder: %zu entries sorted in %f seconds; Database written in %f seconds." ENDL, - RenX::LadderDatabase::getEntries(), + getEntries(), static_cast(sort_duration.count()) * (static_cast(std::chrono::steady_clock::duration::period::num) / static_cast(std::chrono::steady_clock::duration::period::den) * static_cast(std::chrono::seconds::duration::period::den / std::chrono::seconds::duration::period::num)), static_cast(write_duration.count()) * (static_cast(std::chrono::steady_clock::duration::period::num) / static_cast(std::chrono::steady_clock::duration::period::den) * static_cast(std::chrono::seconds::duration::period::den / std::chrono::seconds::duration::period::num))); str.println(stdout); @@ -608,38 +602,32 @@ void RenX::LadderDatabase::updateLadder(RenX::Server &server, const RenX::TeamTy } } -void RenX::LadderDatabase::erase() -{ - if (RenX::LadderDatabase::head != nullptr) - { - RenX::LadderDatabase::entries = 0; - while (RenX::LadderDatabase::head->next != nullptr) - { - RenX::LadderDatabase::head = head->next; - delete head->prev; +void RenX::LadderDatabase::erase() { + if (m_head != nullptr) { + m_entries = 0; + while (m_head->next != nullptr) { + m_head = m_head->next; + delete m_head->prev; } - delete RenX::LadderDatabase::head; - RenX::LadderDatabase::head = nullptr; - RenX::LadderDatabase::end = nullptr; + + delete m_head; + m_head = nullptr; + m_end = nullptr; } } -const Jupiter::ReadableString &RenX::LadderDatabase::getName() const -{ - return RenX::LadderDatabase::name; +const Jupiter::ReadableString &RenX::LadderDatabase::getName() const { + return m_name; } -void RenX::LadderDatabase::setName(const Jupiter::ReadableString &in_name) -{ - RenX::LadderDatabase::name = in_name; +void RenX::LadderDatabase::setName(const Jupiter::ReadableString &in_name) { + m_name = in_name; } -bool RenX::LadderDatabase::getOutputTimes() const -{ - return RenX::LadderDatabase::output_times; +bool RenX::LadderDatabase::getOutputTimes() const { + return m_output_times; } -void RenX::LadderDatabase::setOutputTimes(bool in_output_times) -{ - RenX::LadderDatabase::output_times = in_output_times; +void RenX::LadderDatabase::setOutputTimes(bool in_output_times) { + m_output_times = in_output_times; } diff --git a/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.h b/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.h index 25ea132..19ef373 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.h +++ b/src/Plugins/RenX/RenX.Core/RenX_LadderDatabase.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2015-2017 Jessica James. + * Copyright (C) 2015-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,7 +23,6 @@ #include #include "Jupiter/Database.h" #include "Jupiter/String.hpp" -#include "Jupiter/ArrayList.h" #include "RenX.h" /** DLL Linkage Nagging */ @@ -32,12 +31,10 @@ #pragma warning(disable: 4251) #endif -namespace RenX -{ +namespace RenX { class Server; - class RENX_API LadderDatabase : public Jupiter::Database - { + class RENX_API LadderDatabase : public Jupiter::Database { public: // Jupiter::Database /** @@ -228,19 +225,19 @@ namespace RenX private: /** Database version */ - const uint8_t write_version = 1; - uint8_t read_version = write_version; - - bool output_times = false; - Jupiter::StringS name; - std::chrono::steady_clock::time_point last_sort = std::chrono::steady_clock::now(); - size_t entries = 0; - Entry *head = nullptr; - Entry *end = nullptr; + const uint8_t m_write_version = 1; + uint8_t m_read_version = m_write_version; + + bool m_output_times = false; + Jupiter::StringS m_name; + std::chrono::steady_clock::time_point m_last_sort = std::chrono::steady_clock::now(); + size_t m_entries = 0; + Entry* m_head = nullptr; + Entry* m_end = nullptr; }; RENX_API extern RenX::LadderDatabase *default_ladder_database; - RENX_API extern Jupiter::ArrayList &ladder_databases; + RENX_API extern std::vector& ladder_databases; } /** Re-enable warnings */ diff --git a/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp b/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp index f18649d..fa490ef 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,649 +19,520 @@ #include "RenX_Plugin.h" #include "RenX_Core.h" -RenX::Plugin::Plugin() -{ - RenX::getCore()->getPlugins()->add(this); +RenX::Plugin::Plugin() { + RenX::getCore()->getPlugins().push_back(this); } -RenX::Plugin::~Plugin() -{ - for (size_t i = 0; i != RenX::getCore()->getPlugins()->size(); i++) - { - if (RenX::getCore()->getPlugins()->get(i) == this) - { - RenX::getCore()->getPlugins()->remove(i); +RenX::Plugin::~Plugin() { + auto& renx_plugins = RenX::getCore()->getPlugins(); + for (auto itr = renx_plugins.begin(); itr != renx_plugins.end(); ++itr) { + if (*itr == this) { + RenX::getCore()->getPlugins().erase(itr); break; } } } -void RenX::Plugin::RenX_SanitizeTags(Jupiter::StringType &) -{ +void RenX::Plugin::RenX_SanitizeTags(Jupiter::StringType &) { return; } -void RenX::Plugin::RenX_ProcessTags(Jupiter::StringType &, const Server *, const PlayerInfo *, const PlayerInfo *, const BuildingInfo *) -{ +void RenX::Plugin::RenX_ProcessTags(Jupiter::StringType &, const Server *, const PlayerInfo *, const PlayerInfo *, const BuildingInfo *) { return; } -void RenX::Plugin::RenX_OnPlayerCreate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnPlayerCreate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnPlayerDelete(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnPlayerDelete(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnPlayerUUIDChange(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnPlayerUUIDChange(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnPlayerRDNS(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnPlayerRDNS(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnPlayerIdentify(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnPlayerIdentify(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnServerCreate(Server &) -{ +void RenX::Plugin::RenX_OnServerCreate(Server &) { return; } -void RenX::Plugin::RenX_OnServerFullyConnected(Server &) -{ +void RenX::Plugin::RenX_OnServerFullyConnected(Server &) { return; } -void RenX::Plugin::RenX_OnServerDisconnect(Server &, RenX::DisconnectReason) -{ +void RenX::Plugin::RenX_OnServerDisconnect(Server &, RenX::DisconnectReason) { return; } -bool RenX::Plugin::RenX_OnBan(Server &, const PlayerInfo &, Jupiter::StringType &) -{ +bool RenX::Plugin::RenX_OnBan(Server &, const PlayerInfo &, Jupiter::StringType &) { return false; } -void RenX::Plugin::RenX_OnCommandTriggered(Server& server, const Jupiter::ReadableString& trigger, RenX::PlayerInfo& player, const Jupiter::ReadableString& parameters, GameCommand& command) -{ +void RenX::Plugin::RenX_OnCommandTriggered(Server& server, const Jupiter::ReadableString& trigger, RenX::PlayerInfo& player, const Jupiter::ReadableString& parameters, GameCommand& command) { return; } -void RenX::Plugin::RenX_OnJoin(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnJoin(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnPart(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnPart(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnKick(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnKick(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnNameChange(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnNameChange(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnTeamChange(Server &, const PlayerInfo &, const TeamType &) -{ +void RenX::Plugin::RenX_OnTeamChange(Server &, const PlayerInfo &, const TeamType &) { return; } -void RenX::Plugin::RenX_OnHWID(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnHWID(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnIDChange(Server &, const PlayerInfo &, int) -{ +void RenX::Plugin::RenX_OnIDChange(Server &, const PlayerInfo &, int) { return; } -void RenX::Plugin::RenX_OnDev(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnDev(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnRank(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnRank(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnExecute(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnExecute(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnPlayerCommand(Server &, const PlayerInfo &, const Jupiter::ReadableString &, GameCommand *) -{ +void RenX::Plugin::RenX_OnPlayerCommand(Server &, const PlayerInfo &, const Jupiter::ReadableString &, GameCommand *) { return; } -void RenX::Plugin::RenX_OnSpeedHack(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnSpeedHack(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnPlayer(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnPlayer(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnChat(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnChat(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnTeamChat(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnTeamChat(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnRadioChat(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnRadioChat(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnHostChat(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnHostChat(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnHostPage(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnHostPage(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnAdminMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnAdminMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnWarnMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnWarnMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnAdminPMessage(Server &server, const PlayerInfo &player, const PlayerInfo &target, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnAdminPMessage(Server &server, const PlayerInfo &player, const PlayerInfo &target, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnWarnPMessage(Server &server, const PlayerInfo &player, const PlayerInfo &target, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnWarnPMessage(Server &server, const PlayerInfo &player, const PlayerInfo &target, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnHostAdminMessage(Server &server, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnHostAdminMessage(Server &server, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnHostAdminPMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnHostAdminPMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnHostWarnMessage(Server &server, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnHostWarnMessage(Server &server, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnHostWarnPMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) -{ +void RenX::Plugin::RenX_OnHostWarnPMessage(Server &server, const PlayerInfo &player, const Jupiter::ReadableString &message) { return; } -void RenX::Plugin::RenX_OnOtherChat(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnOtherChat(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDeploy(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDeploy(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnOverMine(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnOverMine(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDisarm(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDisarm(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDisarm(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnDisarm(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnExplode(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnExplode(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnExplode(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnExplode(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnSuicide(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnSuicide(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnKill(Server &, const PlayerInfo &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnKill(Server &, const PlayerInfo &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnKill(Server &, const Jupiter::ReadableString &, const TeamType &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnKill(Server &, const Jupiter::ReadableString &, const TeamType &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDie(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDie(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDie(Server &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDie(Server &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDestroy(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &, ObjectType) -{ +void RenX::Plugin::RenX_OnDestroy(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &, ObjectType) { return; } -void RenX::Plugin::RenX_OnDestroy(Server &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &, ObjectType) -{ +void RenX::Plugin::RenX_OnDestroy(Server &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &, const TeamType &, const Jupiter::ReadableString &, ObjectType) { return; } -void RenX::Plugin::RenX_OnCapture(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const TeamType &) -{ +void RenX::Plugin::RenX_OnCapture(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const TeamType &) { return; } -void RenX::Plugin::RenX_OnNeutralize(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const TeamType &) -{ +void RenX::Plugin::RenX_OnNeutralize(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const TeamType &) { return; } -void RenX::Plugin::RenX_OnCharacterPurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnCharacterPurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnItemPurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnItemPurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnWeaponPurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnWeaponPurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnRefillPurchase(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnRefillPurchase(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVehiclePurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnVehiclePurchase(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnVehicleSpawn(Server &, const TeamType &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnVehicleSpawn(Server &, const TeamType &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnSpawn(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnSpawn(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnBotJoin(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnBotJoin(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVehicleCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnVehicleCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnTSVehicleCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnTSVehicleCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnRAVehicleCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnRAVehicleCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDeathCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnDeathCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnMoneyCrate(Server &, const PlayerInfo &, int) -{ +void RenX::Plugin::RenX_OnMoneyCrate(Server &, const PlayerInfo &, int) { return; } -void RenX::Plugin::RenX_OnCharacterCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnCharacterCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnSpyCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnSpyCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnRefillCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnRefillCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnTimeBombCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnTimeBombCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnSpeedCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnSpeedCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnNukeCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnNukeCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnAbductionCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnAbductionCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnUnspecifiedCrate(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnUnspecifiedCrate(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnOtherCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnOtherCrate(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnSteal(Server &, const PlayerInfo &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnSteal(Server &, const PlayerInfo &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnSteal(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnSteal(Server &, const PlayerInfo &, const Jupiter::ReadableString &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnDonate(Server &, const PlayerInfo &, const PlayerInfo &, double) -{ +void RenX::Plugin::RenX_OnDonate(Server &, const PlayerInfo &, const PlayerInfo &, double) { return; } -void RenX::Plugin::RenX_OnGameOver(Server &, RenX::WinType, const TeamType &, int, int) -{ +void RenX::Plugin::RenX_OnGameOver(Server &, RenX::WinType, const TeamType &, int, int) { return; } -void RenX::Plugin::RenX_OnGame(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnGame(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnExecute(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnExecute(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnSubscribe(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnSubscribe(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnUnsubscribe(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnUnsubscribe(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnBlock(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnBlock(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnConnect(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnConnect(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnAuthenticate(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnAuthenticate(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnBan(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnBan(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnInvalidPassword(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnInvalidPassword(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDrop(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDrop(Server &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDisconnect(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDisconnect(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnStopListen(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnStopListen(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnResumeListen(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnResumeListen(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnWarning(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnWarning(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnRCON(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnRCON(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnAdminLogin(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnAdminLogin(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnAdminGrant(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnAdminGrant(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnAdminLogout(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnAdminLogout(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnAdmin(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnAdmin(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnVoteAddBots(Server &, const TeamType &, const PlayerInfo &, const TeamType &, int, int) -{ +void RenX::Plugin::RenX_OnVoteAddBots(Server &, const TeamType &, const PlayerInfo &, const TeamType &, int, int) { return; } -void RenX::Plugin::RenX_OnVoteChangeMap(Server &, const TeamType &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnVoteChangeMap(Server &, const TeamType &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVoteKick(Server &, const TeamType &, const PlayerInfo &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnVoteKick(Server &, const TeamType &, const PlayerInfo &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVoteMineBan(Server &, const TeamType &, const PlayerInfo &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnVoteMineBan(Server &, const TeamType &, const PlayerInfo &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVoteRemoveBots(Server &, const TeamType &, const PlayerInfo &, const TeamType &, int) -{ +void RenX::Plugin::RenX_OnVoteRemoveBots(Server &, const TeamType &, const PlayerInfo &, const TeamType &, int) { return; } -void RenX::Plugin::RenX_OnVoteRestartMap(Server &, const TeamType &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnVoteRestartMap(Server &, const TeamType &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVoteSurrender(Server &, const TeamType &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnVoteSurrender(Server &, const TeamType &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVoteSurvey(Server &, const TeamType &, const PlayerInfo &, const Jupiter::ReadableString &text) -{ +void RenX::Plugin::RenX_OnVoteSurvey(Server &, const TeamType &, const PlayerInfo &, const Jupiter::ReadableString &text) { return; } -void RenX::Plugin::RenX_OnVoteOther(Server &, const TeamType &, const Jupiter::ReadableString &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnVoteOther(Server &, const TeamType &, const Jupiter::ReadableString &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnVoteOver(Server &, const TeamType &, const Jupiter::ReadableString &, bool, int, int) -{ +void RenX::Plugin::RenX_OnVoteOver(Server &, const TeamType &, const Jupiter::ReadableString &, bool, int, int) { return; } -void RenX::Plugin::RenX_OnVoteCancel(Server &, const TeamType &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnVoteCancel(Server &, const TeamType &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnVote(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnVote(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnMapChange(Server &, const Jupiter::ReadableString &, bool) -{ +void RenX::Plugin::RenX_OnMapChange(Server &, const Jupiter::ReadableString &, bool) { return; } -void RenX::Plugin::RenX_OnMapLoad(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnMapLoad(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnMapStart(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnMapStart(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnMap(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnMap(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDemoRecord(Server &, const PlayerInfo &) -{ +void RenX::Plugin::RenX_OnDemoRecord(Server &, const PlayerInfo &) { return; } -void RenX::Plugin::RenX_OnDemoRecord(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDemoRecord(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnDemoRecordStop(Server &) -{ +void RenX::Plugin::RenX_OnDemoRecordStop(Server &) { return; } -void RenX::Plugin::RenX_OnDemo(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnDemo(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnLog(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnLog(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnCommand(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnCommand(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnError(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnError(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnVersion(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnVersion(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnAuthorized(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnAuthorized(Server &, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnOther(Server &, char, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnOther(Server &, char, const Jupiter::ReadableString &) { return; } -void RenX::Plugin::RenX_OnRaw(Server &, const Jupiter::ReadableString &) -{ +void RenX::Plugin::RenX_OnRaw(Server &, const Jupiter::ReadableString &) { return; } \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.Core/RenX_Server.cpp b/src/Plugins/RenX/RenX.Core/RenX_Server.cpp index fca1c94..8eef14e 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Server.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Server.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -32,363 +32,334 @@ using namespace Jupiter::literals; -int RenX::Server::think() -{ - if (RenX::Server::connected == false) - { +// This could probably be templated but I really just want this done quickly right this moment so I can purge ArrayList +#define CALL_RX_PLUGIN_EVENT(event, ...) \ + { for (auto plugin : RenX::getCore()->getPlugins()) { plugin->event(__VA_ARGS__); } } + +int RenX::Server::think() { + if (m_connected == false) { // Not connected; attempt retry if needed - if (RenX::Server::maxAttempts < 0 || RenX::Server::attempts < RenX::Server::maxAttempts) - { - if (std::chrono::steady_clock::now() >= RenX::Server::lastAttempt + RenX::Server::delay) - { - if (RenX::Server::connect()) - RenX::Server::sendLogChan(IRCCOLOR "03[RenX]" IRCCOLOR " Socket successfully reconnected to Renegade-X server."); - else RenX::Server::sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Failed to reconnect to Renegade-X server."); + if (m_maxAttempts < 0 || m_attempts < m_maxAttempts) { + if (std::chrono::steady_clock::now() >= m_lastAttempt + m_delay) { + if (connect()) { + sendLogChan(IRCCOLOR "03[RenX]" IRCCOLOR " Socket successfully reconnected to Renegade-X server."); + } + else { + sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Failed to reconnect to Renegade-X server."); + } } } - else + else { return 1; + } } - else if (RenX::Server::awaitingPong && std::chrono::steady_clock::now() - RenX::Server::lastActivity >= RenX::Server::pingTimeoutThreshold) // ping timeout - { + else if (m_awaitingPong && std::chrono::steady_clock::now() - m_lastActivity >= m_pingTimeoutThreshold) { // ping timeout // Ping timeout; disconnect immediately - RenX::Server::sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (ping timeout).")); - RenX::Server::disconnect(RenX::DisconnectReason::PingTimeout); + sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (ping timeout).")); + disconnect(RenX::DisconnectReason::PingTimeout); } - else - { - auto cycle_player_rdns = [this]() // Cycles through any pending RDNS resolutions, and fires events as necessary. - { - if (this->player_rdns_resolutions_pending != 0) - { - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (auto node = this->players.begin(); node != this->players.end(); ++node) - { - if (node->rdns_thread.joinable() && node->rdns_mutex.try_lock()) // RDNS event hasn't fired AND RDNS value has been resolved - { + else { + auto cycle_player_rdns = [this]() { // Cycles through any pending RDNS resolutions, and fires events as necessary. + if (m_player_rdns_resolutions_pending != 0) { + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + if (node->rdns_thread.joinable() && node->rdns_mutex.try_lock()) { // RDNS event hasn't fired AND RDNS value has been resolved node->rdns_mutex.unlock(); node->rdns_thread.join(); - --this->player_rdns_resolutions_pending; + --m_player_rdns_resolutions_pending; // Check for bans - this->banCheck(*node); + banCheck(*node); // Fire RDNS resolved event - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnPlayerRDNS(*this, *node); + for (const auto& plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_OnPlayerRDNS(*this, *node); + } // Fire player indentified event if ready - if (node->hwid.isNotEmpty()) - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnPlayerIdentify(*this, *node); + if (node->hwid.isNotEmpty()) { + for (auto plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_OnPlayerIdentify(*this, *node); + } + } - if (this->player_rdns_resolutions_pending == 0) // No more resolutions pending + if (m_player_rdns_resolutions_pending == 0) { // No more resolutions pending return; + } } } } }; // Connected and fine - if (RenX::Server::sock.recv() > 0) // Data received - { + if (m_sock.recv() > 0) { // Data received cycle_player_rdns(); - Jupiter::ReadableString::TokenizeResult result = Jupiter::ReferenceString::tokenize(RenX::Server::sock.getBuffer(), '\n'); - if (result.token_count != 0) - { - RenX::Server::lastActivity = std::chrono::steady_clock::now(); - RenX::Server::lastLine.concat(result.tokens[0]); - if (result.token_count != 1) - { - RenX::Server::processLine(RenX::Server::lastLine); - RenX::Server::lastLine = result.tokens[result.token_count - 1]; + Jupiter::ReadableString::TokenizeResult result = Jupiter::ReferenceString::tokenize(m_sock.getBuffer(), '\n'); + if (result.token_count != 0) { + m_lastActivity = std::chrono::steady_clock::now(); + m_lastLine.concat(result.tokens[0]); + if (result.token_count != 1) { + processLine(m_lastLine); + m_lastLine = result.tokens[result.token_count - 1]; - for (size_t index = 1; index != result.token_count - 1; ++index) - RenX::Server::processLine(result.tokens[index]); + for (size_t index = 1; index != result.token_count - 1; ++index) { + processLine(result.tokens[index]); + } } } } - else if (Jupiter::Socket::getLastError() == JUPITER_SOCK_EWOULDBLOCK) // Operation would block (no new data) - { + else if (Jupiter::Socket::getLastError() == JUPITER_SOCK_EWOULDBLOCK) { // Operation would block (no new data) cycle_player_rdns(); - if (RenX::Server::awaitingPong == false && std::chrono::steady_clock::now() - RenX::Server::lastActivity >= RenX::Server::pingRate) { + if (m_awaitingPong == false && std::chrono::steady_clock::now() - m_lastActivity >= m_pingRate) { startPing(); } } - else // This is a serious error - { - RenX::Server::wipeData(); - if (RenX::Server::maxAttempts != 0) - { - RenX::Server::sendLogChan(IRCCOLOR "07[Warning]" IRCCOLOR " Connection to Renegade-X server lost. Reconnection attempt in progress."); - if (RenX::Server::reconnect(RenX::DisconnectReason::SocketError)) - RenX::Server::sendLogChan(IRCCOLOR "06[Progress]" IRCCOLOR " Connection to Renegade-X server reestablished. Initializing Renegade-X RCON protocol..."); - else - RenX::Server::sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Connection to Renegade-X server lost. Reconnection attempt failed."); + else { // This is a serious error + wipeData(); + if (m_maxAttempts != 0) { + sendLogChan(IRCCOLOR "07[Warning]" IRCCOLOR " Connection to Renegade-X server lost. Reconnection attempt in progress."); + if (reconnect(RenX::DisconnectReason::SocketError)) { + sendLogChan(IRCCOLOR "06[Progress]" IRCCOLOR " Connection to Renegade-X server reestablished. Initializing Renegade-X RCON protocol..."); + } + else { + sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Connection to Renegade-X server lost. Reconnection attempt failed."); + } } - else - { - RenX::Server::sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Connection to Renegade-X server lost. No attempt will be made to reconnect."); + else { + sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Connection to Renegade-X server lost. No attempt will be made to reconnect."); return 1; } return 0; } // Updating client and building lists, if there is a game in progress and it's time for an update - if (RenX::Server::rconVersion >= 3 && RenX::Server::players.size() != 0) - { - if (RenX::Server::clientUpdateRate != std::chrono::milliseconds::zero() && std::chrono::steady_clock::now() > RenX::Server::lastClientListUpdate + RenX::Server::clientUpdateRate) - RenX::Server::updateClientList(); + if (m_rconVersion >= 3 && this->players.size() != 0) { + if (m_clientUpdateRate != std::chrono::milliseconds::zero() && std::chrono::steady_clock::now() > m_lastClientListUpdate + m_clientUpdateRate) { + updateClientList(); + } - if (RenX::Server::buildingUpdateRate != std::chrono::milliseconds::zero() && std::chrono::steady_clock::now() > RenX::Server::lastBuildingListUpdate + RenX::Server::buildingUpdateRate) - RenX::Server::updateBuildingList(); + if (m_buildingUpdateRate != std::chrono::milliseconds::zero() && std::chrono::steady_clock::now() > m_lastBuildingListUpdate + m_buildingUpdateRate) { + updateBuildingList(); + } } // Trigger gameover, if one is pending - if (RenX::Server::gameover_pending && RenX::Server::gameover_time < std::chrono::steady_clock::now()) - { - this->gameover(); - RenX::Server::gameover_pending = false; + if (m_gameover_pending && m_gameover_time < std::chrono::steady_clock::now()) { + gameover(); + m_gameover_pending = false; } // Trigger ping if we haven't sent anything over the socket in a while, to prevent the server from disconnecting - if (RenX::Server::awaitingPong == false && std::chrono::steady_clock::now() - RenX::Server::lastSendActivity >= RenX::Server::pingRate) { + if (m_awaitingPong == false && std::chrono::steady_clock::now() - m_lastSendActivity >= m_pingRate) { startPing(); } } + return 0; } -int RenX::Server::OnRehash() -{ - std::string oldHostname = RenX::Server::hostname; - std::string oldClientHostname = RenX::Server::clientHostname; - Jupiter::StringS oldPass = RenX::Server::pass; - unsigned short oldPort = RenX::Server::port; - int oldSteamFormat = RenX::Server::steamFormat; - RenX::Server::commands.emptyAndDelete(); - RenX::Server::init(*RenX::getCore()->getConfig().getSection(RenX::Server::configSection)); - if (RenX::Server::port == 0 || !RenX::Server::hostname.empty()) - { - RenX::Server::hostname = oldHostname; - RenX::Server::clientHostname = oldClientHostname; - RenX::Server::pass = oldPass; - RenX::Server::port = oldPort; +int RenX::Server::OnRehash() { + std::string oldHostname = m_hostname; + std::string oldClientHostname = m_clientHostname; + Jupiter::StringS oldPass = m_pass; + unsigned short oldPort = m_port; + int oldSteamFormat = m_steamFormat; + m_commands.clear(); + init(*RenX::getCore()->getConfig().getSection(m_configSection)); + if (m_port == 0 || !m_hostname.empty()) { + m_hostname = oldHostname; + m_clientHostname = oldClientHostname; + m_pass = oldPass; + m_port = oldPort; } - else if (Jupiter::ReferenceString(oldHostname.c_str()).equalsi(RenX::Server::hostname) == false - || oldPort != RenX::Server::port - || Jupiter::ReferenceString(oldClientHostname.c_str()).equalsi(RenX::Server::clientHostname) == false - || oldPass.equalsi(RenX::Server::pass) == false) { - RenX::Server::reconnect(RenX::DisconnectReason::Rehash); + else if (Jupiter::ReferenceString(oldHostname.c_str()).equalsi(m_hostname) == false + || oldPort != m_port + || Jupiter::ReferenceString(oldClientHostname.c_str()).equalsi(m_clientHostname) == false + || oldPass.equalsi(m_pass) == false) { + reconnect(RenX::DisconnectReason::Rehash); } return 0; } -bool RenX::Server::OnBadRehash(bool removed) -{ +bool RenX::Server::OnBadRehash(bool removed) { return removed; } -bool RenX::Server::isConnected() const -{ - return RenX::Server::connected; +bool RenX::Server::isConnected() const { + return m_connected; } -bool RenX::Server::isSubscribed() const -{ - return RenX::Server::subscribed; +bool RenX::Server::isSubscribed() const { + return m_subscribed; } -bool RenX::Server::isFullyConnected() const -{ - return RenX::Server::fully_connected; +bool RenX::Server::isFullyConnected() const { + return m_fully_connected; } -bool RenX::Server::isFirstKill() const -{ - return RenX::Server::firstKill; +bool RenX::Server::isFirstKill() const { + return m_firstKill; } -bool RenX::Server::isFirstDeath() const -{ - return RenX::Server::firstDeath; +bool RenX::Server::isFirstDeath() const { + return m_firstDeath; } -bool RenX::Server::isFirstAction() const -{ - return RenX::Server::firstAction; +bool RenX::Server::isFirstAction() const { + return m_firstAction; } -bool RenX::Server::isSeamless() const -{ - return RenX::Server::seamless; +bool RenX::Server::isSeamless() const { + return m_seamless; } -bool RenX::Server::isReliable() const -{ - return RenX::Server::reliable; +bool RenX::Server::isReliable() const { + return m_reliable; } -bool RenX::Server::isMatchPending() const -{ - return RenX::Server::match_state == 0 || RenX::Server::isTravelling(); +bool RenX::Server::isMatchPending() const { + return m_match_state == 0 || isTravelling(); } -bool RenX::Server::isMatchInProgress() const -{ - return RenX::Server::match_state == 1; +bool RenX::Server::isMatchInProgress() const { + return m_match_state == 1; } -bool RenX::Server::isMatchOver() const -{ - return RenX::Server::match_state == 2 || RenX::Server::isMatchOver(); +bool RenX::Server::isMatchOver() const { + return m_match_state == 2 || isMatchOver(); } -bool RenX::Server::isTravelling() const -{ - return RenX::Server::match_state == 3; +bool RenX::Server::isTravelling() const { + return m_match_state == 3; } -bool RenX::Server::isCompetitive() const -{ - return RenX::Server::competitive; +bool RenX::Server::isCompetitive() const { + return m_competitive; } -bool RenX::Server::isPublicLogChanType(int type) const -{ - return RenX::Server::logChanType == type; +bool RenX::Server::isPublicLogChanType(int type) const { + return m_logChanType == type; } -bool RenX::Server::isAdminLogChanType(int type) const -{ - return RenX::Server::adminLogChanType == type; +bool RenX::Server::isAdminLogChanType(int type) const { + return m_adminLogChanType == type; } -bool RenX::Server::isLogChanType(int type) const -{ - return RenX::Server::isPublicLogChanType(type) || RenX::Server::isAdminLogChanType(type); +bool RenX::Server::isLogChanType(int type) const { + return isPublicLogChanType(type) || isAdminLogChanType(type); } -bool RenX::Server::isPure() const -{ - return RenX::Server::pure; +bool RenX::Server::isPure() const { + return m_pure; } -int RenX::Server::send(const Jupiter::ReadableString &command) -{ - return RenX::Server::sendSocket("c"_jrs + RenX::escapifyRCON(command) + '\n'); +int RenX::Server::send(const Jupiter::ReadableString &command) { + return sendSocket("c"_jrs + RenX::escapifyRCON(command) + '\n'); } -int RenX::Server::sendSocket(const Jupiter::ReadableString &text) -{ - lastSendActivity = std::chrono::steady_clock::now(); - return sock.send(text); +int RenX::Server::sendSocket(const Jupiter::ReadableString &text) { + m_lastSendActivity = std::chrono::steady_clock::now(); + return m_sock.send(text); } -int RenX::Server::sendMessage(const Jupiter::ReadableString &message) -{ +int RenX::Server::sendMessage(const Jupiter::ReadableString &message) { Jupiter::String msg = RenX::escapifyRCON(message); - if (RenX::Server::neverSay) - { - int r = 0; - if (RenX::Server::players.size() != 0) - for (auto node = this->players.begin(); node != this->players.end(); ++node) - if (node->isBot == false) - r += RenX::Server::sendSocket(Jupiter::StringS::Format("chostprivatesay pid%d %.*s\n", node->id, msg.size(), msg.ptr())); - return r; + if (m_neverSay) { + int result = 0; + if (this->players.size() != 0) { + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + if (node->isBot == false) { + result += sendSocket(Jupiter::StringS::Format("chostprivatesay pid%d %.*s\n", node->id, msg.size(), msg.ptr())); + } + } + } + return result; } - else - return RenX::Server::sendSocket("chostsay "_jrs + msg + '\n'); + + return sendSocket("chostsay "_jrs + msg + '\n'); } -int RenX::Server::sendMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message) -{ - return RenX::Server::sendSocket("chostprivatesay pid"_jrs + Jupiter::StringS::Format("%d ", player.id) + RenX::escapifyRCON(message) + '\n'); +int RenX::Server::sendMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message) { + return 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 Jupiter::ReadableString &message) { + return 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::sendAdminMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message) { + return 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::sendWarnMessage(const RenX::PlayerInfo &player, const Jupiter::ReadableString &message) { + return 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); +int RenX::Server::sendData(const Jupiter::ReadableString &data) { + return sendSocket(data); } -RenX::BuildingInfo *RenX::Server::getBuildingByName(const Jupiter::ReadableString &name) const -{ - for (size_t index = 0; index != RenX::Server::buildings.size(); ++index) - if (RenX::Server::buildings.get(index)->name.equalsi(name)) - return RenX::Server::buildings.get(index); +RenX::BuildingInfo *RenX::Server::getBuildingByName(const Jupiter::ReadableString &name) const { + for (size_t index = 0; index != RenX::Server::buildings.size(); ++index) { + if (RenX::Server::buildings[index]->name.equalsi(name)) { + return RenX::Server::buildings[index].get(); + } + } + return nullptr; } -bool RenX::Server::hasMapInRotation(const Jupiter::ReadableString &name) const -{ +bool RenX::Server::hasMapInRotation(const Jupiter::ReadableString &name) const { size_t index = RenX::Server::maps.size(); - while (index != 0) - if (RenX::Server::maps.get(--index)->name.equalsi(name)) + while (index != 0) { + if (RenX::Server::maps[--index].name.equalsi(name)) { return true; + } + } + return false; } -const Jupiter::ReadableString *RenX::Server::getMapName(const Jupiter::ReadableString &name) const -{ +const Jupiter::ReadableString *RenX::Server::getMapName(const Jupiter::ReadableString &name) const { size_t index = RenX::Server::maps.size(); const Jupiter::ReadableString *map_name; - while (index != 0) - { - map_name = &RenX::Server::maps.get(--index)->name; + while (index != 0) { + map_name = &RenX::Server::maps[--index].name; if (map_name->findi(name) != Jupiter::INVALID_INDEX) return map_name; } return nullptr; } -const Jupiter::ReadableString &RenX::Server::getCurrentRCONCommand() const -{ - return RenX::Server::lastCommand; +const Jupiter::ReadableString &RenX::Server::getCurrentRCONCommand() const { + return m_lastCommand; } -const Jupiter::ReadableString &RenX::Server::getCurrentRCONCommandParameters() const -{ - return RenX::Server::lastCommandParams; +const Jupiter::ReadableString &RenX::Server::getCurrentRCONCommandParameters() const { + return m_lastCommandParams; } -std::chrono::milliseconds RenX::Server::getGameTime() const -{ - return std::chrono::duration_cast(std::chrono::steady_clock::now() - RenX::Server::gameStart); +std::chrono::milliseconds RenX::Server::getGameTime() const { + return std::chrono::duration_cast(std::chrono::steady_clock::now() - m_gameStart); } -std::chrono::milliseconds RenX::Server::getGameTime(const RenX::PlayerInfo &player) const -{ - if (player.joinTime < RenX::Server::gameStart) - return RenX::Server::getGameTime(); +std::chrono::milliseconds RenX::Server::getGameTime(const RenX::PlayerInfo &player) const { + if (player.joinTime < m_gameStart) + return getGameTime(); return std::chrono::duration_cast(std::chrono::steady_clock::now() - player.joinTime); } -size_t RenX::Server::getBotCount() const -{ +size_t RenX::Server::getBotCount() const { size_t count = 0; - for (auto node = this->players.begin(); node != this->players.end(); ++node) - if (node->isBot) + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + if (node->isBot) { ++count; + } + } return count; //return RenX::Server::bot_count; @@ -409,8 +380,7 @@ std::vector RenX::Server::activePlayers(bool includeBot return result; } -RenX::PlayerInfo *RenX::Server::getPlayer(int id) const -{ +RenX::PlayerInfo *RenX::Server::getPlayer(int id) const { for (auto node = this->players.begin(); node != this->players.end(); ++node) if (node->id == id) return const_cast(&*node); @@ -418,42 +388,47 @@ RenX::PlayerInfo *RenX::Server::getPlayer(int id) const return nullptr; } -RenX::PlayerInfo *RenX::Server::getPlayerByName(const Jupiter::ReadableString &name) const -{ - if (RenX::Server::players.size() == 0) +RenX::PlayerInfo *RenX::Server::getPlayerByName(const Jupiter::ReadableString &name) const { + if (this->players.size() == 0) { return nullptr; + } - for (auto node = this->players.begin(); node != this->players.end(); ++node) - if (node->name == name) - return const_cast(&*node); + // Try full name match + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + if (node->name == name) { + return const_cast(&*node); + } + } + // Try player ID Jupiter::ReferenceString idToken = name; - if (name.matchi("Player?*")) + if (name.matchi("Player?*")) { idToken.shiftRight(6); - else if (name.matchi("pid?*")) + } + else if (name.matchi("pid?*")) { idToken.shiftRight(3); - else + } + else { return nullptr; - int id = idToken.asInt(10); + } - return this->getPlayer(id); + int id = idToken.asInt(10); + return getPlayer(id); } -RenX::PlayerInfo *RenX::Server::getPlayerByPartName(const Jupiter::ReadableString &partName) const -{ - if (RenX::Server::players.size() == 0) +RenX::PlayerInfo *RenX::Server::getPlayerByPartName(const Jupiter::ReadableString &partName) const { + if (this->players.size() == 0) return nullptr; - RenX::PlayerInfo *r = RenX::Server::getPlayerByName(partName); + RenX::PlayerInfo *r = getPlayerByName(partName); if (r != nullptr) return r; - return RenX::Server::getPlayerByPartNameFast(partName); + return getPlayerByPartNameFast(partName); } -RenX::PlayerInfo *RenX::Server::getPlayerByPartNameFast(const Jupiter::ReadableString &partName) const -{ - if (RenX::Server::players.size() == 0) +RenX::PlayerInfo *RenX::Server::getPlayerByPartNameFast(const Jupiter::ReadableString &partName) const { + if (this->players.size() == 0) return nullptr; for (auto node = this->players.begin(); node != this->players.end(); ++node) @@ -463,17 +438,15 @@ RenX::PlayerInfo *RenX::Server::getPlayerByPartNameFast(const Jupiter::ReadableS return nullptr; } -Jupiter::StringS RenX::Server::formatSteamID(const RenX::PlayerInfo &player) const -{ - return RenX::Server::formatSteamID(player.steamid); +Jupiter::StringS RenX::Server::formatSteamID(const RenX::PlayerInfo &player) const { + return formatSteamID(player.steamid); } -Jupiter::StringS RenX::Server::formatSteamID(uint64_t id) const -{ +Jupiter::StringS RenX::Server::formatSteamID(uint64_t id) const { if (id == 0) return Jupiter::ReferenceString::empty; - switch (RenX::Server::steamFormat) + switch (m_steamFormat) { default: case 16: @@ -494,178 +467,171 @@ Jupiter::StringS RenX::Server::formatSteamID(uint64_t id) const } } -void RenX::Server::kickPlayer(int id, const Jupiter::ReadableString &in_reason) -{ +void RenX::Server::kickPlayer(int id, const Jupiter::ReadableString &in_reason) { Jupiter::String reason = RenX::escapifyRCON(in_reason); if (reason.isEmpty()) - RenX::Server::sendSocket(Jupiter::StringS::Format("ckick pid%d\n", id)); + sendSocket(Jupiter::StringS::Format("ckick pid%d\n", id)); else - RenX::Server::sendSocket(Jupiter::StringS::Format("ckick pid%d %.*s\n", id, reason.size(), reason.ptr())); + sendSocket(Jupiter::StringS::Format("ckick pid%d %.*s\n", id, reason.size(), reason.ptr())); } -void RenX::Server::kickPlayer(const RenX::PlayerInfo &player, const Jupiter::ReadableString &reason) -{ - if ((player.exemption_flags & RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK) == 0) - RenX::Server::kickPlayer(player.id, reason); +void RenX::Server::kickPlayer(const RenX::PlayerInfo &player, const Jupiter::ReadableString &reason) { + if ((player.exemption_flags & RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK) == 0) { + kickPlayer(player.id, reason); + } } -void RenX::Server::forceKickPlayer(int id, const Jupiter::ReadableString &in_reason) -{ +void RenX::Server::forceKickPlayer(int id, const Jupiter::ReadableString &in_reason) { Jupiter::String reason = RenX::escapifyRCON(in_reason); - if (reason.isEmpty()) - RenX::Server::sendSocket(Jupiter::StringS::Format("cfkick pid%d You were kicked from the server.\n", id)); - else - RenX::Server::sendSocket(Jupiter::StringS::Format("cfkick pid%d %.*s\n", id, reason.size(), reason.ptr())); + if (reason.isEmpty()) { + sendSocket(Jupiter::StringS::Format("cfkick pid%d You were kicked from the server.\n", id)); + return; + } + + sendSocket(Jupiter::StringS::Format("cfkick pid%d %.*s\n", id, reason.size(), reason.ptr())); } -void RenX::Server::forceKickPlayer(const RenX::PlayerInfo &player, const Jupiter::ReadableString &reason) -{ - if ((player.exemption_flags & RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK) == 0) - RenX::Server::forceKickPlayer(player.id, reason); +void RenX::Server::forceKickPlayer(const RenX::PlayerInfo &player, const Jupiter::ReadableString &reason) { + if ((player.exemption_flags & RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK) == 0) { + forceKickPlayer(player.id, reason); + } } -void RenX::Server::banCheck() -{ - if (RenX::Server::players.size() != 0) - for (auto node = this->players.begin(); node != this->players.end(); ++node) - if (node->isBot == false) - this->banCheck(*node); +void RenX::Server::banCheck() { + if (this->players.size() != 0) { + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + if (node->isBot == false) { + banCheck(*node); + } + } + } } -void RenX::Server::banCheck(RenX::PlayerInfo &player) -{ - if ((player.exemption_flags & (RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK)) != 0) +void RenX::Server::banCheck(RenX::PlayerInfo &player) { + if ((player.exemption_flags & (RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN | RenX::ExemptionDatabase::Entry::FLAG_TYPE_KICK)) != 0) { return; + } - const Jupiter::ArrayList &entries = RenX::banDatabase->getEntries(); - RenX::BanDatabase::Entry *entry = nullptr; uint32_t netmask; - RenX::BanDatabase::Entry *last_to_expire[7]; + RenX::BanDatabase::Entry* last_to_expire[7]; // TODO: what the fuck is this? for (size_t index = 0; index != sizeof(last_to_expire) / sizeof(RenX::BanDatabase::Entry *); ++index) last_to_expire[index] = nullptr; - auto handle_type = [&entry, &last_to_expire](size_t index) - { - if (last_to_expire[index] == nullptr) + auto handle_type = [&last_to_expire](RenX::BanDatabase::Entry* entry, size_t index) { + if (last_to_expire[index] == nullptr) { last_to_expire[index] = entry; - else if (last_to_expire[index]->length == std::chrono::seconds::zero()) - { + } + else if (last_to_expire[index]->length == std::chrono::seconds::zero()) { // favor older bans if they're also permanent - if (entry->length == std::chrono::seconds::zero() && entry->timestamp < last_to_expire[index]->timestamp) + if (entry->length == std::chrono::seconds::zero() && entry->timestamp < last_to_expire[index]->timestamp) { last_to_expire[index] = entry; + } } - else if (entry->length == std::chrono::seconds::zero() || entry->timestamp + entry->length > last_to_expire[index]->timestamp + last_to_expire[index]->length) + else if (entry->length == std::chrono::seconds::zero() || entry->timestamp + entry->length > last_to_expire[index]->timestamp + last_to_expire[index]->length) { last_to_expire[index] = entry; + } }; - for (size_t i = 0; i != entries.size(); i++) - { - entry = entries.get(i); - if (entry->is_active()) - { - if (entry->length != std::chrono::seconds::zero() && entry->timestamp + entry->length < std::chrono::system_clock::now()) - banDatabase->deactivate(i); - else - { - if (entry->prefix_length >= 32) + for (const auto& entry : RenX::banDatabase->getEntries()) { + if (entry->is_active()) { + if (entry->length != std::chrono::seconds::zero() && entry->timestamp + entry->length < std::chrono::system_clock::now()) { + banDatabase->deactivate(entry.get()); + } + else { + if (entry->prefix_length >= 32) { netmask = 0xFFFFFFFF; - else + } + else { netmask = Jupiter_prefix_length_to_netmask(entry->prefix_length); + } - if ((this->localSteamBan && entry->steamid != 0 && entry->steamid == player.steamid) - || (this->localIPBan && entry->ip != 0 && (entry->ip & netmask) == (player.ip32 & netmask)) - || (this->localHWIDBan && entry->hwid.isNotEmpty() && entry->hwid.equals(player.hwid)) - || (this->localRDNSBan && entry->rdns.isNotEmpty() && entry->is_rdns_ban() && player.rdns_thread.joinable() == false && player.rdns.match(entry->rdns)) - || (this->localNameBan && entry->name.isNotEmpty() && entry->name.equalsi(player.name))) - { + if ((m_localSteamBan && entry->steamid != 0 && entry->steamid == player.steamid) + || (m_localIPBan && entry->ip != 0 && (entry->ip & netmask) == (player.ip32 & netmask)) + || (m_localHWIDBan && entry->hwid.isNotEmpty() && entry->hwid.equals(player.hwid)) + || (m_localRDNSBan && entry->rdns.isNotEmpty() && entry->is_rdns_ban() && player.rdns_thread.joinable() == false && player.rdns.match(entry->rdns)) + || (m_localNameBan && entry->name.isNotEmpty() && entry->name.equalsi(player.name))) { player.ban_flags |= entry->flags; if (entry->is_type_game()) - handle_type(0); + handle_type(entry.get(), 0); if (entry->is_type_chat()) - handle_type(1); + handle_type(entry.get(), 1); if (entry->is_type_bot()) - handle_type(2); + handle_type(entry.get(), 2); if (entry->is_type_vote()) - handle_type(3); + handle_type(entry.get(), 3); if (entry->is_type_mine()) - handle_type(4); + handle_type(entry.get(), 4); if (entry->is_type_ladder()) - handle_type(5); + handle_type(entry.get(), 5); if (entry->is_type_alert()) - handle_type(6); + handle_type(entry.get(), 6); } } } } char timeStr[256]; - if (last_to_expire[0] != nullptr) // Game ban - { + if (last_to_expire[0] != nullptr) { // Game ban time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[0]->timestamp + last_to_expire[0]->length); strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(¤t_time)); - if (last_to_expire[0]->length == std::chrono::seconds::zero()) - this->forceKickPlayer(player, Jupiter::StringS::Format("You were permanently banned from %.*s on %s for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), timeStr, last_to_expire[0]->reason.size(), last_to_expire[0]->reason.ptr())); - else - this->forceKickPlayer(player, Jupiter::StringS::Format("You are banned from %.*s until %s for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), timeStr, last_to_expire[0]->reason.size(), last_to_expire[0]->reason.ptr())); + if (last_to_expire[0]->length == std::chrono::seconds::zero()) { + forceKickPlayer(player, Jupiter::StringS::Format("You were permanently banned from %.*s on %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[0]->reason.size(), last_to_expire[0]->reason.ptr())); + } + else { + forceKickPlayer(player, Jupiter::StringS::Format("You are banned from %.*s until %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[0]->reason.size(), last_to_expire[0]->reason.ptr())); + } player.ban_flags |= RenX::BanDatabase::Entry::FLAG_TYPE_BOT; // implies FLAG_TYPE_BOT } - else - { - if (last_to_expire[1] != nullptr) // Chat ban - { + else { + if (last_to_expire[1] != nullptr) { // Chat ban time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[1]->timestamp + last_to_expire[1]->length); strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(¤t_time)); - this->mute(player); + mute(player); if (last_to_expire[1]->length == std::chrono::seconds::zero()) - this->sendMessage(player, Jupiter::StringS::Format("You were permanently muted from %.*s on %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[1]->reason.size(), last_to_expire[1]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You were permanently muted from %.*s on %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[1]->reason.size(), last_to_expire[1]->reason.ptr())); else - this->sendMessage(player, Jupiter::StringS::Format("You are muted from %.*s until %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[1]->reason.size(), last_to_expire[1]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You are muted from %.*s until %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[1]->reason.size(), last_to_expire[1]->reason.ptr())); player.ban_flags |= RenX::BanDatabase::Entry::FLAG_TYPE_BOT; // implies FLAG_TYPE_BOT } - else if (last_to_expire[2] != nullptr) // Bot ban - { + else if (last_to_expire[2] != nullptr) { // Bot ban time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[2]->timestamp + last_to_expire[2]->length); strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(¤t_time)); if (last_to_expire[2]->length == std::chrono::seconds::zero()) - this->sendMessage(player, Jupiter::StringS::Format("You were permanently bot-muted from %.*s on %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[2]->reason.size(), last_to_expire[2]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You were permanently bot-muted from %.*s on %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[2]->reason.size(), last_to_expire[2]->reason.ptr())); else - this->sendMessage(player, Jupiter::StringS::Format("You are bot-muted from %.*s until %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[2]->reason.size(), last_to_expire[2]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You are bot-muted from %.*s until %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[2]->reason.size(), last_to_expire[2]->reason.ptr())); } - if (last_to_expire[3] != nullptr) // Vote ban - { + if (last_to_expire[3] != nullptr) { // Vote ban time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[3]->timestamp + last_to_expire[3]->length); strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(¤t_time)); if (last_to_expire[3]->length == std::chrono::seconds::zero()) - this->sendMessage(player, Jupiter::StringS::Format("You were permanently vote-muted from %.*s on %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[3]->reason.size(), last_to_expire[3]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You were permanently vote-muted from %.*s on %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[3]->reason.size(), last_to_expire[3]->reason.ptr())); else - this->sendMessage(player, Jupiter::StringS::Format("You are vote-muted from %.*s until %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[3]->reason.size(), last_to_expire[3]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You are vote-muted from %.*s until %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[3]->reason.size(), last_to_expire[3]->reason.ptr())); } - if (last_to_expire[4] != nullptr) // Mine ban - { + if (last_to_expire[4] != nullptr) { // Mine ban time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[4]->timestamp + last_to_expire[4]->length); - this->mineBan(player); + mineBan(player); strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(¤t_time)); if (last_to_expire[4]->length == std::chrono::seconds::zero()) - this->sendMessage(player, Jupiter::StringS::Format("You were permanently mine-banned from %.*s on %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[4]->reason.size(), last_to_expire[4]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You were permanently mine-banned from %.*s on %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[4]->reason.size(), last_to_expire[4]->reason.ptr())); else - this->sendMessage(player, Jupiter::StringS::Format("You are mine-banned from %.*s until %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[4]->reason.size(), last_to_expire[4]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You are mine-banned from %.*s until %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[4]->reason.size(), last_to_expire[4]->reason.ptr())); } - if (last_to_expire[5] != nullptr) // Ladder ban - { + if (last_to_expire[5] != nullptr) { // Ladder ban time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[5]->timestamp + last_to_expire[5]->length); strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(¤t_time)); if (last_to_expire[5]->length == std::chrono::seconds::zero()) - this->sendMessage(player, Jupiter::StringS::Format("You were permanently ladder-banned from %.*s on %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[5]->reason.size(), last_to_expire[5]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You were permanently ladder-banned from %.*s on %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[5]->reason.size(), last_to_expire[5]->reason.ptr())); else - this->sendMessage(player, Jupiter::StringS::Format("You are ladder-banned from %.*s until %s for: %.*s", ban_from_str.size(), ban_from_str.ptr(), timeStr, last_to_expire[5]->reason.size(), last_to_expire[5]->reason.ptr())); + sendMessage(player, Jupiter::StringS::Format("You are ladder-banned from %.*s until %s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), timeStr, last_to_expire[5]->reason.size(), last_to_expire[5]->reason.ptr())); } - if (last_to_expire[6] != nullptr) // Alert - { + if (last_to_expire[6] != nullptr) { // Alert IRC_Bot *server; Jupiter::String fmtName = RenX::getFormattedPlayerName(player); Jupiter::StringL user_message = Jupiter::StringL::Format(IRCCOLOR "04[Alert] " IRCCOLOR IRCBOLD "%.*s" IRCBOLD IRCCOLOR " is marked for monitoring by %.*s for: \"%.*s\". Please keep an eye on them in ", fmtName.size(), fmtName.ptr(), last_to_expire[6]->banner.size(), last_to_expire[6]->banner.ptr(), last_to_expire[6]->reason.size(), last_to_expire[6]->reason.ptr()); @@ -674,8 +640,7 @@ void RenX::Server::banCheck(RenX::PlayerInfo &player) for (size_t server_index = 0; server_index < serverManager->size(); ++server_index) { server = serverManager->getServer(server_index); for (auto& channel : server->getChannels()) { - if (this->isAdminLogChanType(channel.second.getType())) - { + if (isAdminLogChanType(channel.second.getType())) { server->sendMessage(channel.second.getName(), channel_message); user_message += channel.second.getName(); @@ -691,66 +656,64 @@ void RenX::Server::banCheck(RenX::PlayerInfo &player) } }; -void RenX::Server::banPlayer(int id, const Jupiter::ReadableString &banner, const Jupiter::ReadableString &reason) -{ - if (RenX::Server::rconBan) - { +void RenX::Server::banPlayer(int id, const Jupiter::ReadableString &banner, const Jupiter::ReadableString &reason) { + if (m_rconBan) { Jupiter::String out_reason = RenX::escapifyRCON(reason); - RenX::Server::sendSocket(Jupiter::StringS::Format("ckickban pid%d %.*s\n", id, out_reason.size(), out_reason.ptr())); + sendSocket(Jupiter::StringS::Format("ckickban pid%d %.*s\n", id, out_reason.size(), out_reason.ptr())); } - else - { - RenX::PlayerInfo *player = RenX::Server::getPlayer(id); - if (player != nullptr) - RenX::Server::banPlayer(*player, banner, reason); + else { + RenX::PlayerInfo *player = getPlayer(id); + if (player != nullptr) { + banPlayer(*player, banner, reason); + } } } -void RenX::Server::banPlayer(const RenX::PlayerInfo &player, const Jupiter::ReadableString &banner, const Jupiter::ReadableString &reason, std::chrono::seconds length) -{ - if ((player.exemption_flags & RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN) == 0) - { - if (RenX::Server::localBan) +void RenX::Server::banPlayer(const RenX::PlayerInfo &player, const Jupiter::ReadableString &banner, const Jupiter::ReadableString &reason, std::chrono::seconds length) { + if ((player.exemption_flags & RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN) == 0) { + if (m_localBan) { RenX::banDatabase->add(this, player, banner, reason, length); + } - if (length == std::chrono::seconds::zero()) - { - if (RenX::Server::rconBan) - { + if (length == std::chrono::seconds::zero()) { + if (m_rconBan) { Jupiter::String out_reason = RenX::escapifyRCON(reason); - RenX::Server::sendSocket(Jupiter::StringS::Format("ckickban pid%d %.*s\n", player.id, out_reason.size(), out_reason.ptr())); + sendSocket(Jupiter::StringS::Format("ckickban pid%d %.*s\n", player.id, out_reason.size(), out_reason.ptr())); + } + else if (banner.isNotEmpty()) { + forceKickPlayer(player, Jupiter::StringS::Format("You are permanently banned from %.*s by %.*s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), banner.size(), banner.ptr(), reason.size(), reason.ptr())); + } + else { + forceKickPlayer(player, Jupiter::StringS::Format("You are permanently banned from %.*s for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), reason.size(), reason.ptr())); } - else if (banner.isNotEmpty()) - RenX::Server::forceKickPlayer(player, Jupiter::StringS::Format("You are permanently banned from %.*s by %.*s for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), banner.size(), banner.ptr(), reason.size(), reason.ptr())); - else - RenX::Server::forceKickPlayer(player, Jupiter::StringS::Format("You are permanently banned from %.*s for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), reason.size(), reason.ptr())); } - else if (banner.isNotEmpty()) - RenX::Server::forceKickPlayer(player, Jupiter::StringS::Format("You are banned from %.*s by %.*s for the next %lld days, %.2d:%.2d:%.2d for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), banner.size(), banner.ptr(), static_cast(length.count() / 86400), static_cast(length.count() % 3600), static_cast((length.count() % 3600) / 60), static_cast(length.count() % 60), reason.size(), reason.ptr())); - else - RenX::Server::forceKickPlayer(player, Jupiter::StringS::Format("You are banned from %.*s for the next %lld days, %.2d:%.2d:%.2d for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), static_cast(length.count() / 86400), static_cast(length.count() % 3600), static_cast((length.count() % 3600) / 60), static_cast(length.count() % 60), reason.size(), reason.ptr())); + else if (banner.isNotEmpty()) { + // TODO: make the time formatting not complete nonsense + forceKickPlayer(player, Jupiter::StringS::Format("You are banned from %.*s by %.*s for the next %lld days, %.2d:%.2d:%.2d for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), banner.size(), banner.ptr(), static_cast(length.count() / 86400), static_cast(length.count() % 3600), static_cast((length.count() % 3600) / 60), static_cast(length.count() % 60), reason.size(), reason.ptr())); + } + else { + forceKickPlayer(player, Jupiter::StringS::Format("You are banned from %.*s for the next %lld days, %.2d:%.2d:%.2d for: %.*s", m_ban_from_str.size(), m_ban_from_str.ptr(), static_cast(length.count() / 86400), static_cast(length.count() % 3600), static_cast((length.count() % 3600) / 60), static_cast(length.count() % 60), reason.size(), reason.ptr())); + } } } -bool RenX::Server::removePlayer(int id) -{ - if (RenX::Server::players.size() == 0) +bool RenX::Server::removePlayer(int id) { + if (this->players.size() == 0) { return false; + } - for (auto node = this->players.begin(); node != this->players.end(); ++node) - { - if (node->id == id) - { - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnPlayerDelete(*this, *node); + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + if (node->id == id) { + for (auto plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_OnPlayerDelete(*this, *node); + } - if (node->isBot) - --this->bot_count; + if (node->isBot) { + --m_bot_count; + } - if (node->rdns_thread.joinable()) // Close the RDNS thread, if one exists - { - --this->player_rdns_resolutions_pending; + if (node->rdns_thread.joinable()) { // Close the RDNS thread, if one exists + --m_player_rdns_resolutions_pending; node->rdns_thread.join(); } @@ -758,611 +721,540 @@ bool RenX::Server::removePlayer(int id) return true; } } + return false; } -bool RenX::Server::removePlayer(RenX::PlayerInfo &player) -{ - return RenX::Server::removePlayer(player.id); +bool RenX::Server::removePlayer(RenX::PlayerInfo &player) { + return removePlayer(player.id); } -bool RenX::Server::fetchClientList() -{ - RenX::Server::lastClientListUpdate = std::chrono::steady_clock::now(); - if (this->rconVersion >= 4) - return RenX::Server::sendSocket("cclientvarlist KILLS DEATHS SCORE CREDITS CHARACTER VEHICLE PING ADMIN STEAM IP HWID PLAYERLOG\n"_jrs) > 0 - && RenX::Server::sendSocket("cbotvarlist KILLS DEATHS SCORE CREDITS CHARACTER VEHICLE PLAYERLOG\n"_jrs) > 0; - else - return RenX::Server::sendSocket("cclientvarlist KILLS\xA0""DEATHS\xA0""SCORE\xA0""CREDITS\xA0""CHARACTER\xA0""VEHICLE\xA0""PING\xA0""ADMIN\xA0""STEAM\xA0""IP\xA0""PLAYERLOG\n"_jrs) > 0 - && RenX::Server::sendSocket("cbotvarlist KILLS\xA0""DEATHS\xA0""SCORE\xA0""CREDITS\xA0""CHARACTER\xA0""VEHICLE\xA0""PLAYERLOG\n"_jrs) > 0; +bool RenX::Server::fetchClientList() { + m_lastClientListUpdate = std::chrono::steady_clock::now(); + // TODO: remove all support for rconVersion < 4 + if (m_rconVersion >= 4) { + return sendSocket("cclientvarlist KILLS DEATHS SCORE CREDITS CHARACTER VEHICLE PING ADMIN STEAM IP HWID PLAYERLOG\n"_jrs) > 0 + && sendSocket("cbotvarlist KILLS DEATHS SCORE CREDITS CHARACTER VEHICLE PLAYERLOG\n"_jrs) > 0; + } + + return sendSocket("cclientvarlist KILLS\xA0""DEATHS\xA0""SCORE\xA0""CREDITS\xA0""CHARACTER\xA0""VEHICLE\xA0""PING\xA0""ADMIN\xA0""STEAM\xA0""IP\xA0""PLAYERLOG\n"_jrs) > 0 + && sendSocket("cbotvarlist KILLS\xA0""DEATHS\xA0""SCORE\xA0""CREDITS\xA0""CHARACTER\xA0""VEHICLE\xA0""PLAYERLOG\n"_jrs) > 0; } -bool RenX::Server::updateClientList() -{ - RenX::Server::lastClientListUpdate = std::chrono::steady_clock::now(); +bool RenX::Server::updateClientList() { + m_lastClientListUpdate = std::chrono::steady_clock::now(); - int r = 0; - if (RenX::Server::players.size() != this->getBotCount()) - { - if (this->rconVersion >= 4) - r = RenX::Server::sendSocket("cclientvarlist ID SCORE CREDITS PING\n"_jrs) > 0; + int result = 0; + if (this->players.size() != getBotCount()) { + if (m_rconVersion >= 4) + result = sendSocket("cclientvarlist ID SCORE CREDITS PING\n"_jrs) > 0; else - r = RenX::Server::sendSocket("cclientvarlist ID\xA0""SCORE\xA0""CREDITS\xA0""PING\n"_jrs) > 0; + result = sendSocket("cclientvarlist ID\xA0""SCORE\xA0""CREDITS\xA0""PING\n"_jrs) > 0; } - if (this->getBotCount() != 0) - { - if (this->rconVersion >= 4) - r |= RenX::Server::sendSocket("cbotvarlist ID SCORE CREDITS\n"_jrs) > 0; + if (getBotCount() != 0) { + if (m_rconVersion >= 4) + result |= sendSocket("cbotvarlist ID SCORE CREDITS\n"_jrs) > 0; else - r |= RenX::Server::sendSocket("cbotvarlist ID\xA0""SCORE\xA0""CREDITS\n"_jrs) > 0; + result |= sendSocket("cbotvarlist ID\xA0""SCORE\xA0""CREDITS\n"_jrs) > 0; } - return r != 0; + return result != 0; } -bool RenX::Server::updateBuildingList() -{ - RenX::Server::lastBuildingListUpdate = std::chrono::steady_clock::now(); - return RenX::Server::sendSocket("cbinfo\n"_jrs) > 0; +bool RenX::Server::updateBuildingList() { + m_lastBuildingListUpdate = std::chrono::steady_clock::now(); + return sendSocket("cbinfo\n"_jrs) > 0; } -bool RenX::Server::gameover() -{ - RenX::Server::gameover_when_empty = false; - return RenX::Server::send("endmap"_jrs) > 0; +bool RenX::Server::gameover() { + m_gameover_when_empty = false; + return send("endmap"_jrs) > 0; } -void RenX::Server::gameover(std::chrono::seconds delay) -{ - if (delay == std::chrono::seconds::zero()) - this->gameover(); - else - { - this->gameover_time = std::chrono::steady_clock::now() + delay; - this->gameover_pending = true; +void RenX::Server::gameover(std::chrono::seconds delay) { + if (delay == std::chrono::seconds::zero()) { + gameover(); + return; } + + m_gameover_time = std::chrono::steady_clock::now() + delay; + m_gameover_pending = true; } -bool RenX::Server::gameoverStop() -{ - if (this->gameover_pending == false) +bool RenX::Server::gameoverStop() { + if (m_gameover_pending == false) { return false; + } - this->gameover_pending = false; + m_gameover_pending = false; return true; } -void RenX::Server::gameoverWhenEmpty() -{ - if (this->players.size() == this->getBotCount()) - this->gameover(); - else - this->gameover_when_empty = true; +void RenX::Server::gameoverWhenEmpty() { + if (this->players.size() == this->getBotCount()) { + gameover(); + return; + } + + m_gameover_when_empty = true; } -bool RenX::Server::setMap(const Jupiter::ReadableString &map) -{ - return RenX::Server::send(Jupiter::StringS::Format("changemap %.*s", map.size(), map.ptr())) > 0; +bool RenX::Server::setMap(const Jupiter::ReadableString &map) { + return send(Jupiter::StringS::Format("changemap %.*s", map.size(), map.ptr())) > 0; } -bool RenX::Server::loadMutator(const Jupiter::ReadableString &mutator) -{ - return RenX::Server::send(Jupiter::StringS::Format("loadmutator %.*s", mutator.size(), mutator.ptr())) > 0; +bool RenX::Server::loadMutator(const Jupiter::ReadableString &mutator) { + return send(Jupiter::StringS::Format("loadmutator %.*s", mutator.size(), mutator.ptr())) > 0; } -bool RenX::Server::unloadMutator(const Jupiter::ReadableString &mutator) -{ - return RenX::Server::send(Jupiter::StringS::Format("unloadmutator %.*s", mutator.size(), mutator.ptr())) > 0; +bool RenX::Server::unloadMutator(const Jupiter::ReadableString &mutator) { + return send(Jupiter::StringS::Format("unloadmutator %.*s", mutator.size(), mutator.ptr())) > 0; } -bool RenX::Server::cancelVote(const RenX::TeamType team) -{ - switch (team) - { +bool RenX::Server::cancelVote(const RenX::TeamType team) { + switch (team) { default: - return RenX::Server::send("cancelvote -1"_jrs) > 0; + return send("cancelvote -1"_jrs) > 0; case TeamType::GDI: - return RenX::Server::send("cancelvote 0"_jrs) > 0; + return send("cancelvote 0"_jrs) > 0; case TeamType::Nod: - return RenX::Server::send("cancelvote 1"_jrs) > 0; + return send("cancelvote 1"_jrs) > 0; } } -bool RenX::Server::swapTeams() -{ - return RenX::Server::send("swapteams"_jrs) > 0; +bool RenX::Server::swapTeams() { + return send("swapteams"_jrs) > 0; } -bool RenX::Server::recordDemo() -{ - return RenX::Server::send("recorddemo"_jrs) > 0; +bool RenX::Server::recordDemo() { + return send("recorddemo"_jrs) > 0; } -bool RenX::Server::mute(const RenX::PlayerInfo &player) -{ - return RenX::Server::send(Jupiter::StringS::Format("textmute pid%u", player.id)) > 0; +bool RenX::Server::mute(const RenX::PlayerInfo &player) { + return send(Jupiter::StringS::Format("textmute pid%u", player.id)) > 0; } -bool RenX::Server::unmute(const RenX::PlayerInfo &player) -{ - return RenX::Server::send(Jupiter::StringS::Format("textunmute pid%u", player.id)) > 0; +bool RenX::Server::unmute(const RenX::PlayerInfo &player) { + return send(Jupiter::StringS::Format("textunmute pid%u", player.id)) > 0; } -bool RenX::Server::giveCredits(int id, double credits) -{ - return RenX::Server::competitive == false && RenX::Server::send(Jupiter::StringS::Format("givecredits pid%d %f", id, credits)) > 0; +bool RenX::Server::giveCredits(int id, double credits) { + return m_competitive == false && send(Jupiter::StringS::Format("givecredits pid%d %f", id, credits)) > 0; } -bool RenX::Server::giveCredits(RenX::PlayerInfo &player, double credits) -{ - return RenX::Server::giveCredits(player.id, credits); +bool RenX::Server::giveCredits(RenX::PlayerInfo &player, double credits) { + return giveCredits(player.id, credits); } -bool RenX::Server::kill(int id) -{ - return RenX::Server::competitive == false && RenX::Server::send(Jupiter::StringS::Format("kill pid%d", id)) > 0; +bool RenX::Server::kill(int id) { + return m_competitive == false && send(Jupiter::StringS::Format("kill pid%d", id)) > 0; } -bool RenX::Server::kill(RenX::PlayerInfo &player) -{ - return RenX::Server::kill(player.id); +bool RenX::Server::kill(RenX::PlayerInfo &player) { + return kill(player.id); } -bool RenX::Server::disarm(int id) -{ - return RenX::Server::competitive == false && RenX::Server::send(Jupiter::StringS::Format("disarm pid%d", id)) > 0; +bool RenX::Server::disarm(int id) { + return m_competitive == false && send(Jupiter::StringS::Format("disarm pid%d", id)) > 0; } -bool RenX::Server::disarm(RenX::PlayerInfo &player) -{ - return RenX::Server::disarm(player.id); +bool RenX::Server::disarm(RenX::PlayerInfo &player) { + return disarm(player.id); } -bool RenX::Server::disarmC4(int id) -{ - return RenX::Server::competitive == false && RenX::Server::send(Jupiter::StringS::Format("disarmc4 pid%d", id)) > 0; +bool RenX::Server::disarmC4(int id) { + return m_competitive == false && send(Jupiter::StringS::Format("disarmc4 pid%d", id)) > 0; } -bool RenX::Server::disarmC4(RenX::PlayerInfo &player) -{ - return RenX::Server::disarmC4(player.id); +bool RenX::Server::disarmC4(RenX::PlayerInfo &player) { + return disarmC4(player.id); } -bool RenX::Server::disarmBeacon(int id) -{ - return RenX::Server::competitive == false && RenX::Server::send(Jupiter::StringS::Format("disarmb pid%d", id)) > 0; +bool RenX::Server::disarmBeacon(int id) { + return m_competitive == false && send(Jupiter::StringS::Format("disarmb pid%d", id)) > 0; } -bool RenX::Server::disarmBeacon(RenX::PlayerInfo &player) -{ - return RenX::Server::disarmBeacon(player.id); +bool RenX::Server::disarmBeacon(RenX::PlayerInfo &player) { + return disarmBeacon(player.id); } -bool RenX::Server::mineBan(int id) -{ - return RenX::Server::send(Jupiter::StringS::Format("mineban pid%d", id)) > 0; +bool RenX::Server::mineBan(int id) { + return send(Jupiter::StringS::Format("mineban pid%d", id)) > 0; } -bool RenX::Server::mineBan(RenX::PlayerInfo &player) -{ - return RenX::Server::mineBan(player.id); +bool RenX::Server::mineBan(RenX::PlayerInfo &player) { + return mineBan(player.id); } -bool RenX::Server::changeTeam(int id, bool resetCredits) -{ - return RenX::Server::send(Jupiter::StringS::Format(resetCredits ? "team pid%d" : "team2 pid%d", id)) > 0; +bool RenX::Server::changeTeam(int id, bool resetCredits) { + return send(Jupiter::StringS::Format(resetCredits ? "team pid%d" : "team2 pid%d", id)) > 0; } -bool RenX::Server::changeTeam(RenX::PlayerInfo &player, bool resetCredits) -{ - return RenX::Server::changeTeam(player.id, resetCredits); +bool RenX::Server::changeTeam(RenX::PlayerInfo &player, bool resetCredits) { + return changeTeam(player.id, resetCredits); } -bool RenX::Server::nmodePlayer(const RenX::PlayerInfo &player) -{ - return RenX::Server::send(Jupiter::StringS::Format("nmode pid%d", player.id)); +bool RenX::Server::nmodePlayer(const RenX::PlayerInfo &player) { + return send(Jupiter::StringS::Format("nmode pid%d", player.id)); } -bool RenX::Server::smodePlayer(const RenX::PlayerInfo &player) -{ - return RenX::Server::send(Jupiter::StringS::Format("smode pid%d", player.id)); +bool RenX::Server::smodePlayer(const RenX::PlayerInfo &player) { + return send(Jupiter::StringS::Format("smode pid%d", player.id)); } -const Jupiter::ReadableString &RenX::Server::getPrefix() const -{ - static Jupiter::String parsed; - RenX::processTags(parsed = RenX::Server::IRCPrefix, this); +const Jupiter::ReadableString &RenX::Server::getPrefix() const { + static Jupiter::String parsed; // TODO: What the hell? + RenX::processTags(parsed = m_IRCPrefix, this); return parsed; } -void RenX::Server::setPrefix(const Jupiter::ReadableString &prefix) -{ - RenX::sanitizeTags(RenX::Server::IRCPrefix = prefix); +void RenX::Server::setPrefix(const Jupiter::ReadableString &prefix) { + RenX::sanitizeTags(m_IRCPrefix = prefix); } -const Jupiter::ReadableString &RenX::Server::getCommandPrefix() const -{ - return RenX::Server::CommandPrefix; +const Jupiter::ReadableString &RenX::Server::getCommandPrefix() const { + return m_CommandPrefix; } -void RenX::Server::setCommandPrefix(const Jupiter::ReadableString &prefix) -{ - RenX::Server::CommandPrefix = prefix; +void RenX::Server::setCommandPrefix(const Jupiter::ReadableString &prefix) { + m_CommandPrefix = prefix; } -void RenX::Server::setRanked(bool in_value) -{ - RenX::Server::m_ranked = in_value; +void RenX::Server::setRanked(bool in_value) { + m_ranked = in_value; } -const Jupiter::ReadableString &RenX::Server::getRules() const -{ - return RenX::Server::rules; +const Jupiter::ReadableString &RenX::Server::getRules() const { + return m_rules; } -const std::string &RenX::Server::getHostname() const -{ - return RenX::Server::hostname; +const std::string &RenX::Server::getHostname() const { + return m_hostname; } -unsigned short RenX::Server::getPort() const -{ - return RenX::Server::port; +unsigned short RenX::Server::getPort() const { + return m_port; } -const std::string &RenX::Server::getSocketHostname() const -{ - return RenX::Server::sock.getRemoteHostname(); +const std::string &RenX::Server::getSocketHostname() const { + return m_sock.getRemoteHostname(); } -unsigned short RenX::Server::getSocketPort() const -{ - return RenX::Server::sock.getRemotePort(); +unsigned short RenX::Server::getSocketPort() const { + return m_sock.getRemotePort(); } -std::chrono::steady_clock::time_point RenX::Server::getLastAttempt() const -{ - return RenX::Server::lastAttempt; +std::chrono::steady_clock::time_point RenX::Server::getLastAttempt() const { + return m_lastAttempt; } -std::chrono::milliseconds RenX::Server::getDelay() const -{ - return RenX::Server::delay; +std::chrono::milliseconds RenX::Server::getDelay() const { + return m_delay; } -int RenX::Server::getMineLimit() const -{ - return RenX::Server::mineLimit; +int RenX::Server::getMineLimit() const { + return m_mineLimit; } -int RenX::Server::getPlayerLimit() const -{ - return RenX::Server::playerLimit; +int RenX::Server::getPlayerLimit() const { + return m_playerLimit; } -int RenX::Server::getVehicleLimit() const -{ - return RenX::Server::vehicleLimit; +int RenX::Server::getVehicleLimit() const { + return m_vehicleLimit; } -int RenX::Server::getTimeLimit() const -{ - return RenX::Server::timeLimit; +int RenX::Server::getTimeLimit() const { + return m_timeLimit; } -int RenX::Server::getTeamMode() const -{ - return RenX::Server::m_team_mode; +int RenX::Server::getTeamMode() const { + return m_team_mode; } -int RenX::Server::getGameType() const -{ - return RenX::Server::m_game_type; +int RenX::Server::getGameType() const { + return m_game_type; } -double RenX::Server::getCrateRespawnDelay() const -{ - return RenX::Server::crateRespawnAfterPickup; +double RenX::Server::getCrateRespawnDelay() const { + return m_crateRespawnAfterPickup; } -bool RenX::Server::isSteamRequired() const -{ - return RenX::Server::steamRequired; +bool RenX::Server::isSteamRequired() const { + return m_steamRequired; } -bool RenX::Server::isPrivateMessageTeamOnly() const -{ - return RenX::Server::privateMessageTeamOnly; +bool RenX::Server::isPrivateMessageTeamOnly() const { + return m_privateMessageTeamOnly; } -bool RenX::Server::isPrivateMessagingEnabled() const -{ - return RenX::Server::allowPrivateMessaging; +bool RenX::Server::isPrivateMessagingEnabled() const { + return m_allowPrivateMessaging; } -bool RenX::Server::isRanked() const -{ - return RenX::Server::m_ranked; +bool RenX::Server::isRanked() const { + return m_ranked; } -bool RenX::Server::isPassworded() const -{ - return RenX::Server::passworded; +bool RenX::Server::isPassworded() const { + return m_passworded; } -bool RenX::Server::isCratesEnabled() const -{ - return RenX::Server::spawnCrates; +bool RenX::Server::isCratesEnabled() const { + return m_spawnCrates; } -bool RenX::Server::isBotsEnabled() const -{ - return RenX::Server::botsEnabled; +bool RenX::Server::isBotsEnabled() const { + return m_botsEnabled; } -const Jupiter::ReadableString &RenX::Server::getPassword() const -{ - return RenX::Server::pass; +const Jupiter::ReadableString &RenX::Server::getPassword() const { + return m_pass; } -const Jupiter::ReadableString &RenX::Server::getUser() const -{ - return RenX::Server::rconUser; +const Jupiter::ReadableString &RenX::Server::getUser() const { + return m_rconUser; } -bool RenX::Server::isDevBot() const -{ - return RenX::Server::devBot; +bool RenX::Server::isDevBot() const { + return m_devBot; } -const Jupiter::ReadableString &RenX::Server::getName() const -{ - return RenX::Server::serverName; +const Jupiter::ReadableString &RenX::Server::getName() const { + return m_serverName; } -const RenX::Map &RenX::Server::getMap() const -{ - return RenX::Server::map; +const RenX::Map &RenX::Server::getMap() const { + return m_map; } -RenX::GameCommand *RenX::Server::getCommand(unsigned int index) const -{ - return RenX::Server::commands.get(index); +RenX::GameCommand *RenX::Server::getCommand(unsigned int index) const { + return m_commands[index].get(); } -RenX::GameCommand *RenX::Server::getCommand(const Jupiter::ReadableString &trigger) const -{ - RenX::GameCommand *cmd; - for (size_t i = 0; i != RenX::Server::commands.size(); i++) - { - cmd = RenX::Server::commands.get(i); - if (cmd->matches(trigger)) - return cmd; +RenX::GameCommand *RenX::Server::getCommand(const Jupiter::ReadableString &trigger) const { + for (const auto& command : m_commands) { + if (command->matches(trigger)) { + return command.get(); + } } return nullptr; } -size_t RenX::Server::getCommandCount() const -{ - return RenX::Server::commands.size(); +size_t RenX::Server::getCommandCount() const { + return m_commands.size(); } -RenX::GameCommand *RenX::Server::triggerCommand(const Jupiter::ReadableString &trigger, RenX::PlayerInfo &player, const Jupiter::ReadableString ¶meters) -{ - RenX::GameCommand *cmd; - +RenX::GameCommand *RenX::Server::triggerCommand(const Jupiter::ReadableString &trigger, RenX::PlayerInfo &player, const Jupiter::ReadableString ¶meters) { RenX::GameCommand::active_server = this; - for (size_t i = 0; i < RenX::Server::commands.size(); i++) - { - cmd = RenX::Server::commands.get(i); - if (cmd->matches(trigger)) - { - if (player.access >= cmd->getAccessLevel()) - cmd->trigger(this, &player, parameters); - else - RenX::Server::sendMessage(player, "Access Denied."_jrs); + for (const auto& command : m_commands) { + if (command->matches(trigger)) { + if (player.access >= command->getAccessLevel()) { + command->trigger(this, &player, parameters); + } + else { + sendMessage(player, "Access Denied."_jrs); + } - Jupiter::ArrayList& xPlugins = *getCore()->getPlugins(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnCommandTriggered(*this, trigger, player, parameters, *cmd); + // TODO: avoiding modifying behavior for now, but this probably doesn't need to be called on access denied + for (const auto& plugin : getCore()->getPlugins()) { + plugin->RenX_OnCommandTriggered(*this, trigger, player, parameters, *command); + } - return cmd; + return command.get(); } } - RenX::GameCommand::active_server = RenX::GameCommand::selected_server; + // TODO: do we need to set active_server on the return above as well? + RenX::GameCommand::active_server = RenX::GameCommand::selected_server; return nullptr; } -void RenX::Server::addCommand(RenX::GameCommand *command) -{ +void RenX::Server::addCommand(RenX::GameCommand* in_command) { + std::unique_ptr command{ in_command }; int access_level; - if (RenX::Server::commandAccessLevels != nullptr) - { - const Jupiter::ReadableString &accessLevel = RenX::Server::commandAccessLevels->get(command->getTrigger()); - if (accessLevel.isNotEmpty()) - { + if (m_commandAccessLevels != nullptr) { + const Jupiter::ReadableString &accessLevel = m_commandAccessLevels->get(command->getTrigger()); + if (accessLevel.isNotEmpty()) { access_level = accessLevel.asInt(); - if (access_level < 0) // Disabled command - { - delete command; + if (access_level < 0) { // Disabled command return; } + command->setAccessLevel(access_level); } } - if (RenX::Server::commandAliases != nullptr) - { - const Jupiter::ReadableString &aliasList = RenX::Server::commandAliases->get(command->getTrigger()); + if (m_commandAliases != nullptr) { + const Jupiter::ReadableString &aliasList = m_commandAliases->get(command->getTrigger()); unsigned int j = aliasList.wordCount(WHITESPACE); - while (j != 0) + while (j != 0) { command->addTrigger(Jupiter::ReferenceString::getWord(aliasList, --j, WHITESPACE)); + } } - RenX::Server::commands.add(command); + m_commands.push_back(std::move(command)); } -bool RenX::Server::removeCommand(RenX::GameCommand *command) -{ - for (size_t i = 0; i != RenX::Server::commands.size(); i++) - if (RenX::Server::commands.get(i) == command) - { - delete RenX::Server::commands.remove(i); +bool RenX::Server::removeCommand(RenX::GameCommand *command) { + for (auto itr = m_commands.begin(); itr != m_commands.end(); ++itr) { + if (itr->get() == command) { + m_commands.erase(itr); return true; } + } + return false; } -bool RenX::Server::removeCommand(const Jupiter::ReadableString &trigger) -{ - for (size_t i = 0; i != RenX::Server::commands.size(); i++) - if (RenX::Server::commands.get(i)->matches(trigger)) - { - delete RenX::Server::commands.remove(i); +bool RenX::Server::removeCommand(const Jupiter::ReadableString &trigger) { + for (auto itr = m_commands.begin(); itr != m_commands.end(); ++itr) { + if ((*itr)->matches(trigger)) { + m_commands.erase(itr); return true; } + } + return false; } -void RenX::Server::setUUIDFunction(RenX::Server::uuid_func func) -{ - RenX::Server::calc_uuid = func; +void RenX::Server::setUUIDFunction(RenX::Server::uuid_func func) { + m_calc_uuid = func; - for (auto node = this->players.begin(); node != this->players.end(); ++node) - RenX::Server::setUUIDIfDifferent(*node, RenX::Server::calc_uuid(*node)); + for (auto node = this->players.begin(); node != this->players.end(); ++node) { + setUUIDIfDifferent(*node, m_calc_uuid(*node)); + } } -RenX::Server::uuid_func RenX::Server::getUUIDFunction() const -{ - return RenX::Server::calc_uuid; +RenX::Server::uuid_func RenX::Server::getUUIDFunction() const { + return m_calc_uuid; } -void RenX::Server::setUUID(RenX::PlayerInfo &player, const Jupiter::ReadableString &uuid) -{ - Jupiter::ArrayList &xPlugins = *getCore()->getPlugins(); - - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnPlayerUUIDChange(*this, player, uuid); +void RenX::Server::setUUID(RenX::PlayerInfo &player, const Jupiter::ReadableString &uuid) { + for (const auto& plugin : getCore()->getPlugins()) { + plugin->RenX_OnPlayerUUIDChange(*this, player, uuid); + } player.uuid = uuid; } -bool RenX::Server::setUUIDIfDifferent(RenX::PlayerInfo &player, const Jupiter::ReadableString &uuid) -{ - if (player.uuid.equals(uuid)) +bool RenX::Server::setUUIDIfDifferent(RenX::PlayerInfo &player, const Jupiter::ReadableString &uuid) { + if (player.uuid.equals(uuid)) { return false; + } setUUID(player, uuid); return true; } -bool RenX::Server::resolvesRDNS() -{ - return RenX::Server::resolve_player_rdns; +bool RenX::Server::resolvesRDNS() { + return m_resolve_player_rdns; } -void RenX::Server::sendPubChan(const char *fmt, ...) const -{ +void RenX::Server::sendPubChan(const char *fmt, ...) const { va_list args; va_start(args, fmt); Jupiter::StringL msg; - const Jupiter::ReadableString &serverPrefix = RenX::Server::getPrefix(); - if (serverPrefix.isNotEmpty()) - { + const Jupiter::ReadableString &serverPrefix = getPrefix(); + if (serverPrefix.isNotEmpty()) { msg += serverPrefix; msg += ' '; msg.avformat(fmt, args); } - else msg.vformat(fmt, args); + else { + msg.vformat(fmt, args); + } va_end(args); - for (size_t i = 0; i != serverManager->size(); i++) - serverManager->getServer(i)->messageChannels(RenX::Server::logChanType, msg); + for (size_t i = 0; i != serverManager->size(); i++) { + serverManager->getServer(i)->messageChannels(m_logChanType, msg); + } } -void RenX::Server::sendPubChan(const Jupiter::ReadableString &msg) const -{ - const Jupiter::ReadableString &prefix = this->getPrefix(); - if (prefix.isNotEmpty()) - { +void RenX::Server::sendPubChan(const Jupiter::ReadableString &msg) const { + const Jupiter::ReadableString &prefix = getPrefix(); + if (prefix.isNotEmpty()) { Jupiter::String m(msg.size() + prefix.size() + 1); m.set(prefix); m += ' '; m += msg; - for (size_t i = 0; i != serverManager->size(); i++) - serverManager->getServer(i)->messageChannels(RenX::Server::logChanType, m); + for (size_t i = 0; i != serverManager->size(); i++) { + serverManager->getServer(i)->messageChannels(m_logChanType, m); + } + + return; + } + + for (size_t i = 0; i != serverManager->size(); i++) { + serverManager->getServer(i)->messageChannels(m_logChanType, msg); } - else - for (size_t i = 0; i != serverManager->size(); i++) - serverManager->getServer(i)->messageChannels(RenX::Server::logChanType, msg); } -void RenX::Server::sendAdmChan(const char *fmt, ...) const -{ +void RenX::Server::sendAdmChan(const char *fmt, ...) const { va_list args; va_start(args, fmt); Jupiter::StringL msg; - const Jupiter::ReadableString &serverPrefix = RenX::Server::getPrefix(); - if (serverPrefix.isNotEmpty()) - { + const Jupiter::ReadableString &serverPrefix = getPrefix(); + if (serverPrefix.isNotEmpty()) { msg += serverPrefix; msg += ' '; msg.avformat(fmt, args); } - else msg.vformat(fmt, args); + else { + msg.vformat(fmt, args); + } va_end(args); - for (size_t i = 0; i != serverManager->size(); i++) - serverManager->getServer(i)->messageChannels(RenX::Server::adminLogChanType, msg); + for (size_t i = 0; i != serverManager->size(); i++) { + serverManager->getServer(i)->messageChannels(m_adminLogChanType, msg); + } } -void RenX::Server::sendAdmChan(const Jupiter::ReadableString &msg) const -{ - const Jupiter::ReadableString &prefix = this->getPrefix(); - if (prefix.isNotEmpty()) - { +void RenX::Server::sendAdmChan(const Jupiter::ReadableString &msg) const { + const Jupiter::ReadableString &prefix = getPrefix(); + if (prefix.isNotEmpty()) { Jupiter::String m(msg.size() + prefix.size() + 1); m.set(prefix); m += ' '; m += msg; - for (size_t i = 0; i != serverManager->size(); i++) - serverManager->getServer(i)->messageChannels(RenX::Server::adminLogChanType, m); + for (size_t i = 0; i != serverManager->size(); i++) { + serverManager->getServer(i)->messageChannels(m_adminLogChanType, m); + } + + return; + } + + for (size_t i = 0; i != serverManager->size(); i++) { + serverManager->getServer(i)->messageChannels(m_adminLogChanType, msg); } - else - for (size_t i = 0; i != serverManager->size(); i++) - serverManager->getServer(i)->messageChannels(RenX::Server::adminLogChanType, msg); } -void RenX::Server::sendLogChan(const char *fmt, ...) const -{ +void RenX::Server::sendLogChan(const char *fmt, ...) const { IRC_Bot *server; va_list args; va_start(args, fmt); Jupiter::StringL msg; - const Jupiter::ReadableString &serverPrefix = RenX::Server::getPrefix(); - if (serverPrefix.isNotEmpty()) - { + const Jupiter::ReadableString &serverPrefix = getPrefix(); + if (serverPrefix.isNotEmpty()) { msg += serverPrefix; msg += ' '; msg.avformat(fmt, args); } - else msg.vformat(fmt, args); + else { + msg.vformat(fmt, args); + } va_end(args); - for (size_t i = 0; i != serverManager->size(); i++) - { + for (size_t i = 0; i != serverManager->size(); i++) { server = serverManager->getServer(i); - server->messageChannels(RenX::Server::logChanType, msg); - server->messageChannels(RenX::Server::adminLogChanType, msg); + server->messageChannels(m_logChanType, msg); + server->messageChannels(m_adminLogChanType, msg); } } -void RenX::Server::sendLogChan(const Jupiter::ReadableString &msg) const -{ +void RenX::Server::sendLogChan(const Jupiter::ReadableString &msg) const { IRC_Bot *server; - const Jupiter::ReadableString &prefix = this->getPrefix(); - if (prefix.isNotEmpty()) - { + const Jupiter::ReadableString &prefix = getPrefix(); + if (prefix.isNotEmpty()) { Jupiter::String m(msg.size() + prefix.size() + 1); m.set(prefix); m += ' '; @@ -1370,27 +1262,28 @@ void RenX::Server::sendLogChan(const Jupiter::ReadableString &msg) const for (size_t i = 0; i != serverManager->size(); i++) { server = serverManager->getServer(i); - server->messageChannels(RenX::Server::logChanType, m); - server->messageChannels(RenX::Server::adminLogChanType, m); + server->messageChannels(m_logChanType, m); + server->messageChannels(m_adminLogChanType, m); } + + return; + } + + for (size_t i = 0; i != serverManager->size(); i++) { + server = serverManager->getServer(i); + server->messageChannels(m_logChanType, msg); + server->messageChannels(m_adminLogChanType, msg); } - else - for (size_t i = 0; i != serverManager->size(); i++) - { - server = serverManager->getServer(i); - server->messageChannels(RenX::Server::logChanType, msg); - server->messageChannels(RenX::Server::adminLogChanType, msg); - } } -void resolve_rdns(RenX::PlayerInfo *player) -{ +void resolve_rdns(RenX::PlayerInfo *player) { player->rdns_mutex.lock(); char *resolved = Jupiter::Socket::resolveHostname_alloc(static_cast(player->ip).c_str(), 0); player->rdns.capture(resolved, strlen(resolved)); player->rdns_mutex.unlock(); } +// TODO: less macros #define PARSE_PLAYER_DATA_P(DATA) \ Jupiter::ReferenceString name; \ TeamType team; \ @@ -1398,13 +1291,12 @@ void resolve_rdns(RenX::PlayerInfo *player) bool isBot; \ parsePlayerData(DATA, name, team, id, isBot); -void RenX::Server::processLine(const Jupiter::ReadableString &line) -{ +void RenX::Server::processLine(const Jupiter::ReadableString &line) { if (line.isEmpty()) return; - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - Jupiter::ReadableString::TokenizeResult tokens = Jupiter::StringS::tokenize(line, this->rconVersion == 3 ? RenX::DelimC3 : RenX::DelimC); + auto& xPlugins = RenX::getCore()->getPlugins(); + Jupiter::ReadableString::TokenizeResult tokens = Jupiter::StringS::tokenize(line, m_rconVersion == 3 ? RenX::DelimC3 : RenX::DelimC); for (size_t index = 0; index != tokens.token_count; ++index) tokens.tokens[index].processEscapeSequences(); @@ -1425,12 +1317,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) }; auto onMapChange = [this]() { - this->firstAction = false; - this->firstKill = false; - this->firstDeath = false; + m_firstAction = false; + m_firstKill = false; + m_firstDeath = false; - if (this->isSeamless() == false) - this->wipePlayers(); + if (isSeamless() == false) + wipePlayers(); else { for (auto node = this->players.begin(); node != this->players.end(); ++node) @@ -1456,7 +1348,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) }; auto onChat = [this](RenX::PlayerInfo &player, const Jupiter::ReadableString &message) { - const Jupiter::ReadableString &prefix = this->getCommandPrefix(); + const Jupiter::ReadableString &prefix = getCommandPrefix(); if ((player.ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_BOT) == 0 && message.find(prefix) == 0 && message.size() != prefix.size()) { Jupiter::ReferenceString command; @@ -1472,14 +1364,14 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) command.shiftRight(prefix.size()); parameters = Jupiter::ReferenceString::gotoWord(message, 1, WHITESPACE); } - this->triggerCommand(command, player, parameters); + triggerCommand(command, player, parameters); } }; auto onAction = [this]() { - if (this->firstAction == false) + if (m_firstAction == false) { - this->firstAction = true; + m_firstAction = true; } }; auto parsePlayerData = [this](const Jupiter::ReadableString &data, Jupiter::ReferenceString &name, TeamType &team, int &id, bool &isBot) @@ -1529,7 +1421,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) return get_next_temp_playerinfo(name, team, isBot); } - RenX::PlayerInfo *player = this->getPlayer(id); + RenX::PlayerInfo *player = getPlayer(id); if (player == nullptr) { // Initialize a new player @@ -1543,10 +1435,10 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) player->hwid = hwid; // RDNS - if (this->resolvesRDNS() && player->ip32 != 0) + if (resolvesRDNS() && player->ip32 != 0) { player->rdns_thread = std::thread(resolve_rdns, player); - ++this->player_rdns_resolutions_pending; + ++m_player_rdns_resolutions_pending; } player->steamid = steamid; @@ -1557,18 +1449,19 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) //if (id != 0) // this->players.add(r); - player->uuid = calc_uuid(*player); + player->uuid = m_calc_uuid(*player); if (player->isBot == false) { RenX::exemptionDatabase->exemption_check(*player); - this->banCheck(*player); + banCheck(*player); } else - ++bot_count; + ++m_bot_count; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnPlayerCreate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnPlayerCreate(*this, *player); + } } else { @@ -1578,10 +1471,10 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { player->ip = ip; player->ip32 = Jupiter::Socket::pton4(static_cast(player->ip).c_str()); - if (this->resolvesRDNS()) + if (resolvesRDNS()) { player->rdns_thread = std::thread(resolve_rdns, player); - ++this->player_rdns_resolutions_pending; + ++m_player_rdns_resolutions_pending; } recalcUUID = true; } @@ -1602,11 +1495,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) } if (recalcUUID) { - this->setUUIDIfDifferent(*player, calc_uuid(*player)); + setUUIDIfDifferent(*player, m_calc_uuid(*player)); if (player->isBot == false) { RenX::exemptionDatabase->exemption_check(*player); - this->banCheck(*player); + banCheck(*player); } } } @@ -1626,7 +1519,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (index >= tokens.token_count) return Jupiter::ReferenceString::empty; - const char delim = this->getVersion() >= 4 ? RenX::DelimC : RenX::DelimC3; + const char delim = getVersion() >= 4 ? RenX::DelimC : RenX::DelimC3; const char *itr = line.ptr(); while (index != 0) @@ -1640,10 +1533,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) }; auto finished_connecting = [this, &xPlugins]() { - this->fully_connected = true; + m_fully_connected = true; - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnServerFullyConnected(*this); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnServerFullyConnected(*this); + } }; if (tokens.tokens[0].isNotEmpty()) @@ -1653,7 +1547,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) switch (header) { case 'r': - if (this->lastCommand.equalsi("clientlist"_jrs)) + if (m_lastCommand.equalsi("clientlist"_jrs)) { // ID | IP | Steam ID | Admin Status | Team | Name if (tokens.tokens[0].isNotEmpty()) @@ -1685,10 +1579,10 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) getPlayerOrAdd(tokens.getToken(5), id, team, isBot, steamid, tokens.getToken(1), Jupiter::ReferenceString::empty)->adminType = adminToken; } } - else if (this->lastCommand.equalsi("clientvarlist"_jrs)) + else if (m_lastCommand.equalsi("clientvarlist"_jrs)) { - if (this->commandListFormat.token_count == 0) - this->commandListFormat = tokens; + if (m_commandListFormat.token_count == 0) + m_commandListFormat = tokens; else { /*e @@ -1699,7 +1593,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) std::unordered_map table; size_t i = tokens.token_count; while (i-- != 0) - table[this->commandListFormat.getToken(i)] = tokens.getToken(i); + table[m_commandListFormat.getToken(i)] = tokens.getToken(i); auto table_get = [&table](const Jupiter::ReadableString& in_key) -> Jupiter::StringS* { auto value = table.find(in_key); @@ -1788,7 +1682,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (steamid != 0) { player->steamid = steamid; - this->setUUIDIfDifferent(*player, calc_uuid(*player)); + setUUIDIfDifferent(*player, m_calc_uuid(*player)); } } @@ -1822,7 +1716,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (steamid != 0) { player->steamid = steamid; - this->setUUIDIfDifferent(*player, calc_uuid(*player)); + setUUIDIfDifferent(*player, m_calc_uuid(*player)); } } @@ -1843,18 +1737,18 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) } } } - else if (this->lastCommand.equalsi("botlist")) + else if (m_lastCommand.equalsi("botlist")) { // Team,ID,Name - if (this->commandListFormat.token_count == 0) - this->commandListFormat = tokens; + if (m_commandListFormat.token_count == 0) + m_commandListFormat = tokens; else parseGetPlayerOrAdd(tokens.tokens[0]); } - else if (this->lastCommand.equalsi("botvarlist")) + else if (m_lastCommand.equalsi("botvarlist")) { - if (this->commandListFormat.token_count == 0) - this->commandListFormat = tokens; + if (m_commandListFormat.token_count == 0) + m_commandListFormat = tokens; else { /* @@ -1865,7 +1759,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) std::unordered_map table; size_t i = tokens.token_count; while (i-- != 0) - table[this->commandListFormat.getToken(i)] = tokens.getToken(i); + table[m_commandListFormat.getToken(i)] = tokens.getToken(i); auto table_get = [&table](const Jupiter::ReadableString& in_key) -> Jupiter::StringS* { auto value = table.find(in_key); @@ -1967,10 +1861,10 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) } } } - else if (this->lastCommand.equalsi("binfo") || this->lastCommand.equalsi("buildinginfo") || this->lastCommand.equalsi("blist") || this->lastCommand.equalsi("buildinglist")) + else if (m_lastCommand.equalsi("binfo") || m_lastCommand.equalsi("buildinginfo") || m_lastCommand.equalsi("blist") || m_lastCommand.equalsi("buildinglist")) { - if (this->commandListFormat.token_count == 0) - this->commandListFormat = tokens; + if (m_commandListFormat.token_count == 0) + m_commandListFormat = tokens; else { /* @@ -1981,7 +1875,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) std::unordered_map table; size_t i = tokens.token_count; while (i-- != 0) - table[this->commandListFormat.getToken(i)] = tokens.getToken(i); + table[m_commandListFormat.getToken(i)] = tokens.getToken(i); auto table_get = [&table](const Jupiter::ReadableString& in_key) -> Jupiter::StringS* { auto value = table.find(in_key); @@ -1998,11 +1892,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) value = table_get("Building"_jrs); if (value != nullptr) { - building = this->getBuildingByName(*value); + building = getBuildingByName(*value); if (building == nullptr) { building = new RenX::BuildingInfo(); - RenX::Server::buildings.add(building); + RenX::Server::buildings.emplace_back(building); building->name = *value; } @@ -2036,131 +1930,122 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) } } } - else if (this->lastCommand.equalsi("ping")) + else if (m_lastCommand.equalsi("ping")) { if (tokens.getToken(1).equals("srv_init_done"_jrs)) finished_connecting(); else - RenX::Server::awaitingPong = false; + m_awaitingPong = false; } - else if (this->lastCommand.equalsi("map")) + else if (m_lastCommand.equalsi("map")) { // Map | Guid - this->map.name = tokens.getToken(0); + m_map.name = tokens.getToken(0); const Jupiter::ReferenceString guid_token = tokens.getToken(1); if (guid_token.size() == 32U) { - this->map.guid[0] = guid_token.substring(size_t{ 0 }, 16U).asUnsignedLongLong(16); - this->map.guid[1] = guid_token.substring(16U).asUnsignedLongLong(16); + m_map.guid[0] = guid_token.substring(size_t{ 0 }, 16U).asUnsignedLongLong(16); + m_map.guid[1] = guid_token.substring(16U).asUnsignedLongLong(16); } } - else if (this->lastCommand.equalsi("serverinfo")) + else if (m_lastCommand.equalsi("serverinfo")) { - if (this->lastCommandParams.isEmpty()) + if (m_lastCommandParams.isEmpty()) { // "Port"�| Port |�"Name" |�Name |�"Level"�| Level | "Players" | Players�| "Bots" | Bots | "LevelGUID" | Level GUID - this->port = static_cast(tokens.getToken(1).asUnsignedInt(10)); - this->serverName = tokens.getToken(3); - this->map.name = tokens.getToken(5); + m_port = static_cast(tokens.getToken(1).asUnsignedInt(10)); + m_serverName = tokens.getToken(3); + m_map.name = tokens.getToken(5); const Jupiter::ReferenceString guid_token = tokens.getToken(11); if (guid_token.size() == 32U) { - this->map.guid[0] = guid_token.substring(size_t{ 0 }, 16U).asUnsignedLongLong(16); - this->map.guid[1] = guid_token.substring(16U).asUnsignedLongLong(16); + m_map.guid[0] = guid_token.substring(size_t{ 0 }, 16U).asUnsignedLongLong(16); + m_map.guid[1] = guid_token.substring(16U).asUnsignedLongLong(16); } } } - else if (this->lastCommand.equalsi("gameinfo"_jrs)) + else if (m_lastCommand.equalsi("gameinfo"_jrs)) { - if (this->lastCommandParams.isEmpty()) + if (m_lastCommandParams.isEmpty()) { // "PlayerLimit" | PlayerLimit | "VehicleLimit" | VehicleLimit | "MineLimit" | MineLimit | "TimeLimit" | TimeLimit | "bPassworded" | bPassworded | "bSteamRequired" | bSteamRequired | "bPrivateMessageTeamOnly" | bPrivateMessageTeamOnly | "bAllowPrivateMessaging" | bAllowPrivateMessaging | "TeamMode" | TeamMode | "bSpawnCrates" | bSpawnCrates | "CrateRespawnAfterPickup" | CrateRespawnAfterPickup | bIsCompetitive | "bIsCompetitive" - this->playerLimit = tokens.getToken(1).asInt(); - this->vehicleLimit = tokens.getToken(3).asInt(); - this->mineLimit = tokens.getToken(5).asInt(); - this->timeLimit = tokens.getToken(7).asInt(); - this->passworded = tokens.getToken(9).asBool(); - this->steamRequired = tokens.getToken(11).asBool(); - this->privateMessageTeamOnly = tokens.getToken(13).asBool(); - this->allowPrivateMessaging = tokens.getToken(15).asBool(); - this->m_team_mode = this->rconVersion >= 4 ? tokens.getToken(17).asInt() : true; - this->spawnCrates = tokens.getToken(19).asBool(); - this->crateRespawnAfterPickup = tokens.getToken(21).asDouble(); - - if (this->rconVersion >= 4) - { - this->competitive = tokens.getToken(23).asBool(); + m_playerLimit = tokens.getToken(1).asInt(); + m_vehicleLimit = tokens.getToken(3).asInt(); + m_mineLimit = tokens.getToken(5).asInt(); + m_timeLimit = tokens.getToken(7).asInt(); + m_passworded = tokens.getToken(9).asBool(); + m_steamRequired = tokens.getToken(11).asBool(); + m_privateMessageTeamOnly = tokens.getToken(13).asBool(); + m_allowPrivateMessaging = tokens.getToken(15).asBool(); + m_team_mode = m_rconVersion >= 4 ? tokens.getToken(17).asInt() : true; + m_spawnCrates = tokens.getToken(19).asBool(); + m_crateRespawnAfterPickup = tokens.getToken(21).asDouble(); + + if (m_rconVersion >= 4) + { + m_competitive = tokens.getToken(23).asBool(); const Jupiter::ReadableString &match_state_token = tokens.getToken(25); if (match_state_token.equalsi("PendingMatch"_jrs)) - this->match_state = 0; + m_match_state = 0; else if (match_state_token.equalsi("MatchInProgress"_jrs)) - this->match_state = 1; + m_match_state = 1; else if (match_state_token.equalsi("RoundOver"_jrs) || match_state_token.equalsi("MatchOver"_jrs)) - this->match_state = 2; + m_match_state = 2; else if (match_state_token.equalsi("TravelTheWorld"_jrs)) - this->match_state = 3; + m_match_state = 3; else // Unknown state -- assume it's in progress - this->match_state = 1; + m_match_state = 1; - this->botsEnabled = tokens.getToken(27).asBool(); - this->m_game_type = tokens.getToken(29).asInt(); + m_botsEnabled = tokens.getToken(27).asBool(); + m_game_type = tokens.getToken(29).asInt(); } } } - else if (this->lastCommand.equalsi("mutatorlist"_jrs)) - { + else if (m_lastCommand.equalsi("mutatorlist"_jrs)) { // "The following mutators are loaded:" [ | Mutator [ | Mutator [ ... ] ] ] - if (tokens.token_count == 1) - RenX::Server::pure = true; - else if (tokens.token_count == 0) - RenX::Server::disconnect(RenX::DisconnectReason::ProtocolError); - else - { - RenX::Server::mutators.emptyAndDelete(); + if (tokens.token_count == 1) { + m_pure = true; + } + else if (tokens.token_count == 0) { + disconnect(RenX::DisconnectReason::ProtocolError); + } + else { + RenX::Server::mutators.clear(); size_t index = tokens.token_count; while (--index != 0) - RenX::Server::mutators.add(new Jupiter::StringS(tokens.tokens[index])); + RenX::Server::mutators.emplace_back(tokens.tokens[index]); } } - else if (this->lastCommand.equalsi("rotation"_jrs)) - { + else if (m_lastCommand.equalsi("rotation"_jrs)) { // Map | Guid const Jupiter::ReadableString &in_map = tokens.getToken(0); - if (this->hasMapInRotation(in_map) == false) - { - const Jupiter::ReferenceString guid_token = tokens.getToken(1); + if (hasMapInRotation(in_map) == false) { + this->maps.emplace_back(in_map); - if (guid_token.size() == 32U) - { - RenX::Map *map = new RenX::Map(in_map); - map->guid[0] = guid_token.substring(size_t{ 0 }, 16U).asUnsignedLongLong(16); - map->guid[1] = guid_token.substring(16U).asUnsignedLongLong(16); - this->maps.add(map); + const Jupiter::ReferenceString guid_token = tokens.getToken(1); + if (guid_token.size() == 32U) { + this->maps.back().guid[0] = guid_token.substring(size_t{ 0 }, 16U).asUnsignedLongLong(16); + this->maps.back().guid[1] = guid_token.substring(16U).asUnsignedLongLong(16); } - else - this->maps.add(new RenX::Map(in_map)); } } - else if (this->lastCommand.equalsi("changename")) - { + else if (m_lastCommand.equalsi("changename")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(0)); Jupiter::StringS newName = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnNameChange(*this, *player, newName); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnNameChange(*this, *player, newName); + } player->name = tokens.getToken(2).gotoToken(2, ','); } break; case 'l': - if (RenX::Server::rconVersion >= 3) - { + if (m_rconVersion >= 3) { Jupiter::ReferenceString subHeader = tokens.getToken(1); - if (tokens.tokens[0].equals("GAME")) - { - if (subHeader.equals("Deployed;")) - { + if (tokens.tokens[0].equals("GAME")) { + if (subHeader.equals("Deployed;")) { // Object (Beacon/Mine) | Player // Object (Beacon/Mine) | Player | "on" | Surface RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); @@ -2169,12 +2054,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) ++player->beaconPlacements; else if (objectType.equals("Rx_Weapon_DeployedProxyC4"_jrs)) ++player->proxy_placements; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDeploy(*this, *player, objectType); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDeploy(*this, *player, objectType); + } onAction(); } - else if (subHeader.equals("Disarmed;")) - { + else if (subHeader.equals("Disarmed;")) { // Object (Beacon/Mine) | "by" | Player // Object (Beacon/Mine) | "by" | Player | "owned by" | Owner RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); @@ -2184,19 +2069,20 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) else if (objectType.equals("Rx_Weapon_DeployedProxyC4"_jrs)) ++player->proxy_disarms; - if (tokens.getToken(5).equals("owned by")) - { + if (tokens.getToken(5).equals("owned by")) { RenX::PlayerInfo *victim = parseGetPlayerOrAdd(tokens.getToken(6)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDisarm(*this, *player, objectType, *victim); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDisarm(*this, *player, objectType, *victim); + } + } + else { + for (const auto& plugin: xPlugins) { + plugin->RenX_OnDisarm(*this, *player, objectType); + } } - else - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDisarm(*this, *player, objectType); onAction(); } - else if (subHeader.equals("Exploded;")) - { + else if (subHeader.equals("Exploded;")) { // Pre-5.15: // Explosive | "at" | Location // Explosive | "at" | Location | "by" | Owner @@ -2204,70 +2090,73 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // Explosive | "near" | Spot Location | "at" | Location | "by" | Owner // Explosive | "near" | Spot Location | "at" | Location Jupiter::ReferenceString explosive = tokens.getToken(2); - if (tokens.getToken(5).equals("at")) // 5.15+ - { - if (tokens.getToken(7).equals("by")) // Player information specified - { + if (tokens.getToken(5).equals("at")) { // 5.15+ + if (tokens.getToken(7).equals("by")) { // Player information specified RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(8)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExplode(*this, *player, explosive); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnExplode(*this, *player, explosive); + } + } + else { // No player information specified + for (const auto& plugin: xPlugins) { + plugin->RenX_OnExplode(*this, explosive); + } } - else // No player information specified - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExplode(*this, explosive); } - else if (tokens.getToken(5).equals("by")) // Pre-5.15 with player information specified - { + else if (tokens.getToken(5).equals("by")) { // Pre-5.15 with player information specified RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(6)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExplode(*this, *player, explosive); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnExplode(*this, *player, explosive); + } + } + else { // Pre-5.15 with no player information specified + for (const auto& plugin: xPlugins) { + plugin->RenX_OnExplode(*this, explosive); + } } - else // Pre-5.15 with no player information specified - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExplode(*this, explosive); onAction(); } - else if (subHeader.equals("ProjectileExploded;")) - { + else if (subHeader.equals("ProjectileExploded;")) { // Explosive | "at" | Location // Explosive | "at" | Location | "by" | Owner Jupiter::ReferenceString explosive = tokens.getToken(2); - if (tokens.getToken(5).equals("by")) - { + if (tokens.getToken(5).equals("by")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(6)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExplode(*this, *player, explosive); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnExplode(*this, *player, explosive); + } + } + else { + for (const auto& plugin: xPlugins) { + plugin->RenX_OnExplode(*this, explosive); + } } - else - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExplode(*this, explosive); onAction(); } - else if (subHeader.equals("Captured;")) - { + else if (subHeader.equals("Captured;")) { // Team ',' Building | "id" | Building ID | "by" | Player Jupiter::ReferenceString teamBuildingToken = tokens.getToken(2); Jupiter::ReferenceString building = teamBuildingToken.getToken(1, ','); TeamType oldTeam = RenX::getTeam(teamBuildingToken.getToken(0, ',')); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(6)); player->captures++; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnCapture(*this, *player, building, oldTeam); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnCapture(*this, *player, building, oldTeam); + } onAction(); } - else if (subHeader.equals("Neutralized;")) - { + else if (subHeader.equals("Neutralized;")) { // Team ',' Building | "id" | Building ID | "by" | Player Jupiter::ReferenceString teamBuildingToken = tokens.getToken(2); Jupiter::ReferenceString building = teamBuildingToken.getToken(1, ','); TeamType oldTeam = RenX::getTeam(teamBuildingToken.getToken(0, ',')); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(6)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnNeutralize(*this, *player, building, oldTeam); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnNeutralize(*this, *player, building, oldTeam); + } onAction(); } - else if (subHeader.equals("Purchase;")) - { + else if (subHeader.equals("Purchase;")) { // "character" | Character | "by" | Player // "item" | Item | "by" | Player // "weapon" | Weapon | "by" | Player @@ -2275,65 +2164,64 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // "vehicle" | Vehicle | "by" | Player Jupiter::ReferenceString type = tokens.getToken(2); Jupiter::ReferenceString obj = tokens.getToken(3); - if (type.equals("character")) - { + if (type.equals("character")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnCharacterPurchase(*this, *player, obj); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnCharacterPurchase(*this, *player, obj); + } player->character = obj; } - else if (type.equals("item")) - { + else if (type.equals("item")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnItemPurchase(*this, *player, obj); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnItemPurchase(*this, *player, obj); + } } - else if (type.equals("weapon")) - { + else if (type.equals("weapon")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnWeaponPurchase(*this, *player, obj); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnWeaponPurchase(*this, *player, obj); + } } - else if (type.equals("refill")) - { + else if (type.equals("refill")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(obj); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnRefillPurchase(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnRefillPurchase(*this, *player); + } } - else if (type.equals("vehicle")) - { + else if (type.equals("vehicle")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVehiclePurchase(*this, *player, obj); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVehiclePurchase(*this, *player, obj); + } } } - else if (subHeader.equals("Spawn;")) - { + else if (subHeader.equals("Spawn;")) { // "vehicle" | Vehicle Team, Vehicle // "player" | Player | "character" | Character // "bot" | Player - if (tokens.getToken(2).equals("vehicle")) - { + if (tokens.getToken(2).equals("vehicle")) { Jupiter::ReferenceString vehicle = tokens.getToken(3); Jupiter::ReferenceString vehicleTeamToken = vehicle.getToken(0, ','); vehicle.shiftRight(vehicleTeamToken.size() + 1); TeamType team = RenX::getTeam(vehicleTeamToken); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVehicleSpawn(*this, team, vehicle); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVehicleSpawn(*this, team, vehicle); + } } - else if (tokens.getToken(2).equals("player")) - { + else if (tokens.getToken(2).equals("player")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(3)); Jupiter::ReferenceString character = tokens.getToken(5); player->character = character; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSpawn(*this, *player, character); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSpawn(*this, *player, character); + } } - else if (tokens.getToken(2).equals("bot")) - { + else if (tokens.getToken(2).equals("bot")) { RenX::PlayerInfo *bot = parseGetPlayerOrAdd(tokens.getToken(3)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnBotJoin(*this, *bot); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnBotJoin(*this, *bot); + } } } else if (subHeader.equals("Crate;")) @@ -2355,97 +2243,112 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { Jupiter::ReferenceString vehicle = tokens.getToken(3); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVehicleCrate(*this, *player, vehicle); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVehicleCrate(*this, *player, vehicle); + } } else if (type.equals("tsvehicle")) { Jupiter::ReferenceString vehicle = tokens.getToken(3); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVehicleCrate(*this, *player, vehicle); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVehicleCrate(*this, *player, vehicle); + } } else if (type.equals("ravehicle")) { Jupiter::ReferenceString vehicle = tokens.getToken(3); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVehicleCrate(*this, *player, vehicle); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVehicleCrate(*this, *player, vehicle); + } } else if (type.equals("death") || type.equals("suicide")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDeathCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDeathCrate(*this, *player); + } } else if (type.equals("money")) { int amount = tokens.getToken(3).asInt(); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnMoneyCrate(*this, *player, amount); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnMoneyCrate(*this, *player, amount); + } } else if (type.equals("character")) { Jupiter::ReferenceString character = tokens.getToken(3); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnCharacterCrate(*this, *player, character); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnCharacterCrate(*this, *player, character); + } player->character = character; } else if (type.equals("spy")) { Jupiter::ReferenceString character = tokens.getToken(3); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSpyCrate(*this, *player, character); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSpyCrate(*this, *player, character); + } player->character = character; } else if (type.equals("refill")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnRefillCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnRefillCrate(*this, *player); + } } else if (type.equals("timebomb")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnTimeBombCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnTimeBombCrate(*this, *player); + } } else if (type.equals("speed")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSpeedCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSpeedCrate(*this, *player); + } } else if (type.equals("nuke")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnNukeCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnNukeCrate(*this, *player); + } } else if (type.equals("abduction")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAbductionCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAbductionCrate(*this, *player); + } } else if (type.equals("by")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(3)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnUnspecifiedCrate(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnUnspecifiedCrate(*this, *player); + } } - else - { + else { RenX::PlayerInfo *player = nullptr; - if (tokens.getToken(3).equals("by")) + if (tokens.getToken(3).equals("by")) { player = parseGetPlayerOrAdd(tokens.getToken(4)); + } - if (player != nullptr) - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnOtherCrate(*this, *player, type); + if (player != nullptr) { + for (const auto& plugin: xPlugins) { + plugin->RenX_OnOtherCrate(*this, *player, type); + } + } } } else if (subHeader.equals("Death;")) @@ -2470,8 +2373,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (kIDToken.equals("ai") || kIDToken.isEmpty()) { player->deaths++; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnKill(*this, kName, vTeam, *player, damageType); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnKill(*this, kName, vTeam, *player, damageType); + } } else { @@ -2489,26 +2393,30 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) kID = kIDToken.asInt(); RenX::PlayerInfo *killer = getPlayerOrAdd(kName, kID, vTeam, kIsBot, 0, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty); killer->kills++; - if (damageType.equals("Rx_DmgType_Headshot")) + if (damageType.equals("Rx_DmgType_Headshot")) { killer->headshots++; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnKill(*this, *killer, *player, damageType); + } + for (const auto& plugin : xPlugins) { + plugin->RenX_OnKill(*this, *killer, *player, damageType); + } } } else if (type.equals("died by")) { player->deaths++; damageType = tokens.getToken(5); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDie(*this, *player, damageType); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDie(*this, *player, damageType); + } } else if (type.equals("suicide by")) { player->deaths++; player->suicides++; damageType = tokens.getToken(5); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSuicide(*this, *player, damageType); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSuicide(*this, *player, damageType); + } } player->character = Jupiter::ReferenceString::empty; } @@ -2524,8 +2432,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); player->steals++; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSteal(*this, *player, vehicle); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSteal(*this, *player, vehicle); + } } else if (byLine.equals("bound to")) { @@ -2533,8 +2442,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(6)); player->steals++; victim->stolen++; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSteal(*this, *player, vehicle, *victim); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSteal(*this, *player, vehicle, *victim); + } } onAction(); } @@ -2565,9 +2475,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::TeamType team = RenX::getTeam(killerToken.getToken(0, ',')); - if (idToken.equals("ai") || idToken.isEmpty()) - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDestroy(*this, name, team, objectName, RenX::getEnemy(team), damageType, type); + if (idToken.equals("ai") || idToken.isEmpty()) { + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDestroy(*this, name, team, objectName, RenX::getEnemy(team), damageType, type); + } + } else { int id; @@ -2591,7 +2503,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::BuildingInfo *building; if (objectName.findi(internalsStr) != Jupiter::INVALID_INDEX) objectName.truncate(internalsStr.size()); - building = RenX::Server::getBuildingByName(objectName); + building = getBuildingByName(objectName); if (building != nullptr) { building->health = 0; @@ -2608,8 +2520,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) default: break; } - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDestroy(*this, *player, objectName, RenX::getEnemy(player->team), damageType, type); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDestroy(*this, *player, objectName, RenX::getEnemy(player->team), damageType, type); + } } } } @@ -2623,8 +2536,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) double amount = tokens.getToken(2).asDouble(); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(4)); RenX::PlayerInfo *donor = parseGetPlayerOrAdd(tokens.getToken(6)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDonate(*this, *donor, *player, amount); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDonate(*this, *donor, *player, amount); + } } } else if (subHeader.equals("OverMine;")) @@ -2633,15 +2547,16 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString location = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnOverMine(*this, *player, location); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnOverMine(*this, *player, location); + } } else if (subHeader.equals("MatchEnd;")) { // "winner" | Winner | Reason("TimeLimit" etc) | "GDI=" GDI Score | "Nod=" Nod Score // "tie" | Reason | "GDI=" GDI Score | "Nod=" Nod Score Jupiter::ReferenceString winTieToken = tokens.getToken(2); - this->match_state = 2; + m_match_state = 2; if (winTieToken.equals("winner")) { @@ -2662,23 +2577,26 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) int nScore = tokens.getToken(6).getToken(1, '=').asInt(); onPreGameOver(winType, team, gScore, nScore); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnGameOver(*this, winType, team, gScore, nScore); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnGameOver(*this, winType, team, gScore, nScore); + } } else if (winTieToken.equals("tie")) { int gScore = tokens.getToken(4).getToken(1, '=').asInt(); int nScore = tokens.getToken(5).getToken(1, '=').asInt(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnGameOver(*this, RenX::WinType::Tie, RenX::TeamType::None, gScore, nScore); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnGameOver(*this, RenX::WinType::Tie, RenX::TeamType::None, gScore, nScore); + } } - this->gameover_pending = false; + m_gameover_pending = false; } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnGame(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnGame(*this, raw); + } } } else if (tokens.tokens[0].equals("CHAT")) @@ -2688,8 +2606,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); onChat(*player, message); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnChat(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnChat(*this, *player, message); + } onAction(); } else if (subHeader.equals("TeamSay;")) @@ -2697,32 +2616,36 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); onChat(*player, message); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnTeamChat(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnTeamChat(*this, *player, message); + } onAction(); } else if (subHeader.equals("Radio;")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnRadioChat(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnRadioChat(*this, *player, message); + } onAction(); } else if (subHeader.equals("AdminMsg;")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAdminMessage(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAdminMessage(*this, *player, message); + } onAction(); } else if (subHeader.equals("AdminWarn;")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnWarnMessage(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnWarnMessage(*this, *player, message); + } onAction(); } else if (subHeader.equals("PAdminMsg;")) @@ -2730,8 +2653,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); RenX::PlayerInfo *target = parseGetPlayerOrAdd(tokens.getToken(4)); Jupiter::ReferenceString message = tokens.getToken(6); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAdminPMessage(*this, *player, *target, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAdminPMessage(*this, *player, *target, message); + } onAction(); } else if (subHeader.equals("PAdminWarn;")) @@ -2739,45 +2663,52 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); RenX::PlayerInfo *target = parseGetPlayerOrAdd(tokens.getToken(4)); Jupiter::ReferenceString message = tokens.getToken(6); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnWarnPMessage(*this, *player, *target, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnWarnPMessage(*this, *player, *target, message); + } onAction(); } else if (subHeader.equals("HostSay;")) { Jupiter::ReferenceString message = tokens.getToken(3); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnHostChat(*this, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHostChat(*this, message); + } } else if (subHeader.equals("HostPMsg;")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnHostPage(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHostPage(*this, *player, message); + } } else if (subHeader.equals("HostAdminMsg;")) { Jupiter::ReferenceString message = tokens.getToken(3); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnHostAdminMessage(*this, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHostAdminMessage(*this, message); + } } else if (subHeader.equals("HostAdminWarn;")) { Jupiter::ReferenceString message = tokens.getToken(3); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnHostWarnMessage(*this, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHostWarnMessage(*this, message); + } } else if (subHeader.equals("HostPAdminMsg;")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnHostAdminPMessage(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHostAdminPMessage(*this, *player, message); + } } else if (subHeader.equals("HostPAdminWarn;")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnHostWarnPMessage(*this, *player, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHostWarnPMessage(*this, *player, message); + } } /*else if (subHeader.equals("AdminSay;")) { @@ -2792,8 +2723,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnOtherChat(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnOtherChat(*this, raw); + } } } else if (tokens.tokens[0].equals("PLAYER")) @@ -2829,11 +2761,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (itr->steam_id == steamid) { player->local_rank = itr->rank; - if (this->devBot) + if (m_devBot) { player->global_rank = itr->rank; - if (this->rconVersion >= 4) - this->sendData(Jupiter::StringS::Format("dset_rank %d %d\n", player->id, player->global_rank)); + if (m_rconVersion >= 4) + sendData(Jupiter::StringS::Format("dset_rank %d %d\n", player->id, player->global_rank)); } break; } @@ -2841,8 +2773,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) itr = itr->next; } } - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnJoin(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnJoin(*this, *player); + } } else if (subHeader.equals("TeamJoin;")) { @@ -2854,8 +2787,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { RenX::TeamType oldTeam = RenX::getTeam(tokens.getToken(6)); if (oldTeam != RenX::TeamType::None) - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnTeamChange(*this, *player, oldTeam); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnTeamChange(*this, *player, oldTeam); + } } } else if (subHeader.equals("HWID;")) @@ -2868,15 +2802,19 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2 + offset)); player->hwid = tokens.getToken(4 + offset); - if (player->isBot == false) - this->banCheck(*player); + if (player->isBot == false) { + banCheck(*player); + } - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnHWID(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnHWID(*this, *player); + } - if (player->rdns.isNotEmpty()) - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnPlayerIdentify(*this, *player); + if (player->rdns.isNotEmpty()) { + for (const auto& plugin : xPlugins) { + plugin->RenX_OnPlayerIdentify(*this, *player); + } + } } else if (subHeader.equals("Exit;")) { @@ -2889,30 +2827,33 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (player != nullptr) { - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnPart(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnPart(*this, *player); + } - this->removePlayer(*player); + removePlayer(*player); } - if (this->gameover_when_empty && this->players.size() == this->getBotCount()) - this->gameover(); + if (m_gameover_when_empty && this->players.size() == getBotCount()) + gameover(); } else if (subHeader.equals("Kick;")) { // Player | "for" | Reason const Jupiter::ReadableString &reason = tokens.getToken(4); RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnKick(*this, *player, reason); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnKick(*this, *player, reason); + } } else if (subHeader.equals("NameChange;")) { // Player | "to:" | New Name RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::StringS newName = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnNameChange(*this, *player, newName); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnNameChange(*this, *player, newName); + } player->name = newName; onAction(); } @@ -2920,35 +2861,37 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { // "to" | New ID | "from" | Old ID int oldID = tokens.getToken(5).asInt(); - RenX::PlayerInfo *player = this->getPlayer(oldID); + RenX::PlayerInfo *player = getPlayer(oldID); if (player != nullptr) { player->id = tokens.getToken(3).asInt(); if (player->isBot == false) - this->banCheck(*player); + banCheck(*player); - if (this->devBot && player->global_rank != 0U) + if (m_devBot && player->global_rank != 0U) { - if (this->rconVersion >= 4) - this->sendData(Jupiter::StringS::Format("dset_rank %d %d\n", player->id, player->global_rank)); + if (m_rconVersion >= 4) + sendData(Jupiter::StringS::Format("dset_rank %d %d\n", player->id, player->global_rank)); } - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnIDChange(*this, *player, oldID); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnIDChange(*this, *player, oldID); + } } } else if (subHeader.equals("Rank;")) { // Player | Rank - if (this->devBot == false) + if (m_devBot == false) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); if (player != nullptr) player->global_rank = tokens.getToken(3).asUnsignedInt(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnRank(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnRank(*this, *player); + } } } else if (subHeader.equals("Dev;")) @@ -2958,15 +2901,17 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (player != nullptr) player->is_dev = tokens.getToken(3).asBool(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDev(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDev(*this, *player); + } } else if (subHeader.equals("SpeedHack;")) { // Player RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSpeedHack(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSpeedHack(*this, *player); + } } else if (subHeader.equals("Command;")) { @@ -2974,16 +2919,18 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString message = gotoToken(3); - RenX::GameCommand *command = this->triggerCommand(Jupiter::ReferenceString::getWord(message, 0, WHITESPACE), *player, Jupiter::ReferenceString::gotoWord(message, 1, WHITESPACE)); + RenX::GameCommand *command = triggerCommand(Jupiter::ReferenceString::getWord(message, 0, WHITESPACE), *player, Jupiter::ReferenceString::gotoWord(message, 1, WHITESPACE)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnPlayerCommand(*this, *player, message, command); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnPlayerCommand(*this, *player, message, command); + } } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnPlayer(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnPlayer(*this, raw); + } } } else if (tokens.tokens[0].equals("RCON")) @@ -2997,13 +2944,14 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) Jupiter::ReferenceString command = gotoToken(4); Jupiter::ReferenceString cmd = command.getWord(0, " "); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExecute(*this, user, command); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnExecute(*this, user, command); + } - if (this->rconUser.equals(user)) + if (m_rconUser.equals(user)) { - this->lastCommand = cmd; - this->lastCommandParams = command.gotoWord(1, " "); + m_lastCommand = cmd; + m_lastCommandParams = command.gotoWord(1, " "); } } } @@ -3012,101 +2960,114 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // User Jupiter::ReferenceString user = tokens.getToken(2); - if (user.equals(this->rconUser)) - this->subscribed = true; + if (user.equals(m_rconUser)) + m_subscribed = true; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnSubscribe(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnSubscribe(*this, user); + } } else if (subHeader.equals("Unsubscribed;")) { // User Jupiter::ReferenceString user = tokens.getToken(2); - if (user.equals(this->rconUser)) - this->subscribed = false; + if (user.equals(m_rconUser)) + m_subscribed = false; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnUnsubscribe(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnUnsubscribe(*this, user); + } } else if (subHeader.equals("Blocked;")) { // User | Reason="(Denied by IP Policy)" / "(Not on Whitelist)" Jupiter::ReferenceString user = tokens.getToken(2); Jupiter::ReferenceString message = tokens.getToken(3); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnBlock(*this, user, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnBlock(*this, user, message); + } } else if (subHeader.equals("Connected;")) { // User Jupiter::ReferenceString user = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnConnect(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnConnect(*this, user); + } } else if (subHeader.equals("Authenticated;")) { // User Jupiter::ReferenceString user = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAuthenticate(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAuthenticate(*this, user); + } } else if (subHeader.equals("Banned;")) { // User | "reason" | Reason="(Too many password attempts)" Jupiter::ReferenceString user = tokens.getToken(2); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnBan(*this, user, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnBan(*this, user, message); + } } else if (subHeader.equals("InvalidPassword;")) { // User Jupiter::ReferenceString user = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnInvalidPassword(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnInvalidPassword(*this, user); + } } else if (subHeader.equals("Dropped;")) { // User | "reason" | Reason="(Auth Timeout)" Jupiter::ReferenceString user = tokens.getToken(2); Jupiter::ReferenceString message = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDrop(*this, user, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDrop(*this, user, message); + } } else if (subHeader.equals("Disconnected;")) { // User Jupiter::ReferenceString user = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDisconnect(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDisconnect(*this, user); + } } else if (subHeader.equals("StoppedListen;")) { // Reason="(Reached Connection Limit)" Jupiter::ReferenceString message = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnStopListen(*this, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnStopListen(*this, message); + } } else if (subHeader.equals("ResumedListen;")) { // Reason="(No longer at Connection Limit)" Jupiter::ReferenceString message = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnResumeListen(*this, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnResumeListen(*this, message); + } } else if (subHeader.equals("Warning;")) { // Warning="(Hit Max Attempt Records - You should investigate Rcon attempts and/or decrease prune time)" Jupiter::ReferenceString message = tokens.getToken(2); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnWarning(*this, message); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnWarning(*this, message); + } } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnRCON(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnRCON(*this, raw); + } } } else if (tokens.tokens[0].equals("ADMIN")) @@ -3118,8 +3079,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); Jupiter::ReferenceString cmd = gotoToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnExecute(*this, *player, cmd); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnExecute(*this, *player, cmd); + } } } else if (subHeader.equals("Login;")) @@ -3127,16 +3089,18 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // Player | "as" | Type="moderator" / "administrator" RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); player->adminType = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAdminLogin(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAdminLogin(*this, *player); + } } else if (subHeader.equals("Logout;")) { // Player | "as" | Type="moderator" / "administrator" RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAdminLogout(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAdminLogout(*this, *player); + } player->adminType.erase(); } @@ -3145,14 +3109,16 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // Player | "as" | Type="moderator" / "administrator" RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(2)); player->adminType = tokens.getToken(4); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAdminGrant(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAdminGrant(*this, *player); + } } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAdmin(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAdmin(*this, raw); + } } } else if (tokens.tokens[0].equals("VOTE")) @@ -3190,17 +3156,18 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(tokens.token_count - 1)); if ((player->ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_VOTE) != 0) - RenX::Server::sendData(Jupiter::StringS::Format("ccancelvote %.*s\n", teamToken.size(), teamToken.ptr())); + sendData(Jupiter::StringS::Format("ccancelvote %.*s\n", teamToken.size(), teamToken.ptr())); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteOther(*this, team, voteType, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteOther(*this, team, voteType, *player); + } } else // 5.15+ (or empty) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(5)); if ((player->ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_VOTE) != 0) - RenX::Server::sendData(Jupiter::StringS::Format("ccancelvote %.*s\n", teamToken.size(), teamToken.ptr())); + sendData(Jupiter::StringS::Format("ccancelvote %.*s\n", teamToken.size(), teamToken.ptr())); // PARSE PARAMETERS HERE @@ -3224,25 +3191,29 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) int amount = tokens.getToken(9).asInt(10); int skill = tokens.getToken(11).asInt(10); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteAddBots(*this, team, *player, victim, amount, skill); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteAddBots(*this, team, *player, victim, amount, skill); + } } else if (voteType.equals("ChangeMap"_jrs)) { - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteChangeMap(*this, team, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteChangeMap(*this, team, *player); + } } else if (voteType.equals("Kick"_jrs)) { RenX::PlayerInfo *victim = parseGetPlayerOrAdd(tokens.getToken(7)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteKick(*this, team, *player, *victim); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteKick(*this, team, *player, *victim); + } } else if (voteType.equals("MineBan"_jrs)) { RenX::PlayerInfo *victim = parseGetPlayerOrAdd(tokens.getToken(7)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteMineBan(*this, team, *player, *victim); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteMineBan(*this, team, *player, *victim); + } } else if (voteType.equals("RemoveBots"_jrs)) { @@ -3259,35 +3230,42 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) int amount = tokens.getToken(9).asInt(10); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteRemoveBots(*this, team, *player, victim, amount); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteRemoveBots(*this, team, *player, victim, amount); + } } else if (voteType.equals("RestartMap"_jrs)) { - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteRestartMap(*this, team, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteRestartMap(*this, team, *player); + } } else if (voteType.equals("Surrender"_jrs)) { - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteSurrender(*this, team, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteSurrender(*this, team, *player); + } } else if (voteType.equals("Survey"_jrs)) { const Jupiter::ReadableString &text = tokens.getToken(7); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteSurvey(*this, team, *player, text); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteSurvey(*this, team, *player, text); + } } else { voteType.shiftLeft(18); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteOther(*this, team, voteType, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteOther(*this, team, voteType, *player); + } + } + } + else { + for (const auto& plugin: xPlugins) { + plugin->RenX_OnVoteOther(*this, team, voteType, *player); } } - else - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteOther(*this, team, voteType, *player); } onAction(); } @@ -3326,8 +3304,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) noVotes = votes_token.asInt(); } - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteOver(*this, team, voteType, success, yesVotes, noVotes); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteOver(*this, team, voteType, success, yesVotes, noVotes); + } } else if (subHeader.equals("Cancelled;")) { @@ -3344,14 +3323,16 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) else team = TeamType::Other; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVoteCancel(*this, team, voteType); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVoteCancel(*this, team, voteType); + } } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVote(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVote(*this, raw); + } } } else if (tokens.tokens[0].equals("MAP")) @@ -3361,16 +3342,17 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // Map | Mode="seamless" / "nonseamless" Jupiter::ReferenceString map = tokens.getToken(2); - this->match_state = 3; + m_match_state = 3; if (tokens.getToken(3).equals("seamless")) - this->seamless = true; + m_seamless = true; else - this->seamless = false; + m_seamless = false; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnMapChange(*this, map, seamless); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnMapChange(*this, map, m_seamless); + } - this->map = map; + m_map = map; onMapChange(); } else if (subHeader.equals("Loaded;")) @@ -3378,30 +3360,33 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) // Map Jupiter::ReferenceString map = tokens.getToken(2); - this->match_state = 0; - this->map = map; + m_match_state = 0; + m_map = map; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnMapLoad(*this, map); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnMapLoad(*this, map); + } } else if (subHeader.equals("Start;")) { // Map Jupiter::ReferenceString map = tokens.getToken(2); - this->match_state = 1; - this->reliable = true; - this->gameStart = std::chrono::steady_clock::now(); - this->map = map; + m_match_state = 1; + m_reliable = true; + m_gameStart = std::chrono::steady_clock::now(); + m_map = map; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnMapStart(*this, map); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnMapStart(*this, map); + } } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnMap(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnMap(*this, raw); + } } } else if (tokens.tokens[0].equals("DEMO")) @@ -3415,27 +3400,31 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) if (type.equals("client request by") || type.equals("admin command by")) { RenX::PlayerInfo *player = parseGetPlayerOrAdd(tokens.getToken(3)); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDemoRecord(*this, *player); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDemoRecord(*this, *player); + } } else { Jupiter::ReferenceString user = tokens.getToken(3); // not actually used, but here for possible future usage - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDemoRecord(*this, user); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDemoRecord(*this, user); + } } } else if (subHeader.equals("RecordStop;")) { // Empty - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDemoRecordStop(*this); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDemoRecordStop(*this); + } } else { Jupiter::ReferenceString raw = gotoToken(1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnDemo(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnDemo(*this, raw); + } } } /*else if (tokens.tokens[0].equals("ERROR;")) // Decided to disable this entirely, since it's unreachable anyways. @@ -3446,8 +3435,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) else { Jupiter::ReferenceString raw = Jupiter::ReferenceString::substring(line, 1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnLog(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnLog(*this, raw); + } } } break; @@ -3461,159 +3451,157 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) case 'c': { Jupiter::ReferenceString raw = Jupiter::ReferenceString::substring(line, 1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnCommand(*this, raw); - this->commandListFormat.erase(); - this->lastCommand = Jupiter::ReferenceString::empty; - this->lastCommandParams = Jupiter::ReferenceString::empty; + for (const auto& plugin : xPlugins) { + plugin->RenX_OnCommand(*this, raw); + } + m_commandListFormat.erase(); + m_lastCommand = Jupiter::ReferenceString::empty; + m_lastCommandParams = Jupiter::ReferenceString::empty; } break; case 'e': { Jupiter::ReferenceString raw = Jupiter::ReferenceString::substring(line, 1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnError(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnError(*this, raw); + } } break; case 'v': { Jupiter::ReferenceString raw = Jupiter::ReferenceString::substring(line, 1); - this->rconVersion = raw.asInt(10); + m_rconVersion = raw.asInt(10); - if (this->rconVersion >= 3) + if (m_rconVersion >= 3) { - if (this->rconVersion == 3) // Old format: 003Open Beta 5.12 - this->gameVersion = raw.substring(3); + if (m_rconVersion == 3) // Old format: 003Open Beta 5.12 + m_gameVersion = raw.substring(3); else // New format: 004 | Game Version Number | Game Version { - this->gameVersionNumber = tokens.getToken(1).asInt(10); - this->gameVersion = tokens.getToken(2); + m_gameVersionNumber = tokens.getToken(1).asInt(10); + m_gameVersion = tokens.getToken(2); - if (this->gameVersion.isEmpty()) + if (m_gameVersion.isEmpty()) { - RenX::Server::sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (Protocol Error).")); - this->disconnect(RenX::DisconnectReason::ProtocolError); + sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (Protocol Error).")); + disconnect(RenX::DisconnectReason::ProtocolError); break; } } - RenX::Server::sendSocket("s\n"_jrs); - RenX::Server::send("serverinfo"_jrs); - RenX::Server::send("gameinfo"_jrs); - RenX::Server::send("gameinfo bIsCompetitive"_jrs); - RenX::Server::send("mutatorlist"_jrs); - RenX::Server::send("rotation"_jrs); - RenX::Server::fetchClientList(); - RenX::Server::updateBuildingList(); - RenX::Server::send("ping srv_init_done"_jrs); + sendSocket("s\n"_jrs); + send("serverinfo"_jrs); + send("gameinfo"_jrs); + send("gameinfo bIsCompetitive"_jrs); + send("mutatorlist"_jrs); + send("rotation"_jrs); + fetchClientList(); + updateBuildingList(); + send("ping srv_init_done"_jrs); - RenX::Server::gameStart = std::chrono::steady_clock::now(); - this->seamless = true; + m_gameStart = std::chrono::steady_clock::now(); + m_seamless = true; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnVersion(*this, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnVersion(*this, raw); + } } else { - RenX::Server::sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (incompatible RCON version).")); - this->disconnect(RenX::DisconnectReason::IncompatibleVersion); + sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (incompatible RCON version).")); + disconnect(RenX::DisconnectReason::IncompatibleVersion); } } break; case 'a': { - RenX::Server::rconUser = Jupiter::ReferenceString::substring(line, 1); - if (rconUser.equals(RenX::DevBotName)) - RenX::Server::devBot = true; + m_rconUser = Jupiter::ReferenceString::substring(line, 1); + if (m_rconUser.equals(RenX::DevBotName)) + m_devBot = true; - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnAuthorized(*this, RenX::Server::rconUser); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnAuthorized(*this, m_rconUser); + } } break; default: { Jupiter::ReferenceString raw = Jupiter::ReferenceString::substring(line, 1); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnOther(*this, header, raw); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnOther(*this, header, raw); + } } break; } - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnRaw(*this, line); + for (const auto& plugin : xPlugins) { + plugin->RenX_OnRaw(*this, line); + } } } -void RenX::Server::disconnect(RenX::DisconnectReason reason) -{ - RenX::Server::connected = false; +void RenX::Server::disconnect(RenX::DisconnectReason reason) { + m_connected = false; - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnServerDisconnect(*this, reason); + for (const auto& plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_OnServerDisconnect(*this, reason); + } - RenX::Server::sock.close(); - RenX::Server::wipeData(); + m_sock.close(); + wipeData(); } -bool RenX::Server::connect() -{ - RenX::Server::lastAttempt = std::chrono::steady_clock::now(); - if (RenX::Server::sock.connect(RenX::Server::hostname.c_str(), RenX::Server::port, RenX::Server::clientHostname.empty() ? nullptr : RenX::Server::clientHostname.c_str())) +bool RenX::Server::connect() { + m_lastAttempt = std::chrono::steady_clock::now(); + if (m_sock.connect(m_hostname.c_str(), m_port, m_clientHostname.empty() ? nullptr : m_clientHostname.c_str())) { - RenX::Server::sock.setBlocking(false); - RenX::Server::sendSocket(Jupiter::StringS::Format("a%.*s\n", RenX::Server::pass.size(), RenX::Server::pass.ptr())); - RenX::Server::connected = true; - RenX::Server::attempts = 0; + m_sock.setBlocking(false); + sendSocket(Jupiter::StringS::Format("a%.*s\n", m_pass.size(), m_pass.ptr())); + m_connected = true; + m_attempts = 0; return true; } - RenX::Server::connected = false; - ++RenX::Server::attempts; + m_connected = false; + ++m_attempts; return false; } -bool RenX::Server::reconnect(RenX::DisconnectReason reason) -{ - RenX::Server::disconnect(static_cast(static_cast(reason) | 0x01)); - return RenX::Server::connect(); -} - -void RenX::Server::wipeData() -{ - RenX::Server::wipePlayers(); - RenX::Server::reliable = false; - RenX::Server::m_team_mode = 3; - RenX::Server::m_game_type = 1; - RenX::Server::m_ranked = false; - RenX::Server::botsEnabled = true; - RenX::Server::match_state = 1; - RenX::Server::subscribed = false; - RenX::Server::fully_connected = false; - RenX::Server::bot_count = 0; - RenX::Server::player_rdns_resolutions_pending = 0; - RenX::Server::buildings.emptyAndDelete(); - RenX::Server::mutators.emptyAndDelete(); - RenX::Server::maps.emptyAndDelete(); - RenX::Server::awaitingPong = false; - RenX::Server::rconVersion = 0; - RenX::Server::rconUser.truncate(RenX::Server::rconUser.size()); -} - -void RenX::Server::wipePlayers() -{ - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - - while (RenX::Server::players.size() != 0) - { - for (size_t index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_OnPlayerDelete(*this, this->players.front()); +bool RenX::Server::reconnect(RenX::DisconnectReason reason) { + disconnect(static_cast(static_cast(reason) | 0x01)); + return connect(); +} + +void RenX::Server::wipeData() { + wipePlayers(); + m_reliable = false; + m_team_mode = 3; + m_game_type = 1; + m_ranked = false; + m_botsEnabled = true; + m_match_state = 1; + m_subscribed = false; + m_fully_connected = false; + m_bot_count = 0; + m_player_rdns_resolutions_pending = 0; + this->buildings.clear(); + this->mutators.clear(); + this->maps.clear(); + m_awaitingPong = false; + m_rconVersion = 0; + m_rconUser.truncate(m_rconUser.size()); +} + +void RenX::Server::wipePlayers() { + while (this->players.size() != 0) { + for (const auto& plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_OnPlayerDelete(*this, this->players.front()); + } - if (this->players.front().rdns_thread.joinable()) // Close the RDNS thread, if one exists - { - --this->player_rdns_resolutions_pending; + if (this->players.front().rdns_thread.joinable()) { // Close the RDNS thread, if one exists + --m_player_rdns_resolutions_pending; this->players.front().rdns_thread.join(); } @@ -3621,89 +3609,82 @@ void RenX::Server::wipePlayers() } } -void RenX::Server::startPing() -{ - RenX::Server::lastActivity = std::chrono::steady_clock::now(); - RenX::Server::sendSocket("cping\n"_jrs); - RenX::Server::awaitingPong = true; +void RenX::Server::startPing() { + m_lastActivity = std::chrono::steady_clock::now(); + sendSocket("cping\n"_jrs); + m_awaitingPong = true; } -unsigned int RenX::Server::getVersion() const -{ - return RenX::Server::rconVersion; +unsigned int RenX::Server::getVersion() const { + return m_rconVersion; } -unsigned int RenX::Server::getGameVersionNumber() const -{ - return RenX::Server::gameVersionNumber; +unsigned int RenX::Server::getGameVersionNumber() const { + return m_gameVersionNumber; } -const Jupiter::ReadableString &RenX::Server::getGameVersion() const -{ - return RenX::Server::gameVersion; +const Jupiter::ReadableString &RenX::Server::getGameVersion() const { + return m_gameVersion; } -const Jupiter::ReadableString &RenX::Server::getRCONUsername() const -{ - return RenX::Server::rconUser; +const Jupiter::ReadableString &RenX::Server::getRCONUsername() const { + return m_rconUser; } -RenX::Server::Server(Jupiter::Socket &&socket, const Jupiter::ReadableString &configurationSection) : Server(configurationSection) -{ - RenX::Server::sock = std::move(socket); - RenX::Server::hostname = RenX::Server::sock.getRemoteHostname(); - RenX::Server::sendSocket(Jupiter::StringS::Format("a%.*s\n", RenX::Server::pass.size(), RenX::Server::pass.ptr())); - RenX::Server::connected = true; +RenX::Server::Server(Jupiter::Socket &&socket, const Jupiter::ReadableString &configurationSection) : Server(configurationSection) { + m_sock = std::move(socket); + m_hostname = m_sock.getRemoteHostname(); + sendSocket(Jupiter::StringS::Format("a%.*s\n", m_pass.size(), m_pass.ptr())); + m_connected = true; } -RenX::Server::Server(const Jupiter::ReadableString &configurationSection) -{ - RenX::Server::configSection = configurationSection; - RenX::Server::calc_uuid = RenX::default_uuid_func; - init(*RenX::getCore()->getConfig().getSection(RenX::Server::configSection)); - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_OnServerCreate(*this); +RenX::Server::Server(const Jupiter::ReadableString &configurationSection) { + m_configSection = configurationSection; + m_calc_uuid = RenX::default_uuid_func; + init(*RenX::getCore()->getConfig().getSection(m_configSection)); + for (const auto& plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_OnServerCreate(*this); + } } -void RenX::Server::init(const Jupiter::Config &config) -{ - RenX::Server::hostname = static_cast(config.get("Hostname"_jrs, "localhost"_jrs)); - RenX::Server::port = config.get("Port"_jrs, 7777); - RenX::Server::clientHostname = static_cast(config.get("ClientAddress"_jrs)); - RenX::Server::pass = config.get("Password"_jrs, "renx"_jrs); - - RenX::Server::logChanType = config.get("ChanType"_jrs); - RenX::Server::adminLogChanType = config.get("AdminChanType"_jrs); - - RenX::Server::setCommandPrefix(config.get("CommandPrefix"_jrs)); - RenX::Server::setPrefix(config.get("IRCPrefix"_jrs)); - - RenX::Server::ban_from_str = config.get("BanFromStr"_jrs, "the server"_jrs); - RenX::Server::rules = config.get("Rules"_jrs, "Anarchy!"_jrs); - RenX::Server::delay = std::chrono::milliseconds(config.get("ReconnectDelay"_jrs, 10000)); - RenX::Server::maxAttempts = config.get("MaxReconnectAttempts"_jrs, -1); - RenX::Server::rconBan = config.get("RCONBan"_jrs, false); - RenX::Server::localSteamBan = config.get("LocalSteamBan"_jrs, true); - RenX::Server::localIPBan = config.get("LocalIPBan"_jrs, true); - RenX::Server::localHWIDBan = config.get("LocalHWIDBan"_jrs, true); - RenX::Server::localRDNSBan = config.get("LocalRDNSBan"_jrs, false); - RenX::Server::localNameBan = config.get("LocalNameBan"_jrs, false); - RenX::Server::localBan = RenX::Server::localIPBan || RenX::Server::localRDNSBan || RenX::Server::localSteamBan || RenX::Server::localNameBan; - RenX::Server::steamFormat = config.get("SteamFormat"_jrs, 16); - RenX::Server::neverSay = config.get("NeverSay"_jrs, false); - RenX::Server::resolve_player_rdns = config.get("ResolvePlayerRDNS"_jrs, true); - RenX::Server::clientUpdateRate = std::chrono::milliseconds(config.get("ClientUpdateRate"_jrs, 2500)); - RenX::Server::buildingUpdateRate = std::chrono::milliseconds(config.get("BuildingUpdateRate"_jrs, 7500)); - RenX::Server::pingRate = std::chrono::milliseconds(config.get("PingUpdateRate"_jrs, 60000)); - RenX::Server::pingTimeoutThreshold = std::chrono::milliseconds(config.get("PingTimeoutThreshold"_jrs, 10000)); +void RenX::Server::init(const Jupiter::Config &config) { + m_hostname = static_cast(config.get("Hostname"_jrs, "localhost"_jrs)); + m_port = config.get("Port"_jrs, 7777); + m_clientHostname = static_cast(config.get("ClientAddress"_jrs)); + m_pass = config.get("Password"_jrs, "renx"_jrs); + + m_logChanType = config.get("ChanType"_jrs); + m_adminLogChanType = config.get("AdminChanType"_jrs); + + setCommandPrefix(config.get("CommandPrefix"_jrs)); + setPrefix(config.get("IRCPrefix"_jrs)); + + m_ban_from_str = config.get("BanFromStr"_jrs, "the server"_jrs); + m_rules = config.get("Rules"_jrs, "Anarchy!"_jrs); + m_delay = std::chrono::milliseconds(config.get("ReconnectDelay"_jrs, 10000)); + m_maxAttempts = config.get("MaxReconnectAttempts"_jrs, -1); + m_rconBan = config.get("RCONBan"_jrs, false); + m_localSteamBan = config.get("LocalSteamBan"_jrs, true); + m_localIPBan = config.get("LocalIPBan"_jrs, true); + m_localHWIDBan = config.get("LocalHWIDBan"_jrs, true); + m_localRDNSBan = config.get("LocalRDNSBan"_jrs, false); + m_localNameBan = config.get("LocalNameBan"_jrs, false); + m_localBan = m_localIPBan || m_localRDNSBan || m_localSteamBan || m_localNameBan; + m_steamFormat = config.get("SteamFormat"_jrs, 16); + m_neverSay = config.get("NeverSay"_jrs, false); + m_resolve_player_rdns = config.get("ResolvePlayerRDNS"_jrs, true); + m_clientUpdateRate = std::chrono::milliseconds(config.get("ClientUpdateRate"_jrs, 2500)); + m_buildingUpdateRate = std::chrono::milliseconds(config.get("BuildingUpdateRate"_jrs, 7500)); + m_pingRate = std::chrono::milliseconds(config.get("PingUpdateRate"_jrs, 60000)); + m_pingTimeoutThreshold = std::chrono::milliseconds(config.get("PingTimeoutThreshold"_jrs, 10000)); Jupiter::Config &commandsFile = RenX::getCore()->getCommandsFile(); - RenX::Server::commandAccessLevels = commandsFile.getSection(RenX::Server::configSection); - RenX::Server::commandAliases = commandsFile.getSection(RenX::Server::configSection + ".Aliases"_jrs); + m_commandAccessLevels = commandsFile.getSection(m_configSection); + m_commandAliases = commandsFile.getSection(m_configSection + ".Aliases"_jrs); - for (size_t i = 0; i != RenX::GameMasterCommandList->size(); ++i) - RenX::Server::addCommand(RenX::GameMasterCommandList->get(i)->copy()); + for (const auto& command : RenX::GameMasterCommandList) { + addCommand(command->copy()); + } auto load_basic_commands = [this, &commandsFile](const Jupiter::ReadableString §ion_prefix) { @@ -3713,26 +3694,25 @@ void RenX::Server::init(const Jupiter::Config &config) Jupiter::Config *basic_commands_help = commandsFile.getSection(section_prefix + ".Basic.Help"_jrs); for (auto& command : basic_commands->getTable()) { - if (this->getCommand(command.first) == nullptr) { + if (getCommand(command.first) == nullptr) { const auto& help_str = basic_commands_help == nullptr ? ""_jrs : basic_commands_help->get(command.second, ""_jrs); - this->addCommand(new RenX::BasicGameCommand(command.first, command.second,help_str)); + addCommand(new RenX::BasicGameCommand(command.first, command.second,help_str)); } } } }; - load_basic_commands(RenX::Server::configSection); + load_basic_commands(m_configSection); load_basic_commands("Default"_jrs); } -RenX::Server::~Server() -{ +RenX::Server::~Server() { + // TODO: This does nothing if (RenX::GameCommand::selected_server == nullptr) RenX::GameCommand::selected_server = nullptr; if (RenX::GameCommand::active_server == nullptr) RenX::GameCommand::active_server = RenX::GameCommand::selected_server; - sock.close(); - RenX::Server::wipeData(); - RenX::Server::commands.emptyAndDelete(); + m_sock.close(); + wipeData(); } diff --git a/src/Plugins/RenX/RenX.Core/RenX_Server.h b/src/Plugins/RenX/RenX.Core/RenX_Server.h index 9665234..6cc16a4 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Server.h +++ b/src/Plugins/RenX/RenX.Core/RenX_Server.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -27,7 +27,6 @@ #include #include #include "Jupiter/TCPSocket.h" -#include "Jupiter/ArrayList.h" #include "Jupiter/String.hpp" #include "Jupiter/Config.h" #include "Jupiter/Thinker.h" @@ -83,9 +82,9 @@ namespace RenX public: // RenX::Server std::list players; /** A list of players in the server */ - Jupiter::ArrayList buildings; /** A list of buildings in the server */ - Jupiter::ArrayList mutators; /** A list of buildings the server is running */ - Jupiter::ArrayList maps; /** A list of maps in the server's rotation */ + std::vector> buildings; /** A list of buildings in the server */ + std::vector mutators; /** A list of buildings the server is running */ + std::vector maps; /** A list of maps in the server's rotation */ Jupiter::Config varData; /** Variable data. */ /** @@ -1068,89 +1067,90 @@ namespace RenX void startPing(); /** Tracking variables */ - bool gameover_when_empty = false; - bool gameover_pending = false; - bool pure = false; - bool connected = false; - bool subscribed = false; - bool fully_connected = false; - bool seamless = false; - bool firstKill = false; - bool firstDeath = false; - bool firstAction = false; - bool awaitingPong = false; - bool passworded = false; - bool steamRequired = false; - bool privateMessageTeamOnly = false; - bool allowPrivateMessaging = true; - bool spawnCrates = true; - bool botsEnabled = true; - bool competitive = false; - bool devBot = false; - bool reliable = false; + bool m_gameover_when_empty = false; + bool m_gameover_pending = false; + bool m_pure = false; + bool m_connected = false; + bool m_subscribed = false; + bool m_fully_connected = false; + bool m_seamless = false; + bool m_firstKill = false; + bool m_firstDeath = false; + bool m_firstAction = false; + bool m_awaitingPong = false; + bool m_passworded = false; + bool m_steamRequired = false; + bool m_privateMessageTeamOnly = false; + bool m_allowPrivateMessaging = true; + bool m_spawnCrates = true; + bool m_botsEnabled = true; + bool m_competitive = false; + bool m_devBot = false; + bool m_reliable = false; bool m_ranked = false; + // TODO: Why aren't these enums? int m_team_mode = 3; /** 0 = static, 1 = swap, 2 = random swap, 3 = shuffle, 4 = traditional (assign as players connect) */ - int match_state = 1; /** 0 = pending, 1 = in progress, 2 = over, 3 = travelling */ + int m_match_state = 1; /** 0 = pending, 1 = in progress, 2 = over, 3 = travelling */ int m_game_type = 1; /** < 0 = Invalid, 0 = Main Menu, 1 = Rx_Game, 2 = TS_Game, > 2 = Unassigned */ - int attempts = 0; - int playerLimit = 0; - int vehicleLimit = 0; - int mineLimit = 0; - int timeLimit = 0; - size_t bot_count = 0; - size_t player_rdns_resolutions_pending = 0; - unsigned int rconVersion = 0; - unsigned int gameVersionNumber = 0; - double crateRespawnAfterPickup = 0.0; - uuid_func calc_uuid; - std::chrono::steady_clock::time_point lastAttempt = std::chrono::steady_clock::now(); - std::chrono::steady_clock::time_point gameStart = std::chrono::steady_clock::now(); - std::chrono::steady_clock::time_point lastClientListUpdate = std::chrono::steady_clock::now(); - std::chrono::steady_clock::time_point lastBuildingListUpdate = std::chrono::steady_clock::now(); - std::chrono::steady_clock::time_point lastActivity = std::chrono::steady_clock::now(); - std::chrono::steady_clock::time_point lastSendActivity = std::chrono::steady_clock::now(); - std::chrono::steady_clock::time_point gameover_time; - Jupiter::String lastLine; - Jupiter::StringS rconUser; - Jupiter::StringS gameVersion; - Jupiter::StringS serverName; - Jupiter::StringS lastCommand; - Jupiter::StringS lastCommandParams; - RenX::Map map; - Jupiter::TCPSocket sock; - Jupiter::ReadableString::TokenizeResult commandListFormat; - Jupiter::ArrayList commands; + int m_attempts = 0; + int m_playerLimit = 0; + int m_vehicleLimit = 0; + int m_mineLimit = 0; + int m_timeLimit = 0; + size_t m_bot_count = 0; + size_t m_player_rdns_resolutions_pending = 0; + unsigned int m_rconVersion = 0; + unsigned int m_gameVersionNumber = 0; + double m_crateRespawnAfterPickup = 0.0; + uuid_func m_calc_uuid; + std::chrono::steady_clock::time_point m_lastAttempt = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point m_gameStart = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point m_lastClientListUpdate = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point m_lastBuildingListUpdate = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point m_lastActivity = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point m_lastSendActivity = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point m_gameover_time; + Jupiter::String m_lastLine; + Jupiter::StringS m_rconUser; + Jupiter::StringS m_gameVersion; + Jupiter::StringS m_serverName; + Jupiter::StringS m_lastCommand; + Jupiter::StringS m_lastCommandParams; + RenX::Map m_map; + Jupiter::TCPSocket m_sock; + Jupiter::ReadableString::TokenizeResult m_commandListFormat; + std::vector> m_commands; /** Configuration variables */ - bool rconBan; - bool localBan; - bool localSteamBan; - bool localIPBan; - bool localHWIDBan; - bool localRDNSBan; - bool localNameBan; - bool neverSay; - bool resolve_player_rdns; - unsigned short port; - int logChanType; - int adminLogChanType; - int maxAttempts; - int steamFormat; /** 16 = hex, 10 = base 10, 8 = octal, -2 = SteamID 2, -3 = SteamID 3 */ - std::chrono::milliseconds delay; - std::chrono::milliseconds clientUpdateRate; - std::chrono::milliseconds buildingUpdateRate; - std::chrono::milliseconds pingRate; - std::chrono::milliseconds pingTimeoutThreshold; - std::string clientHostname; - std::string hostname; - Jupiter::StringS pass; - Jupiter::StringS configSection; - Jupiter::StringS rules; - Jupiter::StringS ban_from_str; - Jupiter::StringS IRCPrefix; - Jupiter::StringS CommandPrefix; - Jupiter::Config *commandAccessLevels; - Jupiter::Config *commandAliases; + bool m_rconBan; + bool m_localBan; + bool m_localSteamBan; + bool m_localIPBan; + bool m_localHWIDBan; + bool m_localRDNSBan; + bool m_localNameBan; + bool m_neverSay; + bool m_resolve_player_rdns; + unsigned short m_port; + int m_logChanType; + int m_adminLogChanType; + int m_maxAttempts; + int m_steamFormat; /** 16 = hex, 10 = base 10, 8 = octal, -2 = SteamID 2, -3 = SteamID 3 */ + std::chrono::milliseconds m_delay; + std::chrono::milliseconds m_clientUpdateRate; + std::chrono::milliseconds m_buildingUpdateRate; + std::chrono::milliseconds m_pingRate; + std::chrono::milliseconds m_pingTimeoutThreshold; + std::string m_clientHostname; + std::string m_hostname; + Jupiter::StringS m_pass; + Jupiter::StringS m_configSection; + Jupiter::StringS m_rules; + Jupiter::StringS m_ban_from_str; + Jupiter::StringS m_IRCPrefix; + Jupiter::StringS m_CommandPrefix; + Jupiter::Config* m_commandAccessLevels; + Jupiter::Config* m_commandAliases; }; } diff --git a/src/Plugins/RenX/RenX.Core/RenX_Tags.cpp b/src/Plugins/RenX/RenX.Core/RenX_Tags.cpp index 1cbdc47..083c83d 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Tags.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Tags.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2015-2017 Jessica James. + * Copyright (C) 2015-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -581,9 +581,9 @@ void TagsImp::processTags(Jupiter::StringType &msg, const RenX::Server *server, PROCESS_TAG(this->INTERNAL_BUILDING_TEAM_LONG_TAG, RenX::getFullTeamName(building->team)); } - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (index = 0; index < xPlugins.size(); ++index) - xPlugins.get(index)->RenX_ProcessTags(msg, server, player, victim, building); + for (const auto& plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_ProcessTags(msg, server, player, victim, building); + } } void TagsImp::processTags(Jupiter::StringType &msg, const RenX::LadderDatabase::Entry &entry) @@ -867,9 +867,9 @@ void TagsImp::sanitizeTags(Jupiter::StringType &fmt) fmt.replace(this->winScoreTag, this->INTERNAL_WIN_SCORE_TAG); fmt.replace(this->loseScoreTag, this->INTERNAL_LOSE_SCORE_TAG); - Jupiter::ArrayList &xPlugins = *RenX::getCore()->getPlugins(); - for (size_t i = 0; i < xPlugins.size(); i++) - xPlugins.get(i)->RenX_SanitizeTags(fmt); + for (const auto& plugin : RenX::getCore()->getPlugins()) { + plugin->RenX_SanitizeTags(fmt); + } } const Jupiter::ReadableString &TagsImp::getUniqueInternalTag() diff --git a/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.cpp b/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.cpp index 28d8b15..d48dc81 100644 --- a/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.cpp +++ b/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,36 +24,33 @@ using namespace Jupiter::literals; -void RenX_GreetingsPlugin::RenX_OnJoin(RenX::Server &server, const RenX::PlayerInfo &player) -{ - auto sendMessage = [&](const Jupiter::ReadableString &m) - { +void RenX_GreetingsPlugin::RenX_OnJoin(RenX::Server &server, const RenX::PlayerInfo &player) { + auto sendMessage = [&](const Jupiter::ReadableString &m) { Jupiter::String msg = m; RenX::sanitizeTags(msg); RenX::processTags(msg, &server, &player); - if (this->sendPrivate) + if (m_sendPrivate) server.sendMessage(player, msg); else server.sendMessage(msg); }; - if (player.isBot == false && server.isMatchInProgress()) - { - switch (RenX_GreetingsPlugin::sendMode) - { + + if (player.isBot == false && server.isMatchInProgress()) { + switch (m_sendMode) { case 0: - RenX_GreetingsPlugin::lastLine = rand() % RenX_GreetingsPlugin::greetingsFile.getLineCount(); - sendMessage(RenX_GreetingsPlugin::greetingsFile.getLine(RenX_GreetingsPlugin::lastLine)); + m_lastLine = rand() % m_greetingsFile.getLineCount(); + sendMessage(m_greetingsFile.getLine(m_lastLine)); break; case 1: - if (++RenX_GreetingsPlugin::lastLine == RenX_GreetingsPlugin::greetingsFile.getLineCount()) - RenX_GreetingsPlugin::lastLine = 0; - sendMessage(RenX_GreetingsPlugin::greetingsFile.getLine(RenX_GreetingsPlugin::lastLine)); + if (++m_lastLine == m_greetingsFile.getLineCount()) + m_lastLine = 0; + sendMessage(m_greetingsFile.getLine(m_lastLine)); break; case 2: - for (RenX_GreetingsPlugin::lastLine = 0; RenX_GreetingsPlugin::lastLine != RenX_GreetingsPlugin::greetingsFile.getLineCount(); RenX_GreetingsPlugin::lastLine++) - sendMessage(RenX_GreetingsPlugin::greetingsFile.getLine(RenX_GreetingsPlugin::lastLine)); + for (m_lastLine = 0; m_lastLine != m_greetingsFile.getLineCount(); m_lastLine++) + sendMessage(m_greetingsFile.getLine(m_lastLine)); break; default: return; @@ -61,22 +58,20 @@ void RenX_GreetingsPlugin::RenX_OnJoin(RenX::Server &server, const RenX::PlayerI } } -int RenX_GreetingsPlugin::OnRehash() -{ +int RenX_GreetingsPlugin::OnRehash() { RenX::Plugin::OnRehash(); - RenX_GreetingsPlugin::greetingsFile.unload(); - return RenX_GreetingsPlugin::initialize() ? 0 : -1; + m_greetingsFile.unload(); + return initialize() ? 0 : -1; } -bool RenX_GreetingsPlugin::initialize() -{ - RenX_GreetingsPlugin::sendPrivate = this->config.get("SendPrivate"_jrs, true); - RenX_GreetingsPlugin::sendMode = this->config.get("SendMode"_jrs, 0); - RenX_GreetingsPlugin::greetingsFile.load(this->config.get("GreetingsFile"_jrs, "RenX.Greetings.txt"_jrs)); - if (RenX_GreetingsPlugin::greetingsFile.getLineCount() == 0) - RenX_GreetingsPlugin::greetingsFile.addData("Please notify the server administrator to properly configure or disable server greetings.\r\n"_jrs); - RenX_GreetingsPlugin::lastLine = RenX_GreetingsPlugin::greetingsFile.getLineCount() - 1; +bool RenX_GreetingsPlugin::initialize() { + m_sendPrivate = this->config.get("SendPrivate"_jrs, true); + m_sendMode = this->config.get("SendMode"_jrs, 0); + m_greetingsFile.load(this->config.get("GreetingsFile"_jrs, "RenX.Greetings.txt"_jrs)); + if (m_greetingsFile.getLineCount() == 0) + m_greetingsFile.addData("Please notify the server administrator to properly configure or disable server greetings.\r\n"_jrs); + m_lastLine = m_greetingsFile.getLineCount() - 1; return true; } @@ -84,7 +79,6 @@ bool RenX_GreetingsPlugin::initialize() // Plugin instantiation and entry point. RenX_GreetingsPlugin pluginInstance; -extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() -{ +extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() { return &pluginInstance; } diff --git a/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.h b/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.h index 781416d..5000c59 100644 --- a/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.h +++ b/src/Plugins/RenX/RenX.Greetings/RenX_Greetings.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2017 Jessica James. + * Copyright (C) 2014-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -35,10 +35,10 @@ public: // Jupiter::Plugin int OnRehash() override; private: - bool sendPrivate; - unsigned int lastLine; - unsigned int sendMode = 0; /** 0 = Send greetings randomly, 1 = Send greetings sequentially, 2 = Send all greetings */ - Jupiter::File greetingsFile; + bool m_sendPrivate; + size_t m_lastLine; + unsigned int m_sendMode = 0; /** 0 = Send greetings randomly, 1 = Send greetings sequentially, 2 = Send all greetings */ + Jupiter::File m_greetingsFile; }; #endif // _RENX_GREETING_H_HEADER \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp b/src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp index 63fff04..4956540 100644 --- a/src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp +++ b/src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2016 Jessica James. + * Copyright (C) 2016-2021 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -25,8 +25,7 @@ using namespace Jupiter::literals; -bool RenX_Ladder_WebPlugin::initialize() -{ +bool RenX_Ladder_WebPlugin::initialize() { RenX_Ladder_WebPlugin::ladder_page_name = this->config.get("LadderPageName"_jrs, ""_jrs); RenX_Ladder_WebPlugin::search_page_name = this->config.get("SearchPageName"_jrs, "search"_jrs); RenX_Ladder_WebPlugin::profile_page_name = this->config.get("ProfilePageName"_jrs, "profile"_jrs); @@ -38,37 +37,35 @@ bool RenX_Ladder_WebPlugin::initialize() /** Initialize content */ Jupiter::HTTP::Server &server = getHTTPServer(); - Jupiter::HTTP::Server::Content *content = new Jupiter::HTTP::Server::Content(RenX_Ladder_WebPlugin::ladder_page_name, handle_ladder_page); + std::unique_ptr content = std::make_unique(RenX_Ladder_WebPlugin::ladder_page_name, handle_ladder_page); content->language = &Jupiter::HTTP::Content::Language::ENGLISH; content->type = &Jupiter::HTTP::Content::Type::Text::HTML; content->charset = &Jupiter::HTTP::Content::Type::Text::Charset::UTF8; - server.hook(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, content); + server.hook(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, std::move(content)); - content = new Jupiter::HTTP::Server::Content(RenX_Ladder_WebPlugin::search_page_name, handle_search_page); + content = std::make_unique(RenX_Ladder_WebPlugin::search_page_name, handle_search_page); content->language = &Jupiter::HTTP::Content::Language::ENGLISH; content->type = &Jupiter::HTTP::Content::Type::Text::HTML; content->charset = &Jupiter::HTTP::Content::Type::Text::Charset::UTF8; - server.hook(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, content); + server.hook(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, std::move(content)); - content = new Jupiter::HTTP::Server::Content(RenX_Ladder_WebPlugin::profile_page_name, handle_profile_page); + content = std::make_unique(RenX_Ladder_WebPlugin::profile_page_name, handle_profile_page); content->language = &Jupiter::HTTP::Content::Language::ENGLISH; content->type = &Jupiter::HTTP::Content::Type::Text::HTML; content->charset = &Jupiter::HTTP::Content::Type::Text::Charset::UTF8; - server.hook(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, content); + server.hook(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, std::move(content)); return true; } -RenX_Ladder_WebPlugin::~RenX_Ladder_WebPlugin() -{ +RenX_Ladder_WebPlugin::~RenX_Ladder_WebPlugin() { Jupiter::HTTP::Server &server = getHTTPServer(); server.remove(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, RenX_Ladder_WebPlugin::ladder_page_name); server.remove(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, RenX_Ladder_WebPlugin::search_page_name); server.remove(RenX_Ladder_WebPlugin::web_hostname, RenX_Ladder_WebPlugin::web_path, RenX_Ladder_WebPlugin::profile_page_name); } -void RenX_Ladder_WebPlugin::init() -{ +void RenX_Ladder_WebPlugin::init() { FILE *file; int chr; @@ -95,11 +92,9 @@ void RenX_Ladder_WebPlugin::init() RenX_Ladder_WebPlugin::ladder_table_footer.erase(); /** Load header */ - if (!RenX_Ladder_WebPlugin::web_header_filename.empty()) - { + if (!RenX_Ladder_WebPlugin::web_header_filename.empty()) { file = fopen(RenX_Ladder_WebPlugin::web_header_filename.c_str(), "rb"); - if (file != nullptr) - { + if (file != nullptr) { while ((chr = fgetc(file)) != EOF) RenX_Ladder_WebPlugin::header += chr; fclose(file); @@ -107,11 +102,9 @@ void RenX_Ladder_WebPlugin::init() } /** Load footer */ - if (!RenX_Ladder_WebPlugin::web_footer_filename.empty()) - { + if (!RenX_Ladder_WebPlugin::web_footer_filename.empty()) { file = fopen(RenX_Ladder_WebPlugin::web_footer_filename.c_str(), "rb"); - if (file != nullptr) - { + if (file != nullptr) { while ((chr = fgetc(file)) != EOF) RenX_Ladder_WebPlugin::footer += chr; fclose(file); @@ -119,11 +112,9 @@ void RenX_Ladder_WebPlugin::init() } /** Load profile */ - if (!RenX_Ladder_WebPlugin::web_profile_filename.empty()) - { + if (!RenX_Ladder_WebPlugin::web_profile_filename.empty()) { file = fopen(RenX_Ladder_WebPlugin::web_profile_filename.c_str(), "rb"); - if (file != nullptr) - { + if (file != nullptr) { while ((chr = fgetc(file)) != EOF) RenX_Ladder_WebPlugin::entry_profile += chr; RenX::sanitizeTags(RenX_Ladder_WebPlugin::entry_profile); @@ -132,11 +123,9 @@ void RenX_Ladder_WebPlugin::init() } /** Load table header */ - if (!RenX_Ladder_WebPlugin::web_ladder_table_header_filename.empty()) - { + if (!RenX_Ladder_WebPlugin::web_ladder_table_header_filename.empty()) { file = fopen(RenX_Ladder_WebPlugin::web_ladder_table_header_filename.c_str(), "rb"); - if (file != nullptr) - { + if (file != nullptr) { while ((chr = fgetc(file)) != EOF) RenX_Ladder_WebPlugin::ladder_table_header += chr; fclose(file); @@ -144,11 +133,9 @@ void RenX_Ladder_WebPlugin::init() } /** Load table footer */ - if (!RenX_Ladder_WebPlugin::web_ladder_table_footer_filename.empty()) - { + if (!RenX_Ladder_WebPlugin::web_ladder_table_footer_filename.empty()) { file = fopen(RenX_Ladder_WebPlugin::web_ladder_table_footer_filename.c_str(), "rb"); - if (file != nullptr) - { + if (file != nullptr) { while ((chr = fgetc(file)) != EOF) RenX_Ladder_WebPlugin::ladder_table_footer += chr; fclose(file); @@ -156,8 +143,7 @@ void RenX_Ladder_WebPlugin::init() } } -int RenX_Ladder_WebPlugin::OnRehash() -{ +int RenX_Ladder_WebPlugin::OnRehash() { RenX::Plugin::OnRehash(); this->init(); return 0; @@ -167,14 +153,11 @@ int RenX_Ladder_WebPlugin::OnRehash() RenX_Ladder_WebPlugin pluginInstance; /** Search bar */ -Jupiter::String generate_search(RenX::LadderDatabase *db) -{ +Jupiter::String generate_search(RenX::LadderDatabase *db) { Jupiter::String result(256); - result = R"database-search(