Skip to content

Commit dac40af

Browse files
kaezaparamat
authored andcommittedJun 11, 2016
Server: Add reason for leave to on_leaveplayer callbacks
1 parent b24d21d commit dac40af

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed
 

‎doc/lua_api.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1912,8 +1912,9 @@ Call these functions only at load time!
19121912
* If it returns a string, the player is disconnected with that string as reason
19131913
* `minetest.register_on_joinplayer(func(ObjectRef))`
19141914
* Called when a player joins the game
1915-
* `minetest.register_on_leaveplayer(func(ObjectRef))`
1915+
* `minetest.register_on_leaveplayer(func(ObjectRef, timed_out))`
19161916
* Called when a player leaves the game
1917+
* `timed_out`: True for timeout, false for other reasons.
19171918
* `minetest.register_on_cheat(func(ObjectRef, cheat))`
19181919
* Called when a player cheats
19191920
* `cheat`: `{type=<cheat_type>}`, where `<cheat_type>` is one of:

‎src/script/cpp_api/s_player.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player)
135135
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
136136
}
137137

138-
void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player)
138+
void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player,
139+
bool timeout)
139140
{
140141
SCRIPTAPI_PRECHECKHEADER
141142

@@ -144,7 +145,8 @@ void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player)
144145
lua_getfield(L, -1, "registered_on_leaveplayers");
145146
// Call callbacks
146147
objectrefGetOrCreate(L, player);
147-
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
148+
lua_pushboolean(L, timeout);
149+
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
148150
}
149151

150152
void ScriptApiPlayer::on_cheat(ServerActiveObject *player,

‎src/script/cpp_api/s_player.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ScriptApiPlayer
3838
bool on_prejoinplayer(const std::string &name, const std::string &ip,
3939
std::string *reason);
4040
void on_joinplayer(ServerActiveObject *player);
41-
void on_leaveplayer(ServerActiveObject *player);
41+
void on_leaveplayer(ServerActiveObject *player, bool timeout);
4242
void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
4343
bool on_punchplayer(ServerActiveObject *player,
4444
ServerActiveObject *hitter, float time_from_last_punch,

‎src/server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason)
26832683
PlayerSAO *playersao = player->getPlayerSAO();
26842684
assert(playersao);
26852685

2686-
m_script->on_leaveplayer(playersao);
2686+
m_script->on_leaveplayer(playersao, reason == CDR_TIMEOUT);
26872687

26882688
playersao->disconnected();
26892689
}

0 commit comments

Comments
 (0)
Please sign in to comment.