-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
70 lines (55 loc) · 2.19 KB
/
Copy pathexample.ts
File metadata and controls
70 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { FiveMServerStream } from './src/index.js';
import type { ServerInfo } from './src/index.js';
function parseFiveMColors(text: string): string {
const colorMap: { [key: string]: string } = {
'^0': '\x1b[30m', // Black
'^1': '\x1b[31m', // Red
'^2': '\x1b[32m', // Green
'^3': '\x1b[33m', // Yellow
'^4': '\x1b[34m', // Blue
'^5': '\x1b[36m', // Cyan
'^6': '\x1b[35m', // Magenta
'^7': '\x1b[37m', // White
'^8': '\x1b[90m', // Dark Gray
'^9': '\x1b[91m' // Light Red
};
let result = text;
Object.entries(colorMap).forEach(([code, ansi]) => {
result = result.replace(new RegExp(code.replace('^', '\\^'), 'g'), ansi);
});
return result + '\x1b[0m';
}
async function main() {
console.log('🚀 Starting FiveM Server Stream...');
const streamClient = new FiveMServerStream({
streamSince: 300,
maxServers: Number.MAX_SAFE_INTEGER
});
try {
const thaiServers = await streamClient.getFilteredServers(
(serverInfo: ServerInfo) => serverInfo.Data?.vars?.locale === "th-TH"
);
thaiServers.sort((a, b) => (b.Data?.clients || 0) - (a.Data?.clients || 0));
console.log(`🇹🇭 พบเซิร์ฟเวอร์ไทย ${thaiServers.length} เซิร์ฟเวอร์`);
console.log('━'.repeat(50));
thaiServers.slice(0, 10).forEach((server, index) => {
const hostname = server.Data?.hostname || 'Unknown';
const coloredHostname = parseFiveMColors(hostname);
console.log(`${index + 1}. ${coloredHostname}`);
console.log(` 👥 ${server.Data?.clients || 0}/${server.Data?.svMaxclients || 0} players`);
console.log('');
});
} catch (error) {
console.error('❌ Failed to get servers:', error);
process.exit(1);
}
}
process.on('SIGINT', () => {
console.log('\n⏹️ Shutting down...');
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\n⏹️ Shutting down...');
process.exit(0);
});
main().catch(console.error);