1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Rework client connecting and enable fallback address use

This commit is contained in:
sfan5 2024-01-01 18:15:58 +01:00
parent 20692d54de
commit 2c390b5473
5 changed files with 81 additions and 32 deletions

View file

@ -97,7 +97,6 @@ void PacketCounter::print(std::ostream &o) const
Client::Client(
const char *playername,
const std::string &password,
const std::string &address_name,
MapDrawControl &control,
IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc,
@ -106,7 +105,6 @@ Client::Client(
ISoundManager *sound,
MtEventManager *event,
RenderingEngine *rendering_engine,
bool ipv6,
GameUI *game_ui,
ELoginRegister allow_login_or_register
):
@ -123,8 +121,6 @@ Client::Client(
tsrc, this
),
m_particle_manager(std::make_unique<ParticleManager>(&m_env)),
m_con(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this)),
m_address_name(address_name),
m_allow_login_or_register(allow_login_or_register),
m_server_ser_ver(SER_FMT_VER_INVALID),
m_last_chat_message_sent(time(NULL)),
@ -338,7 +334,8 @@ bool Client::isShutdown()
Client::~Client()
{
m_shutdown = true;
m_con->Disconnect();
if (m_con)
m_con->Disconnect();
deleteAuthData();
@ -381,13 +378,32 @@ Client::~Client()
m_sounds_client_to_server.clear();
}
void Client::connect(Address address, bool is_local_server)
void Client::connect(const Address &address, const std::string &address_name,
bool is_local_server)
{
initLocalMapSaving(address, m_address_name, is_local_server);
if (m_con) {
// can't do this if the connection has entered auth phase
sanity_check(m_state == LC_Created && m_proto_ver == 0);
infostream << "Client connection will be recreated" << std::endl;
m_access_denied = false;
m_access_denied_reconnect = false;
m_access_denied_reason.clear();
}
m_address_name = address_name;
m_con.reset(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT,
address.isIPv6(), this));
infostream << "Connecting to server at ";
address.print(infostream);
infostream << std::endl;
// Since we use TryReceive() a timeout here would be ineffective anyway
m_con->SetTimeoutMs(0);
m_con->Connect(address);
initLocalMapSaving(address, m_address_name, is_local_server);
}
void Client::step(float dtime)
@ -908,6 +924,10 @@ void Client::initLocalMapSaving(const Address &address,
if (!g_settings->getBool("enable_local_map_saving") || is_local_server) {
return;
}
if (m_localdb) {
infostream << "Local map saving already running" << std::endl;
return;
}
std::string world_path;
#define set_world_path(hostname) \
@ -935,6 +955,8 @@ void Client::ReceiveAll()
NetworkPacket pkt;
u64 start_ms = porting::getTimeMs();
const u64 budget = 10;
FATAL_ERROR_IF(!m_con, "Networking not initialized");
for(;;) {
// Limit time even if there would be huge amounts of data to
// process
@ -1767,7 +1789,7 @@ ClientEvent *Client::getClientEvent()
const Address Client::getServerAddress()
{
return m_con->GetPeerAddress(PEER_ID_SERVER);
return m_con ? m_con->GetPeerAddress(PEER_ID_SERVER) : Address();
}
float Client::mediaReceiveProgress()
@ -1873,11 +1895,13 @@ void Client::afterContentReceived()
float Client::getRTT()
{
assert(m_con);
return m_con->getPeerStat(PEER_ID_SERVER,con::AVG_RTT);
}
float Client::getCurRate()
{
assert(m_con);
return (m_con->getLocalStat(con::CUR_INC_RATE) +
m_con->getLocalStat(con::CUR_DL_RATE));
}