The attached is an untested version (or loosely tested by simulating its behaviors) and is obviously unfinished.
A test module template:
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
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
testMod_module = {} --************-- --*Initialize*-- --************-- function testMod_init(arg) 	--just print to the server output stream. 	pr(1, "asdf") end testMod_module.init = function(arg) testMod_init(arg) end --******-- --*Acts*-- --******-- testMod_module.acts = {} --Sample command - sampleAct - parameters {p, typ, cmd} function testMod_sampleAct(p, x, cmd) 	if (cmd) then cmd = "sampleAct Command with the parameters: "..cmd else cmd = "sampleAct command with no parameters" end 	msg2(p, cmd) end --Add the sampleAct command to the acts list - Do not forget to use all lower for the name of the field testMod_module.acts.sampleact = function(p, x, cmd) testMod_sampleAct(p, x, cmd) end --Admin Acts testMod_module.admacts = {} --Admin Privilege testMod_module.privilege = {} --Sample command - sampleAdmAct - parameters {p, typ, cmd} function testMod_sampleAdmAct(p, x, cmd) 	msg2(p, cmd) end --Add the sampleAdmAct command to the acts and privilege list - Do not forget to use all lower for the name of the field testMod_module.admacts.sampleadmact = function(p, x, cmd) testMod_sampleAdmAct(p, x, cmd) end testMod_module.privilege.sampleadmact= "a b c d e" --*******-- --*Hooks*-- --*******-- function testMod_hooktype(arg) 	--does nothing here... 	print("calling hooktype with "..arg) end testMod_module.hooktype = function(arg) testMod_hooktype(arg) end --********-- --*Return*-- --********-- return testMod_module
where any command to the server are called acts and any admin commands are called admacts. The hook functions are renamed from hook_hooktype to modName_hooktype, and then add the functions into the modName_module element and you're all set.
The ModHCS script
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
description = {} description.credits = [[ Author: Lee Gao License: Creative Common Title: Modular Hook and commands system - ModHCS ]] --************************-- --*Global Initializations*-- --************************-- users = {} players = {} modules = {} admins = {} cmd_priv = {} --Temp msg2(p, t) function msg2(p, t) 	print (p, t) end --Temp pr(p, t) function d(t) 	print (t) end --*******************-- --*Utility Functions*-- --*******************-- function switch(t) 	t.act = function (self,x, p, com) 		local f=self[x] or self.default 		if f then 			if type(f)=="function" then 				f(p, x, com) 			else 				error("case "..tostring(x).." not a function") 			end 		end 	end 	return t end function tableToString(t, n) 	local s = "" 	if (n == nil) then n = 1 end 	while (n <= #t) do 		s = s .. t[n] .. " " 		n = n + 1 	end 	return s end function admin_init() 	for line in io.lines("admins.cfg") do 		local tempUser = {} 		for word in string.gmatch(line, "%w+") do 			table.insert(tempUser, word) 		end 		users[tempUser[1]] = {password=tempUser[2], privilege = tempUser[3]} 	end end function mod_init(file) 	if (file == nil or type(file) ~= "string") then file = "mods.cfg" end for line in io.lines(file) do 		local f = loadfile(line) 		modules[line] = f() 		for k,v in pairs(modules[line].privilege) do 			tempPriv = {toString = v} 			for word in string.gmatch(v, "%w+") do 				tempPriv[word] = word 			end 			cmd_priv[k] = tempPriv 		end 	end 	local acts = {} 	acts.default = function(p, typ, cmd) msg2(p, "Error: Command Does Not Exist: "..typ) end 	local admacts = {} 	admacts.default = function(p, typ, cmd) msg2(p, "Error: Admin Command Does Not Exist: "..typ) end 	for mod_name, module in pairs(modules) do 		for act_name, act_fn in pairs(module.acts) do 			acts[act_name] = act_fn 		end 		for admact_name, admact_fn in pairs(module.admacts) do 			admacts[admact_name] = admact_fn 		end 	end 	action = switch(acts) 	admin_action = switch(admacts) end function parseCmd(t, priv, a) 	local cmd = {} 	local p = a[1] 	if (type(priv) ~= "boolean") then p = priv; priv = false end 	for word in string.gmatch(t, "%w+") do 		table.insert(cmd, word) 	end 	local typ = string.lower(cmd[1]) 	table.remove(cmd, 1) 	if priv then 		if (typ == "login") then 			username = cmd[1] 			password = cmd[2] 			if (users[username]) then 				if (users[username].password == password) then 					admins[p] = users[username].privilege 					msg2(p, "User \""..username.."\" logged in successfully, your privilege mask is \""..admins[p].."\"") 				else 					msg2(p, "User Found but Incorrect Password") 				end 			else 				msg2(p, "No User with the Username: "..username) 			end 		elseif (cmd_priv[typ][admins[p]]) then 			local privilege = admins[p] 			command = tableToString(cmd) 			admin_action:act(typ, p, command) 		else 			msg2(p, "No admin privileges") 		end 	else 		command = tableToString(cmd) 		action:act(typ, p, command) 	end end --*******-- --*Hooks*-- --*******-- function hook_init() 	--Initialize the Mods system 	mod_init() 	--Initialize the User system 	admin_init() 	for modName, mod in pairs(modules) do 		if type(mod.init) == "function" then 			local f = mod.init() 		end 	end end function hook_say(p, t) 	if (string.lower(string.sub(t, 1, 1)) == "@") then 		t = string.sub(t, 1) 		parseCmd(t, true, {p}) 	elseif (string.lower(string.sub(t, 1, 1)) == "/") then 		t = string.sub(t, 1) 		parseCmd(t, false, {p}) 	end 	--hook_say shouldn't need a mod iteration. end --Substitute this for each of the hook type. function hook_anything (p, arg1, arg2, argn) 	--hook_hooktype iteration 	for modName, mod in pairs(modules) do 		if type(mod.hooktype) == "function" then 			local f = mod.hooktype(p, arg1, arg2, argn) 		end 	end end hook_init() hook_say(1, "/sampleAct 2") hook_say(1, "@login adm") hook_say(1, "@login admin") hook_say(1, "@login admin pass") hook_say(1, "@sampleAdmAct asdfasdf") i=1 while (i<10) do 	hook_anything(i) 	i=i+1 end
@ Can you create a way to disable bubbling the behaviors of the hooks to the default when a return nil is added to the hook?