From 142e2d3b74ad886eed83b0fc9d6cfea100dae10a Mon Sep 17 00:00:00 2001 From: sapier Date: Thu, 13 Feb 2014 20:17:42 +0100 Subject: Cleanup client init states by bumping protocol version Don't use TOSERVER_RECEIVED_MEDIA but TOSERVER_CLIENT_READY as indicatio for client ready Handle clients with protocol version < 23 (almost) same way as before Make client tell server about it's version Add client state to not send bogus player position updates prior init complete Add access to statistics information (peer connction time,rtt,version) Fix clients standing stalled in world while preloading item visuals (new clients only) Add get_player_information to read client specific information from lua --- src/client.cpp | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index 654052ac0..5b3ebed66 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -47,6 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serialization.h" #include "util/serialize.h" #include "config.h" +#include "cmake_config_githash.h" #include "util/directiontables.h" #include "util/pointedthing.h" #include "version.h" @@ -252,7 +253,8 @@ Client::Client( m_last_time_of_day_f(-1), m_time_of_day_update_timer(0), m_recommended_send_interval(0.1), - m_removed_sounds_check_timer(0) + m_removed_sounds_check_timer(0), + m_state(LC_Created) { m_packetcounter_timer = 0.0; //m_delete_unused_sectors_timer = 0.0; @@ -325,17 +327,6 @@ void Client::connect(Address address) m_con.Connect(address); } -bool Client::connectedAndInitialized() -{ - if(m_con.Connected() == false) - return false; - - if(m_server_ser_ver == SER_FMT_VER_INVALID) - return false; - - return true; -} - void Client::step(float dtime) { DSTACK(__FUNCTION_NAME); @@ -372,9 +363,6 @@ void Client::step(float dtime) m_packetcounter.clear(); } } - - // Get connection status - bool connected = connectedAndInitialized(); #if 0 { @@ -467,7 +455,7 @@ void Client::step(float dtime) } #endif - if(connected == false) + if(m_state == LC_Created) { float &counter = m_connection_reinit_timer; counter -= dtime; @@ -632,7 +620,7 @@ void Client::step(float dtime) { counter = 0.0; // connectedAndInitialized() is true, peer exists. - float avg_rtt = m_con.GetPeerAvgRTT(PEER_ID_SERVER); + float avg_rtt = getRTT(); infostream<<"Client: avg_rtt="<= m_recommended_send_interval) + if((m_state == LC_Ready) && (counter >= m_recommended_send_interval)) { counter = 0.0; sendPlayerPos(); @@ -1051,6 +1039,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) // Send as reliable m_con.Send(PEER_ID_SERVER, 1, reply, true); + m_state = LC_Init; + return; } @@ -1937,7 +1927,7 @@ void Client::Send(u16 channelnum, SharedBuffer data, bool reliable) void Client::interact(u8 action, const PointedThing& pointed) { - if(connectedAndInitialized() == false){ + if(m_state != LC_Ready){ infostream<<"Client::interact() " "cancelled (not connected)" < data((u8*)s.c_str(), s.size()); + // Send as reliable + Send(0, data, true); +} + void Client::sendPlayerPos() { LocalPlayer *myplayer = m_env.getLocalPlayer(); @@ -2650,16 +2661,14 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font) infostream<<"- Starting mesh update thread"<