aboutsummaryrefslogtreecommitdiff
path: root/clientmods
Commit message (Expand)AuthorAge
* [CSM] Fix and improve minetest.get_language()sfan52019-11-11
* [CSM] Implement minetest.get_csm_restrictions()sfan52019-11-11
* Run on_item_use CSM callback even if item is not marked usablesfan52019-11-11
* [CSM] Expose more env functionssfan52019-11-11
* Be lenient with extra slashes for CSM pathssfan52019-11-09
* [CSM] Remove non-functional minetest.get_day_count()sfan52019-11-09
* Introduce get_modpath() for CSMsfan52019-11-09
* CSM/SSM: Add on_mods_loaded callback (#7411)Loïc Blot2018-06-06
* [CSM] Remove `on_connect` callback (#6941)red-0012018-01-21
* [CSM] Add basic HUD manipulation. (#6067)red-0012018-01-20
* [CSM] Add callback on open inventory (#5793)Vincent Glize2017-10-02
* preview: try to send mod channel messages 4 seconds after joining, not after ...Loic Blot2017-09-26
* Implement mod communication channels (#6351)Loïc Blot2017-09-26
* Create a filesystem abstraction layer for CSM and only allow accessing files ...red-0012017-06-30
* CSM: Fix documentation error for register_on_*_chat_messages (#5917)DS2017-06-09
* [CSM] Add function to get player privileges (#5933)red-0012017-06-07
* [CSM] Fix crash when the minimap is disabled. Caused by e25a38eSmallJoker2017-05-20
* [CSM] add `on_item_use` (#5544)red-0012017-05-06
* Add function to get server info.red-0012017-05-04
* [CSM] Add event on_place_node API lua (#5548)Vincent Glize2017-04-29
* [CSM] Add function to set minimap shape (#5569)bigfoot5472017-04-14
* [CSM] Move `.list_players` and `.disconnect` to builtin. (#5550)red-0012017-04-10
* [CSM] Add event on_connect player API lua (#5540)Vincent Glize2017-04-08
* [CSM] Add function to get the server protocol version. (#5529)red-0012017-04-06
* [CSM] Add function and chat command to disconnect from server. (#5487)red-0012017-04-01
* [CSM] Add function to get player names in range (#5435)bigfoot5472017-03-22
* Give CSM access to use `core.colorize()` (#5113)red-0012017-03-17
* [CSM] Fix minimap problems (#5405)Loïc Blot2017-03-17
* [CSM] Add core.get_timeofday & core.get_day_count env calls (#5401)Loïc Blot2017-03-17
* [CSM] Add minimap API modifiers (#5399)Loïc Blot2017-03-16
* Add ModStorageAPI to client side modding (#5396)Loïc Blot2017-03-16
* Add `get_wielded_item`red-0012017-03-13
* [CSM] Add `on_punchnode` callbackred-0012017-03-13
* [CSM] Add `get_node` and `get_node_or_nil`red-0012017-03-13
* [CSM] Add `on_dignode` callback (#5140)red-0012017-03-13
* [CSM] storage + fixesLoic Blot2017-03-13
* [CSM] implement client side mod loading (#5123)Loïc Blot2017-03-13
wd">PCALL_RES(lua_pcall(L, 1, 1, error_handler)); lua_remove(L, -2); // Remove auth handler lua_remove(L, error_handler); // nil = login not allowed if (lua_isnil(L, -1)) return false; luaL_checktype(L, -1, LUA_TTABLE); std::string password; if (!getstringfield(L, -1, "password", password)) throw LuaError("Authentication handler didn't return password"); if (dst_password) *dst_password = password; lua_getfield(L, -1, "privileges"); if (!lua_istable(L, -1)) throw LuaError("Authentication handler didn't return privilege table"); if (dst_privs) readPrivileges(-1, *dst_privs); lua_pop(L, 1); // Remove key from privs table s64 last_login; if(!getintfield(L, -1, "last_login", last_login)) throw LuaError("Authentication handler didn't return last_login"); if (dst_last_login) *dst_last_login = (s64)last_login; return true; } void ScriptApiServer::getAuthHandler() { lua_State *L = getStack(); lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_auth_handler"); if (lua_isnil(L, -1)){ lua_pop(L, 1); lua_getfield(L, -1, "builtin_auth_handler"); } setOriginFromTable(-1); lua_remove(L, -2); // Remove core if (lua_type(L, -1) != LUA_TTABLE) throw LuaError("Authentication handler table not valid"); } void ScriptApiServer::readPrivileges(int index, std::set<std::string> &result) { lua_State *L = getStack(); result.clear(); lua_pushnil(L); if (index < 0) index -= 1; while (lua_next(L, index) != 0) { // key at index -2 and value at index -1 std::string key = luaL_checkstring(L, -2); bool value = readParam<bool>(L, -1); if (value) result.insert(key); // removes value, keeps key for next iteration lua_pop(L, 1); } } void ScriptApiServer::createAuth(const std::string &playername, const std::string &password) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); getAuthHandler(); lua_getfield(L, -1, "create_auth"); lua_remove(L, -2); // Remove auth handler if (lua_type(L, -1) != LUA_TFUNCTION) throw LuaError("Authentication handler missing create_auth"); lua_pushstring(L, playername.c_str()); lua_pushstring(L, password.c_str()); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 1); // Pop error handler } bool ScriptApiServer::setPassword(const std::string &playername, const std::string &password) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); getAuthHandler(); lua_getfield(L, -1, "set_password"); lua_remove(L, -2); // Remove auth handler if (lua_type(L, -1) != LUA_TFUNCTION) throw LuaError("Authentication handler missing set_password"); lua_pushstring(L, playername.c_str()); lua_pushstring(L, password.c_str()); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); lua_remove(L, error_handler); return lua_toboolean(L, -1); } bool ScriptApiServer::on_chat_message(const std::string &name, const std::string &message) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_chat_messages lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_chat_messages"); // Call callbacks lua_pushstring(L, name.c_str()); lua_pushstring(L, message.c_str()); runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC); return readParam<bool>(L, -1); } void ScriptApiServer::on_mods_loaded() { SCRIPTAPI_PRECHECKHEADER // Get registered shutdown hooks lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_mods_loaded"); // Call callbacks runCallbacks(0, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiServer::on_shutdown() { SCRIPTAPI_PRECHECKHEADER // Get registered shutdown hooks lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_shutdown"); // Call callbacks runCallbacks(0, RUN_CALLBACKS_MODE_FIRST); } std::string ScriptApiServer::formatChatMessage(const std::string &name, const std::string &message) { SCRIPTAPI_PRECHECKHEADER // Push function onto stack lua_getglobal(L, "core"); lua_getfield(L, -1, "format_chat_message"); // Push arguments onto stack lua_pushstring(L, name.c_str()); lua_pushstring(L, message.c_str()); // Actually call the function lua_call(L, 2, 1); // Fetch return value std::string ret = lua_tostring(L, -1); lua_pop(L, 1); return ret; }