mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
Remove callback support and global Gamedig.debug option
This commit is contained in:
parent
fdc08b5c09
commit
dfa5c95efc
5 changed files with 28 additions and 46 deletions
|
|
@ -5,7 +5,7 @@ class GlobalUdpSocket {
|
|||
constructor() {
|
||||
this.socket = null;
|
||||
this.callbacks = new Set();
|
||||
this.debug = false;
|
||||
this.debuggingCallbacks = new Set();
|
||||
}
|
||||
|
||||
_getSocket() {
|
||||
|
|
@ -14,12 +14,18 @@ class GlobalUdpSocket {
|
|||
udpSocket.unref();
|
||||
udpSocket.bind();
|
||||
udpSocket.on('message', (buffer, rinfo) => {
|
||||
const fromAddress = rinfo.address;
|
||||
const fromPort = rinfo.port;
|
||||
if (this.debuggingCallbacks.size) {
|
||||
console.log(fromAddress + ':' + fromPort + " <--UDP");
|
||||
console.log(HexUtil.debugDump(buffer));
|
||||
}
|
||||
for (const cb of this.callbacks) {
|
||||
cb(rinfo.address, rinfo.port, buffer);
|
||||
cb(fromAddress, fromPort, buffer);
|
||||
}
|
||||
});
|
||||
udpSocket.on('error', (e) => {
|
||||
if (this.debug) {
|
||||
if (this.debuggingCallbacks.size) {
|
||||
console.log("UDP ERROR: " + e);
|
||||
}
|
||||
});
|
||||
|
|
@ -31,11 +37,15 @@ class GlobalUdpSocket {
|
|||
this._getSocket().send(buffer,0,buffer.length,port,address);
|
||||
}
|
||||
|
||||
addCallback(callback) {
|
||||
addCallback(callback, debug) {
|
||||
this.callbacks.add(callback);
|
||||
if (debug) {
|
||||
this.debuggingCallbacks.add(callback);
|
||||
}
|
||||
}
|
||||
removeCallback(callback) {
|
||||
this.callbacks.delete(callback);
|
||||
this.debuggingCallbacks.delete(callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue