mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Merge remote-tracking branch 'upstream/master' into Visuals-Vol-2
This commit is contained in:
commit
00ef9b14d0
1043 changed files with 44800 additions and 28934 deletions
101
src/server.cpp
101
src/server.cpp
|
@ -1,21 +1,6 @@
|
|||
/*
|
||||
Minetest
|
||||
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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.
|
||||
*/
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
#include "server.h"
|
||||
#include <iostream>
|
||||
|
@ -147,7 +132,8 @@ void *ServerThread::run()
|
|||
|
||||
try {
|
||||
// see explanation inside
|
||||
if (dtime > step_settings.steplen)
|
||||
// (+1 ms, because we don't sleep more fine-grained)
|
||||
if (dtime > step_settings.steplen + 0.001f)
|
||||
m_server->yieldToOtherThreads(dtime);
|
||||
|
||||
m_server->AsyncRunStep(step_settings.pause ? 0.0f : dtime);
|
||||
|
@ -586,12 +572,11 @@ void Server::start()
|
|||
|
||||
// ASCII art for the win!
|
||||
const char *art[] = {
|
||||
" __. __. __. ",
|
||||
" _____ |__| ____ _____ / |_ _____ _____ / |_ ",
|
||||
" / \\| |/ \\ / __ \\ _\\/ __ \\/ __> _\\",
|
||||
"| Y Y \\ | | \\ ___/| | | ___/\\___ \\| | ",
|
||||
"|__|_| / |___| /\\______> | \\______>_____/| | ",
|
||||
" \\/ \\/ \\/ \\/ \\/ "
|
||||
R"( _ _ _ )",
|
||||
R"(| |_ _ __ _ _ __ | |_(_))",
|
||||
R"(| | | | |/ _` | '_ \| __| |)",
|
||||
R"(| | |_| | (_| | | | | |_| |)",
|
||||
R"(|_|\__,_|\__,_|_| |_|\__|_|)",
|
||||
};
|
||||
|
||||
if (!m_admin_chat) {
|
||||
|
@ -1084,15 +1069,15 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
|
|||
m_shutdown_state.tick(dtime, this);
|
||||
}
|
||||
|
||||
void Server::Receive(float timeout)
|
||||
void Server::Receive(float min_time)
|
||||
{
|
||||
ZoneScoped;
|
||||
auto framemarker = FrameMarker("Server::Receive()-frame").started();
|
||||
|
||||
const u64 t0 = porting::getTimeUs();
|
||||
const float timeout_us = timeout * 1e6f;
|
||||
const float min_time_us = min_time * 1e6f;
|
||||
auto remaining_time_us = [&]() -> float {
|
||||
return std::max(0.0f, timeout_us - (porting::getTimeUs() - t0));
|
||||
return std::max(0.0f, min_time_us - (porting::getTimeUs() - t0));
|
||||
};
|
||||
|
||||
NetworkPacket pkt;
|
||||
|
@ -1101,15 +1086,17 @@ void Server::Receive(float timeout)
|
|||
pkt.clear();
|
||||
peer_id = 0;
|
||||
try {
|
||||
if (!m_con->ReceiveTimeoutMs(&pkt,
|
||||
(u32)remaining_time_us() / 1000)) {
|
||||
// Round up since the target step length is the minimum step length,
|
||||
// we only have millisecond precision and we don't want to busy-wait
|
||||
// by calling ReceiveTimeoutMs(.., 0) repeatedly.
|
||||
const u32 cur_timeout_ms = std::ceil(remaining_time_us() / 1000.0f);
|
||||
|
||||
if (!m_con->ReceiveTimeoutMs(&pkt, cur_timeout_ms)) {
|
||||
// No incoming data.
|
||||
// Already break if there's 1ms left, as ReceiveTimeoutMs is too coarse
|
||||
// and a faster server-step is better than busy waiting.
|
||||
if (remaining_time_us() < 1000.0f)
|
||||
break;
|
||||
else
|
||||
if (remaining_time_us() > 0.0f)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
peer_id = pkt.getPeerId();
|
||||
|
@ -2542,11 +2529,11 @@ bool Server::addMediaFile(const std::string &filename,
|
|||
}
|
||||
// If name is not in a supported format, ignore it
|
||||
const char *supported_ext[] = {
|
||||
".png", ".jpg", ".bmp", ".tga",
|
||||
".png", ".jpg", ".tga",
|
||||
".ogg",
|
||||
".x", ".b3d", ".obj", ".gltf", ".glb",
|
||||
// Custom translation file format
|
||||
".tr",
|
||||
// Translation file formats
|
||||
".tr", ".po", ".mo",
|
||||
NULL
|
||||
};
|
||||
if (removeStringEnd(filename, supported_ext).empty()) {
|
||||
|
@ -2568,13 +2555,6 @@ bool Server::addMediaFile(const std::string &filename,
|
|||
return false;
|
||||
}
|
||||
|
||||
const char *deprecated_ext[] = { ".bmp", nullptr };
|
||||
if (!removeStringEnd(filename, deprecated_ext).empty())
|
||||
{
|
||||
warningstream << "Media file \"" << filename << "\" is using a"
|
||||
" deprecated format and will stop working in the future." << std::endl;
|
||||
}
|
||||
|
||||
SHA1 sha1;
|
||||
sha1.addBytes(filedata);
|
||||
|
||||
|
@ -2629,14 +2609,20 @@ void Server::fillMediaCache()
|
|||
|
||||
void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_code)
|
||||
{
|
||||
std::string lang_suffix = ".";
|
||||
lang_suffix.append(lang_code).append(".tr");
|
||||
std::string translation_formats[3] = { ".tr", ".po", ".mo" };
|
||||
std::string lang_suffixes[3];
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
lang_suffixes[i].append(".").append(lang_code).append(translation_formats[i]);
|
||||
}
|
||||
|
||||
auto include = [&] (const std::string &name, const MediaInfo &info) -> bool {
|
||||
auto include = [&] (const std::string &name, const MediaInfo &info) -> bool {
|
||||
if (info.no_announce)
|
||||
return false;
|
||||
if (str_ends_with(name, ".tr") && !str_ends_with(name, lang_suffix))
|
||||
return false;
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
if (str_ends_with(name, translation_formats[j]) && !str_ends_with(name, lang_suffixes[j])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -3063,6 +3049,8 @@ std::wstring Server::handleChat(const std::string &name,
|
|||
if (g_settings->getBool("strip_color_codes"))
|
||||
wmessage = unescape_enriched(wmessage);
|
||||
|
||||
wmessage = trim(wmessage);
|
||||
|
||||
if (player) {
|
||||
switch (player->canSendChatMessage()) {
|
||||
case RPLAYER_CHATRESULT_FLOODING: {
|
||||
|
@ -3089,13 +3077,12 @@ std::wstring Server::handleChat(const std::string &name,
|
|||
L"It was refused. Send a shorter message";
|
||||
}
|
||||
|
||||
auto message = trim(wide_to_utf8(wmessage));
|
||||
auto message = wide_to_utf8(wmessage);
|
||||
if (message.empty())
|
||||
return L"";
|
||||
|
||||
if (message.find_first_of("\n\r") != std::wstring::npos) {
|
||||
if (message.find_first_of("\r\n") != std::string::npos)
|
||||
return L"Newlines are not permitted in chat messages";
|
||||
}
|
||||
|
||||
// Run script hook, exit if script ate the chat message
|
||||
if (m_script->on_chat_message(name, message))
|
||||
|
@ -3117,8 +3104,7 @@ std::wstring Server::handleChat(const std::string &name,
|
|||
#ifdef __ANDROID__
|
||||
line += L"<" + utf8_to_wide(name) + L"> " + wmessage;
|
||||
#else
|
||||
line += utf8_to_wide(m_script->formatChatMessage(name,
|
||||
wide_to_utf8(wmessage)));
|
||||
line += utf8_to_wide(m_script->formatChatMessage(name, message));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -4175,12 +4161,11 @@ Translations *Server::getTranslationLanguage(const std::string &lang_code)
|
|||
// [] will create an entry
|
||||
auto *translations = &server_translations[lang_code];
|
||||
|
||||
std::string suffix = "." + lang_code + ".tr";
|
||||
for (const auto &i : m_media) {
|
||||
if (str_ends_with(i.first, suffix)) {
|
||||
if (Translations::getFileLanguage(i.first) == lang_code) {
|
||||
std::string data;
|
||||
if (fs::ReadFile(i.second.path, data, true)) {
|
||||
translations->loadTranslation(data);
|
||||
translations->loadTranslation(i.first, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue