aboutsummaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp57
1 files changed, 33 insertions, 24 deletions
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="<<avg_rtt<<std::endl;
}
}
@@ -643,7 +631,7 @@ void Client::step(float dtime)
{
float &counter = m_playerpos_send_timer;
counter += dtime;
- if(counter >= 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<u8> 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)"
<<std::endl;
@@ -2152,6 +2142,27 @@ void Client::sendRespawn()
Send(0, data, true);
}
+void Client::sendReady()
+{
+ DSTACK(__FUNCTION_NAME);
+ std::ostringstream os(std::ios_base::binary);
+
+ writeU16(os, TOSERVER_CLIENT_READY);
+ writeU8(os,VERSION_MAJOR);
+ writeU8(os,VERSION_MINOR);
+ writeU8(os,VERSION_PATCH_ORIG);
+ writeU8(os,0);
+
+ writeU16(os,strlen(CMAKE_VERSION_GITHASH));
+ os.write(CMAKE_VERSION_GITHASH,strlen(CMAKE_VERSION_GITHASH));
+
+ // Make data buffer
+ std::string s = os.str();
+ SharedBuffer<u8> 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"<<std::endl;
m_mesh_update_thread.Start();
+ m_state = LC_Ready;
+ sendReady();
infostream<<"Client::afterContentReceived() done"<<std::endl;
}
float Client::getRTT(void)
{
- try{
- return m_con.GetPeerAvgRTT(PEER_ID_SERVER);
- } catch(con::PeerNotFoundException &e){
- return 1337;
- }
+ return m_con.getPeerStat(PEER_ID_SERVER,con::AVG_RTT);
}
// IGameDef interface