diff --git a/src/WSServer.ts b/src/WSServer.ts index 5045bb2..b6c2d9f 100644 --- a/src/WSServer.ts +++ b/src/WSServer.ts @@ -38,6 +38,8 @@ export default class WSServer { private voteTimeoutInterval? : NodeJS.Timer; // Completely disable turns private turnsAllowed : boolean; + // Indefinite turn + private indefiniteTurn : User | null; private ModPerms : number; private VM : QEMUVM; constructor(config : IConfig, vm : QEMUVM) { @@ -51,6 +53,7 @@ export default class WSServer { this.voteTime = 0; this.voteTimeout = 0; this.turnsAllowed = true; + this.indefiniteTurn = null; this.ModPerms = Utilities.MakeModPerms(this.Config.collabvm.moderatorPermissions); this.server = http.createServer(); this.socket = new WebSocketServer({noServer: true}); @@ -206,6 +209,9 @@ export default class WSServer { if (msgArr.length === 1) takingTurn = true; else switch (msgArr[1]) { case "0": + if (this.indefiniteTurn === client) { + this.indefiniteTurn = null; + } takingTurn = false; break; case "1": @@ -418,6 +424,7 @@ export default class WSServer { } break; case "22": + // Toggle turns if (client.rank !== Rank.Admin) return; if (msgArr.length !== 3) return; switch (msgArr[2]) { @@ -430,6 +437,13 @@ export default class WSServer { break; } break; + case "23": + // Indefinite turn + if (client.rank !== Rank.Admin) return; + this.indefiniteTurn = client; + this.TurnQueue = Queue.from([client, ...this.TurnQueue.toArray().filter(c=>c!==client)]); + this.sendTurnUpdate(); + break; } break; @@ -498,7 +512,10 @@ export default class WSServer { } private sendTurnUpdate(client? : User) { var turnQueueArr = this.TurnQueue.toArray(); - var arr = ["turn", (this.TurnTime * 1000).toString(), this.TurnQueue.size.toString()]; + var turntime; + if (this.indefiniteTurn === null) turntime = (this.TurnTime * 1000); + else turntime = 9999999999; + var arr = ["turn", turntime.toString(), this.TurnQueue.size.toString()]; // @ts-ignore this.TurnQueue.forEach((c) => arr.push(c.username)); var currentTurningUser = this.TurnQueue.peek(); @@ -508,7 +525,9 @@ export default class WSServer { } this.clients.filter(c => (c !== currentTurningUser && c.connectedToNode)).forEach((c) => { if (turnQueueArr.indexOf(c) !== -1) { - var time = ((this.TurnTime * 1000) + ((turnQueueArr.indexOf(c) - 1) * this.Config.collabvm.turnTime * 1000)); + var time; + if (this.indefiniteTurn === null) time = ((this.TurnTime * 1000) + ((turnQueueArr.indexOf(c) - 1) * this.Config.collabvm.turnTime * 1000)); + else time = 9999999999; c.sendMsg(guacutils.encode(...arr, time.toString())); } else { c.sendMsg(guacutils.encode(...arr)); @@ -549,6 +568,7 @@ export default class WSServer { } private turnInterval() { + if (this.indefiniteTurn !== null) return; this.TurnTime--; if (this.TurnTime < 1) { this.TurnQueue.dequeue();