@zardoy/flying-squid 0.0.113 → 0.0.115
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/chat.js +1 -1
- package/dist/lib/modules/log.d.ts +8 -0
- package/dist/lib/modules/log.js +93 -7
- package/dist/lib/modules/moderation.d.ts +1 -1
- package/dist/lib/modules/moderation.js +39 -27
- package/dist/lib/modules/playerLogin.js +3 -3
- package/dist/modules.d.ts +0 -1
- package/package.json +1 -1
package/dist/lib/modules/chat.js
CHANGED
|
@@ -11,7 +11,7 @@ const server = function (serv) {
|
|
|
11
11
|
if (whitelist.type === 'player')
|
|
12
12
|
whitelist = [whitelist];
|
|
13
13
|
// Log the broadcast message
|
|
14
|
-
serv.log(`[
|
|
14
|
+
serv.log(`[SERVER BROADCAST]: ${message}`);
|
|
15
15
|
whitelist.filter(w => blacklist.indexOf(w) === -1).forEach(player => {
|
|
16
16
|
if (!system)
|
|
17
17
|
player.chat(message);
|
|
@@ -18,5 +18,13 @@ declare global {
|
|
|
18
18
|
interface Options {
|
|
19
19
|
/** Whether to redirect console.log output to server log file. Defaults to true. */
|
|
20
20
|
noConsoleLogRedirect?: boolean;
|
|
21
|
+
logging?: boolean | string;
|
|
22
|
+
/** Whether to clear the log file when server starts. Defaults to false. */
|
|
23
|
+
clearLogOnStart?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum log file size in MB before rotation. When exceeded, keeps 70% of recent lines.
|
|
26
|
+
* @default 30
|
|
27
|
+
*/
|
|
28
|
+
maxLogFileSize?: number;
|
|
21
29
|
}
|
|
22
30
|
}
|
package/dist/lib/modules/log.js
CHANGED
|
@@ -76,6 +76,29 @@ const server = function (serv, settings) {
|
|
|
76
76
|
// Initialize log streams
|
|
77
77
|
let logStream = null;
|
|
78
78
|
let logPath = null;
|
|
79
|
+
// Log file size management
|
|
80
|
+
const checkLogFileSize = () => {
|
|
81
|
+
if (!logPath)
|
|
82
|
+
return;
|
|
83
|
+
const maxSize = settings.maxLogFileSize ?? 30; // Default to 30MB
|
|
84
|
+
if (!maxSize)
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
const stats = fs_1.default.statSync(logPath);
|
|
88
|
+
const fileSizeMB = stats.size / (1024 * 1024); // Convert to MB
|
|
89
|
+
if (fileSizeMB > maxSize) {
|
|
90
|
+
// Rotate log file by removing old lines
|
|
91
|
+
const lines = fs_1.default.readFileSync(logPath, 'utf8').split('\n');
|
|
92
|
+
const linesToKeep = Math.floor(lines.length * 0.7); // Keep 70% of lines
|
|
93
|
+
const newContent = lines.slice(-linesToKeep).join('\n');
|
|
94
|
+
fs_1.default.writeFileSync(logPath, newContent);
|
|
95
|
+
serv.info(`Log file rotated: ${fileSizeMB.toFixed(2)}MB -> ${(fs_1.default.statSync(logPath).size / (1024 * 1024)).toFixed(2)}MB`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
serv.warn(`Failed to check log file size: ${err.message}`);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
79
102
|
// Setup logging if enabled
|
|
80
103
|
if (settings.logging) {
|
|
81
104
|
try {
|
|
@@ -98,6 +121,18 @@ const server = function (serv, settings) {
|
|
|
98
121
|
if (logPath) {
|
|
99
122
|
// Ensure directory exists
|
|
100
123
|
fs_1.default.mkdirSync(path_1.default.dirname(logPath), { recursive: true });
|
|
124
|
+
// Clear log file if requested
|
|
125
|
+
if (settings.clearLogOnStart) {
|
|
126
|
+
try {
|
|
127
|
+
if (fs_1.default.existsSync(logPath)) {
|
|
128
|
+
fs_1.default.writeFileSync(logPath, '');
|
|
129
|
+
serv.info(`Cleared existing log file: ${logPath}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
serv.warn(`Failed to clear log file: ${err.message}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
101
136
|
// Create write stream
|
|
102
137
|
logStream = fs_1.default.createWriteStream(logPath, {
|
|
103
138
|
flags: 'a', // Append mode
|
|
@@ -112,6 +147,7 @@ const server = function (serv, settings) {
|
|
|
112
147
|
// Disable logging on error
|
|
113
148
|
// logStream = null
|
|
114
149
|
});
|
|
150
|
+
// serv.setInterval(checkLogFileSize, 5 * 60 * 1000) // 5 minutes
|
|
115
151
|
serv.cleanupFunctions.push(() => {
|
|
116
152
|
if (logStream) {
|
|
117
153
|
logStream.end('\n[INFO]: Logging ended\n');
|
|
@@ -166,6 +202,10 @@ const server = function (serv, settings) {
|
|
|
166
202
|
// Write to log file if stream is available
|
|
167
203
|
if (logStream?.writable) {
|
|
168
204
|
logStream.write(plain + '\n');
|
|
205
|
+
// Check log file size periodically (every 100 log entries)
|
|
206
|
+
if (serv._logBuffer.length % 100 === 0) {
|
|
207
|
+
checkLogFileSize();
|
|
208
|
+
}
|
|
169
209
|
}
|
|
170
210
|
};
|
|
171
211
|
serv.info = message => {
|
|
@@ -181,19 +221,19 @@ const server = function (serv, settings) {
|
|
|
181
221
|
serv.log(line);
|
|
182
222
|
};
|
|
183
223
|
if (isInNode) {
|
|
184
|
-
|
|
185
|
-
|
|
224
|
+
// Helper function to create console method wrapper
|
|
225
|
+
const createConsoleWrapper = (originalMethod, prefix) => {
|
|
186
226
|
return function () {
|
|
187
227
|
readline.cursorTo(process.stdout, 0);
|
|
188
|
-
// Apply original
|
|
189
|
-
|
|
228
|
+
// Apply original method to stdout
|
|
229
|
+
originalMethod.apply(console, arguments);
|
|
190
230
|
// Redirect to server log if enabled and not disabled
|
|
191
231
|
if (!settings.noConsoleLogRedirect && logStream?.writable) {
|
|
192
232
|
const args = Array.from(arguments);
|
|
193
233
|
const message = args.map(arg => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)).join(' ');
|
|
194
|
-
// Add timestamp and prefix for console
|
|
234
|
+
// Add timestamp and prefix for console entries
|
|
195
235
|
const timestamp = new Date().toISOString();
|
|
196
|
-
const logEntry = `[${timestamp}] [CONSOLE]: ${message}\n`;
|
|
236
|
+
const logEntry = `[${timestamp}] [CONSOLE ${prefix}]: ${message}\n`;
|
|
197
237
|
try {
|
|
198
238
|
logStream.write(logEntry);
|
|
199
239
|
}
|
|
@@ -203,7 +243,53 @@ const server = function (serv, settings) {
|
|
|
203
243
|
}
|
|
204
244
|
rl.prompt(true);
|
|
205
245
|
};
|
|
206
|
-
}
|
|
246
|
+
};
|
|
247
|
+
// Patch console.log
|
|
248
|
+
console.log = createConsoleWrapper(console.log, 'LOG');
|
|
249
|
+
// Patch console.error
|
|
250
|
+
console.error = createConsoleWrapper(console.error, 'ERROR');
|
|
251
|
+
// Patch console.warn
|
|
252
|
+
console.warn = createConsoleWrapper(console.warn, 'WARN');
|
|
253
|
+
// Patch console.time and console.timeEnd
|
|
254
|
+
const originalTime = console.time;
|
|
255
|
+
const originalTimeEnd = console.timeEnd;
|
|
256
|
+
const timeLabels = new Map();
|
|
257
|
+
console.time = function (label) {
|
|
258
|
+
const startTime = Date.now();
|
|
259
|
+
timeLabels.set(label, startTime);
|
|
260
|
+
originalTime.call(console, label);
|
|
261
|
+
if (!settings.noConsoleLogRedirect && logStream?.writable) {
|
|
262
|
+
const timestamp = new Date().toISOString();
|
|
263
|
+
const logEntry = `[${timestamp}] [CONSOLE TIME]: Timer '${label}' started\n`;
|
|
264
|
+
try {
|
|
265
|
+
logStream.write(logEntry);
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
// Silently fail if log writing fails to avoid infinite loops
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
console.timeEnd = function (label) {
|
|
273
|
+
const startTime = timeLabels.get(label);
|
|
274
|
+
if (startTime) {
|
|
275
|
+
const duration = Date.now() - startTime;
|
|
276
|
+
timeLabels.delete(label);
|
|
277
|
+
originalTimeEnd.call(console, label);
|
|
278
|
+
if (!settings.noConsoleLogRedirect && logStream?.writable) {
|
|
279
|
+
const timestamp = new Date().toISOString();
|
|
280
|
+
const logEntry = `[${timestamp}] [CONSOLE TIME]: Timer '${label}' ended: ${duration}ms\n`;
|
|
281
|
+
try {
|
|
282
|
+
logStream.write(logEntry);
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
// Silently fail if log writing fails to avoid infinite loops
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
originalTimeEnd.call(console, label);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
207
293
|
}
|
|
208
294
|
// Return current log file path
|
|
209
295
|
serv.getLogPath = () => logPath;
|
|
@@ -3,7 +3,7 @@ export declare const player: (player: Player, serv: Server) => void;
|
|
|
3
3
|
declare global {
|
|
4
4
|
interface Server {
|
|
5
5
|
/** Ban player given a uuid. If the player is online, using `player.ban()`. Bans with reason or `You are banned!`. */
|
|
6
|
-
"ban": (uuid: string, reason?: string) =>
|
|
6
|
+
"ban": (uuid: string, reason?: string, kick?: boolean) => boolean;
|
|
7
7
|
/** Gets UUID from username. Since it needs to fetch from mojang servers, it is not immediate.
|
|
8
8
|
*
|
|
9
9
|
* Arguments in format: `callback(uuid)`. `uuid` is null if no such username exists.
|
|
@@ -6,26 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.player = exports.server = void 0;
|
|
7
7
|
const user_error_1 = __importDefault(require("../user_error"));
|
|
8
8
|
const server = function (serv, settings) {
|
|
9
|
-
serv.ban =
|
|
9
|
+
serv.ban = (uuid, reason, kick = true) => {
|
|
10
10
|
if (!serv.bannedPlayers[uuid]) {
|
|
11
|
+
console.log('banning player', uuid, reason);
|
|
12
|
+
reason ||= 'Your account is banned!';
|
|
11
13
|
serv.bannedPlayers[uuid] = {
|
|
12
14
|
time: Date.now(),
|
|
13
|
-
reason: reason
|
|
15
|
+
reason: reason
|
|
14
16
|
};
|
|
17
|
+
if (kick) {
|
|
18
|
+
const player = serv.players.find(player => player.uuid === uuid);
|
|
19
|
+
if (player)
|
|
20
|
+
player.kick(reason);
|
|
21
|
+
}
|
|
15
22
|
return true;
|
|
16
23
|
}
|
|
17
24
|
else
|
|
18
25
|
return false;
|
|
19
26
|
};
|
|
20
|
-
serv.banIP =
|
|
27
|
+
serv.banIP = (IP, reason, kick = true) => {
|
|
21
28
|
if (!serv.bannedIPs[IP]) {
|
|
29
|
+
reason ||= 'Your IP is banned!';
|
|
22
30
|
serv.bannedIPs[IP] = {
|
|
23
31
|
time: Date.now(),
|
|
24
|
-
reason: reason
|
|
32
|
+
reason: reason
|
|
25
33
|
};
|
|
26
|
-
|
|
27
|
-
.
|
|
28
|
-
|
|
34
|
+
if (kick) {
|
|
35
|
+
Object.keys(serv.players)
|
|
36
|
+
.filter(uuid => serv.players[uuid]._client.socket?.remoteAddress === IP)
|
|
37
|
+
.forEach(uuid => serv.players[uuid].kick(serv.bannedIPs[serv.players[uuid]._client.socket?.remoteAddress].reason));
|
|
38
|
+
}
|
|
29
39
|
return true;
|
|
30
40
|
}
|
|
31
41
|
else
|
|
@@ -35,6 +45,10 @@ const server = function (serv, settings) {
|
|
|
35
45
|
return plainUUID.length === 32 ? plainUUID.substring(0, 8) + '-' + plainUUID.substring(8, 12) + '-' + plainUUID.substring(12, 16) + '-' + plainUUID.substring(16, 20) + '-' + plainUUID.substring(20) : plainUUID;
|
|
36
46
|
}
|
|
37
47
|
serv.getUUIDFromUsername = async (username) => {
|
|
48
|
+
// quick lookup in players list
|
|
49
|
+
const player = serv.players.find(player => player.username.toLowerCase() === username.toLowerCase());
|
|
50
|
+
if (player)
|
|
51
|
+
return player.uuid;
|
|
38
52
|
return await new Promise((resolve, reject) => {
|
|
39
53
|
fetch('https://api.mojang.com/users/profiles/minecraft/' + username)
|
|
40
54
|
.then(response => response.json())
|
|
@@ -46,16 +60,16 @@ const server = function (serv, settings) {
|
|
|
46
60
|
.catch(err => { throw err; });
|
|
47
61
|
});
|
|
48
62
|
};
|
|
49
|
-
serv.
|
|
63
|
+
serv.banUUID = async (username, reason) => {
|
|
50
64
|
return serv.ban(username, reason);
|
|
51
65
|
};
|
|
52
|
-
serv.
|
|
66
|
+
serv.banUsername = async (username, reason) => {
|
|
53
67
|
return serv.getUUIDFromUsername(username).then(uuid => serv.ban(uuid, reason));
|
|
54
68
|
};
|
|
55
|
-
serv.
|
|
69
|
+
serv.pardonUUID = async (username) => {
|
|
56
70
|
return pardon(username);
|
|
57
71
|
};
|
|
58
|
-
serv.
|
|
72
|
+
serv.pardonUsername = async (username) => {
|
|
59
73
|
return serv.getUUIDFromUsername(username)
|
|
60
74
|
.then(pardon);
|
|
61
75
|
};
|
|
@@ -296,21 +310,19 @@ const server = function (serv, settings) {
|
|
|
296
310
|
};
|
|
297
311
|
},
|
|
298
312
|
action({ IP, reason }, ctx) {
|
|
299
|
-
serv.banIP(IP, reason)
|
|
300
|
-
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
});
|
|
313
|
+
const result = serv.banIP(IP, reason);
|
|
314
|
+
if (result) {
|
|
315
|
+
if (ctx.player)
|
|
316
|
+
ctx.player.chat(`IP ${IP} was banned ${reason ? '(' + reason + ')' : ''}`);
|
|
317
|
+
else
|
|
318
|
+
serv.info(`IP ${IP} was banned ${reason ? '(' + reason + ')' : ''}`);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
if (ctx.player)
|
|
322
|
+
ctx.player.chat(`IP ${IP} is banned!`);
|
|
323
|
+
else
|
|
324
|
+
serv.err(`IP ${IP} is banned!`);
|
|
325
|
+
}
|
|
314
326
|
}
|
|
315
327
|
});
|
|
316
328
|
serv.commands.add({
|
|
@@ -432,7 +444,7 @@ const player = function (player, serv) {
|
|
|
432
444
|
const uuid = player.uuid;
|
|
433
445
|
return serv.ban(uuid, reason);
|
|
434
446
|
};
|
|
435
|
-
player.banUsername = reason => {
|
|
447
|
+
player.banUsername = async (reason) => {
|
|
436
448
|
reason = reason || 'You were banned!';
|
|
437
449
|
player.kick(reason);
|
|
438
450
|
const nick = player.username;
|
|
@@ -128,6 +128,9 @@ const server = function (serv, options) {
|
|
|
128
128
|
});
|
|
129
129
|
};
|
|
130
130
|
const addPlayerShared = async (player) => {
|
|
131
|
+
player.op = options['everybody-op'] ?? false;
|
|
132
|
+
player.username = player._client.username;
|
|
133
|
+
player.uuid = player._client.uuid;
|
|
131
134
|
player.serv = serv;
|
|
132
135
|
patchClient(player._client, player);
|
|
133
136
|
for (const plugin of Object.values({ ...serv.modules, ...serv.plugins }))
|
|
@@ -210,9 +213,6 @@ const player = async function (player, serv, settings) {
|
|
|
210
213
|
async function addPlayer() {
|
|
211
214
|
player.type = 'player';
|
|
212
215
|
player.crouching = false; // Needs added in prismarine-entity later
|
|
213
|
-
player.op = settings['everybody-op'] ?? false;
|
|
214
|
-
player.username = player._client.username;
|
|
215
|
-
player.uuid = player._client.uuid;
|
|
216
216
|
player.getDisplayName = (location) => player.displayName ?? player.username;
|
|
217
217
|
player.setLoadingStatus('Findig spawn point');
|
|
218
218
|
player.setLoadingStatus('Reading player data');
|
package/dist/modules.d.ts
CHANGED