-
Notifications
You must be signed in to change notification settings - Fork 13
/
RenX_GameCommand.h
167 lines (140 loc) · 5.14 KB
/
RenX_GameCommand.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* Copyright (C) 2014-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 <jessica.aj@outlook.com>
*/
#if !defined _RENX_GAMECOMMAND_H_HEADER
#define _RENX_GAMECOMMAND_H_HEADER
/**
* @file RenX_GameCommand.h
* @brief Provides the basis of the in-game Renegade-X chat command system.
*/
#include "Jupiter/Command.h"
#include "Jupiter/String.hpp"
#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 */
class Server;
struct PlayerInfo;
class GameCommand;
/** Master command list */
RENX_API extern Jupiter::ArrayList<GameCommand> *GameMasterCommandList;
/**
* @brief Provides an extendable interface from which in-game commands can be created.
*/
class RENX_API GameCommand : public Jupiter::Command
{
public:
/**
* @brief Fetches a command's minimum access level.
*
* @return Minimum access level.
*/
int getAccessLevel();
/**
* @brief Sets a command's minimum access level.
*
* @param accessLevel Access level.
*/
void setAccessLevel(int accessLevel);
/**
* @brief Called when a player with the proper access privledges executes this command.
*
* @param source Renegade-X server where the player is located.
* @param player Player who executed the command.
* @param parameters Parameters following the command.
*/
virtual void trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters) = 0;
/**
* @brief Called when the command is intially created. Define triggers and access levels here.
*/
virtual void create() = 0;
/**
* @brief Used internally to provide per-server configurable commands.
* Note: This is automatically generated by the GAME_COMMAND_INIT macro.
*/
virtual GameCommand *copy() = 0;
/**
* @brief Same as the Default constructor, except that the command is not added to the master command list.
*/
GameCommand(std::nullptr_t);
/**
* @brief Copy constructor for a Game Command.
* Note: This is automatically generated by the GENERIC_GAME_COMMAND macro.
*/
GameCommand(const GameCommand &command);
/**
* @brief Default constructor for a Game Command.
* Note: This is automatically generated by the BASE_GAME_COMMAND macro.
*/
GameCommand();
/**
* @brief Destructor for a Game Command.
* Note: This is not automatically generated by any macro, and is available for use.
*/
virtual ~GameCommand();
/** Public members */
static RenX::Server *active_server; /** Currently active IRC server */
static RenX::Server *selected_server; /** Currently selected IRC server */
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 */
/** Defines the core of a game command's declaration. This should be included in every game command. */
#define BASE_GAME_COMMAND(CLASS) \
public: \
void trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString ¶meters); \
const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString ¶meters); \
CLASS *copy(); \
void create(); \
CLASS() { this->create(); RenX::getCore()->addCommand(this); }
/** Expands to become the entire declaration for a game command. In most cases, this will be sufficient. */
#define GENERIC_GAME_COMMAND(CLASS) \
class CLASS : public RenX::GameCommand { \
BASE_GAME_COMMAND(CLASS) \
CLASS(CLASS &c) : RenX::GameCommand(c) { this->create(); } };
/** Instantiates a game command, and also defines neccessary core functions for compatibility. */
#define GAME_COMMAND_INIT(CLASS) \
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