-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthcontrol.cfg
151 lines (131 loc) · 5.56 KB
/
authcontrol.cfg
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
//AuthControl for Remod by subbed74
//Adds commands to allow the modification of authkeys in-game
//IMPORTANT: Requires the authkeys to be stored in the sqlite database, or a MySQL database
//Command aliases
cmd_addauth = [
auth_priv = (? (=s $arg4 "") "m" $arg4)
if (|| (=s $auth_priv "m") (=s $auth_priv "a")) [
tempstring = (format "SELECT name, pubkey FROM %1 WHERE name='%2' OR pubkey='%3'" $auth_table $arg2 $arg3)
authquery = (db_query $tempstring $auth_db)
if (= $authquery -1) [
db_error $auth_db
] [
authrow = (db_getrow $authquery $auth_db)
db_finalize $authquery $auth_db
if (!=s $authrow "") [
pm $arg1 "^f3[ ERROR ] ^f0That key or username is already being used!"
] [
add_query = (format "INSERT INTO '%1' (name, pubkey, rights, enabled) VALUES ('%2', '%3', '%4', 1)" $auth_table $arg2 $arg3 $auth_priv)
res = (db_query $add_query $auth_db)
//Tell the player the key was added
if (=s $res -1) [
db_error $auth_db
] [
auth_load_from_db
pm $arg1 (format "^f6[ AUTHCONTROL ] ^f0A key was successfully added for ^f5%1 ^f0with ^f5%2 ^f0privileges!" $arg2 (? (=s $auth_priv "a") "admin" "master"))
]
]
]
] [
pm $arg1 "^f3[ ERROR ] ^f0You must provide an ^"a^" or an ^"m^" for admin/master privileges, or leave it blank for the default privilege (master)!"
]
]
cmd_authstate = [
tempstring = (format "SELECT rights FROM %1 WHERE name='%2'" $auth_table $arg2)
authquery = (db_query $tempstring $auth_db)
if (= $authquery -1) [
db_error $auth_db
] [
authrow = (db_getrow $authquery $auth_db)
db_finalize $authquery $auth_db
if (=s $authrow "") [
pm $arg1 (format "^f3[ ERROR ] ^f0No one has an authkey with the name ^f5%1" $arg2)
] [
// If $arg3 not present, toggle enable/disable
if (=s $arg3 "") [
querystring = (format "SELECT enabled FROM %1 WHERE name='%2'" $auth_table $arg2)
query = (db_query $querystring $auth_db)
oldstate = (db_getrow $query $auth_db)
if (=s (at $oldstate 0) "0") [ new_state = 1 ] [ new_state = 0 ]
] [
new_state = $arg3
]
cond (= $new_state -1) [ //Delete the authkey
query = (format "DELETE FROM '%1' WHERE name='%2'" $auth_table $arg2)
res = (db_query $query $auth_db)
//Send a message to the user if successful then reload keys
if (= $res -1) [
db_error $auth_db
] [
pm $arg1 (format "^f6[ AUTHCONTROL ] ^f0The authkey for ^f5%1 ^f0was successfully deleted!" $arg2)
]
] (|| (= $new_state 1) (! $new_state)) [ //Enables/Disables the authkey
query = (format "UPDATE '%1' SET enabled=%2 WHERE name='%3'" $auth_table $new_state $arg2)
res = (db_query $query $auth_db)
//Send a message to the user if successful then reload keys
if (= $res -1) [
db_error $auth_db
] [
pm $arg1 (format "^f6[ AUTHCONTROL ] ^f0The authkey for ^f5%1 ^f0is now %2" $arg2 (? ($new_state) "enabled" "^f3disabled"))
]
] [
pm $arg1 "^f3[ ERROR ] ^f0You must choose -1, 0, or 1 to change state of this authkey! Leave the state blank to toggle enable/disable!"
]
]
]
]
cmd_authpriv = [
//Check if user exists
tempstring = (format "SELECT rights FROM %1 WHERE name='%2'" $auth_table $arg2)
authquery = (db_query $tempstring $auth_db)
if (= $authquery -1) [
db_error $auth_db
] [
authrow = (db_getrow $authquery $auth_db)
db_finalize $authquery $auth_db
if (=s $authrow "") [
pm $arg1 (format "^f3[ ERROR ] ^f0No one has an authkey with the name ^f5%1" $arg2)
] [ //Change the user's privileges
if (&& (!=s $arg3 "m") (!=s $arg3 "a")) [ //Validate the privilege
pm $arg1 "^f3[ ERROR ] ^f0You must specify ^"a^" or ^"m^" for the privilege!"
] [
query = (format "UPDATE '%1' SET rights='%2' WHERE name='%3'" $auth_table $arg3 $arg2)
res = (db_query $query $auth_db)
if (= $res -1) [
db_error $auth_db
] [
pm $arg1 (format "^f6[ AUTHCONTROL ] ^f0Privileges for ^f5%1 ^f0set to %2" $arg2 (? (=s $arg3 "m") "master" "^f6admin"))
auth_load_from_db
]
]
]
]
]
cmd_listauth = [
// Get all the users
db__uid = (db_get_dbuid $auth_db)
tempstring = (format "SELECT name, rights FROM %1" $auth_table)
authquery = (db_query $tempstring $auth_db)
// Check for error, if no error store data in list
if (= $authquery -1) [
db_error $auth_db
] [
auth_list = ""
// Loop through the data and concat it to the list
while [ row = (db_getrow $authquery $auth_db); result (!=s $row "")] [
auth_list = (format "%1 %2%3" $auth_list (? (=s (at $row 1) "m") "^f0" "^f6") (at $row 0))
]
db_finalize $authquery $auth_db
// PM the list to the user
pm $arg1 (format "^f3[ AUTH ] ^f0Users: %1" $auth_list)
]
]
//Register commands
if (=s $auth_db "") [
log_warn "[ AUTHCONTROL ] Commands disabled! You must use a MySQL/SQLite database in order to use this script!"
] [
registercommand "addauth" cmd_addauth 3 "ww|w" "addauth [NAME] [PUBLIC KEY] (a\m - Default: m) | Adds an authkey with the given information."
registercommand "authstate" cmd_authstate 3 "w|i" "authstate [NAME] (-1|0|1 - If blank, toggles the key) | Changes the state of an authkey. -1 = delete, 0 = disable, 1 = enable. NOTE: You must run ^f5#syncauth ^f0after using this command!"
registercommand "authpriv" cmd_authpriv 3 "ww" "authpriv [NAME] [a|m] | Changes the privileges for a user's authkey between master or admin."
registercommand "listauth" cmd_listauth 3 "" "listauth | Lists all users with an authkey. Green names are masters, orange names are admins."
]