Add indefinite turn opcode
This commit is contained in:
@@ -38,6 +38,8 @@ export default class WSServer {
|
|||||||
private voteTimeoutInterval? : NodeJS.Timer;
|
private voteTimeoutInterval? : NodeJS.Timer;
|
||||||
// Completely disable turns
|
// Completely disable turns
|
||||||
private turnsAllowed : boolean;
|
private turnsAllowed : boolean;
|
||||||
|
// Indefinite turn
|
||||||
|
private indefiniteTurn : User | null;
|
||||||
private ModPerms : number;
|
private ModPerms : number;
|
||||||
private VM : QEMUVM;
|
private VM : QEMUVM;
|
||||||
constructor(config : IConfig, vm : QEMUVM) {
|
constructor(config : IConfig, vm : QEMUVM) {
|
||||||
@@ -51,6 +53,7 @@ export default class WSServer {
|
|||||||
this.voteTime = 0;
|
this.voteTime = 0;
|
||||||
this.voteTimeout = 0;
|
this.voteTimeout = 0;
|
||||||
this.turnsAllowed = true;
|
this.turnsAllowed = true;
|
||||||
|
this.indefiniteTurn = null;
|
||||||
this.ModPerms = Utilities.MakeModPerms(this.Config.collabvm.moderatorPermissions);
|
this.ModPerms = Utilities.MakeModPerms(this.Config.collabvm.moderatorPermissions);
|
||||||
this.server = http.createServer();
|
this.server = http.createServer();
|
||||||
this.socket = new WebSocketServer({noServer: true});
|
this.socket = new WebSocketServer({noServer: true});
|
||||||
@@ -206,6 +209,9 @@ export default class WSServer {
|
|||||||
if (msgArr.length === 1) takingTurn = true;
|
if (msgArr.length === 1) takingTurn = true;
|
||||||
else switch (msgArr[1]) {
|
else switch (msgArr[1]) {
|
||||||
case "0":
|
case "0":
|
||||||
|
if (this.indefiniteTurn === client) {
|
||||||
|
this.indefiniteTurn = null;
|
||||||
|
}
|
||||||
takingTurn = false;
|
takingTurn = false;
|
||||||
break;
|
break;
|
||||||
case "1":
|
case "1":
|
||||||
@@ -418,6 +424,7 @@ export default class WSServer {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "22":
|
case "22":
|
||||||
|
// Toggle turns
|
||||||
if (client.rank !== Rank.Admin) return;
|
if (client.rank !== Rank.Admin) return;
|
||||||
if (msgArr.length !== 3) return;
|
if (msgArr.length !== 3) return;
|
||||||
switch (msgArr[2]) {
|
switch (msgArr[2]) {
|
||||||
@@ -430,6 +437,13 @@ export default class WSServer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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;
|
break;
|
||||||
|
|
||||||
@@ -498,7 +512,10 @@ export default class WSServer {
|
|||||||
}
|
}
|
||||||
private sendTurnUpdate(client? : User) {
|
private sendTurnUpdate(client? : User) {
|
||||||
var turnQueueArr = this.TurnQueue.toArray();
|
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
|
// @ts-ignore
|
||||||
this.TurnQueue.forEach((c) => arr.push(c.username));
|
this.TurnQueue.forEach((c) => arr.push(c.username));
|
||||||
var currentTurningUser = this.TurnQueue.peek();
|
var currentTurningUser = this.TurnQueue.peek();
|
||||||
@@ -508,7 +525,9 @@ export default class WSServer {
|
|||||||
}
|
}
|
||||||
this.clients.filter(c => (c !== currentTurningUser && c.connectedToNode)).forEach((c) => {
|
this.clients.filter(c => (c !== currentTurningUser && c.connectedToNode)).forEach((c) => {
|
||||||
if (turnQueueArr.indexOf(c) !== -1) {
|
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()));
|
c.sendMsg(guacutils.encode(...arr, time.toString()));
|
||||||
} else {
|
} else {
|
||||||
c.sendMsg(guacutils.encode(...arr));
|
c.sendMsg(guacutils.encode(...arr));
|
||||||
@@ -549,6 +568,7 @@ export default class WSServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private turnInterval() {
|
private turnInterval() {
|
||||||
|
if (this.indefiniteTurn !== null) return;
|
||||||
this.TurnTime--;
|
this.TurnTime--;
|
||||||
if (this.TurnTime < 1) {
|
if (this.TurnTime < 1) {
|
||||||
this.TurnQueue.dequeue();
|
this.TurnQueue.dequeue();
|
||||||
|
|||||||
Reference in New Issue
Block a user