2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2010-2016 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
// Copyright (C) 2014-2016 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
|
2016-10-08 19:08:23 +02:00
|
|
|
|
|
|
|
#include "remoteplayer.h"
|
2017-01-27 08:59:30 +01:00
|
|
|
#include <json/json.h>
|
2016-10-08 19:08:23 +02:00
|
|
|
#include "filesys.h"
|
|
|
|
#include "gamedef.h"
|
|
|
|
#include "porting.h" // strlcpy
|
2017-01-27 08:59:30 +01:00
|
|
|
#include "server.h"
|
2016-10-08 19:08:23 +02:00
|
|
|
#include "settings.h"
|
2017-09-26 20:30:14 +02:00
|
|
|
#include "convert_json.h"
|
2020-04-11 09:59:09 +02:00
|
|
|
#include "server/player_sao.h"
|
2016-10-08 19:08:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
RemotePlayer
|
|
|
|
*/
|
2022-01-22 13:37:26 +01:00
|
|
|
|
2016-10-08 19:08:23 +02:00
|
|
|
// static config cache for remoteplayer
|
|
|
|
bool RemotePlayer::m_setting_cache_loaded = false;
|
|
|
|
float RemotePlayer::m_setting_chat_message_limit_per_10sec = 0.0f;
|
|
|
|
u16 RemotePlayer::m_setting_chat_message_limit_trigger_kick = 0;
|
|
|
|
|
2023-11-12 15:25:46 +01:00
|
|
|
RemotePlayer::RemotePlayer(const std::string &name, IItemDefManager *idef):
|
2017-06-18 19:55:15 +02:00
|
|
|
Player(name, idef)
|
2016-10-08 19:08:23 +02:00
|
|
|
{
|
|
|
|
if (!RemotePlayer::m_setting_cache_loaded) {
|
|
|
|
RemotePlayer::m_setting_chat_message_limit_per_10sec =
|
|
|
|
g_settings->getFloat("chat_message_limit_per_10sec");
|
|
|
|
RemotePlayer::m_setting_chat_message_limit_trigger_kick =
|
|
|
|
g_settings->getU16("chat_message_limit_trigger_kick");
|
|
|
|
RemotePlayer::m_setting_cache_loaded = true;
|
|
|
|
}
|
2022-01-22 13:37:26 +01:00
|
|
|
|
2016-10-08 19:08:23 +02:00
|
|
|
movement_acceleration_default = g_settings->getFloat("movement_acceleration_default") * BS;
|
|
|
|
movement_acceleration_air = g_settings->getFloat("movement_acceleration_air") * BS;
|
|
|
|
movement_acceleration_fast = g_settings->getFloat("movement_acceleration_fast") * BS;
|
|
|
|
movement_speed_walk = g_settings->getFloat("movement_speed_walk") * BS;
|
|
|
|
movement_speed_crouch = g_settings->getFloat("movement_speed_crouch") * BS;
|
|
|
|
movement_speed_fast = g_settings->getFloat("movement_speed_fast") * BS;
|
|
|
|
movement_speed_climb = g_settings->getFloat("movement_speed_climb") * BS;
|
|
|
|
movement_speed_jump = g_settings->getFloat("movement_speed_jump") * BS;
|
|
|
|
movement_liquid_fluidity = g_settings->getFloat("movement_liquid_fluidity") * BS;
|
|
|
|
movement_liquid_fluidity_smooth = g_settings->getFloat("movement_liquid_fluidity_smooth") * BS;
|
|
|
|
movement_liquid_sink = g_settings->getFloat("movement_liquid_sink") * BS;
|
|
|
|
movement_gravity = g_settings->getFloat("movement_gravity") * BS;
|
2017-03-17 10:39:47 +01:00
|
|
|
|
2019-08-21 22:47:45 +02:00
|
|
|
// Skybox defaults:
|
2022-01-22 13:37:26 +01:00
|
|
|
m_cloud_params = SkyboxDefaults::getCloudDefaults();
|
2022-01-22 12:42:49 +01:00
|
|
|
m_skybox_params = SkyboxDefaults::getSkyDefaults();
|
2022-01-22 13:37:26 +01:00
|
|
|
m_sun_params = SkyboxDefaults::getSunDefaults();
|
|
|
|
m_moon_params = SkyboxDefaults::getMoonDefaults();
|
|
|
|
m_star_params = SkyboxDefaults::getStarDefaults();
|
2016-10-08 19:08:23 +02:00
|
|
|
}
|
|
|
|
|
2024-02-02 22:13:24 +01:00
|
|
|
RemotePlayer::~RemotePlayer()
|
|
|
|
{
|
|
|
|
if (m_sao)
|
|
|
|
m_sao->setPlayer(nullptr);
|
|
|
|
}
|
2016-10-08 19:08:23 +02:00
|
|
|
|
2021-09-27 17:45:44 +02:00
|
|
|
RemotePlayerChatResult RemotePlayer::canSendChatMessage()
|
2016-10-08 19:08:23 +02:00
|
|
|
{
|
|
|
|
// Rate limit messages
|
|
|
|
u32 now = time(NULL);
|
|
|
|
float time_passed = now - m_last_chat_message_sent;
|
|
|
|
m_last_chat_message_sent = now;
|
|
|
|
|
|
|
|
// If this feature is disabled
|
|
|
|
if (m_setting_chat_message_limit_per_10sec <= 0.0) {
|
|
|
|
return RPLAYER_CHATRESULT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_chat_message_allowance += time_passed * (m_setting_chat_message_limit_per_10sec / 8.0f);
|
|
|
|
if (m_chat_message_allowance > m_setting_chat_message_limit_per_10sec) {
|
|
|
|
m_chat_message_allowance = m_setting_chat_message_limit_per_10sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_chat_message_allowance < 1.0f) {
|
|
|
|
infostream << "Player " << m_name
|
|
|
|
<< " chat limited due to excessive message amount." << std::endl;
|
|
|
|
|
|
|
|
// Kick player if flooding is too intensive
|
|
|
|
m_message_rate_overhead++;
|
|
|
|
if (m_message_rate_overhead > RemotePlayer::m_setting_chat_message_limit_trigger_kick) {
|
|
|
|
return RPLAYER_CHATRESULT_KICK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RPLAYER_CHATRESULT_FLOODING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reinit message overhead
|
|
|
|
if (m_message_rate_overhead > 0) {
|
|
|
|
m_message_rate_overhead = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_chat_message_allowance -= 1.0f;
|
|
|
|
return RPLAYER_CHATRESULT_OK;
|
|
|
|
}
|
2019-01-04 10:20:04 +01:00
|
|
|
|
2019-01-04 11:33:04 +01:00
|
|
|
void RemotePlayer::onSuccessfulSave()
|
2019-01-04 10:20:04 +01:00
|
|
|
{
|
|
|
|
setModified(false);
|
|
|
|
if (m_sao)
|
|
|
|
m_sao->getMeta().setModified(false);
|
|
|
|
}
|