Add IPData, Windows support, bugfixes (#2)

* Add IPData, Windows support, bugfixes

Changes:
- Added IPData: mutes and votes are now tracked per-IP instead of per-user.
- Windows support: QMP over TCP can now be enabled in the config.
- Vote cooldown can now be specified in the config.
- Fixed bugs:
"Username is already taken" message appearing when it shouldn't

* Remove vote from closed connections

---------

Co-authored-by: Elijah R <62162399+elijahr2411@users.noreply.github.com>
This commit is contained in:
MDMCK10
2023-02-11 15:58:20 +01:00
committed by GitHub
parent 006edd4453
commit cea28ebf8c
7 changed files with 93 additions and 45 deletions

View File

@@ -4,12 +4,14 @@ import { Mutex } from "async-mutex";
export default class QMPClient extends EventEmitter {
socketfile : string;
sockettype: string;
socket : Socket;
connected : boolean;
sentConnected : boolean;
cmdMutex : Mutex; // So command outputs don't get mixed up
constructor(socketfile : string) {
constructor(socketfile : string, sockettype: string) {
super();
this.sockettype = sockettype;
this.socketfile = socketfile;
this.socket = new Socket();
this.connected = false;
@@ -20,7 +22,12 @@ export default class QMPClient extends EventEmitter {
return new Promise((res, rej) => {
if (this.connected) {res(); return;}
try {
this.socket.connect(this.socketfile);
if(this.sockettype == "tcp:") {
let _sock = this.socketfile.split(':');
this.socket.connect(parseInt(_sock[1]), _sock[0]);
}else{
this.socket.connect(this.socketfile);
}
} catch (e) {
this.onClose();
}