-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCommandHandlers.lua
More file actions
125 lines (85 loc) · 2.51 KB
/
CommandHandlers.lua
File metadata and controls
125 lines (85 loc) · 2.51 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
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
function HandleLoginCommand(a_Split, a_Player)
local PlayerState = GetPlayerState(a_Player)
if (PlayerState:IsLoggedIn()) then
a_Player:SendMessage("You are already logged in")
return true
end
local Password = a_Split[2]
if (not Password) then
a_Player:SendMessage("Usage: /login <password>")
return true
end
local res, Err = PlayerState:TryLogin(Password)
if (not res) then
a_Player:SendMessage(Err)
return true
end
a_Player:SendMessage("You logged in")
return true
end
function HandleRegisterCommand(a_Split, a_Player)
local PlayerState = GetPlayerState(a_Player)
if (PlayerState:IsLoggedIn()) then
a_Player:SendMessage("You are already logged in")
return true
end
if ((a_Split[2] == nil) or (a_Split[3] == nil)) then
a_Player:SendMessage("Usage: /register <password> <confirmpassword>")
return true
end
if (a_Split[2] ~= a_Split[3]) then
a_Player:SendMessage("The password doesn't match the confirmation password")
return true
end
local res, Err = PlayerState:TryRegister(a_Split[2])
if (not res) then
a_Player:SendMessage(Err)
return true
end
a_Player:SendMessage("You have registered")
return true
end
function HandleChangePassCommand(a_Split, a_Player)
local PlayerState = GetPlayerState(a_Player)
if (not PlayerState:IsLoggedIn()) then
a_Player:SendMessage("Login first before trying to change your name")
return true
end
if (#a_Split ~= 4) then
a_Player:SendMessage(a_Split[1] .. " <current password> <new password> <confirm password>")
return true
end
if (a_Split[3] ~= a_Split[4]) then
a_Player:SendMessage("The new password and confirmation password don't match")
return true
end
local res, Err = PlayerState:TryChangePassword(a_Split[2], a_Split[3])
if (not res) then
a_Player:SendMessage(Err)
return true
end
a_Player:SendMessage("The password is changed")
return true
end
function HandleRemoveAccountCommand(a_Split, a_Player)
if (not a_Split[2]) then
a_Player:SendMessage("Usage: /removeacc <username>")
return true
end
-- Remove /removeacc from the split table
table.remove(a_Split, 1)
-- Get the full username
local PlayerName = table.concat(a_Split, " ")
local TargetUUID = GetUUIDFromPlayerName(PlayerName)
if (not g_PassStorage:UUIDExists(TargetUUID)) then
a_Player:SendMessage("Player doesn't exist")
return true
end
local res, Err = g_PassStorage:DeleteUUID(TargetUUID)
if (not res) then
a_Player:SendMessage(Err)
return true
end
a_Player:SendMessage("The player is removed")
return true
end