summaryrefslogtreecommitdiff
path: root/src/command.cpp
blob: 5c754cd8d288a8f9fbab0f61268d1f286bbb0cde (plain)
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
#include "services.h"
#include "modules.h"

Command::Command(const std::string &sname, size_t min_params, size_t max_params) : MaxParams(max_params), MinParams(min_params), name(sname)
{
	this->flags = 0;
	this->help_param1 = NULL;
	this->help_param2 = NULL;
	this->help_param3 = NULL;
	this->help_param4 = NULL;
	this->core = 0;
	this->next = NULL;
	this->mod_name = NULL;
	this->service = NULL;
	this->all_help = NULL;
	this->regular_help = NULL;
	this->oper_help = NULL;
	this->admin_help = NULL;
	this->root_help = NULL;
}

Command::~Command()
{
	if (this->mod_name) {
		delete [] this->mod_name;
	}
	if (this->service) {
		delete [] this->service;
	}
	this->next = NULL;
}

/** Execute this command.
 * @param u The user executing the command.
 */
CommandReturn Command::Execute(User *u, std::vector<std::string> &) { return MOD_CONT; }

/** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
 * @param u The user requesting help
 * @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL")
 * @return true if help was provided to the user, false otherwise.
 */
bool Command::OnHelp(User *u, const std::string &subcommand) { return false; }

/** Requested when the user provides bad syntax to this command (not enough params, etc).
 * @param u The user executing the command.
 */
void Command::OnSyntaxError(User *u) { }

/** Set a certain flag on this command.
 * @param flag The CommandFlag to set on this command.
 */
void Command::SetFlag(CommandFlags flag)
{
	this->flags |= flag;
}

/** Remove a certain flag from this command.
 * @param flag The CommandFlag to unset.
 */
void Command::UnsetFlag(CommandFlags flag)
{
	this->flags &= ~flag;
}

/** Check whether a certain flag is set on this command.
 * @param flag The CommandFlag to check.
 * @return bool True if the flag is set, false else.
 */
bool Command::HasFlag(CommandFlags flag) const
{
	return this->flags & flag;
}