Repository navigation
Expand file tree
/
Copy pathdebug_data_map.mjs
More file actions
682 lines (602 loc) · 23.7 KB
/
Copy pathdebug_data_map.mjs
File metadata and controls
682 lines (602 loc) · 23.7 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/**
* Stream Veri Haritası Debug Scripti
* ================================
* Bu script 100 sunucu verisini analiz eder ve standart bir veri haritası (schema) çıkarır.
*
* Kullanım:
* node debug_data_map.mjs # Canlı stream'den 100 örnek
* node debug_data_map.mjs local # Mevcut stream_full.bin kullan
* node debug_data_map.mjs full # Tüm veriyi analiz et
*/
import { gunzipSync } from 'node:zlib';
import { readFileSync, existsSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const STREAM_BASE = 'https://frontend.cfx-services.net/api/servers/stream/';
const STREAM_REDIR = 'https://frontend.cfx-services.net/api/servers/streamRedir/';
const STREAM_ID_INTERVAL_SEC = 30;
// Varint oku
function readVarint(buf, offset) {
let value = 0, shift = 0, bytesRead = 0;
while (offset + bytesRead < buf.length && bytesRead < 5) {
const b = buf[offset + bytesRead]; bytesRead++;
value |= (b & 0x7f) << shift;
if ((b & 0x80) === 0) break;
shift += 7;
}
return { value, bytesRead };
}
// Protobuf items parse et (recursive)
function parseProtoItems(buf, maxSteps = 100000) {
const items = [];
let offset = 0, steps = 0;
while (offset < buf.length && steps++ < maxSteps) {
const tagRes = readVarint(buf, offset);
if (tagRes.bytesRead === 0) break;
offset += tagRes.bytesRead;
const fieldNum = tagRes.value >>> 3;
const wireType = tagRes.value & 7;
if (wireType === 2) { // Length-delimited
const lenRes = readVarint(buf, offset);
if (lenRes.bytesRead === 0) break;
offset += lenRes.bytesRead;
const len = lenRes.value;
if (len <= 0 || len > 2 * 1024 * 1024 || offset + len > buf.length) break;
const raw = buf.subarray(offset, offset + len);
offset += len;
try {
const s = raw.toString('utf8').replace(/\0/g, '').trim();
const isPrint = s.length >= 1 && /^[\x20-\x7e]*$/.test(s);
if (isPrint) {
items.push({ f: fieldNum, t: 'str', v: s });
} else if (raw.length >= 2 && raw.length <= 10000) {
const nested = parseProtoItems(raw, 5000);
if (nested.length > 0) items.push({ f: fieldNum, t: 'msg', v: nested });
}
} catch (_) {}
} else if (wireType === 0) { // Varint
const vRes = readVarint(buf, offset);
if (vRes.bytesRead === 0) break;
offset += vRes.bytesRead;
items.push({ f: fieldNum, t: 'int', v: vRes.value });
} else if (wireType === 1) { // 64-bit
if (offset + 8 > buf.length) break;
offset += 8;
items.push({ f: fieldNum, t: '64b', v: '...' });
} else break;
}
return items;
}
// Frame'leri parse et
function parseFrames(buffer) {
const frames = [];
let offset = 0;
while (offset + 4 <= buffer.length) {
const frameLen = buffer.readUInt32LE(offset);
offset += 4;
if (frameLen <= 0 || frameLen > 10 * 1024 * 1024 || offset + frameLen > buffer.length) break;
frames.push(buffer.subarray(offset, offset + frameLen));
offset += frameLen;
}
return frames;
}
// Enhanced field analizi - nested field'ları daha iyi yakala
function analyzeFieldsEnhanced(frames, sampleCount) {
const fieldStats = new Map();
const sampleSize = Math.min(sampleCount, frames.length);
const allVars = new Map(); // Field 12 key-value analizi için
for (let i = 0; i < sampleSize; i++) {
const items = parseProtoItems(frames[i]);
for (const item of items) {
if (!fieldStats.has(item.f)) {
fieldStats.set(item.f, {
count: 0,
types: new Set(),
values: [],
nested: new Map(),
examples: []
});
}
const stat = fieldStats.get(item.f);
stat.count++;
stat.types.add(item.t);
if (item.t === 'str' && item.v.length > 0 && item.v.length < 100) {
stat.values.push(item.v);
if (stat.examples.length < 5) stat.examples.push(item.v);
} else if (item.t === 'int') {
stat.values.push(item.v);
if (stat.examples.length < 5 && item.v >= 0 && item.v < 10000) stat.examples.push(item.v);
} else if (item.t === 'msg') {
// Nested field analizi - özellikle field 2'nin içini aç
for (const sub of item.v) {
const nestedKey = `${item.f}.${sub.f}`;
if (!stat.nested.has(nestedKey)) {
stat.nested.set(nestedKey, { count: 0, types: new Set(), examples: [], stringValues: [] });
}
const n = stat.nested.get(nestedKey);
n.count++;
n.types.add(sub.t);
if (sub.t === 'str' && sub.v.length < 50) {
if (n.examples.length < 3) n.examples.push(sub.v);
n.stringValues.push(sub.v);
// Field 12 (vars) için özel analiz
if (item.f === 12) {
// Bu bir key-value çifti olabilir
const keyVal = analyzeKeyValuePair(item.v, sub.f, sub.v);
if (keyVal) {
const varCount = allVars.get(keyVal.key) || { count: 0, values: [] };
varCount.count++;
if (keyVal.value && varCount.values.length < 5) varCount.values.push(keyVal.value);
allVars.set(keyVal.key, varCount);
}
}
} else if (sub.t === 'int' && n.examples.length < 3) {
n.examples.push(sub.v);
} else if (sub.t === 'msg') {
// İki seviye nested - hostname (field 4) için
for (const sub2 of sub.v) {
const nestedKey2 = `${nestedKey}.${sub2.f}`;
if (!stat.nested.has(nestedKey2)) {
stat.nested.set(nestedKey2, { count: 0, types: new Set(), examples: [] });
}
const n2 = stat.nested.get(nestedKey2);
n2.count++;
n2.types.add(sub2.t);
if (sub2.t === 'str' && sub2.v.length < 60 && n2.examples.length < 3) {
n2.examples.push(sub2.v);
}
}
}
}
}
}
}
return { fieldStats, sampleSize, allVars };
}
// Key-value pair analizi
function analyzeKeyValuePair(msgItems, currentField, currentValue) {
// Field 12 içinde: f1 = key, f2 = value
if (currentField === 1) {
// Bu bir key, sonraki value'yu bekle
return { key: currentValue, isKey: true };
}
if (currentField === 2) {
// Bu bir value ama hangi key'e ait?
// Basit yaklaşım: önceki field'ı kontrol et
return null; // Daha karmaşık analiz gerekli
}
return null;
}
// En sık kullanılan string değerleri analiz et
function analyzeCommonStrings(frames, sampleCount) {
const stringCounts = new Map();
const sampleSize = Math.min(sampleCount, frames.length);
for (let i = 0; i < sampleSize; i++) {
const items = parseProtoItems(frames[i]);
for (const item of items) {
if (item.t === 'str' && item.v.length >= 2 && item.v.length < 64) {
const count = stringCounts.get(item.v) || 0;
stringCounts.set(item.v, count + 1);
}
}
}
// En sık tekrarlananları bul
const sorted = [...stringCounts.entries()].sort((a, b) => b[1] - a[1]);
return sorted.slice(0, 50);
}
// Standart veri haritası oluştur
function generateSchema(fieldStats, commonStrings, varsAnalysis) {
const schema = {
_meta: {
generated: new Date().toISOString(),
description: "FiveM Stream veri haritası - protobuf field yapısı"
},
topLevelFields: {},
commonStrings: commonStrings.slice(0, 20).map(([str, count]) => ({ value: str, occurrences: count })),
vars: {},
recommendations: []
};
// Vars'ı ekle
if (varsAnalysis) {
for (const [key, data] of varsAnalysis) {
schema.vars[key] = {
occurrences: data.count,
exampleValue: data.exampleValue
};
}
}
// Field'ları analiz et
const sortedFields = [...fieldStats.entries()].sort((a, b) => b[1].count - a[1].count);
for (const [fieldNum, stat] of sortedFields) {
const types = [...stat.types].join('|');
const example = stat.examples[0] || null;
schema.topLevelFields[fieldNum] = {
fieldNumber: fieldNum,
type: types,
occurrences: stat.count,
sampleValues: stat.examples.slice(0, 3),
description: guessFieldDescription(fieldNum, types, stat.examples, commonStrings)
};
// Nested field'ları ekle
if (stat.nested.size > 0) {
schema.topLevelFields[fieldNum].nestedFields = {};
for (const [nestedKey, nestedStat] of stat.nested) {
schema.topLevelFields[fieldNum].nestedFields[nestedKey] = {
type: [...nestedStat.types].join('|'),
occurrences: nestedStat.count,
examples: nestedStat.examples
};
}
}
}
// Öneriler ekle
schema.recommendations = generateRecommendations(fieldStats, commonStrings, varsAnalysis);
return schema;
}
// Field açıklamasını tahmin et
function guessFieldDescription(fieldNum, types, examples, commonStrings) {
const fieldDescriptions = {
1: { desc: "Join code (örn: jaz6ml)", confidence: "high" },
2: { desc: "Sunucu bilgileri nested mesaj", confidence: "high" },
3: { desc: "Bilinmiyor - genellikle boş", confidence: "low" },
4: { desc: "Hostname / Server name", confidence: "high" },
5: { desc: "Game mode", confidence: "high" },
6: { desc: "Map name", confidence: "high" },
7: { desc: "Bilinmiyor", confidence: "low" },
8: { desc: "Bilinmiyor", confidence: "low" },
9: { desc: "Server version", confidence: "high" },
10: { desc: "Bilinmiyor", confidence: "low" },
11: { desc: "Internal hash", confidence: "medium" },
12: { desc: "Key-value değişkenler (vars)", confidence: "high" },
13: { desc: "Bilinmiyor", confidence: "low" },
14: { desc: "Bilinmiyor", confidence: "low" },
15: { desc: "Bilinmiyor", confidence: "low" },
16: { desc: "Boolean flag", confidence: "medium" },
17: { desc: "Premium sort değeri", confidence: "medium" },
18: { desc: "IP:Port endpoint", confidence: "high" },
};
if (fieldDescriptions[fieldNum]) {
return fieldDescriptions[fieldNum];
}
return { desc: "Bilinmiyor - daha fazla örnek gerekli", confidence: "low" };
}
// Öneriler üret
function generateRecommendations(fieldStats, commonStrings, varsAnalysis) {
const recs = [];
// En sık kullanılan field'ları kontrol et
const sortedFields = [...fieldStats.entries()].sort((a, b) => b[1].count - a[1].count);
if (sortedFields.length > 0) {
recs.push({
priority: "high",
title: "Kritik Field'lar",
description: `En sık kullanılan field numaraları: ${sortedFields.slice(0, 5).map(([f]) => f).join(', ')}`
});
}
// Key-value yapısını kontrol et
const field12 = fieldStats.get(12);
if (field12 && field12.nested.size > 0) {
const kvFields = [...field12.nested.entries()].slice(0, 10);
recs.push({
priority: "high",
title: "Vars (Key-Value) Field'ları",
description: `Field 12 içinde bulunan key'ler: ${kvFields.map(([k]) => k).join(', ')}`
});
}
// Vars analizinden gelen gerçek key-value'ları göster
if (varsAnalysis && varsAnalysis.size > 0) {
const sortedVars = [...varsAnalysis.entries()].sort((a, b) => b[1].count - a[1].count);
const topVars = sortedVars.slice(0, 15).map(([k, v]) => `${k}(${v.count})`).join(', ');
recs.push({
priority: "high",
title: "Tanımlanmış Var Değişkenleri",
description: `Stream'de bulunan en sık var değişkenleri: ${topVars}`
});
}
// Yaygın string değerlerini kontrol et
const knownKeys = ['gamename', 'locale', 'tags', 'sv_projectName', 'sv_projectDesc',
'banner_detail', 'banner_connecting', 'premium', 'sv_scriptHookAllowed',
'sv_enforceGameBuild', 'mapname', 'version'];
const foundKeys = commonStrings
.filter(([s]) => knownKeys.includes(s.toLowerCase()))
.map(([s, c]) => s);
if (foundKeys.length > 0) {
recs.push({
priority: "medium",
title: "Tanımlanmış Var Key'leri",
description: `Stream'de bulunan bilinen var keyleri: ${foundKeys.join(', ')}`
});
}
return recs;
}
// Ana fonksiyon
async function main() {
const args = process.argv.slice(2);
const mode = args[0] || 'live';
const sampleCount = args[1] ? parseInt(args[1]) : 100;
console.log('='.repeat(60));
console.log('FiveM Stream Veri Haritası Analizi');
console.log('='.repeat(60));
console.log(`Mod: ${mode}, Örnek sayısı: ${sampleCount}`);
console.log('');
let buffer;
if (mode === 'local') {
// Yerel dosyadan oku
const binPath = join(__dirname, 'src/api/stream_full.bin');
if (!existsSync(binPath)) {
console.error('Hata: stream_full.bin bulunamadı. Önce veriyi çekmelisiniz.');
process.exit(1);
}
console.log('Yerel dosya okunuyor:', binPath);
buffer = readFileSync(binPath);
} else if (mode === 'full') {
// Canlı stream'den çek
console.log('Canlı stream indiriliyor...');
const streamId = Math.floor(Math.floor(Date.now() / 1000) / STREAM_ID_INTERVAL_SEC) * STREAM_ID_INTERVAL_SEC;
const url = `${STREAM_BASE}${streamId}/`;
const response = await fetch(url, {
headers: {
'User-Agent': 'FiveM-Server-List/1.0',
Accept: '*/*',
Referer: 'https://servers.fivem.net/'
}
});
if (!response.ok) {
console.log('Stream başarısız, streamRedir deneniyor...');
const response2 = await fetch(STREAM_REDIR, {
headers: {
'User-Agent': 'FiveM-Server-List/1.0',
Accept: '*/*',
Referer: 'https://servers.fivem.net/'
}
});
if (!response2.ok) throw new Error(`HTTP ${response2.status}`);
buffer = Buffer.concat([...(await response2.arrayBuffer())]);
} else {
buffer = Buffer.concat([...(await response.arrayBuffer())]);
}
// Gzip kontrolü
if (buffer[0] === 0x1f && buffer[1] === 0x8b) {
console.log('Gzip açılıyor...');
buffer = gunzipSync(buffer);
}
} else {
// Default: Canlı stream
console.log('Canlı stream indiriliyor...');
const streamId = Math.floor(Math.floor(Date.now() / 1000) / STREAM_ID_INTERVAL_SEC) * STREAM_ID_INTERVAL_SEC;
const url = `${STREAM_BASE}${streamId}/`;
const response = await fetch(url, {
headers: {
'User-Agent': 'FiveM-Server-List/1.0',
Accept: '*/*',
Referer: 'https://servers.fivem.net/'
}
});
if (!response.ok) {
console.log('Stream başarısız, streamRedir deneniyor...');
const response2 = await fetch(STREAM_REDIR, {
headers: {
'User-Agent': 'FiveM-Server-List/1.0',
Accept: '*/*',
Referer: 'https://servers.fivem.net/'
}
});
if (!response2.ok) throw new Error(`HTTP ${response2.status}`);
buffer = Buffer.concat([...(await response2.arrayBuffer())]);
} else {
buffer = Buffer.concat([...(await response.arrayBuffer())]);
}
// Gzip kontrolü
if (buffer[0] === 0x1f && buffer[1] === 0x8b) {
console.log('Gzip açılıyor...');
buffer = gunzipSync(buffer);
}
}
console.log(`Toplam veri boyutu: ${buffer.length} bytes`);
console.log('');
// Frame'leri parse et
const frames = parseFrames(buffer);
console.log(`Toplam frame sayısı: ${frames.length}`);
console.log('');
// Enhanced field analizi - daha fazla örnek ile
const actualSampleCount = Math.min(sampleCount, frames.length);
console.log('-'.repeat(60));
console.log('FIELD ANALİZİ (Geliştirilmiş)');
console.log('-'.repeat(60));
const { fieldStats, sampleSize, allVars } = analyzeFieldsEnhanced(frames, actualSampleCount);
console.log(`Analiz edilen örnek sayısı: ${sampleSize}`);
console.log(`Bulunan unique field sayısı: ${fieldStats.size}`);
console.log('');
// En sık kullanılan field'ları göster
console.log('En sık kullanılan top-level fieldlar:');
const sortedFields = [...fieldStats.entries()].sort((a, b) => b[1].count - a[1].count);
for (let i = 0; i < Math.min(15, sortedFields.length); i++) {
const [fieldNum, stat] = sortedFields[i];
const types = [...stat.types].join('|');
const desc = guessFieldDescription(fieldNum, types, stat.examples, []).desc;
console.log(` Field ${fieldNum}: ${types} (${stat.count}/${sampleSize}) - ${desc}`);
}
console.log('');
// Field 2'nin iç detayı
console.log('-'.repeat(60));
console.log('FIELD 2 (SUNUCU BİLGİLERİ) İÇ DETAY');
console.log('-'.repeat(60));
const field2 = fieldStats.get(2);
if (field2 && field2.nested) {
const sortedNested = [...field2.nested.entries()].sort((a, b) => b[1].count - a[1].count);
console.log('Field 2 içindeki nested fieldlar:');
for (const [nestedKey, nestedStat] of sortedNested) {
const types = [...nestedStat.types].join('|');
const examples = nestedStat.examples.slice(0, 3).join(', ');
console.log(` ${nestedKey}: ${types} (${nestedStat.count}/${sampleSize})`);
if (examples) console.log(` Örnek: ${examples}`);
}
}
console.log('');
// Common strings analizi
console.log('-'.repeat(60));
console.log('EN SIK TEKRARLANAN DEĞERLER');
console.log('-'.repeat(60));
const commonStrings = analyzeCommonStrings(frames, sampleSize);
console.log('En sık tekrarlanan string değerleri:');
for (let i = 0; i < Math.min(25, commonStrings.length); i++) {
const [str, count] = commonStrings[i];
console.log(` "${str}": ${count} kez`);
}
console.log('');
// Vars (key-value) analizi
console.log('-'.repeat(60));
console.log('VARS (KEY-VALUE) DEĞİŞKENLERİ');
console.log('-'.repeat(60));
// Field 12 içindeki key-value çiftlerini analiz et
const varsAnalysis = analyzeVarsInFrames(frames, sampleSize);
console.log('Tanımlanan var değişkenleri:');
const sortedVars = [...varsAnalysis.entries()].sort((a, b) => b[1].count - a[1].count);
for (let i = 0; i < Math.min(30, sortedVars.length); i++) {
const [key, data] = sortedVars[i];
console.log(` ${key}: ${data.count} kez, örnek değer: ${data.exampleValue || 'yok'}`);
}
console.log('');
// Schema oluştur
console.log('-'.repeat(60));
console.log('STANDART VERİ HARİTASI');
console.log('-'.repeat(60));
const schema = generateSchema(fieldStats, commonStrings, varsAnalysis);
console.log('\n=== ÖNERİLER ===');
for (const rec of schema.recommendations) {
console.log(`[${rec.priority.toUpperCase()}] ${rec.title}`);
console.log(` ${rec.description}`);
}
console.log('\n=== DETAYLI FIELD AÇIKLAMALARI ===');
for (const [fieldNum, fieldData] of Object.entries(schema.topLevelFields)) {
console.log(`\nField ${fieldNum}:`);
console.log(` Tip: ${fieldData.type}`);
console.log(` Açıklama: ${fieldData.description.desc}`);
console.log(` Örnekler: ${fieldData.sampleValues.join(', ')}`);
if (fieldData.nestedFields) {
console.log(` Nested fieldlar:`);
for (const [nestedKey, nestedData] of Object.entries(fieldData.nestedFields)) {
console.log(` ${nestedKey}: ${nestedData.type} - Örnek: ${nestedData.examples.join(', ')}`);
}
}
}
// Örnek frame gösterimi
console.log('\n' + '='.repeat(60));
console.log('ÖRNEK FRAME DETAYLARI (İlk 5 sunucu - Hostname düzeltmeli)');
console.log('='.repeat(60));
for (let i = 0; i < Math.min(5, frames.length); i++) {
const items = parseProtoItems(frames[i]);
console.log(`\n--- Frame #${i} (${frames[i].length} bytes) ---`);
// Join code ve server info'yu bul
let joinCode = null;
let serverInfo = null;
let maxPlayers = null;
let online = null;
let hostname = null;
let gameMode = null;
let mapName = null;
let version = null;
let endpoint = null;
const vars = {};
for (const item of items) {
if (item.f === 1 && item.t === 'str') joinCode = item.v;
if (item.f === 2 && item.t === 'msg') serverInfo = item.v;
}
console.log(`Join Code: ${joinCode || 'BULUNAMADI'}`);
if (serverInfo) {
// Server info içinde döngü
for (const sub of serverInfo) {
if (sub.f === 1 && sub.t === 'int') maxPlayers = sub.v;
else if (sub.f === 2 && sub.t === 'int') online = sub.v;
else if (sub.f === 4 && sub.t === 'str') hostname = sub.v;
else if (sub.f === 4 && sub.t === 'msg') {
// Nested hostname - içindeki string'i bul (printable olanı)
for (const sub4 of sub.v) {
if (sub4.t === 'str' && sub4.v && sub4.v.length > 0 && sub4.v.length < 100 && /^[\x20-\x7e]+$/.test(sub4.v)) {
hostname = sub4.v;
break;
}
}
}
else if (sub.f === 5 && sub.t === 'str') gameMode = sub.v;
else if (sub.f === 5 && sub.t === 'msg') {
for (const sub5 of sub.v) {
if (sub5.t === 'str' && sub5.v && /^[\x20-\x7e]+$/.test(sub5.v)) gameMode = sub5.v;
}
}
else if (sub.f === 6 && sub.t === 'str') mapName = sub.v;
else if (sub.f === 6 && sub.t === 'msg') {
for (const sub6 of sub.v) {
if (sub6.t === 'str' && sub6.v && /^[\x20-\x7e]+$/.test(sub6.v)) mapName = sub6.v;
}
}
else if (sub.f === 9 && sub.t === 'str') version = sub.v;
else if (sub.f === 18 && sub.t === 'str') endpoint = sub.v;
else if (sub.f === 12 && sub.t === 'msg') {
// Key-value pairs
let lastKey = null;
for (const kv in sub.v) {
const kvItem = sub.v[kv];
if (kvItem.f === 1 && kvItem.t === 'str') lastKey = kvItem.v;
else if (kvItem.f === 2 && kvItem.t === 'str' && lastKey) {
vars[lastKey] = kvItem.v;
lastKey = null;
}
}
}
}
// Vars'dan hostname'i dene (sv_projectName fallback)
if (!hostname && vars.sv_projectName) {
hostname = vars.sv_projectName;
}
console.log(` Max Players: ${maxPlayers || '?'}, Online: ${online || '?'}`);
console.log(` Hostname: ${hostname || '?'}`);
console.log(` Game Mode: ${gameMode || '?'}`);
console.log(` Map: ${mapName || '?'}`);
console.log(` Version: ${version || '?'}`);
console.log(` Endpoint: ${endpoint || '?'}`);
if (Object.keys(vars).length > 0) {
console.log(` Vars: ${JSON.stringify(vars)}`);
}
}
}
console.log('\n' + '='.repeat(60));
console.log('ANALİZ TAMAMLANDI');
console.log('='.repeat(60));
return schema;
}
// Vars analizi - field 12 içindeki key-value çiftlerini bul
function analyzeVarsInFrames(frames, sampleCount) {
const varsMap = new Map();
const sampleSize = Math.min(sampleCount, frames.length);
for (let i = 0; i < sampleSize; i++) {
const items = parseProtoItems(frames[i]);
for (const item of items) {
if (item.f === 2 && item.t === 'msg') {
// Server info
for (const sub of item.v) {
if (sub.f === 12 && sub.t === 'msg') {
// Vars - key-value pairs
let lastKey = null;
for (const kv of sub.v) {
if (kv.f === 1 && kv.t === 'str') {
lastKey = kv.v;
} else if (kv.f === 2 && kv.t === 'str' && lastKey) {
// Key-value çifti bulundu
if (!varsMap.has(lastKey)) {
varsMap.set(lastKey, { count: 0, exampleValue: null });
}
const v = varsMap.get(lastKey);
v.count++;
if (!v.exampleValue) v.exampleValue = kv.v;
lastKey = null;
}
}
}
}
}
}
}
return varsMap;
}
main().catch(console.error);