forked from Mirrorlandia_minetest/minetest
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
This commit is contained in:
parent
35a4082727
commit
1d4a2a6ea7
@ -52,7 +52,7 @@ struct ClientEvent
|
|||||||
//} none;
|
//} none;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u8 amount;
|
u16 amount;
|
||||||
} player_damage;
|
} player_damage;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -375,11 +375,11 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Old message; try to approximate speed of time by ourselves
|
// Old message; try to approximate speed of time by ourselves
|
||||||
float time_of_day_f = (float)time_of_day / 24000.0;
|
float time_of_day_f = (float)time_of_day / 24000.0f;
|
||||||
float tod_diff_f = 0;
|
float tod_diff_f = 0;
|
||||||
|
|
||||||
if (time_of_day_f < 0.2 && m_last_time_of_day_f > 0.8)
|
if (time_of_day_f < 0.2 && m_last_time_of_day_f > 0.8)
|
||||||
tod_diff_f = time_of_day_f - m_last_time_of_day_f + 1.0;
|
tod_diff_f = time_of_day_f - m_last_time_of_day_f + 1.0f;
|
||||||
else
|
else
|
||||||
tod_diff_f = time_of_day_f - m_last_time_of_day_f;
|
tod_diff_f = time_of_day_f - m_last_time_of_day_f;
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt)
|
|||||||
m_time_of_day_update_timer = 0;
|
m_time_of_day_update_timer = 0;
|
||||||
|
|
||||||
if (m_time_of_day_set) {
|
if (m_time_of_day_set) {
|
||||||
time_speed = (3600.0 * 24.0) * tod_diff_f / time_diff;
|
time_speed = (3600.0f * 24.0f) * tod_diff_f / time_diff;
|
||||||
infostream << "Client: Measured time_of_day speed (old format): "
|
infostream << "Client: Measured time_of_day speed (old format): "
|
||||||
<< time_speed << " tod_diff_f=" << tod_diff_f
|
<< time_speed << " tod_diff_f=" << tod_diff_f
|
||||||
<< " time_diff=" << time_diff << std::endl;
|
<< " time_diff=" << time_diff << std::endl;
|
||||||
@ -565,9 +565,9 @@ void Client::handleCommand_HP(NetworkPacket* pkt)
|
|||||||
LocalPlayer *player = m_env.getLocalPlayer();
|
LocalPlayer *player = m_env.getLocalPlayer();
|
||||||
assert(player != NULL);
|
assert(player != NULL);
|
||||||
|
|
||||||
u8 oldhp = player->hp;
|
u16 oldhp = player->hp;
|
||||||
|
|
||||||
u8 hp;
|
u16 hp;
|
||||||
*pkt >> hp;
|
*pkt >> hp;
|
||||||
|
|
||||||
player->hp = hp;
|
player->hp = hp;
|
||||||
@ -966,7 +966,7 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
|
|||||||
std::string texture = deSerializeLongString(is);
|
std::string texture = deSerializeLongString(is);
|
||||||
bool vertical = false;
|
bool vertical = false;
|
||||||
bool collision_removal = false;
|
bool collision_removal = false;
|
||||||
struct TileAnimationParams animation;
|
TileAnimationParams animation;
|
||||||
animation.type = TAT_NONE;
|
animation.type = TAT_NONE;
|
||||||
u8 glow = 0;
|
u8 glow = 0;
|
||||||
try {
|
try {
|
||||||
@ -1020,7 +1020,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
|
|||||||
|
|
||||||
bool vertical = false;
|
bool vertical = false;
|
||||||
bool collision_removal = false;
|
bool collision_removal = false;
|
||||||
struct TileAnimationParams animation;
|
TileAnimationParams animation;
|
||||||
animation.type = TAT_NONE;
|
animation.type = TAT_NONE;
|
||||||
u8 glow = 0;
|
u8 glow = 0;
|
||||||
u16 attached_id = 0;
|
u16 attached_id = 0;
|
||||||
|
@ -780,8 +780,8 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
|
|||||||
*pkt >> f32pitch;
|
*pkt >> f32pitch;
|
||||||
*pkt >> f32yaw;
|
*pkt >> f32yaw;
|
||||||
|
|
||||||
f32 pitch = (f32)f32pitch / 100.0;
|
f32 pitch = (f32)f32pitch / 100.0f;
|
||||||
f32 yaw = (f32)f32yaw / 100.0;
|
f32 yaw = (f32)f32yaw / 100.0f;
|
||||||
u32 keyPressed = 0;
|
u32 keyPressed = 0;
|
||||||
|
|
||||||
// default behavior (in case an old client doesn't send these)
|
// default behavior (in case an old client doesn't send these)
|
||||||
@ -792,13 +792,13 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
|
|||||||
*pkt >> keyPressed;
|
*pkt >> keyPressed;
|
||||||
if (pkt->getRemainingBytes() >= 1) {
|
if (pkt->getRemainingBytes() >= 1) {
|
||||||
*pkt >> f32fov;
|
*pkt >> f32fov;
|
||||||
fov = (f32)f32fov / 80.0;
|
fov = (f32)f32fov / 80.0f;
|
||||||
}
|
}
|
||||||
if (pkt->getRemainingBytes() >= 1)
|
if (pkt->getRemainingBytes() >= 1)
|
||||||
*pkt >> wanted_range;
|
*pkt >> wanted_range;
|
||||||
|
|
||||||
v3f position((f32)ps.X / 100.0, (f32)ps.Y / 100.0, (f32)ps.Z / 100.0);
|
v3f position((f32)ps.X / 100.0f, (f32)ps.Y / 100.0f, (f32)ps.Z / 100.0f);
|
||||||
v3f speed((f32)ss.X / 100.0, (f32)ss.Y / 100.0, (f32)ss.Z / 100.0);
|
v3f speed((f32)ss.X / 100.0f, (f32)ss.Y / 100.0f, (f32)ss.Z / 100.0f);
|
||||||
|
|
||||||
pitch = modulo360f(pitch);
|
pitch = modulo360f(pitch);
|
||||||
yaw = wrapDegrees_0_360(yaw);
|
yaw = wrapDegrees_0_360(yaw);
|
||||||
@ -1406,7 +1406,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||||||
if (max_d < 0 && max_d_hand >= 0)
|
if (max_d < 0 && max_d_hand >= 0)
|
||||||
max_d = max_d_hand;
|
max_d = max_d_hand;
|
||||||
else if (max_d < 0)
|
else if (max_d < 0)
|
||||||
max_d = BS * 4.0;
|
max_d = BS * 4.0f;
|
||||||
// cube diagonal: sqrt(3) = 1.73
|
// cube diagonal: sqrt(3) = 1.73
|
||||||
if (d > max_d * 1.73) {
|
if (d > max_d * 1.73) {
|
||||||
actionstream << "Player " << player->getName()
|
actionstream << "Player " << player->getName()
|
||||||
|
@ -1431,7 +1431,7 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao)
|
|||||||
DiePlayer(peer_id);
|
DiePlayer(peer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::SendHP(u16 peer_id, u8 hp)
|
void Server::SendHP(u16 peer_id, u16 hp)
|
||||||
{
|
{
|
||||||
DSTACK(FUNCTION_NAME);
|
DSTACK(FUNCTION_NAME);
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ private:
|
|||||||
friend class RemoteClient;
|
friend class RemoteClient;
|
||||||
|
|
||||||
void SendMovement(u16 peer_id);
|
void SendMovement(u16 peer_id);
|
||||||
void SendHP(u16 peer_id, u8 hp);
|
void SendHP(u16 peer_id, u16 hp);
|
||||||
void SendBreath(u16 peer_id, u16 breath);
|
void SendBreath(u16 peer_id, u16 breath);
|
||||||
void SendAccessDenied(u16 peer_id, AccessDeniedCode reason,
|
void SendAccessDenied(u16 peer_id, AccessDeniedCode reason,
|
||||||
const std::string &custom_reason, bool reconnect = false);
|
const std::string &custom_reason, bool reconnect = false);
|
||||||
|
@ -246,7 +246,7 @@ void TestConnection::testConnectSendReceive()
|
|||||||
NetworkPacket pkt;
|
NetworkPacket pkt;
|
||||||
pkt.putRawPacket((u8*) "Hello World !", 14, 0);
|
pkt.putRawPacket((u8*) "Hello World !", 14, 0);
|
||||||
|
|
||||||
Buffer<u8> sentdata = pkt.oldForgePacket();
|
SharedBuffer<u8> sentdata = pkt.oldForgePacket();
|
||||||
|
|
||||||
infostream<<"** running client.Send()"<<std::endl;
|
infostream<<"** running client.Send()"<<std::endl;
|
||||||
client.Send(PEER_ID_SERVER, 0, &pkt, true);
|
client.Send(PEER_ID_SERVER, 0, &pkt, true);
|
||||||
@ -261,7 +261,7 @@ void TestConnection::testConnectSendReceive()
|
|||||||
<< ", data=" << (const char*)pkt.getU8Ptr(0)
|
<< ", data=" << (const char*)pkt.getU8Ptr(0)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
Buffer<u8> recvdata = pkt.oldForgePacket();
|
SharedBuffer<u8> recvdata = pkt.oldForgePacket();
|
||||||
|
|
||||||
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
|
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user