@zardoy/flying-squid 0.0.81 → 0.0.83
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/lib/modules/customBlockBreakTime.js +3 -1
- package/dist/lib/modules/customSync.d.ts +18 -0
- package/dist/lib/modules/customSync.js +122 -0
- package/dist/lib/modules/customWaypoints.d.ts +4 -3
- package/dist/lib/modules/customWaypoints.js +13 -9
- package/dist/lib/modules/database.d.ts +2 -0
- package/dist/lib/modules/digging.js +11 -4
- package/dist/lib/modules/errorHandler.d.ts +0 -2
- package/dist/lib/modules/errorHandler.js +2 -2
- package/dist/lib/modules/index.js +1 -0
- package/dist/lib/modules/log.d.ts +1 -1
- package/dist/lib/modules/log.js +19 -20
- package/dist/lib/modules/login.js +1 -0
- package/dist/lib/modules/pvp.d.ts +2 -0
- package/dist/lib/modules/pvp.js +27 -2
- package/dist/lib/modules/world.d.ts +1 -0
- package/dist/lib/modules/world.js +2 -2
- package/dist/modules.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const server: (serv: Server, options: Options) => {
|
|
2
|
+
lastSyncRequests: Map<string, {
|
|
3
|
+
time: number;
|
|
4
|
+
requestId: number;
|
|
5
|
+
}>;
|
|
6
|
+
nextRequestId: number;
|
|
7
|
+
/** @internal */
|
|
8
|
+
requestSync: (player: Player) => void;
|
|
9
|
+
handleSyncResponse: (player: Player, data: {
|
|
10
|
+
data: string;
|
|
11
|
+
}) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const player: (player: Player, serv: Server) => void;
|
|
14
|
+
declare global {
|
|
15
|
+
interface Server {
|
|
16
|
+
customSync: ReturnType<typeof server>;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.player = exports.server = void 0;
|
|
4
|
+
const SYNC_REQUEST_CHANNEL = 'minecraft-web-client:sync-request';
|
|
5
|
+
const SYNC_RESPONSE_CHANNEL = 'minecraft-web-client:sync-response';
|
|
6
|
+
const CHECK_INTERVAL = 1000; // 1 second
|
|
7
|
+
const server = (serv, options) => {
|
|
8
|
+
const module = {
|
|
9
|
+
// Track when we last requested sync from each player
|
|
10
|
+
lastSyncRequests: new Map(),
|
|
11
|
+
nextRequestId: 0,
|
|
12
|
+
// Request entity list from a player
|
|
13
|
+
/** @internal */
|
|
14
|
+
requestSync: (player) => {
|
|
15
|
+
const requestId = module.nextRequestId++;
|
|
16
|
+
const request = {
|
|
17
|
+
requestId,
|
|
18
|
+
time: Date.now()
|
|
19
|
+
};
|
|
20
|
+
player._client.writeChannel(SYNC_REQUEST_CHANNEL, {
|
|
21
|
+
data: JSON.stringify({ requestId })
|
|
22
|
+
});
|
|
23
|
+
module.lastSyncRequests.set(player.uuid, request);
|
|
24
|
+
},
|
|
25
|
+
// Handle sync response from client
|
|
26
|
+
handleSyncResponse: (player, data) => {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(data.data);
|
|
29
|
+
// Type guard to validate response shape
|
|
30
|
+
const isValidResponse = (obj) => {
|
|
31
|
+
return typeof obj === 'object' && obj !== null &&
|
|
32
|
+
typeof obj.requestId === 'number' &&
|
|
33
|
+
Array.isArray(obj.entityIds) &&
|
|
34
|
+
obj.entityIds.every(id => typeof id === 'number');
|
|
35
|
+
};
|
|
36
|
+
if (!isValidResponse(parsed)) {
|
|
37
|
+
throw new Error('Invalid response format');
|
|
38
|
+
}
|
|
39
|
+
const { requestId, entityIds } = parsed;
|
|
40
|
+
// Verify this is a response to our last request
|
|
41
|
+
const lastRequest = module.lastSyncRequests.get(player.uuid);
|
|
42
|
+
if (!lastRequest || lastRequest.requestId !== requestId) {
|
|
43
|
+
return; // Ignore out of order responses
|
|
44
|
+
}
|
|
45
|
+
// Calculate and update latency
|
|
46
|
+
const latency = Date.now() - lastRequest.time;
|
|
47
|
+
player._client.latency = latency;
|
|
48
|
+
// Clean up the request
|
|
49
|
+
module.lastSyncRequests.delete(player.uuid);
|
|
50
|
+
const trackedIds = new Set(entityIds);
|
|
51
|
+
const expectedIds = new Set();
|
|
52
|
+
// Find entities that should be visible to the player
|
|
53
|
+
for (const entity of Object.values(serv.entities)) {
|
|
54
|
+
if (entity.id === player.id)
|
|
55
|
+
continue; // Skip self
|
|
56
|
+
// Check if entity is within view distance
|
|
57
|
+
const dx = entity.position.x - player.position.x;
|
|
58
|
+
const dy = entity.position.y - player.position.y;
|
|
59
|
+
const dz = entity.position.z - player.position.z;
|
|
60
|
+
const distanceSquared = dx * dx + dy * dy + dz * dz;
|
|
61
|
+
const viewDistance = entity.viewDistance ?? 150;
|
|
62
|
+
if (distanceSquared <= viewDistance * viewDistance) {
|
|
63
|
+
expectedIds.add(entity.id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Find missing entities
|
|
67
|
+
for (const entityId of expectedIds) {
|
|
68
|
+
if (!trackedIds.has(entityId)) {
|
|
69
|
+
const entity = serv.entities[entityId];
|
|
70
|
+
if (!entity)
|
|
71
|
+
continue;
|
|
72
|
+
serv.warn(`Player ${player.username} missing entity ${entityId} (${entity.name ?? entity.type}), respawning... (ping: ${latency}ms)`);
|
|
73
|
+
// Respawn the entity for this player
|
|
74
|
+
player._client.write(entity.spawnPacketName, entity.getSpawnPacket());
|
|
75
|
+
// Send metadata if needed
|
|
76
|
+
if (serv.supportFeature('entityMetadataSentSeparately')) {
|
|
77
|
+
entity.sendMetadata(entity.metadata);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Log extra entities (debugging)
|
|
82
|
+
for (const entityId of trackedIds) {
|
|
83
|
+
if (!expectedIds.has(entityId) && !serv.entities[entityId]) {
|
|
84
|
+
serv.warn(`Player ${player.username} tracking non-existent entity ${entityId}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
serv.err(`Error handling sync response from ${player.username}: ${err}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
serv.customSync = module;
|
|
94
|
+
return module;
|
|
95
|
+
};
|
|
96
|
+
exports.server = server;
|
|
97
|
+
const player = (player, serv) => {
|
|
98
|
+
// Register sync channels with simplified string format
|
|
99
|
+
player._client.registerChannel(SYNC_REQUEST_CHANNEL, ['container', [
|
|
100
|
+
{
|
|
101
|
+
name: 'data',
|
|
102
|
+
type: ['pstring', { countType: 'i16' }]
|
|
103
|
+
}
|
|
104
|
+
]]);
|
|
105
|
+
player._client.registerChannel(SYNC_RESPONSE_CHANNEL, ['container', [
|
|
106
|
+
{
|
|
107
|
+
name: 'data',
|
|
108
|
+
type: ['pstring', { countType: 'i16' }]
|
|
109
|
+
}
|
|
110
|
+
]]);
|
|
111
|
+
// Handle sync responses from client
|
|
112
|
+
player._client.on(SYNC_RESPONSE_CHANNEL, (data) => {
|
|
113
|
+
serv.customSync.handleSyncResponse(player, data);
|
|
114
|
+
});
|
|
115
|
+
// Start periodic sync checks
|
|
116
|
+
player.on('spawned', () => {
|
|
117
|
+
player.setInterval(() => {
|
|
118
|
+
serv.customSync.requestSync(player);
|
|
119
|
+
}, CHECK_INTERVAL);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
exports.player = player;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const server: (serv: Server) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
waypoints: Record<string, Waypoint>;
|
|
3
|
+
addWaypoint: (id: string, waypoint: Waypoint, players?: Player[]) => void;
|
|
4
|
+
removeWaypoint: (id: string) => void;
|
|
5
5
|
};
|
|
6
6
|
export declare const player: (player: Player, serv: Server) => Promise<void>;
|
|
7
7
|
export type Waypoint = {
|
|
@@ -11,6 +11,7 @@ export type Waypoint = {
|
|
|
11
11
|
minDistance?: number;
|
|
12
12
|
label?: string;
|
|
13
13
|
color?: number;
|
|
14
|
+
_players?: string[];
|
|
14
15
|
};
|
|
15
16
|
declare global {
|
|
16
17
|
interface Server {
|
|
@@ -5,16 +5,16 @@ const ADD_CHANNEL = 'minecraft-web-client:waypoint-add';
|
|
|
5
5
|
const DELETE_CHANNEL = 'minecraft-web-client:waypoint-delete';
|
|
6
6
|
const server = (serv) => {
|
|
7
7
|
const module = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
waypoints: {},
|
|
9
|
+
addWaypoint: (id, waypoint, players) => {
|
|
10
|
+
module.waypoints[id] = { ...waypoint, _players: players ? players.map(p => p.uuid) : undefined };
|
|
11
11
|
// Broadcast add/update to all online players
|
|
12
|
-
for (const player of serv.players ?? []) {
|
|
12
|
+
for (const player of (players ?? serv.players ?? [])) {
|
|
13
13
|
sendAddWaypoint(player, id, waypoint);
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
|
|
17
|
-
delete
|
|
16
|
+
removeWaypoint: (id) => {
|
|
17
|
+
delete module.waypoints[id];
|
|
18
18
|
// Broadcast delete to all online players
|
|
19
19
|
for (const player of serv.players ?? []) {
|
|
20
20
|
sendDeleteWaypoint(player, id);
|
|
@@ -40,9 +40,11 @@ function sendDeleteWaypoint(player, id) {
|
|
|
40
40
|
player._client.writeChannel(DELETE_CHANNEL, { id });
|
|
41
41
|
}
|
|
42
42
|
function sendAllWaypoints(player, serv) {
|
|
43
|
-
const entries = Object.entries(serv.customWaypoints.
|
|
43
|
+
const entries = Object.entries(serv.customWaypoints.waypoints ?? {});
|
|
44
44
|
for (const [id, waypoint] of entries) {
|
|
45
|
-
|
|
45
|
+
if (!waypoint._players || waypoint._players.includes(player.uuid)) {
|
|
46
|
+
sendAddWaypoint(player, id, waypoint);
|
|
47
|
+
}
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
const player = async (player, serv) => {
|
|
@@ -66,6 +68,8 @@ const player = async (player, serv) => {
|
|
|
66
68
|
{ name: 'id', type: ['pstring', { countType: 'i16' }] },
|
|
67
69
|
]]);
|
|
68
70
|
// Send current server waypoints on join
|
|
69
|
-
|
|
71
|
+
player.on('login', () => {
|
|
72
|
+
sendAllWaypoints(player, serv);
|
|
73
|
+
});
|
|
70
74
|
};
|
|
71
75
|
exports.player = player;
|
|
@@ -142,6 +142,7 @@ const player = function (player, serv, { version }) {
|
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
+
const blockDropVelocity = new vec3_1.Vec3(Math.random() * 4 - 2, Math.random() * 2 + 2, Math.random() * 4 - 2);
|
|
145
146
|
async function completeDigging(location) {
|
|
146
147
|
clearInterval(animationInterval);
|
|
147
148
|
const diggingTime = Date.now() - startDiggingTime;
|
|
@@ -168,18 +169,24 @@ const player = function (player, serv, { version }) {
|
|
|
168
169
|
if (typeof mcData.blockLoot === 'undefined') {
|
|
169
170
|
drops.push({
|
|
170
171
|
...dropBase,
|
|
171
|
-
blockDropVelocity:
|
|
172
|
+
blockDropVelocity: blockDropVelocity,
|
|
172
173
|
blockDropId: serv.supportFeature('theFlattening') ? currentlyDugBlock.drops?.[0] : currentlyDugBlock.type
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
176
|
else {
|
|
176
177
|
const heldItem = player.inventory.slots[36 + player.heldItemSlot];
|
|
177
|
-
|
|
178
|
+
let enchants;
|
|
179
|
+
try {
|
|
180
|
+
enchants = heldItem?.enchants;
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
}
|
|
184
|
+
const silkTouch = enchants?.map(enchant => enchant.name).includes('silk_touch');
|
|
178
185
|
const blockDrops = mcData.blockLoot[currentlyDugBlock.name].drops.filter(drop => !(drop[`${silkTouch ? 'noS' : 's'}ilkTouch`] ?? false));
|
|
179
186
|
for (const drop of blockDrops) {
|
|
180
187
|
drops.push({
|
|
181
188
|
...dropBase,
|
|
182
|
-
blockDropVelocity:
|
|
189
|
+
blockDropVelocity: blockDropVelocity,
|
|
183
190
|
blockDropId: mcData.itemsByName[drop.item].id
|
|
184
191
|
});
|
|
185
192
|
}
|
|
@@ -240,7 +247,7 @@ const player = function (player, serv, { version }) {
|
|
|
240
247
|
dropBlock: false,
|
|
241
248
|
blockDropPosition: location.offset(0.5, 0.5, 0.5),
|
|
242
249
|
blockDropWorld: player.world,
|
|
243
|
-
blockDropVelocity:
|
|
250
|
+
blockDropVelocity: blockDropVelocity,
|
|
244
251
|
blockDropId: currentlyDugBlock.type,
|
|
245
252
|
blockDropDamage: currentlyDugBlock.metadata,
|
|
246
253
|
blockDropPickup: 500,
|
|
@@ -6,7 +6,7 @@ const player = async function (player, serv) {
|
|
|
6
6
|
serv.warn('-------------------------------');
|
|
7
7
|
serv.warn('Please report this flying-squid! This is bug (mabye)');
|
|
8
8
|
serv.warn('Unhandled rejection warning!');
|
|
9
|
-
serv.warn('Error: ' + promise);
|
|
9
|
+
serv.warn('Error: ' + (promise.stack ?? promise));
|
|
10
10
|
serv.warn('Report this error here: https://github.com/PrismarineJS/flying-squid/issues');
|
|
11
11
|
serv.warn('-------------------------------');
|
|
12
12
|
serv.emit('unhandledRejectionWarning');
|
|
@@ -15,7 +15,7 @@ const player = async function (player, serv) {
|
|
|
15
15
|
serv.err('-------------------------------');
|
|
16
16
|
serv.err('Please report this flying-squid! This is bug (mabye)');
|
|
17
17
|
serv.err('Something went wrong!');
|
|
18
|
-
serv.err('Error: ' + err.stack);
|
|
18
|
+
serv.err('Error: ' + (err.stack ?? err));
|
|
19
19
|
serv.err('Report this error here: https://github.com/PrismarineJS/flying-squid/issues');
|
|
20
20
|
serv.err('-------------------------------');
|
|
21
21
|
serv.emit('crash');
|
|
@@ -15,6 +15,7 @@ module.exports = {
|
|
|
15
15
|
'communication': require('./communication'),
|
|
16
16
|
'crafting': require('./crafting'),
|
|
17
17
|
'customBlockBreakTime': require('./customBlockBreakTime'),
|
|
18
|
+
'customSync': require('./customSync'),
|
|
18
19
|
'customWaypoints': require('./customWaypoints'),
|
|
19
20
|
'database': require('./database'),
|
|
20
21
|
'daycycle': require('./daycycle'),
|
|
@@ -5,7 +5,7 @@ declare global {
|
|
|
5
5
|
/** You can override this function so you can process the message before sending it to the console. */
|
|
6
6
|
formatMessage(message: any): any;
|
|
7
7
|
/** Logs a `message` */
|
|
8
|
-
"log": (message: any) => void;
|
|
8
|
+
"log": (message: any, isError?: boolean) => void;
|
|
9
9
|
/** Logs a `message` as info */
|
|
10
10
|
"info": (message: any) => void;
|
|
11
11
|
/** Logs a `message` as error */
|
package/dist/lib/modules/log.js
CHANGED
|
@@ -85,46 +85,45 @@ const server = function (serv, settings) {
|
|
|
85
85
|
serv.on('banned', (banner, bannedUsername, reason) => serv.info(banner.username + ' banned ' + bannedUsername + (reason ? ' (' + reason + ')' : '')));
|
|
86
86
|
serv.on('seed', (seed) => serv.info('World seed: ' + seed));
|
|
87
87
|
const logFile = path_1.default.join('logs', timeStarted + '.log');
|
|
88
|
-
serv.log = message => {
|
|
88
|
+
serv.log = (message, isError = false) => {
|
|
89
89
|
readline?.cursorTo(process.stdout, 0);
|
|
90
90
|
let date = new Date();
|
|
91
91
|
let formattedDate = `${date.toLocaleString('default', { month: 'long' })} ${date.getDate()} ${date.getFullYear()}, ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
// Prefix timestamp first
|
|
93
|
+
let fullMessage = formattedDate + ' ' + message; // todo use intl
|
|
94
|
+
// Allow user-defined formatting to modify the full line
|
|
95
|
+
fullMessage = serv.formatMessage?.(fullMessage) ?? fullMessage;
|
|
96
|
+
if (!fullMessage)
|
|
95
97
|
return;
|
|
98
|
+
// Push to buffers (plain text, with timestamp)
|
|
99
|
+
const plain = fullMessage.replace(/\x1B\[[0-9;]*m/g, '');
|
|
100
|
+
serv._logBuffer.push(plain);
|
|
101
|
+
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
102
|
+
serv._logBuffer.shift();
|
|
103
|
+
if (isError) {
|
|
104
|
+
serv._errorBuffer.push(plain);
|
|
105
|
+
if (serv._errorBuffer.length > MAX_BUFFER_LINES)
|
|
106
|
+
serv._errorBuffer.shift();
|
|
107
|
+
}
|
|
96
108
|
if (!settings.noConsoleOutput)
|
|
97
|
-
console.log(
|
|
109
|
+
console.log(fullMessage);
|
|
98
110
|
if (!settings.logging)
|
|
99
111
|
return;
|
|
100
|
-
fs_1.default.appendFile(logFile,
|
|
112
|
+
fs_1.default.appendFile(logFile, plain + '\n', (err) => {
|
|
101
113
|
if (err)
|
|
102
114
|
console.log(err);
|
|
103
115
|
});
|
|
104
116
|
};
|
|
105
117
|
serv.info = message => {
|
|
106
118
|
const line = '[' + chalk_1.default.green('INFO') + ']: ' + message;
|
|
107
|
-
serv._logBuffer.push(line.replace(/\x1B\[[0-9;]*m/g, ''));
|
|
108
|
-
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
109
|
-
serv._logBuffer.shift();
|
|
110
119
|
serv.log(line);
|
|
111
120
|
};
|
|
112
121
|
serv.err = message => {
|
|
113
122
|
const line = '[' + chalk_1.default.red('ERROR') + ']: ' + message;
|
|
114
|
-
|
|
115
|
-
serv._logBuffer.push(plain);
|
|
116
|
-
serv._errorBuffer.push(plain);
|
|
117
|
-
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
118
|
-
serv._logBuffer.shift();
|
|
119
|
-
if (serv._errorBuffer.length > MAX_BUFFER_LINES)
|
|
120
|
-
serv._errorBuffer.shift();
|
|
121
|
-
serv.log(line);
|
|
123
|
+
serv.log(line, true);
|
|
122
124
|
};
|
|
123
125
|
serv.warn = message => {
|
|
124
126
|
const line = '[' + chalk_1.default.yellow('WARN') + ']: ' + message;
|
|
125
|
-
serv._logBuffer.push(line.replace(/\x1B\[[0-9;]*m/g, ''));
|
|
126
|
-
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
127
|
-
serv._logBuffer.shift();
|
|
128
127
|
serv.log(line);
|
|
129
128
|
};
|
|
130
129
|
if (isInNode) {
|
|
@@ -241,6 +241,7 @@ const player = async function (player, serv, settings) {
|
|
|
241
241
|
isDebug: false,
|
|
242
242
|
isFlat: settings.generation?.name === 'superflat'
|
|
243
243
|
});
|
|
244
|
+
player.emit('login');
|
|
244
245
|
if (serv.supportFeature('difficultySentSeparately')) {
|
|
245
246
|
player._client.write('difficulty', {
|
|
246
247
|
difficulty: serv.difficulty,
|
|
@@ -3,6 +3,8 @@ export declare const entity: (entity: Entity, serv: Server) => void;
|
|
|
3
3
|
export declare const server: (serv: Server) => void;
|
|
4
4
|
declare global {
|
|
5
5
|
interface Entity {
|
|
6
|
+
/** Whether the entity is invincible to all damage */
|
|
7
|
+
invincible: boolean;
|
|
6
8
|
/** How many half-hearts an entity has of health (e.g. Player has 20). Not really used for objects, only players and mobs. */
|
|
7
9
|
health: number;
|
|
8
10
|
/** * sound: Sound to play (default is game.player.hurt)
|
package/dist/lib/modules/pvp.js
CHANGED
|
@@ -7,15 +7,35 @@ exports.server = exports.entity = exports.player = void 0;
|
|
|
7
7
|
const vec3_1 = require("vec3");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const user_error_1 = __importDefault(require("../user_error"));
|
|
10
|
+
const MAX_ATTACK_DISTANCE = 4; // Maximum reach in blocks
|
|
11
|
+
const ATTACK_COOLDOWN_MS = 250; // Minimum time between attacks
|
|
12
|
+
const DEFAULT_KNOCKBACK = new vec3_1.Vec3(0, 0.4, 0); // Base vertical knockback
|
|
13
|
+
const KNOCKBACK_MULTIPLIER = 0.4; // Horizontal knockback scaling
|
|
10
14
|
const player = function (player, serv) {
|
|
15
|
+
let lastAttackTime = 0;
|
|
11
16
|
function attackEntity(entityId) {
|
|
12
17
|
const attackedEntity = serv.entities[entityId];
|
|
13
18
|
const attackedPlayer = attackedEntity.type === 'player' ? attackedEntity : undefined;
|
|
14
|
-
if (!attackedEntity
|
|
19
|
+
if (!attackedEntity)
|
|
15
20
|
return;
|
|
21
|
+
if (attackedPlayer && (attackedPlayer.gameMode === 1 || attackedPlayer.gameMode === 3 || attackedPlayer.invincible))
|
|
22
|
+
return;
|
|
23
|
+
// Anti-cheat: Distance check
|
|
24
|
+
const distance = player.position.distanceTo(attackedEntity.position);
|
|
25
|
+
if (distance > MAX_ATTACK_DISTANCE) {
|
|
26
|
+
return; // Silently fail suspicious attacks
|
|
27
|
+
}
|
|
28
|
+
// Rate limiting
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
if (now - lastAttackTime < ATTACK_COOLDOWN_MS)
|
|
31
|
+
return;
|
|
32
|
+
lastAttackTime = now;
|
|
33
|
+
// Calculate knockback direction and strength
|
|
34
|
+
const knockbackDir = attackedEntity.position.minus(player.position).normalize();
|
|
35
|
+
const velocity = DEFAULT_KNOCKBACK.plus(knockbackDir.scaled(KNOCKBACK_MULTIPLIER));
|
|
16
36
|
player.behavior('attack', {
|
|
17
37
|
attackedEntity,
|
|
18
|
-
velocity
|
|
38
|
+
velocity
|
|
19
39
|
}, (o) => o.attackedEntity.takeDamage(o));
|
|
20
40
|
}
|
|
21
41
|
player._client.on('use_entity', ({ mouse, target } = {}) => {
|
|
@@ -35,7 +55,10 @@ const player = function (player, serv) {
|
|
|
35
55
|
};
|
|
36
56
|
exports.player = player;
|
|
37
57
|
const entity = function (entity, serv) {
|
|
58
|
+
entity.invincible = false;
|
|
38
59
|
entity.takeDamage = ({ sound = 'game.player.hurt', damage = 1, velocity = new vec3_1.Vec3(0, 0, 0), maxVelocity = new vec3_1.Vec3(4, 4, 4), animation = true }) => {
|
|
60
|
+
if (entity.invincible)
|
|
61
|
+
return;
|
|
39
62
|
entity.updateHealth(entity.health - damage);
|
|
40
63
|
serv.playSound(sound, entity.world, entity.position);
|
|
41
64
|
entity.sendVelocity(velocity, maxVelocity);
|
|
@@ -73,6 +96,7 @@ const server = function (serv) {
|
|
|
73
96
|
info: 'Kill entities',
|
|
74
97
|
usage: '/kill <selector>|<player>',
|
|
75
98
|
tab: ['player'],
|
|
99
|
+
op: true,
|
|
76
100
|
parse(str) {
|
|
77
101
|
return str || false;
|
|
78
102
|
},
|
|
@@ -105,6 +129,7 @@ const server = function (serv) {
|
|
|
105
129
|
info: 'Applies damage to the specified entities',
|
|
106
130
|
usage: '/damage',
|
|
107
131
|
tab: ['player', 'number'],
|
|
132
|
+
op: true,
|
|
108
133
|
parse(string, ctx) {
|
|
109
134
|
return string.split(' '); // todo validate
|
|
110
135
|
},
|
|
@@ -28,6 +28,7 @@ declare global {
|
|
|
28
28
|
/** Alias to serv.overworld.seed */
|
|
29
29
|
seed: number;
|
|
30
30
|
writeLevelDat: () => Promise<void>;
|
|
31
|
+
broadcastSaved?: boolean;
|
|
31
32
|
"overworldOriginalGenerator": (chunkX: number, chunkZ: number) => any;
|
|
32
33
|
"overworldGeneratorOverride"?: (chunkX: number, chunkZ: number, generationOptions: any) => any;
|
|
33
34
|
}
|
|
@@ -344,7 +344,7 @@ const server = async function (serv, options) {
|
|
|
344
344
|
console.log('worlds init done');
|
|
345
345
|
// Periodic autosave: world and all players
|
|
346
346
|
const autosaveMs = options.savingInterval === false ? 0 : (typeof options.savingInterval === 'number' ? options.savingInterval : 60_000);
|
|
347
|
-
if (autosaveMs > 0) {
|
|
347
|
+
if (autosaveMs > 0 && options.worldFolder) {
|
|
348
348
|
let lastBroadcastTs = 0;
|
|
349
349
|
const doAutosave = async () => {
|
|
350
350
|
try {
|
|
@@ -358,7 +358,7 @@ const server = async function (serv, options) {
|
|
|
358
358
|
await serv.saveAllPlayerDataToDisk?.();
|
|
359
359
|
// Broadcast a single "Server saved" message (no spam more than once per interval)
|
|
360
360
|
const now = Date.now();
|
|
361
|
-
if (now - lastBroadcastTs > autosaveMs -
|
|
361
|
+
if (now - lastBroadcastTs > autosaveMs - 10_000 && serv.broadcastSaved !== false) {
|
|
362
362
|
serv.broadcast('§7[autosave] Server saved');
|
|
363
363
|
lastBroadcastTs = now;
|
|
364
364
|
}
|
package/dist/modules.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare global {
|
|
|
17
17
|
/** Emitted when the player's data is loaded from playerdata folder and can be patched if needed (but will be saved back to playerdata folder if patched) */
|
|
18
18
|
dataLoaded: () => void;
|
|
19
19
|
databaseLoaded: () => void;
|
|
20
|
+
login: () => void;
|
|
20
21
|
}
|
|
21
22
|
interface ServerEvents {
|
|
22
23
|
error: (error: Error, pluginName?: string) => void;
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import "./lib/modules/commands.d.ts"
|
|
|
12
12
|
import "./lib/modules/communication.d.ts"
|
|
13
13
|
import "./lib/modules/crafting.d.ts"
|
|
14
14
|
import "./lib/modules/customBlockBreakTime.d.ts"
|
|
15
|
+
import "./lib/modules/customSync.d.ts"
|
|
15
16
|
import "./lib/modules/customWaypoints.d.ts"
|
|
16
17
|
import "./lib/modules/database.d.ts"
|
|
17
18
|
import "./lib/modules/daycycle.d.ts"
|