1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Add server/client annotations to settingtypes.txt and make use of them (#15756)

This commit is contained in:
grorp 2025-04-01 07:55:47 -04:00 committed by GitHub
parent 6724068659
commit c30c94dfaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 231 additions and 96 deletions

View file

@ -367,8 +367,7 @@ Client::~Client()
g_fontengine->clearMediaFonts();
}
void Client::connect(const Address &address, const std::string &address_name,
bool is_local_server)
void Client::connect(const Address &address, const std::string &address_name)
{
if (m_con) {
// can't do this if the connection has entered auth phase
@ -389,7 +388,7 @@ void Client::connect(const Address &address, const std::string &address_name,
m_con->Connect(address);
initLocalMapSaving(address, m_address_name, is_local_server);
initLocalMapSaving(address, m_address_name);
}
void Client::step(float dtime)
@ -917,11 +916,9 @@ void Client::request_media(const std::vector<std::string> &file_requests)
<< pkt.getSize() << ")" << std::endl;
}
void Client::initLocalMapSaving(const Address &address,
const std::string &hostname,
bool is_local_server)
void Client::initLocalMapSaving(const Address &address, const std::string &hostname)
{
if (!g_settings->getBool("enable_local_map_saving") || is_local_server) {
if (!g_settings->getBool("enable_local_map_saving") || m_internal_server) {
return;
}
if (m_localdb) {

View file

@ -140,8 +140,7 @@ public:
bool isShutdown();
void connect(const Address &address, const std::string &address_name,
bool is_local_server);
void connect(const Address &address, const std::string &address_name);
/*
Stuff that references the environment is valid only as
@ -338,8 +337,17 @@ public:
u16 getProtoVersion() const
{ return m_proto_ver; }
// Whether the server is in "simple singleplayer mode".
// This implies "m_internal_server = true".
bool m_simple_singleplayer_mode;
// Whether the server is hosted by the same Luanti instance and singletons
// like g_settings are shared between client and server.
//
// This is intentionally *not* true if we're just connecting to a localhost
// server hosted by a different Luanti instance.
bool m_internal_server;
float mediaReceiveProgress();
void drawLoadScreen(const std::wstring &text, float dtime, int percent);
@ -441,9 +449,7 @@ private:
void peerAdded(con::IPeer *peer) override;
void deletingPeer(con::IPeer *peer, bool timeout) override;
void initLocalMapSaving(const Address &address,
const std::string &hostname,
bool is_local_server);
void initLocalMapSaving(const Address &address, const std::string &hostname);
void ReceiveAll();

View file

@ -508,7 +508,7 @@ protected:
bool init(const std::string &map_dir, const std::string &address,
u16 port, const SubgameSpec &gamespec);
bool initSound();
bool createSingleplayerServer(const std::string &map_dir,
bool createServer(const std::string &map_dir,
const SubgameSpec &gamespec, u16 port);
void copyServerClientCache();
@ -908,7 +908,6 @@ bool Game::startup(bool *kill,
g_client_translations->clear();
// address can change if simple_singleplayer_mode
if (!init(start_data.world_spec.path, start_data.address,
start_data.socket_port, start_data.game_spec))
return false;
@ -1138,7 +1137,7 @@ bool Game::init(
// Create a server if not connecting to an existing one
if (address.empty()) {
if (!createSingleplayerServer(map_dir, gamespec, port))
if (!createServer(map_dir, gamespec, port))
return false;
}
@ -1173,7 +1172,7 @@ bool Game::initSound()
return true;
}
bool Game::createSingleplayerServer(const std::string &map_dir,
bool Game::createServer(const std::string &map_dir,
const SubgameSpec &gamespec, u16 port)
{
showOverlayMessage(N_("Creating server..."), 0, 5);
@ -1389,7 +1388,6 @@ bool Game::connectToServer(const GameStartData &start_data,
{
*connect_ok = false; // Let's not be overly optimistic
*connection_aborted = false;
bool local_server_mode = false;
const auto &address_name = start_data.address;
showOverlayMessage(N_("Resolving address..."), 0, 15);
@ -1409,7 +1407,6 @@ bool Game::connectToServer(const GameStartData &start_data,
} else {
connect_address.setAddress(127, 0, 0, 1);
}
local_server_mode = true;
}
} catch (ResolveError &e) {
*error_message = fmtgettext("Couldn't resolve address: %s", e.what());
@ -1455,13 +1452,13 @@ bool Game::connectToServer(const GameStartData &start_data,
client->migrateModStorage();
client->m_simple_singleplayer_mode = simple_singleplayer_mode;
client->m_internal_server = !!server;
/*
Wait for server to accept connection
*/
client->connect(connect_address, address_name,
simple_singleplayer_mode || local_server_mode);
client->connect(connect_address, address_name);
try {
input->clear();
@ -1508,12 +1505,11 @@ bool Game::connectToServer(const GameStartData &start_data,
}
wait_time += dtime;
if (local_server_mode) {
if (server) {
// never time out
} else if (wait_time > GAME_FALLBACK_TIMEOUT && !did_fallback) {
if (!client->hasServerReplied() && fallback_address.isValid()) {
client->connect(fallback_address, address_name,
simple_singleplayer_mode || local_server_mode);
client->connect(fallback_address, address_name);
}
did_fallback = true;
} else if (wait_time > GAME_CONNECTION_TIMEOUT) {

View file

@ -25,6 +25,7 @@ enum class ELoginRegister {
};
// Information processed by main menu
// TODO: unify with MainMenuData
struct GameStartData : GameParams
{
GameStartData() = default;
@ -33,7 +34,11 @@ struct GameStartData : GameParams
std::string name;
std::string password;
// If empty, we're hosting a server.
// This may or may not be in "simple singleplayer mode".
std::string address;
// If true, we're hosting a server and are *not* in "simple singleplayer
// mode".
bool local_server;
ELoginRegister allow_login_or_register = ELoginRegister::Any;

View file

@ -16,10 +16,13 @@ struct MainMenuDataForScript {
std::string errormessage = "";
};
// TODO: unify with GameStartData
struct MainMenuData {
// Client options
std::string servername;
std::string serverdescription;
// If empty, we're hosting a server.
// This may or may not be in "simple singleplayer mode".
std::string address;
std::string port;
std::string name;
@ -29,6 +32,7 @@ struct MainMenuData {
// Server options
int selected_world = 0;
// If true, we're hosting a server and *are* in "simple singleplayer mode".
bool simple_singleplayer_mode = false;
// Data to be passed to the script

View file

@ -5,6 +5,7 @@
#include "l_pause_menu.h"
#include "gui/mainmenumanager.h"
#include "lua_api/l_internal.h"
#include "client/client.h"
int ModApiPauseMenu::l_show_keys_menu(lua_State *L)
@ -21,8 +22,16 @@ int ModApiPauseMenu::l_show_touchscreen_layout(lua_State *L)
}
int ModApiPauseMenu::l_is_internal_server(lua_State *L)
{
lua_pushboolean(L, getClient(L)->m_internal_server);
return 1;
}
void ModApiPauseMenu::Initialize(lua_State *L, int top)
{
API_FCT(show_keys_menu);
API_FCT(show_touchscreen_layout);
API_FCT(is_internal_server);
}

View file

@ -11,6 +11,7 @@ class ModApiPauseMenu: public ModApiBase
private:
static int l_show_keys_menu(lua_State *L);
static int l_show_touchscreen_layout(lua_State *L);
static int l_is_internal_server(lua_State *L);
public:
static void Initialize(lua_State *L, int top);