3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "scripting_server.h"
24 #include "cpp_api/s_internal.h"
25 #include "lua_api/l_areastore.h"
26 #include "lua_api/l_auth.h"
27 #include "lua_api/l_base.h"
28 #include "lua_api/l_craft.h"
29 #include "lua_api/l_env.h"
30 #include "lua_api/l_inventory.h"
31 #include "lua_api/l_item.h"
32 #include "lua_api/l_itemstackmeta.h"
33 #include "lua_api/l_mapgen.h"
34 #include "lua_api/l_modchannels.h"
35 #include "lua_api/l_nodemeta.h"
36 #include "lua_api/l_nodetimer.h"
37 #include "lua_api/l_noise.h"
38 #include "lua_api/l_object.h"
39 #include "lua_api/l_playermeta.h"
40 #include "lua_api/l_particles.h"
41 #include "lua_api/l_rollback.h"
42 #include "lua_api/l_server.h"
43 #include "lua_api/l_util.h"
44 #include "lua_api/l_vmanip.h"
45 #include "lua_api/l_settings.h"
46 #include "lua_api/l_http.h"
47 #include "lua_api/l_storage.h"
53 ServerScripting::ServerScripting(Server* server):
54 ScriptApiBase(ScriptingType::Server)
58 // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
59 // once the environment has been created
61 SCRIPTAPI_PRECHECKHEADER
63 if (g_settings->getBool("secure.enable_security")) {
66 warningstream << "\\!/ Mod security should never be disabled, as it allows any mod to "
67 << "access the host machine."
68 << "Mods should use minetest.request_insecure_environment() instead \\!/" << std::endl;
71 lua_getglobal(L, "core");
72 int top = lua_gettop(L);
75 lua_setfield(L, -2, "object_refs");
78 lua_setfield(L, -2, "luaentities");
80 // Initialize our lua_api modules
81 InitializeModApi(L, top);
84 // Push builtin initialization type
85 lua_pushstring(L, "game");
86 lua_setglobal(L, "INIT");
88 infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
91 void ServerScripting::InitializeModApi(lua_State *L, int top)
93 // Register reference classes (userdata)
95 ItemStackMetaRef::Register(L);
96 LuaAreaStore::Register(L);
97 LuaItemStack::Register(L);
98 LuaPerlinNoise::Register(L);
99 LuaPerlinNoiseMap::Register(L);
100 LuaPseudoRandom::Register(L);
101 LuaPcgRandom::Register(L);
102 LuaRaycast::Register(L);
103 LuaSecureRandom::Register(L);
104 LuaVoxelManip::Register(L);
105 NodeMetaRef::Register(L);
106 NodeTimerRef::Register(L);
107 ObjectRef::Register(L);
108 PlayerMetaRef::Register(L);
109 LuaSettings::Register(L);
110 StorageRef::Register(L);
111 ModChannelRef::Register(L);
113 // Initialize mod api modules
114 ModApiAuth::Initialize(L, top);
115 ModApiCraft::Initialize(L, top);
116 ModApiEnvMod::Initialize(L, top);
117 ModApiInventory::Initialize(L, top);
118 ModApiItemMod::Initialize(L, top);
119 ModApiMapgen::Initialize(L, top);
120 ModApiParticles::Initialize(L, top);
121 ModApiRollback::Initialize(L, top);
122 ModApiServer::Initialize(L, top);
123 ModApiUtil::Initialize(L, top);
124 ModApiHttp::Initialize(L, top);
125 ModApiStorage::Initialize(L, top);
126 ModApiChannels::Initialize(L, top);