mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Add server/client annotations to settingtypes.txt and make use of them (#15756)
This commit is contained in:
parent
6724068659
commit
c30c94dfaa
12 changed files with 231 additions and 96 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue