Browse Source

Added RenX::BasicGameCommand, and appropriate config sections in RenXGameCommands.ini.

pull/3/head
JustinAJ 9 years ago
parent
commit
12eece3e0e
  1. BIN
      Release/Plugins/RenX.Core.lib
  2. 46
      RenX.Core/RenX_GameCommand.cpp
  3. 35
      RenX.Core/RenX_GameCommand.h
  4. 36
      RenX.Core/RenX_Server.cpp
  5. 24
      RenXGameCommands.ini

BIN
Release/Plugins/RenX.Core.lib

Binary file not shown.

46
RenX.Core/RenX_GameCommand.cpp

@ -22,6 +22,10 @@
Jupiter::ArrayList<RenX::GameCommand> _GameMasterCommandList;
Jupiter::ArrayList<RenX::GameCommand> *RenX::GameMasterCommandList = &_GameMasterCommandList;
RenX::GameCommand::GameCommand(nullptr_t)
{
}
RenX::GameCommand::GameCommand(const RenX::GameCommand &command)
{
//RenX::GameMasterCommandList->add(this);
@ -60,3 +64,45 @@ 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 &parameters)
{
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()
{
}

35
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 &parameters);
const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters);
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

36
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 &section_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()

24
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)

Loading…
Cancel
Save