Skip to content

Commit 1d4a2a6

Browse files
authoredAug 29, 2017
Network proto handlers/container fixes (#6334)
* Fix HP transport + some double <-> float problems TOCLIENT_HP transport u16 hp as a u8, use u16 HP, this prevent HP over 255 to overflow across network * Fix more double/float problem in serverpackethandler & remove implicit struct type for TileAnimationParams * Fix connection unittests container
1 parent 35a4082 commit 1d4a2a6

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed
 

Diff for: ‎src/client/clientevent.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ClientEvent
5252
//} none;
5353
struct
5454
{
55-
u8 amount;
55+
u16 amount;
5656
} player_damage;
5757
struct
5858
{

Diff for: ‎src/network/clientpackethandler.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,11 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt)
375375
}
376376
else {
377377
// Old message; try to approximate speed of time by ourselves
378-
float time_of_day_f = (float)time_of_day / 24000.0;
378+
float time_of_day_f = (float)time_of_day / 24000.0f;
379379
float tod_diff_f = 0;
380380

381381
if (time_of_day_f < 0.2 && m_last_time_of_day_f > 0.8)
382-
tod_diff_f = time_of_day_f - m_last_time_of_day_f + 1.0;
382+
tod_diff_f = time_of_day_f - m_last_time_of_day_f + 1.0f;
383383
else
384384
tod_diff_f = time_of_day_f - m_last_time_of_day_f;
385385

@@ -388,7 +388,7 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt)
388388
m_time_of_day_update_timer = 0;
389389

390390
if (m_time_of_day_set) {
391-
time_speed = (3600.0 * 24.0) * tod_diff_f / time_diff;
391+
time_speed = (3600.0f * 24.0f) * tod_diff_f / time_diff;
392392
infostream << "Client: Measured time_of_day speed (old format): "
393393
<< time_speed << " tod_diff_f=" << tod_diff_f
394394
<< " time_diff=" << time_diff << std::endl;
@@ -565,9 +565,9 @@ void Client::handleCommand_HP(NetworkPacket* pkt)
565565
LocalPlayer *player = m_env.getLocalPlayer();
566566
assert(player != NULL);
567567

568-
u8 oldhp = player->hp;
568+
u16 oldhp = player->hp;
569569

570-
u8 hp;
570+
u16 hp;
571571
*pkt >> hp;
572572

573573
player->hp = hp;
@@ -966,7 +966,7 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
966966
std::string texture = deSerializeLongString(is);
967967
bool vertical = false;
968968
bool collision_removal = false;
969-
struct TileAnimationParams animation;
969+
TileAnimationParams animation;
970970
animation.type = TAT_NONE;
971971
u8 glow = 0;
972972
try {
@@ -1020,7 +1020,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
10201020

10211021
bool vertical = false;
10221022
bool collision_removal = false;
1023-
struct TileAnimationParams animation;
1023+
TileAnimationParams animation;
10241024
animation.type = TAT_NONE;
10251025
u8 glow = 0;
10261026
u16 attached_id = 0;

Diff for: ‎src/network/serverpackethandler.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
780780
*pkt >> f32pitch;
781781
*pkt >> f32yaw;
782782

783-
f32 pitch = (f32)f32pitch / 100.0;
784-
f32 yaw = (f32)f32yaw / 100.0;
783+
f32 pitch = (f32)f32pitch / 100.0f;
784+
f32 yaw = (f32)f32yaw / 100.0f;
785785
u32 keyPressed = 0;
786786

787787
// default behavior (in case an old client doesn't send these)
@@ -792,13 +792,13 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
792792
*pkt >> keyPressed;
793793
if (pkt->getRemainingBytes() >= 1) {
794794
*pkt >> f32fov;
795-
fov = (f32)f32fov / 80.0;
795+
fov = (f32)f32fov / 80.0f;
796796
}
797797
if (pkt->getRemainingBytes() >= 1)
798798
*pkt >> wanted_range;
799799

800-
v3f position((f32)ps.X / 100.0, (f32)ps.Y / 100.0, (f32)ps.Z / 100.0);
801-
v3f speed((f32)ss.X / 100.0, (f32)ss.Y / 100.0, (f32)ss.Z / 100.0);
800+
v3f position((f32)ps.X / 100.0f, (f32)ps.Y / 100.0f, (f32)ps.Z / 100.0f);
801+
v3f speed((f32)ss.X / 100.0f, (f32)ss.Y / 100.0f, (f32)ss.Z / 100.0f);
802802

803803
pitch = modulo360f(pitch);
804804
yaw = wrapDegrees_0_360(yaw);
@@ -1406,7 +1406,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
14061406
if (max_d < 0 && max_d_hand >= 0)
14071407
max_d = max_d_hand;
14081408
else if (max_d < 0)
1409-
max_d = BS * 4.0;
1409+
max_d = BS * 4.0f;
14101410
// cube diagonal: sqrt(3) = 1.73
14111411
if (d > max_d * 1.73) {
14121412
actionstream << "Player " << player->getName()

Diff for: ‎src/server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao)
14311431
DiePlayer(peer_id);
14321432
}
14331433

1434-
void Server::SendHP(u16 peer_id, u8 hp)
1434+
void Server::SendHP(u16 peer_id, u16 hp)
14351435
{
14361436
DSTACK(FUNCTION_NAME);
14371437

Diff for: ‎src/server.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
347347
friend class RemoteClient;
348348

349349
void SendMovement(u16 peer_id);
350-
void SendHP(u16 peer_id, u8 hp);
350+
void SendHP(u16 peer_id, u16 hp);
351351
void SendBreath(u16 peer_id, u16 breath);
352352
void SendAccessDenied(u16 peer_id, AccessDeniedCode reason,
353353
const std::string &custom_reason, bool reconnect = false);

Diff for: ‎src/unittest/test_connection.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void TestConnection::testConnectSendReceive()
246246
NetworkPacket pkt;
247247
pkt.putRawPacket((u8*) "Hello World !", 14, 0);
248248

249-
Buffer<u8> sentdata = pkt.oldForgePacket();
249+
SharedBuffer<u8> sentdata = pkt.oldForgePacket();
250250

251251
infostream<<"** running client.Send()"<<std::endl;
252252
client.Send(PEER_ID_SERVER, 0, &pkt, true);
@@ -261,7 +261,7 @@ void TestConnection::testConnectSendReceive()
261261
<< ", data=" << (const char*)pkt.getU8Ptr(0)
262262
<< std::endl;
263263

264-
Buffer<u8> recvdata = pkt.oldForgePacket();
264+
SharedBuffer<u8> recvdata = pkt.oldForgePacket();
265265

266266
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
267267
}

0 commit comments

Comments
 (0)