Skip to content

Commit

Permalink
Rename packet from PLAYER_POS to MOVE_PLAYER_REL. Add backward compat…
Browse files Browse the repository at this point in the history
…ibility. Update doc.
  • Loading branch information
sfence committed Dec 27, 2023
1 parent 5067c67 commit 752caca
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7464,7 +7464,7 @@ child will follow movement and rotation of that bone.
* No-op if object is attached.
* `pos` is a vector `{x=num, y=num, z=num}`
* `add_pos(pos)`:
* Changes pos by addint to the current pos.
* Changes position by adding to the current position.
* No-op if object is attached.
* `pos` is a vector `{x=num, y=num, z=num}`.
* `get_velocity()`: returns the velocity, a vector.
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void handleCommand_HP(NetworkPacket* pkt);
void handleCommand_Breath(NetworkPacket* pkt);
void handleCommand_MovePlayer(NetworkPacket* pkt);
void handleCommand_PlayerPos(NetworkPacket* pkt);
void handleCommand_MovePlayerRel(NetworkPacket* pkt);
void handleCommand_DeathScreen(NetworkPacket* pkt);
void handleCommand_AnnounceMedia(NetworkPacket* pkt);
void handleCommand_Media(NetworkPacket* pkt);
Expand Down
2 changes: 1 addition & 1 deletion src/network/clientopcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_FORMSPEC_PREPEND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FormspecPrepend }, // 0x61,
{ "TOCLIENT_MINIMAP_MODES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MinimapModes }, // 0x62,
{ "TOCLIENT_SET_LIGHTING", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SetLighting }, // 0x63,
{ "TOCLIENT_PLAYER_POS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_PlayerPos }, // 0x64,
{ "TOCLIENT_MOVE_PLAYER_REL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MovePlayerRel }, // 0x64,
};

const static ServerCommandFactory null_command_factory = { "TOSERVER_NULL", 0, false };
Expand Down
2 changes: 1 addition & 1 deletion src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
m_client_event_queue.push(event);
}

void Client::handleCommand_PlayerPos(NetworkPacket *pkt)
void Client::handleCommand_MovePlayerRel(NetworkPacket *pkt)
{
v3f added_pos;

Expand Down
4 changes: 2 additions & 2 deletions src/network/networkprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
[scheduled bump for 5.8.0]
PROTOCOL VERSION 44:
AO_CMD_SET_BONE_POSITION extended
Add TOCLUENT_OKATER_POS
Add TOCLIENT_MOVE_PLAYER_REL
[scheduled bump for 5.9.0]
*/

Expand Down Expand Up @@ -874,7 +874,7 @@ enum ToClientCommand
f32 center_weight_power
*/

TOCLIENT_PLAYER_POS = 0x64,
TOCLIENT_MOVE_PLAYER_REL = 0x64,
/*
v3f added_pos
*/
Expand Down
8 changes: 6 additions & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,9 +1960,9 @@ void Server::SendMovePlayer(session_t peer_id)
Send(&pkt);
}

void Server::SendPlayerPos(session_t peer_id, const v3f &added_pos)
void Server::SendMovePlayerRel(session_t peer_id, const v3f &added_pos)
{
NetworkPacket pkt(TOCLIENT_PLAYER_POS, 0, peer_id);
NetworkPacket pkt(TOCLIENT_MOVE_PLAYER_REL, 0, peer_id);
pkt << added_pos;
Send(&pkt);
}
Expand Down Expand Up @@ -3420,6 +3420,10 @@ Address Server::getPeerAddress(session_t peer_id)
// Note that this is only set after Init was received in Server::handleCommand_Init
return getClient(peer_id, CS_Invalid)->getAddress();
}
u16 Server::getPeerProtocolVersion(session_t peer_id)
{
return m_clients.getProtocolVersion(peer_id);
}

void Server::setLocalPlayerAnimations(RemotePlayer *player,
v2s32 animation_frames[4], f32 frame_speed)
Expand Down
3 changes: 2 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
void hudSetHotbarSelectedImage(RemotePlayer *player, const std::string &name);

Address getPeerAddress(session_t peer_id);
u16 getPeerProtocolVersion(session_t peer_id);

void setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
f32 frame_speed);
Expand Down Expand Up @@ -364,7 +365,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
void SendPlayerBreath(PlayerSAO *sao);
void SendInventory(PlayerSAO *playerSAO, bool incremental);
void SendMovePlayer(session_t peer_id);
void SendPlayerPos(session_t peer_id, const v3f &added_pos);
void SendMovePlayerRel(session_t peer_id, const v3f &added_pos);
void SendPlayerSpeed(session_t peer_id, const v3f &added_vel);
void SendPlayerFov(session_t peer_id);

Expand Down
8 changes: 7 additions & 1 deletion src/server/player_sao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ void PlayerSAO::setPos(const v3f &pos)

void PlayerSAO::addPos(const v3f &added_pos)
{
// Backward compatibility for older clients
if (m_env->getGameDef()->getPeerProtocolVersion(m_peer_id) < 44) {
setPos(getBasePosition()+added_pos);
return;
}

if(isAttached())
return;

Expand All @@ -382,7 +388,7 @@ void PlayerSAO::addPos(const v3f &added_pos)
m_last_good_position = getBasePosition();
m_move_pool.empty();
m_time_from_last_teleport = 0.0;
m_env->getGameDef()->SendPlayerPos(m_peer_id, added_pos);
m_env->getGameDef()->SendMovePlayerRel(m_peer_id, added_pos);
}

void PlayerSAO::moveTo(v3f pos, bool continuous)
Expand Down

0 comments on commit 752caca

Please sign in to comment.