@@ -774,9 +774,10 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
774
774
}
775
775
}
776
776
777
- void Server::handleCommand_PlayerPos (NetworkPacket* pkt)
777
+ void Server::process_PlayerPos (RemotePlayer *player, PlayerSAO *playersao,
778
+ NetworkPacket *pkt)
778
779
{
779
- if (pkt->getSize () < 12 + 12 + 4 + 4 )
780
+ if (pkt->getRemainingBytes () < 12 + 12 + 4 + 4 )
780
781
return ;
781
782
782
783
v3s32 ps, ss;
@@ -791,7 +792,7 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt)
791
792
f32 yaw = (f32)f32yaw / 100.0 ;
792
793
u32 keyPressed = 0 ;
793
794
794
- if (pkt->getSize () >= 12 + 12 + 4 + 4 + 4 )
795
+ if (pkt->getRemainingBytes () >= 4 )
795
796
*pkt >> keyPressed;
796
797
797
798
v3f position ((f32)ps.X / 100.0 , (f32)ps.Y / 100.0 , (f32)ps.Z / 100.0 );
@@ -800,6 +801,30 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt)
800
801
pitch = modulo360f (pitch);
801
802
yaw = modulo360f (yaw);
802
803
804
+ playersao->setBasePosition (position);
805
+ player->setSpeed (speed);
806
+ playersao->setPitch (pitch);
807
+ playersao->setYaw (yaw);
808
+ player->keyPressed = keyPressed;
809
+ player->control .up = (keyPressed & 1 );
810
+ player->control .down = (keyPressed & 2 );
811
+ player->control .left = (keyPressed & 4 );
812
+ player->control .right = (keyPressed & 8 );
813
+ player->control .jump = (keyPressed & 16 );
814
+ player->control .aux1 = (keyPressed & 32 );
815
+ player->control .sneak = (keyPressed & 64 );
816
+ player->control .LMB = (keyPressed & 128 );
817
+ player->control .RMB = (keyPressed & 256 );
818
+
819
+ if (playersao->checkMovementCheat ()) {
820
+ // Call callbacks
821
+ m_script->on_cheat (playersao, " moved_too_fast" );
822
+ SendMovePlayer (pkt->getPeerId ());
823
+ }
824
+ }
825
+
826
+ void Server::handleCommand_PlayerPos (NetworkPacket* pkt)
827
+ {
803
828
RemotePlayer *player = m_env->getPlayer (pkt->getPeerId ());
804
829
if (player == NULL ) {
805
830
errorstream << " Server::ProcessData(): Canceling: "
@@ -825,26 +850,7 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt)
825
850
return ;
826
851
}
827
852
828
- playersao->setBasePosition (position);
829
- player->setSpeed (speed);
830
- playersao->setPitch (pitch);
831
- playersao->setYaw (yaw);
832
- player->keyPressed = keyPressed;
833
- player->control .up = (keyPressed & 1 );
834
- player->control .down = (keyPressed & 2 );
835
- player->control .left = (keyPressed & 4 );
836
- player->control .right = (keyPressed & 8 );
837
- player->control .jump = (keyPressed & 16 );
838
- player->control .aux1 = (keyPressed & 32 );
839
- player->control .sneak = (keyPressed & 64 );
840
- player->control .LMB = (keyPressed & 128 );
841
- player->control .RMB = (keyPressed & 256 );
842
-
843
- if (playersao->checkMovementCheat ()) {
844
- // Call callbacks
845
- m_script->on_cheat (playersao, " moved_too_fast" );
846
- SendMovePlayer (pkt->getPeerId ());
847
- }
853
+ process_PlayerPos (player, playersao, pkt);
848
854
}
849
855
850
856
void Server::handleCommand_DeletedBlocks (NetworkPacket* pkt)
@@ -1281,25 +1287,25 @@ void Server::handleCommand_Respawn(NetworkPacket* pkt)
1281
1287
1282
1288
void Server::handleCommand_Interact (NetworkPacket* pkt)
1283
1289
{
1284
- std::string datastring (pkt->getString (0 ), pkt->getSize ());
1285
- std::istringstream is (datastring, std::ios_base::binary);
1286
-
1287
1290
/*
1288
1291
[0] u16 command
1289
1292
[2] u8 action
1290
1293
[3] u16 item
1291
- [5] u32 length of the next item
1294
+ [5] u32 length of the next item (plen)
1292
1295
[9] serialized PointedThing
1296
+ [9 + plen] player position information
1293
1297
actions:
1294
1298
0: start digging (from undersurface) or use
1295
1299
1: stop digging (all parameters ignored)
1296
1300
2: digging completed
1297
1301
3: place block or item (to abovesurface)
1298
1302
4: use item
1299
1303
*/
1300
- u8 action = readU8 (is);
1301
- u16 item_i = readU16 (is);
1302
- std::istringstream tmp_is (deSerializeLongString (is), std::ios::binary);
1304
+ u8 action;
1305
+ u16 item_i;
1306
+ *pkt >> action;
1307
+ *pkt >> item_i;
1308
+ std::istringstream tmp_is (pkt->readLongString (), std::ios::binary);
1303
1309
PointedThing pointed;
1304
1310
pointed.deSerialize (tmp_is);
1305
1311
@@ -1331,6 +1337,8 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
1331
1337
return ;
1332
1338
}
1333
1339
1340
+ process_PlayerPos (player, playersao, pkt);
1341
+
1334
1342
v3f player_pos = playersao->getLastGoodPosition ();
1335
1343
1336
1344
// Update wielded item
0 commit comments