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 "cpp_api/s_player.h"
22 void ScriptApiPlayer::on_newplayer(ServerActiveObject *player)
24 SCRIPTAPI_PRECHECKHEADER
26 // Get minetest.registered_on_newplayers
27 lua_getglobal(L, "minetest");
28 lua_getfield(L, -1, "registered_on_newplayers");
30 objectrefGetOrCreate(player);
31 runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
34 void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player)
36 SCRIPTAPI_PRECHECKHEADER
38 // Get minetest.registered_on_dieplayers
39 lua_getglobal(L, "minetest");
40 lua_getfield(L, -1, "registered_on_dieplayers");
42 objectrefGetOrCreate(player);
43 runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
46 bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player)
48 SCRIPTAPI_PRECHECKHEADER
50 // Get minetest.registered_on_respawnplayers
51 lua_getglobal(L, "minetest");
52 lua_getfield(L, -1, "registered_on_respawnplayers");
54 objectrefGetOrCreate(player);
55 runCallbacks(1, RUN_CALLBACKS_MODE_OR);
56 bool positioning_handled_by_some = lua_toboolean(L, -1);
57 return positioning_handled_by_some;
60 void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player)
62 SCRIPTAPI_PRECHECKHEADER
64 // Get minetest.registered_on_joinplayers
65 lua_getglobal(L, "minetest");
66 lua_getfield(L, -1, "registered_on_joinplayers");
68 objectrefGetOrCreate(player);
69 runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
72 void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player)
74 SCRIPTAPI_PRECHECKHEADER
76 // Get minetest.registered_on_leaveplayers
77 lua_getglobal(L, "minetest");
78 lua_getfield(L, -1, "registered_on_leaveplayers");
80 objectrefGetOrCreate(player);
81 runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
84 void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
85 const std::string &formname,
86 const std::map<std::string, std::string> &fields)
88 SCRIPTAPI_PRECHECKHEADER
90 // Get minetest.registered_on_chat_messages
91 lua_getglobal(L, "minetest");
92 lua_getfield(L, -1, "registered_on_player_receive_fields");
95 objectrefGetOrCreate(player);
97 lua_pushstring(L, formname.c_str());
100 for(std::map<std::string, std::string>::const_iterator
101 i = fields.begin(); i != fields.end(); i++){
102 const std::string &name = i->first;
103 const std::string &value = i->second;
104 lua_pushstring(L, name.c_str());
105 lua_pushlstring(L, value.c_str(), value.size());
108 runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC);
110 ScriptApiPlayer::~ScriptApiPlayer() {