scripting_server.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "scripting_server.h"
  17. #include "server.h"
  18. #include "log.h"
  19. #include "settings.h"
  20. #include "cpp_api/s_internal.h"
  21. #include "lua_api/l_areastore.h"
  22. #include "lua_api/l_base.h"
  23. #include "lua_api/l_craft.h"
  24. #include "lua_api/l_env.h"
  25. #include "lua_api/l_inventory.h"
  26. #include "lua_api/l_item.h"
  27. #include "lua_api/l_itemstackmeta.h"
  28. #include "lua_api/l_mapgen.h"
  29. #include "lua_api/l_modchannels.h"
  30. #include "lua_api/l_nodemeta.h"
  31. #include "lua_api/l_nodetimer.h"
  32. #include "lua_api/l_noise.h"
  33. #include "lua_api/l_object.h"
  34. #include "lua_api/l_playermeta.h"
  35. #include "lua_api/l_particles.h"
  36. #include "lua_api/l_rollback.h"
  37. #include "lua_api/l_server.h"
  38. #include "lua_api/l_util.h"
  39. #include "lua_api/l_vmanip.h"
  40. #include "lua_api/l_settings.h"
  41. #include "lua_api/l_http.h"
  42. #include "lua_api/l_storage.h"
  43. extern "C" {
  44. #include "lualib.h"
  45. }
  46. ServerScripting::ServerScripting(Server* server):
  47. ScriptApiBase(ScriptingType::Server)
  48. {
  49. setGameDef(server);
  50. // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
  51. // once the environment has been created
  52. SCRIPTAPI_PRECHECKHEADER
  53. if (g_settings->getBool("secure.enable_security")) {
  54. initializeSecurity();
  55. }
  56. lua_getglobal(L, "core");
  57. int top = lua_gettop(L);
  58. lua_newtable(L);
  59. lua_setfield(L, -2, "object_refs");
  60. lua_newtable(L);
  61. lua_setfield(L, -2, "luaentities");
  62. // Initialize our lua_api modules
  63. InitializeModApi(L, top);
  64. lua_pop(L, 1);
  65. // Push builtin initialization type
  66. lua_pushstring(L, "game");
  67. lua_setglobal(L, "INIT");
  68. infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
  69. }
  70. void ServerScripting::InitializeModApi(lua_State *L, int top)
  71. {
  72. // Register reference classes (userdata)
  73. InvRef::Register(L);
  74. ItemStackMetaRef::Register(L);
  75. LuaAreaStore::Register(L);
  76. LuaItemStack::Register(L);
  77. LuaPerlinNoise::Register(L);
  78. LuaPerlinNoiseMap::Register(L);
  79. LuaPseudoRandom::Register(L);
  80. LuaPcgRandom::Register(L);
  81. LuaRaycast::Register(L);
  82. LuaSecureRandom::Register(L);
  83. LuaVoxelManip::Register(L);
  84. NodeMetaRef::Register(L);
  85. NodeTimerRef::Register(L);
  86. ObjectRef::Register(L);
  87. PlayerMetaRef::Register(L);
  88. LuaSettings::Register(L);
  89. StorageRef::Register(L);
  90. ModChannelRef::Register(L);
  91. // Initialize mod api modules
  92. ModApiCraft::Initialize(L, top);
  93. ModApiEnvMod::Initialize(L, top);
  94. ModApiInventory::Initialize(L, top);
  95. ModApiItemMod::Initialize(L, top);
  96. ModApiMapgen::Initialize(L, top);
  97. ModApiParticles::Initialize(L, top);
  98. ModApiRollback::Initialize(L, top);
  99. ModApiServer::Initialize(L, top);
  100. ModApiUtil::Initialize(L, top);
  101. ModApiHttp::Initialize(L, top);
  102. ModApiStorage::Initialize(L, top);
  103. ModApiChannels::Initialize(L, top);
  104. }
  105. void log_deprecated(const std::string &message)
  106. {
  107. log_deprecated(NULL, message);
  108. }