move turn to protocol
everything now uses the protocol layer! woohoo.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import IConfig from './IConfig.js';
|
import IConfig from './IConfig.js';
|
||||||
import * as Utilities from './Utilities.js';
|
import * as Utilities from './Utilities.js';
|
||||||
import { User, Rank } from './User.js';
|
import { User, Rank } from './User.js';
|
||||||
import * as cvm from '@cvmts/cvm-rs';
|
|
||||||
// I hate that you have to do it like this
|
// I hate that you have to do it like this
|
||||||
import CircularBuffer from 'mnemonist/circular-buffer.js';
|
import CircularBuffer from 'mnemonist/circular-buffer.js';
|
||||||
import Queue from 'mnemonist/queue.js';
|
import Queue from 'mnemonist/queue.js';
|
||||||
@@ -801,17 +800,20 @@ export default class CollabVMServer implements IProtocolHandlers {
|
|||||||
|
|
||||||
private sendTurnUpdate(client?: User) {
|
private sendTurnUpdate(client?: User) {
|
||||||
var turnQueueArr = this.TurnQueue.toArray();
|
var turnQueueArr = this.TurnQueue.toArray();
|
||||||
var turntime;
|
var turntime: number;
|
||||||
if (this.indefiniteTurn === null) turntime = this.TurnTime * 1000;
|
if (this.indefiniteTurn === null) turntime = this.TurnTime * 1000;
|
||||||
else turntime = 9999999999;
|
else turntime = 9999999999;
|
||||||
var arr = ['turn', turntime.toString(), this.TurnQueue.size.toString()];
|
var users: string[] = [];
|
||||||
// @ts-ignore
|
|
||||||
this.TurnQueue.forEach((c) => arr.push(c.username));
|
this.TurnQueue.forEach((c) => users.push(c.username!));
|
||||||
|
|
||||||
var currentTurningUser = this.TurnQueue.peek();
|
var currentTurningUser = this.TurnQueue.peek();
|
||||||
|
|
||||||
if (client) {
|
if (client) {
|
||||||
client.sendMsg(cvm.guacEncode(...arr));
|
client.protocol.sendTurnQueue(turntime, users);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clients
|
this.clients
|
||||||
.filter((c) => c !== currentTurningUser && c.connectedToNode)
|
.filter((c) => c !== currentTurningUser && c.connectedToNode)
|
||||||
.forEach((c) => {
|
.forEach((c) => {
|
||||||
@@ -819,12 +821,12 @@ export default class CollabVMServer implements IProtocolHandlers {
|
|||||||
var time;
|
var time;
|
||||||
if (this.indefiniteTurn === null) time = this.TurnTime * 1000 + (turnQueueArr.indexOf(c) - 1) * this.Config.collabvm.turnTime * 1000;
|
if (this.indefiniteTurn === null) time = this.TurnTime * 1000 + (turnQueueArr.indexOf(c) - 1) * this.Config.collabvm.turnTime * 1000;
|
||||||
else time = 9999999999;
|
else time = 9999999999;
|
||||||
c.sendMsg(cvm.guacEncode(...arr, time.toString()));
|
c.protocol.sendTurnQueueWaiting(turntime, users, time);
|
||||||
} else {
|
} else {
|
||||||
c.sendMsg(cvm.guacEncode(...arr));
|
c.protocol.sendTurnQueue(turntime, users);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (currentTurningUser) currentTurningUser.sendMsg(cvm.guacEncode(...arr));
|
if (currentTurningUser) currentTurningUser.protocol.sendTurnQueue(turntime, users);
|
||||||
}
|
}
|
||||||
private nextTurn() {
|
private nextTurn() {
|
||||||
clearInterval(this.TurnInterval);
|
clearInterval(this.TurnInterval);
|
||||||
|
|||||||
@@ -326,6 +326,20 @@ export class GuacamoleProtocol extends ProtocolBase implements IProtocol {
|
|||||||
this.user?.sendMsg(cvm.guacEncode('vote', '3', ms.toString()));
|
this.user?.sendMsg(cvm.guacEncode('vote', '3', ms.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getTurnQueueBase(turnTime: number, users: string[]): string[] {
|
||||||
|
return ['turn', turnTime.toString(), users.length.toString(), ...users];
|
||||||
|
}
|
||||||
|
|
||||||
|
sendTurnQueue(turnTime: number, users: string[]): void {
|
||||||
|
this.user?.sendMsg(cvm.guacEncode(...this.getTurnQueueBase(turnTime, users)));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendTurnQueueWaiting(turnTime: number, users: string[], waitTime: number): void {
|
||||||
|
let queue = this.getTurnQueueBase(turnTime, users);
|
||||||
|
queue.push(waitTime.toString());
|
||||||
|
this.user?.sendMsg(cvm.guacEncode(...queue));
|
||||||
|
}
|
||||||
|
|
||||||
sendScreenResize(width: number, height: number): void {
|
sendScreenResize(width: number, height: number): void {
|
||||||
this.user?.sendMsg(cvm.guacEncode('size', '0', width.toString(), height.toString()));
|
this.user?.sendMsg(cvm.guacEncode('size', '0', width.toString(), height.toString()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,9 @@ export interface IProtocol {
|
|||||||
|
|
||||||
sendListResponse(list: ListEntry[]): void;
|
sendListResponse(list: ListEntry[]): void;
|
||||||
|
|
||||||
|
sendTurnQueue(turnTime: number, users: string[]): void;
|
||||||
|
sendTurnQueueWaiting(turnTime: number, users: string[], waitTime: number): void
|
||||||
|
|
||||||
sendVoteStarted(): void;
|
sendVoteStarted(): void;
|
||||||
sendVoteStats(msLeft: number, nrYes: number, nrNo: number): void;
|
sendVoteStats(msLeft: number, nrYes: number, nrNo: number): void;
|
||||||
sendVoteEnded(): void;
|
sendVoteEnded(): void;
|
||||||
|
|||||||
Reference in New Issue
Block a user