diff --git a/Bot/Bot.vcxproj b/Bot/Bot.vcxproj index 29a4484..5d7b0e5 100644 --- a/Bot/Bot.vcxproj +++ b/Bot/Bot.vcxproj @@ -88,7 +88,6 @@ - @@ -96,7 +95,6 @@ - diff --git a/Bot/Bot.vcxproj.filters b/Bot/Bot.vcxproj.filters index 9478b74..e11e6f6 100644 --- a/Bot/Bot.vcxproj.filters +++ b/Bot/Bot.vcxproj.filters @@ -30,9 +30,6 @@ Source Files - - Source Files - @@ -50,9 +47,6 @@ Header Files - - Header Files - diff --git a/Bot/Console_Command.h b/Bot/Console_Command.h index aae90ca..7d79d6b 100644 --- a/Bot/Console_Command.h +++ b/Bot/Console_Command.h @@ -24,10 +24,9 @@ * @brief Provides an extendable command system specialized for console-based commands. */ -#include "Jupiter/Command.h" +#include "Jupiter/GenericCommand.h" #include "Jupiter/ArrayList.h" #include "Jupiter_Bot.h" -#include "Generic_Command.h" class ConsoleCommand; @@ -114,11 +113,11 @@ template Generic_Command_As_Console_Command::Generic_Command_As_ template void Generic_Command_As_Console_Command::trigger(const Jupiter::ReadableString ¶meters) { - GenericCommand::ResponseLine *del; - GenericCommand::ResponseLine *ret = T::instance.trigger(parameters); + Jupiter::GenericCommand::ResponseLine *del; + Jupiter::GenericCommand::ResponseLine *ret = T::instance.trigger(parameters); while (ret != nullptr) { - ret->response.println(ret->type == GenericCommand::DisplayType::PublicError || ret->type == GenericCommand::DisplayType::PrivateError ? stderr : stdout); + ret->response.println(ret->type == Jupiter::GenericCommand::DisplayType::PublicError || ret->type == Jupiter::GenericCommand::DisplayType::PrivateError ? stderr : stdout); del = ret; ret = ret->next; delete del; @@ -139,4 +138,4 @@ template const Jupiter::ReadableString &Generic_Command_As_Console_C #pragma warning(pop) #endif -#endif // _CONSOLE_COMMAND_H_HEADER \ No newline at end of file +#endif // _CONSOLE_COMMAND_H_HEADER diff --git a/Bot/Generic_Command.cpp b/Bot/Generic_Command.cpp deleted file mode 100644 index 3cefd51..0000000 --- a/Bot/Generic_Command.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (C) 2015 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 - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Written by Jessica James - */ - -#include "Generic_Command.h" - -Jupiter::ArrayList _genericCommands; -Jupiter::ArrayList *genericCommands = &_genericCommands; - -GenericCommand::GenericCommand() -{ - _genericCommands.add(this); -} - -GenericCommand::~GenericCommand() -{ - size_t count = _genericCommands.size(); - while (count != 0) - if (_genericCommands.get(--count) == this) - { - _genericCommands.remove(count); - break; - } -} - -GenericCommand *getGenericCommand(const Jupiter::ReadableString &trigger) -{ - size_t count = _genericCommands.size(); - while (count != 0) - { - GenericCommand *cmd = _genericCommands.get(--count); - if (cmd->matches(trigger)) - return cmd; - } - return nullptr; -} - -GenericCommand::ResponseLine::ResponseLine(const Jupiter::ReadableString &response_, GenericCommand::DisplayType type_) -{ - GenericCommand::ResponseLine::response = response_; - GenericCommand::ResponseLine::type = type_; -} - -GenericCommand::ResponseLine *GenericCommand::ResponseLine::set(const Jupiter::ReadableString &response_, GenericCommand::DisplayType type_) -{ - GenericCommand::ResponseLine::response = response_; - GenericCommand::ResponseLine::type = type_; - return this; -} \ No newline at end of file diff --git a/Bot/Generic_Command.h b/Bot/Generic_Command.h deleted file mode 100644 index 0412a30..0000000 --- a/Bot/Generic_Command.h +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright (C) 2015 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 - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Written by Jessica James - */ - -#if !defined _GENERIC_COMMAND_H_HEADER -#define _GENERIC_COMMAND_H_HEADER - -/** -* @file Generic_Command.h -* @brief Provides an extendable command system. -*/ - -#include "Jupiter/Command.h" -#include "Jupiter/String.h" -#include "Jupiter_Bot.h" - -class GenericCommand; - -/** DLL Linkage Nagging */ -#if defined _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4251) -#endif - -/** Generic command list */ -JUPITER_BOT_API extern Jupiter::ArrayList *genericCommands; - -/** -* @brief Provides the base for generic commands. -*/ -class JUPITER_BOT_API GenericCommand : public Jupiter::Command -{ -public: - /** Enumerated class to guide output in generic command interpreters */ - enum class DisplayType - { - PublicSuccess, - PrivateSuccess, - PublicError, - PrivateError, - }; - - /** Data entry returned by trigger() */ - struct JUPITER_BOT_API ResponseLine - { - Jupiter::StringS response; - GenericCommand::DisplayType type; - ResponseLine *next = nullptr; - - /** - * @brief Sets the response and type of the ResponseLine. - * - * @param in_response Value to set response to. - * @param in_type Value to set type to. - * @return This. - */ - ResponseLine *set(const Jupiter::ReadableString &response, GenericCommand::DisplayType type); - ResponseLine() = default; - ResponseLine(const Jupiter::ReadableString &response, GenericCommand::DisplayType type); - }; - - /** - * @brief Called when the command is to be executed. - * - * @param input Parameters passed to the command by the user. - */ - virtual ResponseLine *trigger(const Jupiter::ReadableString &input) = 0; - - /** - * @brief Default constructor for the generic command class. - */ - GenericCommand(); - - /** - * @brief Destructor for the generic command class. - */ - ~GenericCommand(); -}; - -/** -* @brief Fetches a generic command based on its trigger. -* -* @param trigger Trigger of the command to fetch. -* @return A generic command if it exists, nullptr otherwise. -*/ -JUPITER_BOT_API extern GenericCommand *getGenericCommand(const Jupiter::ReadableString &trigger); - -/** Generic Command Macros */ - -/** Defines the core of a generic command's declaration. This should be included in every generic command. */ -#define BASE_GENERIC_COMMAND(CLASS) \ - public: \ - CLASS(); \ - GenericCommand::ResponseLine *trigger(const Jupiter::ReadableString ¶meters); \ - const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString ¶meters); \ - static CLASS instance; - -/** Expands to become the entire declaration for a generic command. In most cases, this will be sufficient. */ -#define GENERIC_GENERIC_COMMAND(CLASS) \ -class CLASS : public GenericCommand { \ - BASE_GENERIC_COMMAND(CLASS) \ -}; - -/** Instantiates a generic command. */ -#define GENERIC_COMMAND_INIT(CLASS) \ - CLASS CLASS :: instance = CLASS (); \ - CLASS & CLASS ## _instance = CLASS :: instance; - -/** Re-enable warnings */ -#if defined _MSC_VER -#pragma warning(pop) -#endif - -#endif // _GENERIC_COMMAND_H_HEADER \ No newline at end of file diff --git a/Bot/IRC_Bot.cpp b/Bot/IRC_Bot.cpp index 615ffe6..65a9f3c 100644 --- a/Bot/IRC_Bot.cpp +++ b/Bot/IRC_Bot.cpp @@ -103,49 +103,67 @@ Jupiter::StringL IRC_Bot::getTriggers(Jupiter::ArrayList &cmds) void IRC_Bot::setCommandAccessLevels() { - // Rewrite this later - // Note: Prepare for abstraction of configuration file type. - Jupiter::StringS commandSection = "DefaultCommands"; - - checkForCommands: - int sIndex = Config->getSectionIndex(commandSection); - if (sIndex >= 0) + auto set_command_access_levels = [this](const Jupiter::ReadableString §ion_name) { - int sLen = Config->getSectionLength(sIndex); - for (int i = 0; i < sLen; i++) + Jupiter::INIFile::Section *section = this->Config->getSection(section_name); + + if (section != nullptr) { - const Jupiter::ReadableString &key = Config->getKey(commandSection, i); - int pos = key.find('.'); - if (pos != Jupiter::INVALID_INDEX) + size_t section_length = section->size(); + Jupiter::INIFile::Section::KeyValuePair *pair; + size_t tmp_index; + Jupiter::ReferenceString tmp_key, tmp_sub_key; + IRCCommand *command; + + for (size_t pair_index = 0; pair_index != section_length; ++pair_index) { - Jupiter::ReferenceString command = Jupiter::ReferenceString(key.ptr(), pos); - if (command != nullptr) + pair = section->getPair(pair_index); + + tmp_index = pair->getKey().find('.'); + if (tmp_index != Jupiter::INVALID_INDEX) { - IRCCommand *cmd = IRC_Bot::getCommand(command); - if (cmd != nullptr) + // non-default access assignment + + tmp_key.set(pair->getKey().ptr(), tmp_index); + + tmp_sub_key = pair->getKey(); + tmp_sub_key.shiftRight(tmp_index + 1); + + if (tmp_sub_key.findi("Type."_jrs) == 0) + { + tmp_sub_key.shiftRight(5); // shift beyond "Type." + + command = this->getCommand(tmp_key); + if (command != nullptr) + command->setAccessLevel(tmp_sub_key.asInt(), pair->getValue().asInt()); + } + else if (tmp_sub_key.findi("Channel."_jrs) == 0) { - Jupiter::ReferenceString channelType(key.ptr() + pos + 1, key.size() - pos - 1); - if (isdigit(key[pos + 1])) - cmd->setAccessLevel(channelType.asInt(10), Config->getInt(commandSection, key)); - else cmd->setAccessLevel(channelType.asInt(10), Config->getInt(commandSection, key)); + tmp_sub_key.shiftRight(8); // shift beyond "Channel." + + // Assign access level to command (if command exists) + command = this->getCommand(tmp_key); + if (command != nullptr) + command->setAccessLevel(tmp_sub_key, pair->getValue().asInt()); + else if (this->getPrintOutput() != nullptr) + fprintf(this->getPrintOutput(), "Unable to find command \"%.*s\"" ENDL, tmp_key.size(), tmp_key.ptr()); } - else if (this->getPrintOutput()) printf("Unable to find command \"%.*s\"" ENDL, key.size(), key.ptr()); } - } - else - { - IRCCommand *cmd = IRC_Bot::getCommand(key); - if (cmd != nullptr) cmd->setAccessLevel(Config->getInt(commandSection, key)); - else if (this->getPrintOutput()) printf("Unable to find command \"%.*s\"" ENDL, key.size(), key.ptr()); + else + { + // Assign access level to command (if command exists) + command = this->getCommand(pair->getKey()); + if (command != nullptr) + command->setAccessLevel(pair->getValue().asInt()); + else if (this->getPrintOutput() != nullptr) + fprintf(this->getPrintOutput(), "Unable to find command \"%.*s\"" ENDL, pair->getKey().size(), pair->getKey().ptr()); + } } } - } - if (commandSection.equals("DefaultCommands")) - { - commandSection = this->getConfigSection(); - commandSection += "Commands"; - if (commandSection.equals("DefaultCommands") == false) goto checkForCommands; - } + }; + + set_command_access_levels("DefaultCommands"_jrs); + set_command_access_levels(this->getConfigSection() + "Commands"_jrs); } int IRC_Bot::OnRehash() diff --git a/Bot/IRC_Command.h b/Bot/IRC_Command.h index 3002b13..7c504d8 100644 --- a/Bot/IRC_Command.h +++ b/Bot/IRC_Command.h @@ -24,14 +24,13 @@ * @brief Provides an extendable command system specialized for IRC chat-based commands. */ -#include "Jupiter/Command.h" +#include "Jupiter/GenericCommand.h" #include "Jupiter/IRC_Client.h" #include "Jupiter/ArrayList.h" #include "Jupiter/String.h" #include "Jupiter_Bot.h" #include "ServerManager.h" #include "IRC_Bot.h" -#include "Generic_Command.h" class IRCCommand; @@ -218,18 +217,18 @@ template Generic_Command_As_IRC_Command::Generic_Command_As_IRC_C template void Generic_Command_As_IRC_Command::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) { - GenericCommand::ResponseLine *del; - GenericCommand::ResponseLine *ret = T::instance.trigger(parameters); + Jupiter::GenericCommand::ResponseLine *del; + Jupiter::GenericCommand::ResponseLine *ret = T::instance.trigger(parameters); while (ret != nullptr) { switch (ret->type) { - case GenericCommand::DisplayType::PublicSuccess: - case GenericCommand::DisplayType::PublicError: + case Jupiter::GenericCommand::DisplayType::PublicSuccess: + case Jupiter::GenericCommand::DisplayType::PublicError: source->sendMessage(channel, ret->response); break; - case GenericCommand::DisplayType::PrivateSuccess: - case GenericCommand::DisplayType::PrivateError: + case Jupiter::GenericCommand::DisplayType::PrivateSuccess: + case Jupiter::GenericCommand::DisplayType::PrivateError: source->sendNotice(nick, ret->response); break; default: @@ -289,4 +288,4 @@ template void Generic_Command_As_IRC_Command::copyTriggers() #pragma warning(pop) #endif -#endif // _IRC_COMMAND_H_HEADER \ No newline at end of file +#endif // _IRC_COMMAND_H_HEADER diff --git a/CoreCommands/CoreCommands.cpp b/CoreCommands/CoreCommands.cpp index 8fbe3a0..2c4bdb3 100644 --- a/CoreCommands/CoreCommands.cpp +++ b/CoreCommands/CoreCommands.cpp @@ -131,10 +131,10 @@ VersionGenericCommand::VersionGenericCommand() this->addTrigger(STRING_LITERAL_AS_REFERENCE("clientinfo")); } -GenericCommand::ResponseLine *VersionGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *VersionGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { - GenericCommand::ResponseLine *ret = new GenericCommand::ResponseLine("Version: "_jrs + Jupiter::ReferenceString(Jupiter::version), GenericCommand::DisplayType::PublicSuccess); - ret->next = new GenericCommand::ResponseLine(Jupiter::ReferenceString(Jupiter::copyright), GenericCommand::DisplayType::PublicSuccess); + 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; } @@ -155,14 +155,14 @@ RehashGenericCommand::RehashGenericCommand() this->addTrigger(STRING_LITERAL_AS_REFERENCE("rehash")); } -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) - return new GenericCommand::ResponseLine(Jupiter::StringS::Format("All %u objects were successfully rehashed.", Jupiter::getRehashableCount()), GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("All %u objects were successfully rehashed.", Jupiter::getRehashableCount()), GenericCommand::DisplayType::PublicSuccess); - return new GenericCommand::ResponseLine(Jupiter::StringS::Format("%u of %u objects failed to successfully rehash.", r, Jupiter::getRehashableCount()), GenericCommand::DisplayType::PublicError); + 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 &) diff --git a/ExtraCommands/ExtraCommands.cpp b/ExtraCommands/ExtraCommands.cpp index d6f6c27..ea2b7f9 100644 --- a/ExtraCommands/ExtraCommands.cpp +++ b/ExtraCommands/ExtraCommands.cpp @@ -31,24 +31,24 @@ SelectGenericCommand::SelectGenericCommand() this->addTrigger("ircselect"_jrs); } -GenericCommand::ResponseLine *SelectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *SelectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { if (IRCCommand::selected_server == nullptr) - return new GenericCommand::ResponseLine("No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess); - return new GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess); } if (IRCCommand::active_server == IRCCommand::selected_server) IRCCommand::active_server = nullptr; IRCCommand::selected_server = serverManager->getServer(parameters); if (IRCCommand::selected_server == nullptr) - return new GenericCommand::ResponseLine("Error: IRC server \""_jrs + parameters + "\" not found. No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: IRC server \""_jrs + parameters + "\" not found. No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); if (IRCCommand::active_server == nullptr) IRCCommand::active_server = IRCCommand::selected_server; - return new GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " is now selected."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " is now selected."_jrs, GenericCommand::DisplayType::PublicSuccess); } const Jupiter::ReadableString &SelectGenericCommand::getHelp(const Jupiter::ReadableString &) @@ -73,12 +73,12 @@ DeselectGenericCommand::DeselectGenericCommand() this->addTrigger("ircunselect"_jrs); } -GenericCommand::ResponseLine *DeselectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *DeselectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { if (IRCCommand::selected_server == nullptr) - return new GenericCommand::ResponseLine("No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess); - GenericCommand::ResponseLine *ret = new GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " has been deselected."_jrs, GenericCommand::DisplayType::PublicSuccess); + Jupiter::GenericCommand::ResponseLine *ret = new Jupiter::GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " has been deselected."_jrs, GenericCommand::DisplayType::PublicSuccess); IRCCommand::selected_server = nullptr; IRCCommand::active_server = IRCCommand::selected_server; return ret; @@ -102,7 +102,7 @@ RawGenericCommand::RawGenericCommand() this->addTrigger("sendraw"_jrs); } -GenericCommand::ResponseLine *RawGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *RawGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { IRC_Bot *server; if (IRCCommand::selected_server != nullptr) @@ -110,13 +110,13 @@ GenericCommand::ResponseLine *RawGenericCommand::trigger(const Jupiter::Readable else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); if (parameters.isEmpty()) - return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: raw "_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Too few parameters. Syntax: raw "_jrs, GenericCommand::DisplayType::PrivateError); server->send(parameters); - return new GenericCommand::ResponseLine("Data has been successfully sent to server."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Data has been successfully sent to server."_jrs, GenericCommand::DisplayType::PublicSuccess); } const Jupiter::ReadableString &RawGenericCommand::getHelp(const Jupiter::ReadableString &) @@ -138,7 +138,7 @@ IRCMessageGenericCommand::IRCMessageGenericCommand() this->addTrigger("privmsg"_jrs); } -GenericCommand::ResponseLine *IRCMessageGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *IRCMessageGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { IRC_Bot *server; if (IRCCommand::selected_server != nullptr) @@ -146,13 +146,13 @@ GenericCommand::ResponseLine *IRCMessageGenericCommand::trigger(const Jupiter::R else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); if (parameters.wordCount(WHITESPACE) < 3) - return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: ircmsg "_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Too few parameters. Syntax: ircmsg "_jrs, GenericCommand::DisplayType::PrivateError); server->sendMessage(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)); - return new GenericCommand::ResponseLine("Message successfully sent."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Message successfully sent."_jrs, GenericCommand::DisplayType::PublicSuccess); } const Jupiter::ReadableString &IRCMessageGenericCommand::getHelp(const Jupiter::ReadableString &) @@ -172,7 +172,7 @@ JoinGenericCommand::JoinGenericCommand() this->addTrigger("Join"_jrs); } -GenericCommand::ResponseLine *JoinGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *JoinGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { IRC_Bot *server; if (IRCCommand::selected_server != nullptr) @@ -180,17 +180,17 @@ GenericCommand::ResponseLine *JoinGenericCommand::trigger(const Jupiter::Readabl else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); if (parameters.isEmpty()) - return new GenericCommand::ResponseLine("Error: Too Few Parameters. Syntax: join [password]"_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: Too Few Parameters. Syntax: join [password]"_jrs, GenericCommand::DisplayType::PublicError); if (parameters.wordCount(WHITESPACE) == 1) server->joinChannel(parameters); else server->joinChannel(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)); - return new GenericCommand::ResponseLine("Request to join channel has been sent."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Request to join channel has been sent."_jrs, GenericCommand::DisplayType::PublicSuccess); } const Jupiter::ReadableString &JoinGenericCommand::getHelp(const Jupiter::ReadableString &) @@ -210,7 +210,7 @@ PartGenericCommand::PartGenericCommand() this->addTrigger("Part"_jrs); } -GenericCommand::ResponseLine *PartGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *PartGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { IRC_Bot *server; if (IRCCommand::selected_server != nullptr) @@ -218,17 +218,17 @@ GenericCommand::ResponseLine *PartGenericCommand::trigger(const Jupiter::Readabl else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); if (parameters.isEmpty()) - return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: part [message]"_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: Too few parameters. Syntax: part [message]"_jrs, GenericCommand::DisplayType::PublicError); if (parameters.wordCount(WHITESPACE) == 1) server->partChannel(parameters); else server->partChannel(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)); - return new GenericCommand::ResponseLine("Part command successfuly sent."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Part command successfuly sent."_jrs, GenericCommand::DisplayType::PublicSuccess); } const Jupiter::ReadableString &PartGenericCommand::getHelp(const Jupiter::ReadableString &) @@ -248,7 +248,7 @@ DebugInfoGenericCommand::DebugInfoGenericCommand() this->addTrigger("debuginfo"_jrs); } -GenericCommand::ResponseLine *DebugInfoGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *DebugInfoGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { IRC_Bot *server; if (IRCCommand::selected_server != nullptr) @@ -256,26 +256,26 @@ GenericCommand::ResponseLine *DebugInfoGenericCommand::trigger(const Jupiter::Re else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); Jupiter::IRC::Client::Channel *chan; Jupiter::IRC::Client::User *user; - GenericCommand::ResponseLine *ret = new GenericCommand::ResponseLine("Prefixes: "_jrs + server->getPrefixes(), GenericCommand::DisplayType::PublicSuccess); - GenericCommand::ResponseLine *line = new GenericCommand::ResponseLine("Prefix Modes: "_jrs + server->getPrefixModes(), GenericCommand::DisplayType::PublicSuccess); + Jupiter::GenericCommand::ResponseLine *ret = new Jupiter::GenericCommand::ResponseLine("Prefixes: "_jrs + server->getPrefixes(), GenericCommand::DisplayType::PublicSuccess); + Jupiter::GenericCommand::ResponseLine *line = new Jupiter::GenericCommand::ResponseLine("Prefix Modes: "_jrs + server->getPrefixModes(), GenericCommand::DisplayType::PublicSuccess); ret->next = line; - line->next = new GenericCommand::ResponseLine(Jupiter::StringS::Format("Outputting data for %u channels...", server->getChannelCount()), GenericCommand::DisplayType::PublicSuccess); + line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("Outputting data for %u channels...", server->getChannelCount()), GenericCommand::DisplayType::PublicSuccess); line = line->next; for (unsigned int index = 0; index < server->getChannelCount(); ++index) { chan = server->getChannel(index); if (chan != nullptr) { - line->next = new GenericCommand::ResponseLine(Jupiter::StringS::Format("Channel %.*s - Type: %d", chan->getName().size(), chan->getName().ptr(), chan->getType()), GenericCommand::DisplayType::PublicSuccess); + line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("Channel %.*s - Type: %d", chan->getName().size(), chan->getName().ptr(), chan->getType()), GenericCommand::DisplayType::PublicSuccess); line = line->next; for (unsigned int j = 0; j != chan->getUserCount(); ++j) { user = chan->getUser(j)->getUser(); - line->next = new GenericCommand::ResponseLine(Jupiter::StringS::Format("User %.*s!%.*s@%.*s (prefix: %c) of channel %.*s (of %u shared)", user->getNickname().size(), user->getNickname().ptr(), user->getUsername().size(), user->getUsername().ptr(), user->getHostname().size(), user->getHostname().ptr(), chan->getUserPrefix(j) ? chan->getUserPrefix(j) : ' ', chan->getName().size(), chan->getName().ptr(), user->getChannelCount()), GenericCommand::DisplayType::PublicSuccess); + line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("User %.*s!%.*s@%.*s (prefix: %c) of channel %.*s (of %u shared)", user->getNickname().size(), user->getNickname().ptr(), user->getUsername().size(), user->getUsername().ptr(), user->getHostname().size(), user->getHostname().ptr(), chan->getUserPrefix(j) ? chan->getUserPrefix(j) : ' ', chan->getName().size(), chan->getName().ptr(), user->getChannelCount()), GenericCommand::DisplayType::PublicSuccess); line = line->next; } } @@ -300,7 +300,7 @@ ExitGenericCommand::ExitGenericCommand() this->addTrigger("exit"_jrs); } -GenericCommand::ResponseLine *ExitGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *ExitGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { exit(0); } @@ -323,7 +323,7 @@ IRCConnectGenericCommand::IRCConnectGenericCommand() this->addTrigger("IRCReconnect"_jrs); } -GenericCommand::ResponseLine *IRCConnectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *IRCConnectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) { @@ -333,20 +333,20 @@ GenericCommand::ResponseLine *IRCConnectGenericCommand::trigger(const Jupiter::R else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); server->disconnect("Connect command used; reconnecting..."_jrs, false); - return new GenericCommand::ResponseLine("Disconnected from IRC server."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Disconnected from IRC server."_jrs, GenericCommand::DisplayType::PublicSuccess); } IRC_Bot *server = serverManager->getServer(parameters); if (server != nullptr) { server->disconnect("Connect command used; reconnecting..."_jrs, false); - return new GenericCommand::ResponseLine("Disconnected from IRC server."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Disconnected from IRC server."_jrs, GenericCommand::DisplayType::PublicSuccess); } if (serverManager->addServer(parameters)) - return new GenericCommand::ResponseLine("Connection successfully established; server added to server list."_jrs, GenericCommand::DisplayType::PublicSuccess); - return new GenericCommand::ResponseLine("Error: Unable to find configuration settings for server, or connection refused."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Connection successfully established; server added to server list."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Error: Unable to find configuration settings for server, or connection refused."_jrs, GenericCommand::DisplayType::PublicError); } const Jupiter::ReadableString &IRCConnectGenericCommand::getHelp(const Jupiter::ReadableString &) @@ -366,7 +366,7 @@ IRCDisconnectGenericCommand::IRCDisconnectGenericCommand() this->addTrigger("IRCDisconnect"_jrs); } -GenericCommand::ResponseLine *IRCDisconnectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *IRCDisconnectGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { IRC_Bot *server; if (IRCCommand::selected_server != nullptr) @@ -374,10 +374,10 @@ GenericCommand::ResponseLine *IRCDisconnectGenericCommand::trigger(const Jupiter else if (IRCCommand::active_server != nullptr) server = IRCCommand::active_server; else - return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError); server->disconnect("Disconnect command used."_jrs, true); - return new GenericCommand::ResponseLine("Disconnected from server."_jrs, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Disconnected from server."_jrs, GenericCommand::DisplayType::PublicSuccess); } const Jupiter::ReadableString &IRCDisconnectGenericCommand::getHelp(const Jupiter::ReadableString &) diff --git a/FunCommands/FunCommands.cpp b/FunCommands/FunCommands.cpp index 87da1c9..df1d5da 100644 --- a/FunCommands/FunCommands.cpp +++ b/FunCommands/FunCommands.cpp @@ -157,29 +157,29 @@ ResolveGenericCommand::ResolveGenericCommand() this->addTrigger("resolve"_jrs); } -GenericCommand::ResponseLine *ResolveGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *ResolveGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { unsigned int count = parameters.wordCount(WHITESPACE); if (count <= 1) - return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: resolve
"_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Too few parameters. Syntax: resolve
"_jrs, GenericCommand::DisplayType::PrivateError); Jupiter::ReferenceString command = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE); if (command.equalsi("hostname"_jrs) || command.equalsi("host"_jrs)) { Jupiter::ReferenceString resolved = Jupiter::Socket::resolveHostname(Jupiter::CStringS::gotoWord(parameters, 1, WHITESPACE).c_str(), 0); if (resolved.isEmpty()) - return new GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError); - return new GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess); } else if (command.equalsi("ip"_jrs)) { Jupiter::ReferenceString resolved = Jupiter::Socket::resolveAddress(Jupiter::CStringS::gotoWord(parameters, 1, WHITESPACE).c_str(), 0); if (resolved.isEmpty()) - return new GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError); - return new GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError); + return new Jupiter::GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess); } - return new GenericCommand::ResponseLine("Error: Invalid type. You can only resolve hostnames and IP addresses."_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Invalid type. You can only resolve hostnames and IP addresses."_jrs, GenericCommand::DisplayType::PrivateError); } const Jupiter::ReadableString &ResolveGenericCommand::getHelp(const Jupiter::ReadableString ¶meters) diff --git a/Jupiter b/Jupiter index 1b697ec..427ddec 160000 --- a/Jupiter +++ b/Jupiter @@ -1 +1 @@ -Subproject commit 1b697ec73adfc406e4ad5244aae8d24978fa36d8 +Subproject commit 427ddecf8d89d64fbe90cbcd8eba3aaa7931939a diff --git a/PluginManager/PluginManager.cpp b/PluginManager/PluginManager.cpp index 5631f30..06eff2a 100644 --- a/PluginManager/PluginManager.cpp +++ b/PluginManager/PluginManager.cpp @@ -31,15 +31,15 @@ PluginGenericCommand::PluginGenericCommand() this->addTrigger(STRING_LITERAL_AS_REFERENCE("modules")); } -GenericCommand::ResponseLine *PluginGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *PluginGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { - GenericCommand::ResponseLine *ret = new GenericCommand::ResponseLine(); + Jupiter::GenericCommand::ResponseLine *ret = new Jupiter::GenericCommand::ResponseLine(); if (parameters.isEmpty() || parameters.matchi("list*")) { - GenericCommand::ResponseLine *line = ret->set(Jupiter::String::Format("There are %u plugins loaded:", Jupiter::plugins->size()), GenericCommand::DisplayType::PublicSuccess); + 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 GenericCommand::ResponseLine(Jupiter::plugins->get(i)->getName(), GenericCommand::DisplayType::PublicSuccess); + line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::plugins->get(i)->getName(), GenericCommand::DisplayType::PublicSuccess); line = line->next; } return ret; diff --git a/PluginManager/PluginManager.h b/PluginManager/PluginManager.h index d9a248c..b6b2870 100644 --- a/PluginManager/PluginManager.h +++ b/PluginManager/PluginManager.h @@ -20,7 +20,7 @@ #define _PLUGINMANAGER_H_HEADER #include "Jupiter/Plugin.h" -#include "Generic_Command.h" +#include "Jupiter/GenericCommand.h" #include "Console_Command.h" #include "IRC_Command.h" @@ -30,4 +30,4 @@ class PluginManager : public Jupiter::Plugin GENERIC_GENERIC_COMMAND(PluginGenericCommand) -#endif // _PLUGINMANAGER_H_HEADER \ No newline at end of file +#endif // _PLUGINMANAGER_H_HEADER diff --git a/Release/Bot.lib b/Release/Bot.lib index 414cb5c..b8e6a58 100644 Binary files a/Release/Bot.lib and b/Release/Bot.lib differ diff --git a/Release/Plugins/RenX.Core.lib b/Release/Plugins/RenX.Core.lib index d74fa81..a1024aa 100644 Binary files a/Release/Plugins/RenX.Core.lib and b/Release/Plugins/RenX.Core.lib differ diff --git a/RenX.Ladder/RenX_Ladder.cpp b/RenX.Ladder/RenX_Ladder.cpp index 0e04b0b..a14d128 100644 --- a/RenX.Ladder/RenX_Ladder.cpp +++ b/RenX.Ladder/RenX_Ladder.cpp @@ -88,13 +88,13 @@ LadderGenericCommand::LadderGenericCommand() this->addTrigger("rank"_jrs); } -GenericCommand::ResponseLine *LadderGenericCommand::trigger(const Jupiter::ReadableString ¶meters) +Jupiter::GenericCommand::ResponseLine *LadderGenericCommand::trigger(const Jupiter::ReadableString ¶meters) { if (parameters.isEmpty()) - return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: ladder "_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Too few parameters. Syntax: ladder "_jrs, GenericCommand::DisplayType::PrivateError); if (RenX::default_ladder_database == nullptr) - return new GenericCommand::ResponseLine("Error: No default ladder database specified."_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: No default ladder database specified."_jrs, GenericCommand::DisplayType::PrivateError); RenX::LadderDatabase::Entry *entry; size_t rank; @@ -102,27 +102,27 @@ GenericCommand::ResponseLine *LadderGenericCommand::trigger(const Jupiter::Reada { rank = parameters.asUnsignedInt(10); if (rank == 0) - return new GenericCommand::ResponseLine("Error: Invalid parameters"_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Invalid parameters"_jrs, GenericCommand::DisplayType::PrivateError); entry = RenX::default_ladder_database->getPlayerEntryByIndex(rank - 1); if (entry == nullptr) - return new GenericCommand::ResponseLine("Error: Player not found"_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Player not found"_jrs, GenericCommand::DisplayType::PrivateError); - return new GenericCommand::ResponseLine(FormatLadderResponse(entry, rank), GenericCommand::DisplayType::PublicSuccess); + return new Jupiter::GenericCommand::ResponseLine(FormatLadderResponse(entry, rank), GenericCommand::DisplayType::PublicSuccess); } Jupiter::SLList> list = RenX::default_ladder_database->getPlayerEntriesAndIndexByPartName(parameters, pluginInstance.getMaxLadderCommandPartNameOutput()); if (list.size() == 0) - return new GenericCommand::ResponseLine("Error: Player not found"_jrs, GenericCommand::DisplayType::PrivateError); + return new Jupiter::GenericCommand::ResponseLine("Error: Player not found"_jrs, GenericCommand::DisplayType::PrivateError); std::pair *pair = list.remove(0); - GenericCommand::ResponseLine *response_head = new GenericCommand::ResponseLine(FormatLadderResponse(std::addressof(pair->first), pair->second + 1), GenericCommand::DisplayType::PrivateSuccess); - GenericCommand::ResponseLine *response_end = response_head; + Jupiter::GenericCommand::ResponseLine *response_head = new Jupiter::GenericCommand::ResponseLine(FormatLadderResponse(std::addressof(pair->first), pair->second + 1), GenericCommand::DisplayType::PrivateSuccess); + Jupiter::GenericCommand::ResponseLine *response_end = response_head; delete pair; while (list.size() != 0) { pair = list.remove(0); - response_end->next = new GenericCommand::ResponseLine(FormatLadderResponse(std::addressof(pair->first), pair->second + 1), GenericCommand::DisplayType::PrivateSuccess); + response_end->next = new Jupiter::GenericCommand::ResponseLine(FormatLadderResponse(std::addressof(pair->first), pair->second + 1), GenericCommand::DisplayType::PrivateSuccess); response_end = response_end->next; delete pair; } @@ -169,8 +169,8 @@ void LadderGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, } else { - GenericCommand::ResponseLine *response = LadderGenericCommand_instance.trigger(parameters); - GenericCommand::ResponseLine *ptr; + Jupiter::GenericCommand::ResponseLine *response = LadderGenericCommand_instance.trigger(parameters); + Jupiter::GenericCommand::ResponseLine *ptr; while (response != nullptr) { source->sendMessage(player, response->response);