aboutsummaryrefslogtreecommitdiff
path: root/src/network/connectionthreads.cpp
Commit message (Collapse)AuthorAge
* Revert RTT fixes (#8187)ANAND2019-02-15
| | | | | The reverted commit 968ce9af598024ec71e9ffb2d15c3997a13ad754 is suspected (through the use of bisection) of causing network slowdowns. Revert for now as we are close to release.
* Remove legacy client handling code.Lars Hofhansl2018-07-14
|
* Ensure that legacy mode is correctly disabled.Lars Hofhansl2018-07-13
|
* Fix rtt >= 0.0f assertion and free_move crashSmallJoker2018-06-24
|
* RTT fixes (#7428)you2018-06-23
| | | | | | | | | | | | * Few code updates * Do not show average RTT before timing out * Fix unwanted integer division in RTTStatistics * Fix float format, prettier jitter calculation * Use +=, 0.1f -> 100.0f for stronger average updates
* Fix wrong channel number representation in logs (#7205)SmallJoker2018-04-18
|
* Add session_t typedef + remove unused functions (#6470)Loïc Blot2017-09-27
| | | | | | * Add session_t typedef + remove unused functions u16 peer_id is used everywhere, to be more consistent and permit some evolutions on this type in the future (i'm working on a PoC), uniformize u16 peer_id to SessionId peer_id
* Network part requires SharedBuffers to be pass as valueLoic Blot2017-09-03
| | | | | | This can trigger unreproductible crashes due to concurrency problem on SharedBuffers This fixes #6354
* Pass SharedBuffer as value to increment reference countLoïc Blot2017-08-28
| | | | | This should fix #6332 Refcount is not increased due to reference, it can make this refcount incorrect in a multithread context
* Network cleanup (#6310)Loïc Blot2017-08-25
* Move Connection threads to dedicated files + various cleanups * ConnectionReceiveThread::processPacket now uses function pointer table to route MT packet types * Various code style fixes * Code style with clang-format * Various SharedBuffer copy removal * SharedBuffer cannot be copied anymore using Buffer * Fix many SharedBuffer copy (thanks to delete operator)
. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "cpp_api/s_player.h" #include "cpp_api/s_internal.h" #include "common/c_converter.h" #include "common/c_content.h" #include "util/string.h" void ScriptApiPlayer::on_newplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_newplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_newplayers"); // Call callbacks objectrefGetOrCreate(L, player); runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_dieplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_dieplayers"); // Call callbacks objectrefGetOrCreate(L, player); runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter, float time_from_last_punch, const ToolCapabilities *toolcap, v3f dir, s16 damage) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_punchplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_punchplayers"); // Call callbacks objectrefGetOrCreate(L, player); objectrefGetOrCreate(L, hitter); lua_pushnumber(L, time_from_last_punch); push_tool_capabilities(L, *toolcap); push_v3f(L, dir); lua_pushnumber(L, damage); runCallbacks(6, RUN_CALLBACKS_MODE_OR); return lua_toboolean(L, -1); } s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, s16 hp_change) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Get core.registered_on_player_hpchange lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_player_hpchange"); lua_remove(L, -2); objectrefGetOrCreate(L, player); lua_pushnumber(L, hp_change); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); hp_change = lua_tointeger(L, -1); lua_pop(L, 2); // Pop result and error handler return hp_change; } bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_respawnplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_respawnplayers"); // Call callbacks objectrefGetOrCreate(L, player); runCallbacks(1, RUN_CALLBACKS_MODE_OR); bool positioning_handled_by_some = lua_toboolean(L, -1); return positioning_handled_by_some; } bool ScriptApiPlayer::on_prejoinplayer( const std::string &name, const std::string &ip, std::string *reason) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_prejoinplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_prejoinplayers"); lua_pushstring(L, name.c_str()); lua_pushstring(L, ip.c_str()); runCallbacks(2, RUN_CALLBACKS_MODE_OR); if (lua_isstring(L, -1)) { reason->assign(lua_tostring(L, -1)); return true; } return false; } void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_joinplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_joinplayers"); // Call callbacks objectrefGetOrCreate(L, player); runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player, bool timeout) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_leaveplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_leaveplayers"); // Call callbacks objectrefGetOrCreate(L, player); lua_pushboolean(L, timeout); runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::on_cheat(ServerActiveObject *player, const std::string &cheat_type) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_cheats lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_cheats"); // Call callbacks objectrefGetOrCreate(L, player); lua_newtable(L); lua_pushlstring(L, cheat_type.c_str(), cheat_type.size()); lua_setfield(L, -2, "type"); runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, const StringMap &fields) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_chat_messages lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_player_receive_fields"); // Call callbacks // param 1 objectrefGetOrCreate(L, player); // param 2 lua_pushstring(L, formname.c_str()); // param 3 lua_newtable(L); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC); } ScriptApiPlayer::~ScriptApiPlayer() { }