aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/privileges.lua
blob: 2ff4c093cdcc032badd121b0dfe747f25d8da1e7 (plain)
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
-- Minetest: builtin/privileges.lua

local S = core.get_translator("__builtin")

--
-- Privileges
--

core.registered_privileges = {}

function core.register_privilege(name, param)
	local function fill_defaults(def)
		if def.give_to_singleplayer == nil then
			def.give_to_singleplayer = true
		end
		if def.give_to_admin == nil then
			def.give_to_admin = def.give_to_singleplayer
		end
		if def.description == nil then
			def.description = S("(no description)")
		end
	end
	local def
	if type(param) == "table" then
		def = param
	else
		def = {description = param}
	end
	fill_defaults(def)
	core.registered_privileges[name] = def
end

core.register_privilege("interact", S("Can interact with things and modify the world"))
core.register_privilege("shout", S("Can speak in chat"))

local basic_privs =
	core.string_to_privs((core.settings:get("basic_privs") or "shout,interact"))
local basic_privs_desc = S("Can modify basic privileges (@1)",
	core.privs_to_string(basic_privs, ', '))
core.register_privilege("basic_privs", basic_privs_desc)

core.register_privilege("privs", S("Can modify privileges"))

core.register_privilege("teleport", {
	description = S("Can teleport self"),
	give_to_singleplayer = false,
})
core.register_privilege("bring", {
	description = S("Can teleport other players"),
	give_to_singleplayer = false,
})
core.register_privilege("settime", {
	description = S("Can set the time of day using /time"),
	give_to_singleplayer = false,
})
core.register_privilege("server", {
	description = S("Can do server maintenance stuff"),
	give_to_singleplayer = false,
	give_to_admin = true,
})
core.register_privilege("protection_bypass", {
	description = S("Can bypass node protection in the world"),
	give_to_singleplayer = false,
})
core.register_privilege("ban", {
	description = S("Can ban and unban players"),
	give_to_singleplayer = false,
	give_to_admin = true,
})
core.register_privilege("kick", {
	description = S("Can kick players"),
	give_to_singleplayer = false,
	give_to_admin = true,
})
core.register_privilege("give", {
	description = S("Can use /give and /giveme"),
	give_to_singleplayer = false,
})
core.register_privilege("password", {
	description = S("Can use /setpassword and /clearpassword"),
	give_to_singleplayer = false,
	give_to_admin = true,
})
core.register_privilege("fly", {
	description = S("Can use fly mode"),
	give_to_singleplayer = false,
})
core.register_privilege("fast", {
	description = S("Can use fast mode"),
	give_to_singleplayer = false,
})
core.register_privilege("noclip", {
	description = S("Can fly through solid nodes using noclip mode"),
	give_to_singleplayer = false,
})
core.register_privilege("rollback", {
	description = S("Can use the rollback functionality"),
	give_to_singleplayer = false,
})
core.register_privilege("debug", {
	description = S("Can enable wireframe"),
	give_to_singleplayer = false,
})

core.register_can_bypass_userlimit(function(name, ip)
	local privs = core.get_player_privs(name)
	return privs["server"] or privs["ban"] or privs["privs"] or privs["password"]
end)
n; i++) setnilvalue(&f->k[i]); for (i=0; i<n; i++) { TValue* o=&f->k[i]; int t=LoadChar(S); switch (t) { case LUA_TNIL: setnilvalue(o); break; case LUA_TBOOLEAN: setbvalue(o,LoadChar(S)!=0); break; case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); break; case LUA_TSTRING: setsvalue2n(S->L,o,LoadString(S)); break; default: error(S,"bad constant"); break; } } n=LoadInt(S); f->p=luaM_newvector(S->L,n,Proto*); f->sizep=n; for (i=0; i<n; i++) f->p[i]=NULL; for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source); } static void LoadDebug(LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->lineinfo=luaM_newvector(S->L,n,int); f->sizelineinfo=n; LoadVector(S,f->lineinfo,n,sizeof(int)); n=LoadInt(S); f->locvars=luaM_newvector(S->L,n,LocVar); f->sizelocvars=n; for (i=0; i<n; i++) f->locvars[i].varname=NULL; for (i=0; i<n; i++) { f->locvars[i].varname=LoadString(S); f->locvars[i].startpc=LoadInt(S); f->locvars[i].endpc=LoadInt(S); } n=LoadInt(S); f->upvalues=luaM_newvector(S->L,n,TString*); f->sizeupvalues=n; for (i=0; i<n; i++) f->upvalues[i]=NULL; for (i=0; i<n; i++) f->upvalues[i]=LoadString(S); } static Proto* LoadFunction(LoadState* S, TString* p) { Proto* f; if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); f=luaF_newproto(S->L); setptvalue2s(S->L,S->L->top,f); incr_top(S->L); f->source=LoadString(S); if (f->source==NULL) f->source=p; f->linedefined=LoadInt(S); f->lastlinedefined=LoadInt(S); f->nups=LoadByte(S); f->numparams=LoadByte(S); f->is_vararg=LoadByte(S); f->maxstacksize=LoadByte(S); LoadCode(S,f); LoadConstants(S,f); LoadDebug(S,f); IF (!luaG_checkcode(f), "bad code"); S->L->top--; S->L->nCcalls--; return f; } static void LoadHeader(LoadState* S) { char h[LUAC_HEADERSIZE]; char s[LUAC_HEADERSIZE]; luaU_header(h); LoadBlock(S,s,LUAC_HEADERSIZE); IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); } /* ** load precompiled chunk */ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) { LoadState S; if (*name=='@' || *name=='=') S.name=name+1; else if (*name==LUA_SIGNATURE[0]) S.name="binary string"; else S.name=name; S.L=L; S.Z=Z; S.b=buff; LoadHeader(&S); return LoadFunction(&S,luaS_newliteral(L,"=?")); } /* * make header */ void luaU_header (char* h) { int x=1; memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); h+=sizeof(LUA_SIGNATURE)-1; *h++=(char)LUAC_VERSION; *h++=(char)LUAC_FORMAT; *h++=(char)*(char*)&x; /* endianness */ *h++=(char)sizeof(int); *h++=(char)sizeof(size_t); *h++=(char)sizeof(Instruction); *h++=(char)sizeof(lua_Number); *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ }