@@ -934,7 +934,6 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
934
934
m_peer_id(peer_id_),
935
935
m_inventory(NULL ),
936
936
m_last_good_position(0 ,0 ,0 ),
937
- m_last_good_position_age(0 ),
938
937
m_time_from_last_punch(0 ),
939
938
m_nocheat_dig_pos(32767 , 32767 , 32767 ),
940
939
m_nocheat_dig_time(0 ),
@@ -1002,7 +1001,6 @@ void PlayerSAO::addedToEnvironment(u32 dtime_s)
1002
1001
m_player->setPlayerSAO (this );
1003
1002
m_player->peer_id = m_peer_id;
1004
1003
m_last_good_position = m_player->getPosition ();
1005
- m_last_good_position_age = 0.0 ;
1006
1004
}
1007
1005
1008
1006
// Called before removing from environment
@@ -1106,6 +1104,19 @@ void PlayerSAO::step(float dtime, bool send_recommended)
1106
1104
m_moved = true ;
1107
1105
}
1108
1106
1107
+ // dstream<<"PlayerSAO::step: dtime: "<<dtime<<std::endl;
1108
+
1109
+ // Set lag pool maximums based on estimated lag
1110
+ const float LAG_POOL_MIN = 5.0 ;
1111
+ float lag_pool_max = m_env->getMaxLagEstimate () * 2.0 ;
1112
+ if (lag_pool_max < LAG_POOL_MIN)
1113
+ lag_pool_max = LAG_POOL_MIN;
1114
+ m_dig_pool.setMax (lag_pool_max);
1115
+ m_move_pool.setMax (lag_pool_max);
1116
+
1117
+ // Increment cheat prevention timers
1118
+ m_dig_pool.add (dtime);
1119
+ m_move_pool.add (dtime);
1109
1120
m_time_from_last_punch += dtime;
1110
1121
m_nocheat_dig_time += dtime;
1111
1122
@@ -1115,66 +1126,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
1115
1126
{
1116
1127
v3f pos = m_env->getActiveObject (m_attachment_parent_id)->getBasePosition ();
1117
1128
m_last_good_position = pos;
1118
- m_last_good_position_age = 0 ;
1119
1129
m_player->setPosition (pos);
1120
1130
}
1121
- else
1122
- {
1123
- if (m_is_singleplayer || g_settings->getBool (" disable_anticheat" ))
1124
- {
1125
- m_last_good_position = m_player->getPosition ();
1126
- m_last_good_position_age = 0 ;
1127
- }
1128
- else
1129
- {
1130
- /*
1131
- Check player movements
1132
-
1133
- NOTE: Actually the server should handle player physics like the
1134
- client does and compare player's position to what is calculated
1135
- on our side. This is required when eg. players fly due to an
1136
- explosion. Altough a node-based alternative might be possible
1137
- too, and much more lightweight.
1138
- */
1139
-
1140
- float player_max_speed = 0 ;
1141
- float player_max_speed_up = 0 ;
1142
- if (m_privs.count (" fast" ) != 0 ){
1143
- // Fast speed
1144
- player_max_speed = BS * 20 ;
1145
- player_max_speed_up = BS * 20 ;
1146
- } else {
1147
- // Normal speed
1148
- player_max_speed = BS * 4.0 ;
1149
- player_max_speed_up = BS * 4.0 ;
1150
- }
1151
- // Tolerance
1152
- player_max_speed *= 2.5 ;
1153
- player_max_speed_up *= 2.5 ;
1154
-
1155
- m_last_good_position_age += dtime;
1156
- if (m_last_good_position_age >= 1.0 ){
1157
- float age = m_last_good_position_age;
1158
- v3f diff = (m_player->getPosition () - m_last_good_position);
1159
- float d_vert = diff.Y ;
1160
- diff.Y = 0 ;
1161
- float d_horiz = diff.getLength ();
1162
- /* infostream<<m_player->getName()<<"'s horizontal speed is "
1163
- <<(d_horiz/age)<<std::endl;*/
1164
- if (d_horiz <= age * player_max_speed &&
1165
- (d_vert < 0 || d_vert < age * player_max_speed_up)){
1166
- m_last_good_position = m_player->getPosition ();
1167
- } else {
1168
- actionstream<<" Player " <<m_player->getName ()
1169
- <<" moved too fast; resetting position"
1170
- <<std::endl;
1171
- m_player->setPosition (m_last_good_position);
1172
- m_moved = true ;
1173
- }
1174
- m_last_good_position_age = 0 ;
1175
- }
1176
- }
1177
- }
1178
1131
1179
1132
if (send_recommended == false )
1180
1133
return ;
@@ -1267,7 +1220,6 @@ void PlayerSAO::setPos(v3f pos)
1267
1220
m_player->setPosition (pos);
1268
1221
// Movement caused by this command is always valid
1269
1222
m_last_good_position = pos;
1270
- m_last_good_position_age = 0 ;
1271
1223
// Force position change on client
1272
1224
m_moved = true ;
1273
1225
}
@@ -1279,7 +1231,6 @@ void PlayerSAO::moveTo(v3f pos, bool continuous)
1279
1231
m_player->setPosition (pos);
1280
1232
// Movement caused by this command is always valid
1281
1233
m_last_good_position = pos;
1282
- m_last_good_position_age = 0 ;
1283
1234
// Force position change on client
1284
1235
m_moved = true ;
1285
1236
}
@@ -1503,6 +1454,59 @@ std::string PlayerSAO::getPropertyPacket()
1503
1454
return gob_cmd_set_properties (m_prop);
1504
1455
}
1505
1456
1457
+ void PlayerSAO::checkMovementCheat ()
1458
+ {
1459
+ if (isAttached () || m_is_singleplayer ||
1460
+ g_settings->getBool (" disable_anticheat" ))
1461
+ {
1462
+ m_last_good_position = m_player->getPosition ();
1463
+ }
1464
+ else
1465
+ {
1466
+ /*
1467
+ Check player movements
1468
+
1469
+ NOTE: Actually the server should handle player physics like the
1470
+ client does and compare player's position to what is calculated
1471
+ on our side. This is required when eg. players fly due to an
1472
+ explosion. Altough a node-based alternative might be possible
1473
+ too, and much more lightweight.
1474
+ */
1475
+
1476
+ float player_max_speed = 0 ;
1477
+ float player_max_speed_up = 0 ;
1478
+ if (m_privs.count (" fast" ) != 0 ){
1479
+ // Fast speed
1480
+ player_max_speed = m_player->movement_speed_fast ;
1481
+ player_max_speed_up = m_player->movement_speed_fast ;
1482
+ } else {
1483
+ // Normal speed
1484
+ player_max_speed = m_player->movement_speed_walk ;
1485
+ player_max_speed_up = m_player->movement_speed_walk ;
1486
+ }
1487
+ // Tolerance. With the lag pool we shouldn't need it.
1488
+ // player_max_speed *= 2.5;
1489
+ // player_max_speed_up *= 2.5;
1490
+
1491
+ v3f diff = (m_player->getPosition () - m_last_good_position);
1492
+ float d_vert = diff.Y ;
1493
+ diff.Y = 0 ;
1494
+ float d_horiz = diff.getLength ();
1495
+ float required_time = d_horiz/player_max_speed;
1496
+ if (d_vert > 0 && d_vert/player_max_speed > required_time)
1497
+ required_time = d_vert/player_max_speed;
1498
+ if (m_move_pool.grab (required_time)){
1499
+ m_last_good_position = m_player->getPosition ();
1500
+ } else {
1501
+ actionstream<<" Player " <<m_player->getName ()
1502
+ <<" moved too fast; resetting position"
1503
+ <<std::endl;
1504
+ m_player->setPosition (m_last_good_position);
1505
+ m_moved = true ;
1506
+ }
1507
+ }
1508
+ }
1509
+
1506
1510
bool PlayerSAO::getCollisionBox (aabb3f *toset) {
1507
1511
// update collision box
1508
1512
*toset = m_player->getCollisionbox ();
@@ -1516,3 +1520,4 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) {
1516
1520
bool PlayerSAO::collideWithObjects (){
1517
1521
return true ;
1518
1522
}
1523
+
0 commit comments