@zardoy/flying-squid 0.0.106 → 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.
package/dist/index.js
CHANGED
|
@@ -115,11 +115,12 @@ class MCServer extends events_1.EventEmitter {
|
|
|
115
115
|
const packetUsername = packet.username.toLowerCase();
|
|
116
116
|
if (connPendingUsernames.has(packetUsername)) {
|
|
117
117
|
client.end('A player with this username is already connecting');
|
|
118
|
+
return;
|
|
118
119
|
}
|
|
119
120
|
connPendingUsernames.add(packetUsername);
|
|
120
121
|
try {
|
|
121
122
|
const username = (await server.customGetUsername?.(packet, client)) ?? packetUsername;
|
|
122
|
-
if (client.ended)
|
|
123
|
+
if (client.ended || client['_endReason'])
|
|
123
124
|
return;
|
|
124
125
|
const existingPlayer = Object.values(server._server.clients)
|
|
125
126
|
.find(c => c.username?.toLowerCase?.() === username);
|
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
|
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 <=
|
|
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:
|
|
233
|
+
speedLimit: speedLimit,
|
|
249
234
|
currentVelocitySquared: estimatedVelocitySquared
|
|
250
235
|
};
|
|
251
236
|
}
|