Filter anormal positions and add position with scan

This commit is contained in:
Sebastien Riviere
2026-03-13 00:59:56 +01:00
parent 296220d9f9
commit 471e514981
7 changed files with 1944 additions and 25741 deletions

View File

@@ -402,9 +402,12 @@ export default {
const team = this.getTeam(teamId);
const enemyTeam = this.getTeam(team.chasing);
const dateNow = Date.now();
// Update distance
// Verify coherence of the new location and update the distance
if (this.state == GameState.PLAYING && team.currentLocation) {
team.distance += Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
const traveledDistance = Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
const timeSinceLastCurrentLocation = (dateNow - team.lastCurrentLocationDate) / 1000;
if (traveledDistance / timeSinceLastCurrentLocation > 8) return false; // Reject the location if it implies a speed > 8m/s (28km/h)
team.distance += traveledDistance;
}
// Update of currentLocation
team.currentLocation = location;

View File

@@ -116,8 +116,9 @@ export function initTeamSocket() {
}
});
socket.on("send_position", () => {
socket.on("send_position", (position) => {
if (!teamId) return;
game.updateLocation(teamId, position);
game.sendLocation(teamId);
});