Skip to content

Commit 4edf087

Browse files
sfan5SmallJoker
authored andcommittedDec 6, 2017
Auth handler: Player deletion & Iterator (#6741)
* Add player deletion method to auth handler (fixes #6653) * Support iterating over the auth database There was no way to do this previously and a recent commit broke doing this the "hacky" way by accessing `core.auth_table`.
1 parent 2b5341c commit 4edf087

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

Diff for: ‎builtin/game/auth.lua

+18
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ core.builtin_auth_handler = {
106106
}
107107
save_auth_file()
108108
end,
109+
delete_auth = function(name)
110+
assert(type(name) == "string")
111+
if not auth_table[name] then
112+
return false
113+
end
114+
core.log('info', "Built-in authentication handler deleting player '"..name.."'")
115+
auth_table[name] = nil
116+
save_auth_file()
117+
return true
118+
end,
109119
set_password = function(name, password)
110120
assert(type(name) == "string")
111121
assert(type(password) == "string")
@@ -154,6 +164,13 @@ core.builtin_auth_handler = {
154164
assert(auth_table[name]).last_login = os.time()
155165
save_auth_file()
156166
end,
167+
iterate = function()
168+
local names = {}
169+
for k in pairs(auth_table) do
170+
names[k] = true
171+
end
172+
return pairs(names)
173+
end,
157174
}
158175

159176
core.register_on_prejoinplayer(function(name, ip)
@@ -204,6 +221,7 @@ end
204221

205222
core.set_player_password = auth_pass("set_password")
206223
core.set_player_privs = auth_pass("set_privileges")
224+
core.remove_player_auth = auth_pass("delete_auth")
207225
core.auth_reload = auth_pass("reload")
208226

209227
local record_login = auth_pass("record_login")

Diff for: ‎doc/lua_api.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -3124,8 +3124,11 @@ These functions return the leftover itemstack.
31243124
* `minetest.get_server_status()`: returns server status string
31253125
* `minetest.get_server_uptime()`: returns the server uptime in seconds
31263126
* `minetest.remove_player(name)`: remove player from database (if he is not connected).
3127-
* Does not remove player authentication data, minetest.player_exists will continue to return true.
3127+
* As auth data is not removed, minetest.player_exists will continue to return true.
3128+
Call the below method as well if you want to remove auth data too.
31283129
* Returns a code (0: successful, 1: no such player, 2: player is connected)
3130+
* `minetest.remove_player_auth(name)`: remove player authentication data
3131+
* Returns boolean indicating success (false if player nonexistant)
31293132

31303133
### Bans
31313134
* `minetest.get_ban_list()`: returns the ban list (same as `minetest.get_ban_description("")`)
@@ -5225,6 +5228,8 @@ Definition tables
52255228
create_auth = func(name, password),
52265229
-- ^ Create new auth data for player `name`
52275230
-- ^ Note that `password` is not plain-text but an arbitrary representation decided by the engine
5231+
delete_auth = func(name),
5232+
-- ^ Delete auth data of player `name`, returns boolean indicating success (false if player nonexistant)
52285233
set_password = func(name, password),
52295234
-- ^ Set password of player `name` to `password`
52305235
Auth data should be created if not present
@@ -5236,5 +5241,7 @@ Definition tables
52365241
-- ^ Returns boolean indicating success
52375242
record_login = func(name),
52385243
-- ^ Called when player joins, used for keeping track of last_login
5244+
iterate = func(),
5245+
-- ^ Returns an iterator (use with `for` loops) for all player names currently in the auth database
52395246
}
52405247

0 commit comments

Comments
 (0)
Please sign in to comment.