@zardoy/flying-squid 0.0.107 → 0.0.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,11 +11,13 @@ const player = function (player, serv) {
11
11
  if (serv.isBlockAllowed && !serv.isBlockAllowed(position, stateId, { player, type: 'updateWorld' })) {
12
12
  return;
13
13
  }
14
- serv.getNearby({
15
- world: player.world,
16
- position
17
- })
18
- .forEach(p => p.sendBlock(position, stateId /* , blockData */)); // todo
14
+ if (!player.debugDigChunkUpdate) {
15
+ serv.getNearby({
16
+ world: player.world,
17
+ position
18
+ })
19
+ .forEach(p => p.sendBlock(position, stateId /* , blockData */)); // todo
20
+ }
19
21
  await player.world.setBlockStateId(position, stateId);
20
22
  if (blockData) {
21
23
  await player.world.setBlockData(position, blockData);
@@ -26,6 +28,16 @@ const player = function (player, serv) {
26
28
  else
27
29
  serv.updateBlock(player.world, position, serv.tickCount, serv.tickCount, true);
28
30
  }
31
+ if (player.debugDigChunkUpdate) {
32
+ // Resend current player chunk to update client with latest block changes
33
+ const playerChunkX = Math.floor(player.position.x / 16);
34
+ const playerChunkZ = Math.floor(player.position.z / 16);
35
+ player.world.getColumn(playerChunkX, playerChunkZ).then((column) => {
36
+ player.sendChunk(playerChunkX, playerChunkZ, column);
37
+ }).catch(err => {
38
+ console.warn('Failed to resend chunk for debug:', err);
39
+ });
40
+ }
29
41
  };
30
42
  player.sendBlock = (position, blockStateId) => // Call from player.setBlock unless you want "local" fake blocks
31
43
  player.behavior('sendBlock', {
@@ -3,6 +3,9 @@ import { Block } from 'prismarine-block';
3
3
  import { CustomWorld } from './world';
4
4
  export declare const player: (player: Player, serv: Server, { version }: Options) => void;
5
5
  declare global {
6
+ interface Player {
7
+ debugDigChunkUpdate?: boolean;
8
+ }
6
9
  interface PlayerBehaviorInputMap {
7
10
  'item_drop': {
8
11
  _input: {
@@ -36,9 +39,13 @@ declare global {
36
39
  };
37
40
  'suspiciousDigStopped': {
38
41
  _input: {
42
+ expectedDiggingTime: number;
43
+ actualDiggingTime: number;
39
44
  tooFast: boolean;
40
45
  tooFar: boolean;
41
46
  location: Vec3;
47
+ digTimeDiff: number;
48
+ digTimeAllowedThreshold: number;
42
49
  };
43
50
  };
44
51
  }
@@ -160,14 +160,18 @@ const player = function (player, serv, { version }) {
160
160
  let stop = false;
161
161
  // const MAX_DIG_DISTANCE = 7
162
162
  const MAX_DIG_DISTANCE = 8;
163
- const tooFast = expectedDiggingTime - diggingTime > 50;
163
+ const digTimeDiff = expectedDiggingTime - diggingTime;
164
+ const DIG_TIME_ALLOWED_THRESHOLD = 50;
165
+ const tooFast = digTimeDiff > DIG_TIME_ALLOWED_THRESHOLD;
164
166
  const tooFar = player.position.distanceTo(location) > MAX_DIG_DISTANCE;
165
167
  if (tooFast || tooFar) {
166
168
  stop = true;
167
169
  await player.behavior('suspiciousDigStopped', {
168
170
  tooFast,
171
+ digTimeDiff,
169
172
  tooFar,
170
- location
173
+ location,
174
+ digTimeAllowedThreshold: DIG_TIME_ALLOWED_THRESHOLD
171
175
  }, () => { }, () => {
172
176
  stop = false;
173
177
  });
@@ -11,7 +11,7 @@ export interface SpeedValidationResult {
11
11
  speedLimit: number;
12
12
  currentVelocitySquared: number;
13
13
  }
14
- export declare function validateMovementSpeed(player: Player, lastPosition: Vec3, newPosition: Vec3, packetCount: number): SpeedValidationResult;
14
+ export declare function validateMovementSpeed(player: Player, lastPosition: Vec3, newPosition: Vec3): SpeedValidationResult;
15
15
  export declare function findSafePosition(playerWorld: CustomWorld, mcData: IndexedData, attemptedPosition: Vec3): Vec3 | undefined;
16
16
  export declare function isInsideStrict(pos: Vec3, box: AABB): boolean;
17
17
  export declare function isInsideExpanded(pos: Vec3, box: AABB, threshold?: number): boolean;
@@ -28,6 +28,9 @@ declare global {
28
28
  basePositionAntiCheat?: boolean;
29
29
  positionAntiCheatNotifyPlayer?: boolean;
30
30
  }
31
+ interface Player {
32
+ debugMovementSpeed?: boolean;
33
+ }
31
34
  interface Server {
32
35
  safeZones: AABB[];
33
36
  resetSafeZones: () => void;
@@ -35,10 +35,6 @@ const server = (serv) => {
35
35
  exports.server = server;
36
36
  const player = (player, serv, { basePositionAntiCheat = false, positionAntiCheatNotifyPlayer = false }) => {
37
37
  let lastMovementTime = Date.now();
38
- let packetCount = 0; // Track move packets per tick (vanilla approach)
39
- serv.on('tick', (deltaTime, tickCount) => {
40
- packetCount = 0;
41
- });
42
38
  player.onReady.then(() => {
43
39
  player.knownPosition ??= player.position.clone();
44
40
  });
@@ -93,35 +89,26 @@ const player = (player, serv, { basePositionAntiCheat = false, positionAntiCheat
93
89
  }
94
90
  // Anti-cheat: Movement speed limit (vanilla-like approach)
95
91
  if (basePositionAntiCheat && lastPosition && !teleport) {
96
- packetCount++;
97
- // Limit packet count per tick like vanilla (max 5 meaningful packets)
98
- if (packetCount > 5) {
99
- packetCount = 1;
100
- }
101
- const speedCheck = validateMovementSpeed(player, lastPosition, position, packetCount);
92
+ const speedCheck = validateMovementSpeed(player, lastPosition, position);
102
93
  // Add debug fields to player
103
94
  player['debugMaxVelocity'] = speedCheck.distanceSquared;
104
95
  player['debugVelocityAllowanceMax'] = speedCheck.speedLimit;
105
96
  player['debugVelocityDiff'] = speedCheck.distanceSquared - speedCheck.speedLimit;
106
97
  player['debugExcessMovement'] = speedCheck.distanceSquared - speedCheck.currentVelocitySquared;
107
98
  player['debugIsValid'] = speedCheck.isValid;
108
- player['debugPacketCount'] = packetCount;
109
- // Debug output for all movements (temporary)
110
- // if (positionAntiCheatNotifyPlayer && speedCheck.distanceSquared > 0.001) {
111
- // player.chat(
112
- // `[DEBUG] distance²=${speedCheck.distanceSquared.toFixed(3)}, ` +
113
- // `limit=${speedCheck.speedLimit.toFixed(3)}, ` +
114
- // `excess=${player['debugExcessMovement'].toFixed(3)}, ` +
115
- // `valid=${speedCheck.isValid}, packets=${packetCount}`
116
- // )
117
- // }
99
+ if (player.debugMovementSpeed && speedCheck.isValid) {
100
+ const currentSpeed = Math.sqrt(speedCheck.distanceSquared).toFixed(3);
101
+ player.chat(`[DEBUG] (valid) ${currentSpeed}<${speedCheck.speedLimit.toFixed(3)}, ` +
102
+ `limit=${speedCheck.speedLimit.toFixed(3)}, ` +
103
+ `excess=${player['debugExcessMovement'].toFixed(3)}, ` +
104
+ `valid=${speedCheck.isValid}`);
105
+ }
118
106
  if (!speedCheck.isValid) {
119
107
  if (positionAntiCheatNotifyPlayer) {
120
- player.chat(`[safeZones] ${speedCheck.reason} ` +
121
- `(distance²=${speedCheck.distanceSquared.toFixed(2)}, ` +
122
- `limit=${speedCheck.speedLimit.toFixed(2)}, ` +
123
- `velocity²=${speedCheck.currentVelocitySquared.toFixed(2)}, ` +
124
- `excess=${player['debugExcessMovement'].toFixed(2)})`);
108
+ const currentSpeed = Math.sqrt(speedCheck.distanceSquared).toFixed(2);
109
+ const maxSpeed = Math.sqrt(speedCheck.speedLimit).toFixed(2);
110
+ const excess = Math.sqrt(Math.max(0, speedCheck.distanceSquared - speedCheck.speedLimit)).toFixed(2);
111
+ player.chat(`[safeZones] ${speedCheck.reason} - ${currentSpeed}>${maxSpeed} (excess ${excess})`);
125
112
  }
126
113
  cancel(false);
127
114
  player.teleport(lastPosition);
@@ -198,7 +185,7 @@ function isPlayerInsideBlock(player, serv, position) {
198
185
  }
199
186
  return false;
200
187
  }
201
- function validateMovementSpeed(player, lastPosition, newPosition, packetCount) {
188
+ function validateMovementSpeed(player, lastPosition, newPosition) {
202
189
  // Calculate movement delta (like vanilla)
203
190
  const deltaX = newPosition.x - lastPosition.x;
204
191
  const deltaY = newPosition.y - lastPosition.y;
@@ -236,16 +223,14 @@ function validateMovementSpeed(player, lastPosition, newPosition, packetCount) {
236
223
  speedLimit = Math.max(speedLimit, KNOCKBACK_VELOCITY * KNOCKBACK_VELOCITY * 4); // Very generous for knockback
237
224
  mode = 'knockback';
238
225
  }
239
- // Apply packet count multiplier (vanilla does this)
240
- const adjustedLimit = speedLimit * packetCount;
241
226
  // Vanilla check: distanceSquared - currentVelocitySquared > limit
242
227
  const excessMovement = distanceSquared - estimatedVelocitySquared;
243
- const isValid = excessMovement <= adjustedLimit;
228
+ const isValid = excessMovement <= speedLimit * 5;
244
229
  return {
245
230
  isValid,
246
231
  reason: isValid ? 'valid' : `Movement too fast (${mode})`,
247
232
  distanceSquared,
248
- speedLimit: adjustedLimit,
233
+ speedLimit: speedLimit,
249
234
  currentVelocitySquared: estimatedVelocitySquared
250
235
  };
251
236
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zardoy/flying-squid",
3
3
  "description": "A minecraft server written in TS",
4
- "version": "0.0.107",
4
+ "version": "0.0.108",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": "dist/app.js",