Replace use of deprecated internal debugLog with logger.debug

This commit is contained in:
CosminPerRam 2023-09-18 10:48:24 +03:00
parent ca69e76ed3
commit bff9507189
12 changed files with 64 additions and 69 deletions

View File

@ -111,7 +111,7 @@ export default class battlefield extends Core {
return await this.tcpSend(socket, outPacket, (data) => {
const decoded = this.decodePacket(data);
if(decoded) {
this.debugLog(decoded);
this.logger.debug(decoded);
if(decoded.shift() !== 'OK') throw new Error('Missing OK');
return decoded;
}
@ -148,7 +148,7 @@ export default class battlefield extends Core {
const header = reader.uint(4);
const totalLength = reader.uint(4);
if(buffer.length < totalLength) return false;
this.debugLog("Expected " + totalLength + " bytes, have " + buffer.length);
this.logger.debug("Expected " + totalLength + " bytes, have " + buffer.length);
const paramCount = reader.uint(4);
const params = [];

View File

@ -111,7 +111,7 @@ export default class Core extends EventEmitter {
this.registerRtt(rtt);
}).catch(() => {});
} else {
this.debugLog("Registered RTT: " + param + "ms");
this.logger.debug("Registered RTT: " + param + "ms");
if (this.shortestRTT === 0 || param < this.shortestRTT) {
this.shortestRTT = param;
}
@ -173,8 +173,8 @@ export default class Core extends EventEmitter {
// Prevent unhandled 'error' events from dumping straight to console
socket.on('error', () => {});
this.debugLog(log => {
this.debugLog(address+':'+port+" TCP Connecting");
this.logger.debug(log => {
this.logger.debug(address+':'+port+" TCP Connecting");
const writeHook = socket.write;
socket.write = (...args) => {
log(address+':'+port+" TCP-->");
@ -276,7 +276,7 @@ export default class Core extends EventEmitter {
}
const result = onPacket(buffer);
if (result !== undefined) {
this.debugLog("UDP send finished by callback");
this.logger.debug("UDP send finished by callback");
resolve(result);
}
} catch(e) {
@ -288,12 +288,12 @@ export default class Core extends EventEmitter {
timeout = Promises.createTimeout(this.options.socketTimeout, 'UDP');
const wrappedTimeout = new Promise((resolve, reject) => {
timeout.catch((e) => {
this.debugLog("UDP timeout detected");
this.logger.debug("UDP timeout detected");
if (onTimeout) {
try {
const result = onTimeout();
if (result !== undefined) {
this.debugLog("UDP timeout resolved by callback");
this.logger.debug("UDP timeout resolved by callback");
resolve(result);
return;
}
@ -331,7 +331,7 @@ export default class Core extends EventEmitter {
request: this.options.socketTimeout
}
});
this.debugLog(log => {
this.logger.debug(log => {
log(() => params.url + " HTTP-->");
requestPromise
.then((response) => log(params.url + " <--HTTP " + response.statusCode))
@ -346,9 +346,4 @@ export default class Core extends EventEmitter {
requestPromise && requestPromise.cancel();
}
}
/** @deprecated */
debugLog(...args) {
this.logger.debug(...args);
}
}

View File

@ -32,7 +32,7 @@ export default class doom3 extends Core {
if (packetContainsSize) {
const size = reader.uint(4);
this.debugLog("Received packet size: " + size);
this.logger.debug("Received packet size: " + size);
}
while(!reader.done()) {
@ -44,7 +44,7 @@ export default class doom3 extends Core {
}
if(!key) break;
state.raw[key] = value;
this.debugLog(key + "=" + value);
this.logger.debug(key + "=" + value);
}
const isEtqw = state.raw.gamename && state.raw.gamename.toLowerCase().includes('etqw');
@ -91,51 +91,51 @@ export default class doom3 extends Core {
}
attemptPlayerParse(rest, isEtqw, hasClanTag, hasClanTagPos, hasTypeFlag) {
this.debugLog("starting player parse attempt:");
this.debugLog("isEtqw: " + isEtqw);
this.debugLog("hasClanTag: " + hasClanTag);
this.debugLog("hasClanTagPos: " + hasClanTagPos);
this.debugLog("hasTypeFlag: " + hasTypeFlag);
this.logger.debug("starting player parse attempt:");
this.logger.debug("isEtqw: " + isEtqw);
this.logger.debug("hasClanTag: " + hasClanTag);
this.logger.debug("hasClanTagPos: " + hasClanTagPos);
this.logger.debug("hasTypeFlag: " + hasTypeFlag);
const reader = this.reader(rest);
let lastId = -1;
const players = [];
while(true) {
this.debugLog("---");
this.logger.debug("---");
if (reader.done()) {
this.debugLog("* aborting attempt, overran buffer *");
this.logger.debug("* aborting attempt, overran buffer *");
return null;
}
const player = {};
player.id = reader.uint(1);
this.debugLog("id: " + player.id);
this.logger.debug("id: " + player.id);
if (player.id <= lastId || player.id > 0x20) {
this.debugLog("* aborting attempt, invalid player id *");
this.logger.debug("* aborting attempt, invalid player id *");
return null;
}
lastId = player.id;
if(player.id === 0x20) {
this.debugLog("* player parse successful *");
this.logger.debug("* player parse successful *");
break;
}
player.ping = reader.uint(2);
this.debugLog("ping: " + player.ping);
this.logger.debug("ping: " + player.ping);
if(!isEtqw) {
player.rate = reader.uint(4);
this.debugLog("rate: " + player.rate);
this.logger.debug("rate: " + player.rate);
}
player.name = this.stripColors(reader.string());
this.debugLog("name: " + player.name);
this.logger.debug("name: " + player.name);
if(hasClanTag) {
if(hasClanTagPos) {
const clanTagPos = reader.uint(1);
this.debugLog("clanTagPos: " + clanTagPos);
this.logger.debug("clanTagPos: " + clanTagPos);
}
player.clantag = this.stripColors(reader.string());
this.debugLog("clan tag: " + player.clantag);
this.logger.debug("clan tag: " + player.clantag);
}
if(hasTypeFlag) {
player.typeflag = reader.uint(1);
this.debugLog("type flag: " + player.typeflag);
this.logger.debug("type flag: " + player.typeflag);
}
players.push(player);
}

View File

@ -7,7 +7,7 @@ export default class ffow extends valve {
this.legacyChallenge = true;
}
async queryInfo(state) {
this.debugLog("Requesting ffow info ...");
this.logger.debug("Requesting ffow info ...");
const b = await this.sendPacket(
0x46,
'LSQ',

View File

@ -87,19 +87,19 @@ export default class gamespy2 extends Core {
// so we can detect this.
if (count > 64) {
reader.skip(-1);
this.debugLog("Detected missing count byte, rewinding by 1");
this.logger.debug("Detected missing count byte, rewinding by 1");
} else {
this.debugLog("Detected row count: " + count);
this.logger.debug("Detected row count: " + count);
}
this.debugLog(() => "Reading fields, starting at: "+reader.rest());
this.logger.debug(() => "Reading fields, starting at: "+reader.rest());
const fields = [];
while(!reader.done()) {
let field = reader.string();
if(!field) break;
fields.push(field);
this.debugLog("field:"+field);
this.logger.debug("field:"+field);
}
if (!fields.length) return [];
@ -111,7 +111,7 @@ export default class gamespy2 extends Core {
let key = fields[iField];
let value = reader.string();
if(!value && iField === 0) break outer;
this.debugLog("value:"+value);
this.logger.debug("value:"+value);
if(key === 'player_') key = 'name';
else if(key === 'score_') key = 'score';
else if(key === 'deaths_') key = 'deaths';

View File

@ -14,7 +14,7 @@ export default class gamespy3 extends Core {
const buffer = await this.sendPacket(9, false, false, false);
const reader = this.reader(buffer);
let challenge = parseInt(reader.string());
this.debugLog("Received challenge key: " + challenge);
this.logger.debug("Received challenge key: " + challenge);
if (challenge === 0) {
// Some servers send us a 0 if they don't want a challenge key used
// BF2 does this.
@ -40,8 +40,8 @@ export default class gamespy3 extends Core {
const packet = packets[iPacket];
const reader = this.reader(packet);
this.debugLog("Parsing packet #" + iPacket);
this.debugLog(packet);
this.logger.debug("Parsing packet #" + iPacket);
this.logger.debug(packet);
// Parse raw server key/values
@ -57,7 +57,7 @@ export default class gamespy3 extends Core {
}
state.raw[key] = value;
this.debugLog(key + " = " + value);
this.logger.debug(key + " = " + value);
}
}
@ -91,7 +91,7 @@ export default class gamespy3 extends Core {
let offset = reader.uint(1);
firstMode = false;
this.debugLog(() => "Parsing new field: itemType=" + itemType + " fieldName=" + fieldName + " startOffset=" + offset);
this.logger.debug(() => "Parsing new field: itemType=" + itemType + " fieldName=" + fieldName + " startOffset=" + offset);
while(!reader.done()) {
const item = reader.string();
@ -99,7 +99,7 @@ export default class gamespy3 extends Core {
while(items.length <= offset) { items.push({}); }
items[offset][fieldName] = item;
this.debugLog("* " + item);
this.logger.debug("* " + item);
offset++;
}
}
@ -177,7 +177,7 @@ export default class gamespy3 extends Core {
packets[id] = reader.rest();
if(this.debug) {
this.debugLog("Received packet #"+id + (last ? " (last)" : ""));
this.logger.debug("Received packet #"+id + (last ? " (last)" : ""));
}
if(!numPackets || Object.keys(packets).length !== numPackets) return;

View File

@ -34,13 +34,13 @@ export default class minecraftvanilla extends Core {
const reader = this.reader(data);
const packetId = reader.varint();
this.debugLog("Packet ID: "+packetId);
this.logger.debug("Packet ID: "+packetId);
const strLen = reader.varint();
this.debugLog("String Length: "+strLen);
this.logger.debug("String Length: "+strLen);
const str = reader.rest().toString('utf8');
this.debugLog(str);
this.logger.debug(str);
const json = JSON.parse(str);
delete json.favicon;

View File

@ -91,13 +91,13 @@ export default class openttd extends Core {
const packetLen = reader.uint(2);
if(packetLen !== buffer.length) {
this.debugLog('Invalid reported packet length: '+packetLen+' '+buffer.length);
this.logger.debug('Invalid reported packet length: '+packetLen+' '+buffer.length);
return;
}
const packetType = reader.uint(1);
if(packetType !== expected) {
this.debugLog('Unexpected response packet type: '+packetType);
this.logger.debug('Unexpected response packet type: '+packetType);
return;
}

View File

@ -17,17 +17,17 @@ export default class tribes1 extends Core {
const reader = this.reader(buffer);
const responseByte = reader.uint(1);
if (responseByte !== this.responseByte) {
this.debugLog('Unexpected response byte');
this.logger.debug('Unexpected response byte');
return;
}
const challenge = reader.uint(2);
if (challenge !== this.challenge) {
this.debugLog('Unexpected challenge');
this.logger.debug('Unexpected challenge');
return;
}
const requestByte = reader.uint(1);
if (requestByte !== this.requestByte) {
this.debugLog('Unexpected request byte');
this.logger.debug('Unexpected request byte');
return;
}
return reader;

View File

@ -23,7 +23,7 @@ export default class tribes1master extends Core {
const reader = this.reader(buffer);
const header = reader.uint(2);
if (header !== 0x0610) {
this.debugLog('Header response does not match: ' + header.toString(16));
this.logger.debug('Header response does not match: ' + header.toString(16));
return;
}
const num = reader.uint(1);
@ -34,11 +34,11 @@ export default class tribes1master extends Core {
total = t;
if (num < 1 || num > total) {
this.debugLog('Invalid packet number: ' + num + ' ' + total);
this.logger.debug('Invalid packet number: ' + num + ' ' + total);
return;
}
if (parts.has(num)) {
this.debugLog('Duplicate part: ' + num);
this.logger.debug('Duplicate part: ' + num);
return;
}

View File

@ -104,7 +104,7 @@ export default class unreal2 extends Core {
const peek = reader.uint(1);
if (peek !== 1) reader.skip(-1);
this.debugLog(log => {
this.logger.debug(log => {
log("UCS2 STRING");
log("UCS2 Length: " + length);
log(reader.buffer.slice(reader.i,reader.i+length));
@ -114,7 +114,7 @@ export default class unreal2 extends Core {
let out = '';
if (ucs2) {
out = reader.string({encoding:'ucs2',length:length});
this.debugLog("UCS2 String decoded: " + out);
this.logger.debug("UCS2 String decoded: " + out);
} else if (length > 0) {
out = reader.string();
}

View File

@ -48,7 +48,7 @@ export default class valve extends Core {
}
async queryInfo(/** Results */ state) {
this.debugLog("Requesting info ...");
this.logger.debug("Requesting info ...");
const b = await this.sendPacket(
this.goldsrcInfo ? undefined : 0x54,
this.goldsrcInfo ? 'details' : 'Source Engine Query\0',
@ -186,7 +186,7 @@ export default class valve extends Core {
if(this.legacyChallenge) {
// sendPacket will catch the response packet and
// save the challenge for us
this.debugLog("Requesting legacy challenge key ...");
this.logger.debug("Requesting legacy challenge key ...");
await this.sendPacket(
0x57,
null,
@ -199,7 +199,7 @@ export default class valve extends Core {
async queryPlayers(/** Results */ state) {
state.raw.players = [];
this.debugLog("Requesting player list ...");
this.logger.debug("Requesting player list ...");
const b = await this.sendPacket(
this.goldsrcInfo ? undefined : 0x55,
this.goldsrcInfo ? 'players' : null,
@ -223,7 +223,7 @@ export default class valve extends Core {
const score = reader.int(4);
const time = reader.float();
this.debugLog("Found player: "+name+" "+score+" "+time);
this.logger.debug("Found player: "+name+" "+score+" "+time);
// connecting players don't count as players.
if(!name) continue;
@ -251,7 +251,7 @@ export default class valve extends Core {
state.raw.rules = rules;
const dayZPayload = [];
this.debugLog("Requesting rules ...");
this.logger.debug("Requesting rules ...");
if (this.goldsrcInfo) {
const b = await this.udpSend('\xff\xff\xff\xffrules', b=>b, ()=>null);
@ -455,11 +455,11 @@ export default class valve extends Core {
(payload) => {
const reader = this.reader(payload);
const type = reader.uint(1);
this.debugLog(() => "Received 0x" + type.toString(16) + " expected 0x" + expect.toString(16));
this.logger.debug(() => "Received 0x" + type.toString(16) + " expected 0x" + expect.toString(16));
if (type === 0x41) {
const key = reader.uint(4);
if (this._challenge !== key) {
this.debugLog('Received new challenge key: 0x' + key.toString(16));
this.logger.debug('Received new challenge key: 0x' + key.toString(16));
this._challenge = key;
receivedNewChallengeKey = true;
}
@ -544,7 +544,7 @@ export default class valve extends Core {
const header = reader.int(4);
if(header === -1) {
// full package
this.debugLog("Received full packet");
this.logger.debug("Received full packet");
return onResponse(reader.rest());
}
if(header === -2) {
@ -572,8 +572,8 @@ export default class valve extends Core {
packets[packetNum] = payload;
this.debugLog(() => "Received partial packet uid: 0x"+uid.toString(16)+" num: "+packetNum);
this.debugLog(() => "Received "+Object.keys(packets).length+'/'+numPackets+" packets for this UID");
this.logger.debug(() => "Received partial packet uid: 0x"+uid.toString(16)+" num: "+packetNum);
this.logger.debug(() => "Received "+Object.keys(packets).length+'/'+numPackets+" packets for this UID");
if(Object.keys(packets).length !== numPackets) return;
@ -588,7 +588,7 @@ export default class valve extends Core {
let assembled = Buffer.concat(list);
if(bzip) {
this.debugLog("BZIP DETECTED - Extracing packet...");
this.logger.debug("BZIP DETECTED - Extracing packet...");
try {
assembled = Bzip2.decode(assembled);
} catch(e) {