mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
Clamp client-sent movement speed control (#15721)
Results in the `movement_x` and `movement_y` fields of `player:get_player_control()` being safe to use (otherwise users would need to compute the length as `(x^2 + y^2)^0.5` and clamp that to 1 themselves).
This commit is contained in:
parent
b2a6c3ba23
commit
a73e71510a
1 changed files with 7 additions and 1 deletions
|
@ -30,6 +30,8 @@
|
|||
#include "util/srp.h"
|
||||
#include "clientdynamicinfo.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
void Server::handleCommand_Deprecated(NetworkPacket* pkt)
|
||||
{
|
||||
infostream << "Server: " << toServerCommandTable[pkt->getCommand()].name
|
||||
|
@ -468,7 +470,11 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
|
|||
*pkt >> bits;
|
||||
|
||||
if (pkt->getRemainingBytes() >= 8) {
|
||||
*pkt >> player->control.movement_speed;
|
||||
f32 movement_speed;
|
||||
*pkt >> movement_speed;
|
||||
if (movement_speed != movement_speed) // NaN
|
||||
movement_speed = 0.0f;
|
||||
player->control.movement_speed = std::clamp(movement_speed, 0.0f, 1.0f);
|
||||
*pkt >> player->control.movement_direction;
|
||||
} else {
|
||||
player->control.movement_speed = 0.0f;
|
||||
|
|
Loading…
Add table
Reference in a new issue