]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/lua_api/l_server.cpp
Add server side ncurses terminal
[dragonfireclient.git] / src / script / lua_api / l_server.cpp
index 96c0327df0e9dff6c3ed529b085c54a27a03c4c7..59d3f5c70351274947e3fe7b9c159df5b519e05e 100644 (file)
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 // request_shutdown()
 int ModApiServer::l_request_shutdown(lua_State *L)
 {
+       NO_MAP_LOCK_REQUIRED;
        const char *msg = lua_tolstring(L, 1, NULL);
        bool reconnect = lua_toboolean(L, 2);
        getServer(L)->requestShutdown(msg ? msg : "", reconnect);
@@ -44,6 +45,16 @@ int ModApiServer::l_get_server_status(lua_State *L)
        return 1;
 }
 
+// print(text)
+int ModApiServer::l_print(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+       std::string text;
+       text = luaL_checkstring(L, 1);
+       getServer(L)->printToConsoleOnly(text);
+       return 0;
+}
+
 // chat_send_all(text)
 int ModApiServer::l_chat_send_all(lua_State *L)
 {
@@ -110,7 +121,7 @@ int ModApiServer::l_get_player_ip(lua_State *L)
        }
        catch(con::PeerNotFoundException) // unlikely
        {
-               dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+               dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
                lua_pushnil(L); // error
                return 1;
        }
@@ -136,7 +147,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
        }
        catch(con::PeerNotFoundException) // unlikely
        {
-               dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+               dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
                lua_pushnil(L); // error
                return 1;
        }
@@ -150,7 +161,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
 
 #define ERET(code)                                                             \
        if (!(code)) {                                                             \
-               dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;     \
+               dstream << FUNCTION_NAME << ": peer was not found" << std::endl;     \
                lua_pushnil(L); /* error */                                            \
                return 1;                                                              \
        }
@@ -281,7 +292,7 @@ int ModApiServer::l_ban_player(lua_State *L)
        }
        catch(con::PeerNotFoundException) // unlikely
        {
-               dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+               dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
                lua_pushboolean(L, false); // error
                return 1;
        }
@@ -345,7 +356,7 @@ int ModApiServer::l_show_formspec(lua_State *L)
 int ModApiServer::l_get_current_modname(lua_State *L)
 {
        NO_MAP_LOCK_REQUIRED;
-       lua_getfield(L, LUA_REGISTRYINDEX, SCRIPT_MOD_NAME_FIELD);
+       lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
        return 1;
 }
 
@@ -438,6 +449,31 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L)
        return 0;
 }
 
+// get_last_run_mod()
+int ModApiServer::l_get_last_run_mod(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+       lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
+       const char *current_mod = lua_tostring(L, -1);
+       if (current_mod == NULL || current_mod[0] == '\0') {
+               lua_pop(L, 1);
+               lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
+       }
+       return 1;
+}
+
+// set_last_run_mod(modname)
+int ModApiServer::l_set_last_run_mod(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+#ifdef SCRIPTAPI_DEBUG
+       const char *mod = lua_tostring(L, 1);
+       getScriptApiBase(L)->setOriginDirect(mod);
+       //printf(">>>> last mod set from Lua: %s\n", mod);
+#endif
+       return 0;
+}
+
 #ifndef NDEBUG
 // cause_error(type_of_error)
 int ModApiServer::l_cause_error(lua_State *L)
@@ -479,6 +515,8 @@ void ModApiServer::Initialize(lua_State *L, int top)
        API_FCT(get_modpath);
        API_FCT(get_modnames);
 
+       API_FCT(print);
+
        API_FCT(chat_send_all);
        API_FCT(chat_send_player);
        API_FCT(show_formspec);
@@ -495,6 +533,8 @@ void ModApiServer::Initialize(lua_State *L, int top)
        API_FCT(unban_player_or_ip);
        API_FCT(notify_authentication_modified);
 
+       API_FCT(get_last_run_mod);
+       API_FCT(set_last_run_mod);
 #ifndef NDEBUG
        API_FCT(cause_error);
 #endif