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
function switch(t)
	t.case = function (self,x)
		local f=self[x] or self.default
		if f then
			if type(f)=="function" then
				f(self)
			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] + " "
	end
	return s
end
if (string.lower(string.sub(t, 1, 5)) == "admin") then
	-- Get the substring from position 11 to the end
	t = string.sub(t, 6)
	-- Dec and init of local variables
	local cmd = {}
	local users = {}
	--Iterates through t and adds each word into the table cmd
	for word in string.gmatch(t, "%a+") do
		table.insert(cmd, word)
	end
	--Command Type + pop top element
	local typ = string.lower(cmd[1])
	table.remove(cmd, 1)
	--This probably go in the init block instead of here.
	for line in io.lines("Admins.cfg") do
		local tempUser = {}
		for word in string.gmatch(line, "%a+") do
			table.insert(tempUser, word)
		end
		users[tempUser[1]] = {password=tempUser[2], priviledge = tempUser[3]}
	end
	
	if (typ == "login") then
		username = cmd[2]
		password = cmd[3]
		if (users[username]) then
			--Here, admin_check will return nil if user id is not in the list				if (users[username].password == password) then
				admin_check[p] = users[username].priviledge
			else
				msg2(p, "Wrong Password")
			end
		else
			msg2(p, "No User with that Username")
		end
	elseif (admin_check[p]) then
		local priviledge = admin_check[p]
		
		command = tableToString(cmd)
		
		--Do the rest of the stuff, you can dec a variable as a fn and store it.
		action = switch {
		["slap"] = function () msg2(p, "This is the slap command") end,
		default = function() msg2(p, "Command Does Not exist") end,
		}
		action:case(typ)
	else
		msg2(p, "No admin priviledges")
	end
end