aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/auth.lua
Commit message (Collapse)AuthorAge
* Run on_grant and on_revoke callbacks after privs change (#11387)AFCMS2021-06-30
| | | Callbacks were run too early. This changes the order to call after the privs are updated.
* Add on_authplayer callback and 'last_login' to on_joinplayer (#9574)sorcerykid2020-05-23
| | | | | | Replace on_auth_fail callback with more versatile on_authplayer Better clarify account login process in Lua API documentation Change initial timestamp for newly registered accounts to -1
* Replace auth.txt with SQLite auth database (#7279)Ben Deutsch2018-08-05
| | | | * Replace auth.txt with SQLite auth database
* Builtin auth handler: Speed up file writing (#7252)SmallJoker2018-04-19
|
* Auth handler: Player deletion & Iterator (#6741)sfan52017-12-06
| | | | | | | | * 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`.
* Make core.auth_table private and structure builtin/auth.luasfan52017-12-01
| | | | If you give modders the ability to do something, they will...
* Make use of safe file writing in auth handler (fixes #6576)sfan52017-11-08
|
* Do not grant all privs to the admin - changes game behavior (#6460)lhofhansl2017-10-07
| | | | | | * Do not grant all privs to admins. * Default give_to_admin to give_to_singleplayer
* Add on_grant and on_revoke callbacks (#4713)rubenwardy2017-08-26
| | | | | | * Add register_on_priv_grant/revoke, and on_grant/revoke to privs. Call from /grant and /revoke * Call on_grant and on_revoke callbacks from set_privs
* [CSM] Add function to get player privileges (#5933)red-0012017-06-07
| | | | | | * [CSM] Add function to get player privileges + move related help functions to common * Added @Zeno- const
* Use a settings object for the main settingsShadowNinja2017-05-06
| | | | | | | This unifies the settings APIs. This also unifies the sync and async registration APIs, since the async registration API did not support adding non-functions to the API table.
* Builtin: Disallow registering users with the same nameSmallJoker2016-08-29
| | | | | Prevents duplicate names: 'NickName', 'nickname', 'NICKNAME'. Skips already registered users, so they can connect as usual.
* Faster insertion into tableRui9142016-03-06
|
* SAPI: Track last executed mod and include in error messageskwolekr2015-08-12
|
* Add strict moduleShadowNinja2014-11-19
| | | | Also fix leaking globals found by it.
* Add last_login field to auth.txtRyan Newell2014-11-08
| | | | Also shortens some related code and adds more parameters to string.split.
* Use "core" namespace internallyShadowNinja2014-05-08
|
* Organize builtin into subdirectoriesShadowNinja2014-05-07
mmon/c_converter.h" #include "common/c_content.h" #include "server.h" bool ScriptApiEntity::luaentity_Add(u16 id, const char *name) { SCRIPTAPI_PRECHECKHEADER verbosestream<<"scriptapi_luaentity_add: id="<<id<<" name=\"" <<name<<"\""<<std::endl; // Get core.registered_entities[name] lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_entities"); luaL_checktype(L, -1, LUA_TTABLE); lua_pushstring(L, name); lua_gettable(L, -2); // Should be a table, which we will use as a prototype //luaL_checktype(L, -1, LUA_TTABLE); if (lua_type(L, -1) != LUA_TTABLE){ errorstream<<"LuaEntity name \""<<name<<"\" not defined"<<std::endl; return false; } int prototype_table = lua_gettop(L); //dump2(L, "prototype_table"); // Create entity object lua_newtable(L); int object = lua_gettop(L); // Set object metatable lua_pushvalue(L, prototype_table); lua_setmetatable(L, -2); // Add object reference // This should be userdata with metatable ObjectRef push_objectRef(L, id); luaL_checktype(L, -1, LUA_TUSERDATA); if (!luaL_checkudata(L, -1, "ObjectRef")) luaL_typerror(L, -1, "ObjectRef"); lua_setfield(L, -2, "object"); // core.luaentities[id] = object lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); lua_pushnumber(L, id); // Push id lua_pushvalue(L, object); // Copy object to top of stack lua_settable(L, -3); return true; } void ScriptApiEntity::luaentity_Activate(u16 id, const std::string &staticdata, u32 dtime_s) { SCRIPTAPI_PRECHECKHEADER verbosestream << "scriptapi_luaentity_activate: id=" << id << std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // Get on_activate function lua_getfield(L, -1, "on_activate"); if (!lua_isnil(L, -1)) { luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self lua_pushlstring(L, staticdata.c_str(), staticdata.size()); lua_pushinteger(L, dtime_s); setOriginFromTable(object); PCALL_RES(lua_pcall(L, 3, 0, error_handler)); } else { lua_pop(L, 1); } lua_pop(L, 2); // Pop object and error handler } void ScriptApiEntity::luaentity_Remove(u16 id) { SCRIPTAPI_PRECHECKHEADER verbosestream << "scriptapi_luaentity_rm: id=" << id << std::endl; // Get core.luaentities table lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); // Set luaentities[id] = nil lua_pushnumber(L, id); // Push id lua_pushnil(L); lua_settable(L, objectstable); lua_pop(L, 2); // pop luaentities, core } std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // Get get_staticdata function lua_getfield(L, -1, "get_staticdata"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop entity and get_staticdata return ""; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self setOriginFromTable(object); PCALL_RES(lua_pcall(L, 1, 1, error_handler)); lua_remove(L, object); lua_remove(L, error_handler); size_t len = 0; const char *s = lua_tolstring(L, -1, &len); lua_pop(L, 1); // Pop static data return std::string(s, len); } void ScriptApiEntity::luaentity_GetProperties(u16 id, ObjectProperties *prop) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl; // Get core.luaentities[id] luaentity_get(L, id); // Set default values that differ from ObjectProperties defaults prop->hp_max = 10; /* Read stuff */ prop->hp_max = getintfield_default(L, -1, "hp_max", 10); getboolfield(L, -1, "physical", prop->physical); getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects); getfloatfield(L, -1, "weight", prop->weight); lua_getfield(L, -1, "collisionbox"); if (lua_istable(L, -1)) prop->collisionbox = read_aabb3f(L, -1, 1.0); lua_pop(L, 1); getstringfield(L, -1, "visual", prop->visual); getstringfield(L, -1, "mesh", prop->mesh); // Deprecated: read object properties directly read_object_properties(L, -1, prop, getServer()->idef()); // Read initial_properties lua_getfield(L, -1, "initial_properties"); read_object_properties(L, -1, prop, getServer()->idef()); lua_pop(L, 1); } void ScriptApiEntity::luaentity_Step(u16 id, float dtime) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // State: object is at top of stack // Get step function lua_getfield(L, -1, "on_step"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop on_step and entity return; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self lua_pushnumber(L, dtime); // dtime setOriginFromTable(object); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 2); // Pop object and error handler } // Calls entity:on_punch(ObjectRef puncher, time_from_last_punch, // tool_capabilities, direction, damage) bool ScriptApiEntity::luaentity_Punch(u16 id, ServerActiveObject *puncher, float time_from_last_punch, const ToolCapabilities *toolcap, v3f dir, s16 damage) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L,id); int object = lua_gettop(L); // State: object is at top of stack // Get function lua_getfield(L, -1, "on_punch"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop on_punch and entity return false; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self objectrefGetOrCreate(L, puncher); // Clicker reference lua_pushnumber(L, time_from_last_punch); push_tool_capabilities(L, *toolcap); push_v3f(L, dir); lua_pushnumber(L, damage); setOriginFromTable(object); PCALL_RES(lua_pcall(L, 6, 1, error_handler)); bool retval = lua_toboolean(L, -1); lua_pop(L, 2); // Pop object and error handler return retval; } // Calls entity:on_rightclick(ObjectRef clicker) void ScriptApiEntity::luaentity_Rightclick(u16 id, ServerActiveObject *clicker) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // State: object is at top of stack // Get function lua_getfield(L, -1, "on_rightclick"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop on_rightclick and entity return; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self objectrefGetOrCreate(L, clicker); // Clicker reference setOriginFromTable(object); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 2); // Pop object and error handler }