-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.cpp
More file actions
89 lines (67 loc) · 1.8 KB
/
module.cpp
File metadata and controls
89 lines (67 loc) · 1.8 KB
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
#include "main.h"
// The main module object
MODULE_CLASS MODULE;
// Return a string representation of the module name and version
string MODULE_CLASS::GetVersion()
{
return string(MODULE_NAME " v") + to_string(MODULE_VERSION);
}
// Register a MUSH command
bool MODULE_CLASS::RegisterCommand(const char *name, MUSHCommand cmd, const char *switches, const char *flags, const char *powers, int ctype)
{
if (!name || !*name || !cmd) {
return false;
}
this->commands.insert(make_pair(name, cmd));
MUSH.AddCommand(name, switches, flags, powers, ctype);
return true;
}
// Delete a registered MUSH command
bool MODULE_CLASS::DeleteCommand(string name)
{
if (!this->FindCommand(name)) {
return false;
}
this->commands.erase(name);
return true;
}
// Find a registered MUSH command
MUSHCommand MODULE_CLASS::FindCommand(string name)
{
map<string, MUSHCommand>::iterator it = this->commands.find(name);
if (it != this->commands.end()) {
return it->second;
}
return NULL;
}
// Register a MUSH function
bool MODULE_CLASS::RegisterFunction(const char *name, MUSHFunction fun, int minargs, int maxargs, int ftype)
{
if (!name || !*name || !fun) {
return false;
}
if (maxargs < minargs) {
maxargs = minargs;
}
this->functions.insert(make_pair(name, fun));
MUSH.AddFunction(name, minargs, maxargs, ftype);
return true;
}
// Delete a registered MUSH function
bool MODULE_CLASS::DeleteFunction(string name)
{
if (!this->FindFunction(name)) {
return false;
}
this->functions.erase(name);
return true;
}
// Find a registered MUSH function
MUSHFunction MODULE_CLASS::FindFunction(string name)
{
map<string, MUSHFunction>::iterator it = this->functions.find(name);
if (it != this->functions.end()) {
return it->second;
}
return NULL;
}