diff --git a/Release/Plugins/RenX.Core.lib b/Release/Plugins/RenX.Core.lib index 1085cc2..e7ab2e8 100644 Binary files a/Release/Plugins/RenX.Core.lib and b/Release/Plugins/RenX.Core.lib differ diff --git a/RenX.Core/RenX_GameCommand.cpp b/RenX.Core/RenX_GameCommand.cpp index 0c550e1..e682868 100644 --- a/RenX.Core/RenX_GameCommand.cpp +++ b/RenX.Core/RenX_GameCommand.cpp @@ -22,6 +22,10 @@ Jupiter::ArrayList _GameMasterCommandList; Jupiter::ArrayList *RenX::GameMasterCommandList = &_GameMasterCommandList; +RenX::GameCommand::GameCommand(nullptr_t) +{ +} + RenX::GameCommand::GameCommand(const RenX::GameCommand &command) { //RenX::GameMasterCommandList->add(this); @@ -59,4 +63,46 @@ int RenX::GameCommand::getAccessLevel() void RenX::GameCommand::setAccessLevel(int accessLevel) { RenX::GameCommand::access = accessLevel; +} + +// Basic Game Command + +RenX::BasicGameCommand::BasicGameCommand() : RenX::GameCommand(nullptr) +{ +} + +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) +{ + this->addTrigger(in_trigger); + RenX::BasicGameCommand::message = in_message; + RenX::BasicGameCommand::help_message = in_help_message; +} + +void RenX::BasicGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) +{ + source->sendMessage(RenX::BasicGameCommand::message); +} + +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()) + return defaultHelp; + return RenX::BasicGameCommand::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; +} + +void RenX::BasicGameCommand::create() +{ } \ No newline at end of file diff --git a/RenX.Core/RenX_GameCommand.h b/RenX.Core/RenX_GameCommand.h index 43b7323..75de127 100644 --- a/RenX.Core/RenX_GameCommand.h +++ b/RenX.Core/RenX_GameCommand.h @@ -25,9 +25,16 @@ */ #include "Jupiter/Command.h" +#include "Jupiter/String.h" #include "RenX.h" #include "RenX_Core.h" // getCore(). + /** DLL Linkage Nagging */ +#if defined _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace RenX { /** Forward delcarations */ @@ -79,6 +86,11 @@ namespace RenX */ virtual GameCommand *copy() = 0; + /** + * @brief Same as the Default constructor, except that the command is not added to the master command list. + */ + GameCommand(nullptr_t); + /** * @brief Copy constructor for a Game Command. * Note: This is automatically generated by the GENERIC_GAME_COMMAND macro. @@ -100,6 +112,24 @@ namespace RenX private: int access = 0; /** Minimum access level */ }; + + /** + * @brief Provides a simple interface for implementing basic text-to-player commands. + */ + class RENX_API BasicGameCommand : public RenX::GameCommand + { + public: + void trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters); + const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString ¶meters); + BasicGameCommand *copy(); + void create(); + BasicGameCommand(); + BasicGameCommand(BasicGameCommand &c); + BasicGameCommand(const Jupiter::ReadableString &trigger, const Jupiter::ReadableString &in_message, const Jupiter::ReadableString &in_help_message); + + private: + Jupiter::StringS message, help_message; + }; } /** Game Command Macros */ @@ -124,4 +154,9 @@ class CLASS : public RenX::GameCommand { \ CLASS CLASS ## _instance; \ CLASS *CLASS::copy() { return new CLASS(*this); } +/** Re-enable warnings */ +#if defined _MSC_VER +#pragma warning(pop) +#endif + #endif // _RENX_GAMECOMMAND_H_HEADER \ No newline at end of file diff --git a/RenX.Core/RenX_Server.cpp b/RenX.Core/RenX_Server.cpp index 5c179e1..134173d 100644 --- a/RenX.Core/RenX_Server.cpp +++ b/RenX.Core/RenX_Server.cpp @@ -2653,10 +2653,42 @@ void RenX::Server::init() Jupiter::INIFile &commandsFile = RenX::getCore()->getCommandsFile(); RenX::Server::commandAccessLevels = commandsFile.getSection(RenX::Server::configSection); - RenX::Server::commandAliases = commandsFile.getSection(Jupiter::StringS::Format("%.*s.Aliases", RenX::Server::configSection.size(), RenX::Server::configSection.ptr())); + RenX::Server::commandAliases = commandsFile.getSection(RenX::Server::configSection + ".Aliases"_jrs); - for (size_t i = 0; i < RenX::GameMasterCommandList->size(); i++) + for (size_t i = 0; i != RenX::GameMasterCommandList->size(); ++i) RenX::Server::addCommand(RenX::GameMasterCommandList->get(i)->copy()); + + auto load_basic_commands = [this, &commandsFile](const Jupiter::ReadableString §ion_prefix) + { + Jupiter::INIFile::Section *basic_commands = commandsFile.getSection(section_prefix + ".Basic"_jrs); + if (basic_commands != nullptr) + { + Jupiter::INIFile::Section *basic_commands_help = commandsFile.getSection(section_prefix + ".Basic.Help"_jrs); + Jupiter::INIFile::Section::KeyValuePair *pair; + size_t i = 0; + if (basic_commands_help == nullptr) + while (i != basic_commands->size()) + { + pair = basic_commands->getPair(i); + ++i; + if (this->getCommand(pair->getKey()) == nullptr) + this->addCommand(new RenX::BasicGameCommand(pair->getKey(), pair->getValue(), ""_jrs)); + } + else + while (i != basic_commands->size()) + { + pair = basic_commands->getPair(i); + ++i; + if (this->getCommand(pair->getKey()) == nullptr) + this->addCommand(new RenX::BasicGameCommand(pair->getKey(), pair->getValue(), basic_commands_help->get(pair->getKey(), ""_jrs))); + } + } + }; + + load_basic_commands(RenX::Server::configSection); + load_basic_commands("Default"_jrs); + + // ADD CHECKS FOR DEFAULT BASIC COMMANDS HERE } RenX::Server::~Server() diff --git a/RenXGameCommands.ini b/RenXGameCommands.ini index 96becc8..9b49a12 100644 --- a/RenXGameCommands.ini +++ b/RenXGameCommands.ini @@ -9,6 +9,30 @@ [Server] +; [(Server).Basic] +; +; Command=String (Default undefined; adds a basic command to the command list which returns this string) +; + +[Default.Basic] +irc=Please set or remove the "irc" command in Jupiter's RenXGameCommands.ini file. +ts=Please set or remove the "irc" command in Jupiter's RenXGameCommands.ini file. +web=Please set or remove the "irc" command in Jupiter's RenXGameCommands.ini file. + +[Server.Basic] + +; [(Server).Basic.Help] +; +; Command=String (Default undefined; defines the result for !help for a basic command) +; + +[Default.Basic.Help] +irc=Displays this server's IRC server information. +ts=Displays this server's TeamSpeak server information. +web=Displays this server's website information. + +[Server.Basic.Help] + ; [(Server).Aliases] ; ; Command=String (No default; adds a list of triggers to a command)