mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-12-03 05:10:04 +01:00
Fix teleport check bypass
This commit is contained in:
1 parent
12dfa1ae49
commit
10066d17de
3 files changed
+22
-7
No files matched your search
+20
-7
@@ -5,7 +5,7 @@ import { decodeMovement, dirToVector, flagsToSpeed, isMovingRight } from '../com
|
||||
import { setPonyState, isSittingState, isLyingState } from '../common/entityUtils';
|
||||
import { setupCamera } from '../common/camera';
|
||||
import { logger } from './logger';
|
||||
import { hasFlag, setFlag } from '../common/utils';
|
||||
import { hasFlag, setFlag, clamp } from '../common/utils';
|
||||
import { EntityState } from '../common/interfaces';
|
||||
import { kickClient, setEntityExpression } from './playerUtils';
|
||||
import { CounterService } from './services/counter';
|
||||
@@ -18,6 +18,8 @@ import { isStaticCollision, isOutsideMap } from '../common/collision';
|
||||
const teleportReportLimit = 10;
|
||||
const maxLagLimitSeconds = 15;
|
||||
const maxLagLimit = maxLagLimitSeconds * SECOND;
|
||||
const maxTimeDeltaSlack = 1 * SECOND;
|
||||
const maxMoveDistance = 8;
|
||||
|
||||
export type Move = ReturnType<typeof createMove>;
|
||||
|
||||
@@ -44,7 +46,7 @@ export const createMove =
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkTeleporting(client, x, y, time, settings, teleportCounter)) {
|
||||
if (checkTeleporting(client, x, y, time, now, settings, teleportCounter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +107,9 @@ export const createMove =
|
||||
|
||||
client.lastX = pony.x;
|
||||
client.lastY = pony.y;
|
||||
client.lastTime = time;
|
||||
// time 0 is reserved for "no previous movement" (after join, map switch or teleport)
|
||||
client.lastTime = time || 1;
|
||||
client.lastMoveTime = now;
|
||||
client.lastVX = pony.vx;
|
||||
client.lastVY = pony.vy;
|
||||
};
|
||||
@@ -147,16 +151,20 @@ function checkLagging(client: IClient, time: number, connectionTime: number, set
|
||||
}
|
||||
|
||||
function checkTeleporting(
|
||||
client: IClient, x: number, y: number, time: number, settings: GameServerSettings, counter: CounterService<void>
|
||||
client: IClient, x: number, y: number, time: number, now: number, settings: GameServerSettings,
|
||||
counter: CounterService<void>
|
||||
): boolean {
|
||||
if (!client.lastTime) {
|
||||
return false;
|
||||
// no previous movement to compare against, only check for moving too far from server position
|
||||
return checkTooFar(client, x, y, settings);
|
||||
}
|
||||
|
||||
const pony = client.pony;
|
||||
const borderX = 0.5;
|
||||
const borderY = 0.5;
|
||||
const delta = ((time - client.lastTime) / 1000) * 1;
|
||||
// do not trust client time more than time that actually passed on the server
|
||||
const maxDelta = (now - client.lastMoveTime + maxTimeDeltaSlack) / 1000;
|
||||
const delta = clamp((time - client.lastTime) / 1000, 0, Math.max(0, maxDelta));
|
||||
|
||||
const afterX = roundPositionX(client.lastX + client.lastVX * delta);
|
||||
const afterY = roundPositionY(client.lastY + client.lastVY * delta);
|
||||
@@ -210,10 +218,15 @@ function checkTeleporting(
|
||||
}
|
||||
}
|
||||
|
||||
return checkTooFar(client, x, y, settings);
|
||||
}
|
||||
|
||||
function checkTooFar(client: IClient, x: number, y: number, settings: GameServerSettings): boolean {
|
||||
const pony = client.pony;
|
||||
const dx = Math.abs(x - pony.x);
|
||||
const dy = Math.abs(y - pony.y);
|
||||
|
||||
if (dx > 8 || dy > 8) {
|
||||
if (dx > maxMoveDistance || dy > maxMoveDistance) {
|
||||
if (settings.fixTeleporting) {
|
||||
pony.vx = 0;
|
||||
pony.vy = 0;
|
||||
|
||||
@@ -136,6 +136,7 @@ export function createClient(
|
||||
client.lastX = pony.x;
|
||||
client.lastY = pony.y;
|
||||
client.lastTime = 0;
|
||||
client.lastMoveTime = 0;
|
||||
client.lastVX = 0;
|
||||
client.lastVY = 0;
|
||||
client.lastMapSwitch = 0;
|
||||
|
||||
@@ -189,6 +189,7 @@ export interface IClient extends ClientActionsTemplate, ClientExtensions {
|
||||
lastX: number;
|
||||
lastY: number;
|
||||
lastTime: number;
|
||||
lastMoveTime: number;
|
||||
lastVX: number;
|
||||
lastVY: number;
|
||||
|
||||
|
||||
Reference in new issue
Block a user