summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp58
1 files changed, 46 insertions, 12 deletions
diff --git a/src/client.cpp b/src/client.cpp
index e47bce142..4117a9130 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -41,6 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound.h"
#include "util/string.h"
#include "hex.h"
+#include "IMeshCache.h"
+#include "util/serialize.h"
static std::string getMediaCacheDir()
{
@@ -265,6 +267,7 @@ Client::Client(
m_time_of_day_set(false),
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_packetcounter_timer = 0.0;
@@ -498,8 +501,9 @@ void Client::step(float dtime)
// [2] u8 SER_FMT_VER_HIGHEST
// [3] u8[20] player_name
// [23] u8[28] password (new in some version)
- // [51] u16 client network protocol version (new in some version)
- SharedBuffer<u8> data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2);
+ // [51] u16 minimum supported network protocol version (added sometime)
+ // [53] u16 maximum supported network protocol version (added later than the previous one)
+ SharedBuffer<u8> data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2);
writeU16(&data[0], TOSERVER_INIT);
writeU8(&data[2], SER_FMT_VER_HIGHEST);
@@ -512,8 +516,8 @@ void Client::step(float dtime)
memset((char*)&data[23], 0, PASSWORD_SIZE);
snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str());
- // This should be incremented in each version
- writeU16(&data[51], PROTOCOL_VERSION);
+ writeU16(&data[51], CLIENT_PROTOCOL_VERSION_MIN);
+ writeU16(&data[53], CLIENT_PROTOCOL_VERSION_MAX);
// Send as unreliable
Send(0, data, false);
@@ -655,7 +659,7 @@ void Client::step(float dtime)
{
float &counter = m_playerpos_send_timer;
counter += dtime;
- if(counter >= 0.2)
+ if(counter >= m_recommended_send_interval)
{
counter = 0.0;
sendPlayerPos();
@@ -821,7 +825,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
if(name != "")
{
verbosestream<<"Client: Attempting to load image "
- <<"file \""<<filename<<"\""<<std::endl;
+ <<"file \""<<filename<<"\""<<std::endl;
io::IFileSystem *irrfs = m_device->getFileSystem();
video::IVideoDriver *vdrv = m_device->getVideoDriver();
@@ -855,11 +859,33 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
if(name != "")
{
verbosestream<<"Client: Attempting to load sound "
- <<"file \""<<filename<<"\""<<std::endl;
+ <<"file \""<<filename<<"\""<<std::endl;
m_sound->loadSoundData(name, data);
return true;
}
+ const char *model_ext[] = {
+ ".x", ".b3d", ".md2", ".obj",
+ NULL
+ };
+ name = removeStringEnd(filename, model_ext);
+ if(name != "")
+ {
+ verbosestream<<"Client: Storing model into Irrlicht: "
+ <<"\""<<filename<<"\""<<std::endl;
+
+ io::IFileSystem *irrfs = m_device->getFileSystem();
+ io::IReadFile *rfile = irrfs->createMemoryReadFile(
+ *data_rw, data_rw.getSize(), filename.c_str());
+ assert(rfile);
+
+ scene::ISceneManager *smgr = m_device->getSceneManager();
+ scene::IAnimatedMesh *mesh = smgr->getMesh(rfile);
+ smgr->getMeshCache()->addMesh(filename.c_str(), mesh);
+
+ return true;
+ }
+
errorstream<<"Client: Don't know how to load file \""
<<filename<<"\""<<std::endl;
return false;
@@ -997,6 +1023,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
m_map_seed = readU64(&data[2+1+6]);
infostream<<"Client: received map seed: "<<m_map_seed<<std::endl;
}
+
+ if(datasize >= 2+1+6+8+4)
+ {
+ // Get map seed
+ m_recommended_send_interval = readF1000(&data[2+1+6+8]);
+ infostream<<"Client: received recommended send interval "
+ <<m_recommended_send_interval<<std::endl;
+ }
// Reply to server
u32 replysize = 2;
@@ -1961,7 +1995,7 @@ void Client::sendPlayerPos()
v3s32 speed(sf.X*100, sf.Y*100, sf.Z*100);
s32 pitch = myplayer->getPitch() * 100;
s32 yaw = myplayer->getYaw() * 100;
-
+ u32 keyPressed=myplayer->keyPressed;
/*
Format:
[0] u16 command
@@ -1969,15 +2003,15 @@ void Client::sendPlayerPos()
[2+12] v3s32 speed*100
[2+12+12] s32 pitch*100
[2+12+12+4] s32 yaw*100
+ [2+12+12+4+4] u32 keyPressed
*/
-
- SharedBuffer<u8> data(2+12+12+4+4);
+ SharedBuffer<u8> data(2+12+12+4+4+4);
writeU16(&data[0], TOSERVER_PLAYERPOS);
writeV3S32(&data[2], position);
writeV3S32(&data[2+12], speed);
writeS32(&data[2+12+12], pitch);
- writeS32(&data[2+12+12+4], yaw);
-
+ writeS32(&data[2+12+12+4], yaw);
+ writeU32(&data[2+12+12+4+4], keyPressed);
// Send as unreliable
Send(0, data, false);
}