move 'vote' to Protocol
This commit is contained in:
@@ -359,9 +359,10 @@ export default class CollabVMServer implements IProtocolHandlers {
|
|||||||
if (!this.authCheck(user, this.Config.auth.guestPermissions.callForReset)) return;
|
if (!this.authCheck(user, this.Config.auth.guestPermissions.callForReset)) return;
|
||||||
|
|
||||||
if (this.voteCooldown !== 0) {
|
if (this.voteCooldown !== 0) {
|
||||||
user.sendMsg(cvm.guacEncode('vote', '3', this.voteCooldown.toString()));
|
user.protocol.sendVoteCooldown(this.voteCooldown);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.startVote();
|
this.startVote();
|
||||||
this.clients.forEach((c) => c.protocol.sendChatMessage('', `${user.username} has started a vote to reset the VM.`));
|
this.clients.forEach((c) => c.protocol.sendChatMessage('', `${user.username} has started a vote to reset the VM.`));
|
||||||
}
|
}
|
||||||
@@ -918,7 +919,7 @@ export default class CollabVMServer implements IProtocolHandlers {
|
|||||||
startVote() {
|
startVote() {
|
||||||
if (this.voteInProgress) return;
|
if (this.voteInProgress) return;
|
||||||
this.voteInProgress = true;
|
this.voteInProgress = true;
|
||||||
this.clients.forEach((c) => c.sendMsg(cvm.guacEncode('vote', '0')));
|
this.clients.forEach((c) => c.protocol.sendVoteStarted());
|
||||||
this.voteTime = this.Config.collabvm.voteTime;
|
this.voteTime = this.Config.collabvm.voteTime;
|
||||||
this.voteInterval = setInterval(() => {
|
this.voteInterval = setInterval(() => {
|
||||||
this.voteTime--;
|
this.voteTime--;
|
||||||
@@ -933,7 +934,7 @@ export default class CollabVMServer implements IProtocolHandlers {
|
|||||||
this.voteInProgress = false;
|
this.voteInProgress = false;
|
||||||
clearInterval(this.voteInterval);
|
clearInterval(this.voteInterval);
|
||||||
var count = this.getVoteCounts();
|
var count = this.getVoteCounts();
|
||||||
this.clients.forEach((c) => c.sendMsg(cvm.guacEncode('vote', '2')));
|
this.clients.forEach((c) => c.protocol.sendVoteEnded());
|
||||||
if (result === true || (result === undefined && count.yes >= count.no)) {
|
if (result === true || (result === undefined && count.yes >= count.no)) {
|
||||||
this.clients.forEach((c) => c.protocol.sendChatMessage('', 'The vote to reset the VM has won.'));
|
this.clients.forEach((c) => c.protocol.sendChatMessage('', 'The vote to reset the VM has won.'));
|
||||||
this.VM.Reset();
|
this.VM.Reset();
|
||||||
@@ -953,9 +954,9 @@ export default class CollabVMServer implements IProtocolHandlers {
|
|||||||
sendVoteUpdate(client?: User) {
|
sendVoteUpdate(client?: User) {
|
||||||
if (!this.voteInProgress) return;
|
if (!this.voteInProgress) return;
|
||||||
var count = this.getVoteCounts();
|
var count = this.getVoteCounts();
|
||||||
var msg = cvm.guacEncode('vote', '1', (this.voteTime * 1000).toString(), count.yes.toString(), count.no.toString());
|
|
||||||
if (client) client.sendMsg(msg);
|
if (client) client.protocol.sendVoteStats(this.voteTime * 1000, count.yes, count.no);
|
||||||
else this.clients.forEach((c) => c.sendMsg(msg));
|
else this.clients.forEach((c) => c.protocol.sendVoteStats(this.voteTime * 1000, count.yes, count.no));
|
||||||
}
|
}
|
||||||
|
|
||||||
getVoteCounts(): VoteTally {
|
getVoteCounts(): VoteTally {
|
||||||
|
|||||||
@@ -291,6 +291,22 @@ export class GuacamoleProtocol extends ProtocolBase implements IProtocol {
|
|||||||
this.user?.sendMsg(cvm.guacEncode(...arr));
|
this.user?.sendMsg(cvm.guacEncode(...arr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendVoteStarted(): void {
|
||||||
|
this.user?.sendMsg(cvm.guacEncode('vote', '0'));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendVoteStats(msLeft: number, nrYes: number, nrNo: number): void {
|
||||||
|
this.user?.sendMsg(cvm.guacEncode('vote', '1', msLeft.toString(), nrYes.toString(), nrNo.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendVoteEnded(): void {
|
||||||
|
this.user?.sendMsg(cvm.guacEncode('vote', '2'));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendVoteCooldown(ms: number): void {
|
||||||
|
this.user?.sendMsg(cvm.guacEncode('vote', '3', ms.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
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()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ export interface IProtocol {
|
|||||||
|
|
||||||
sendListResponse(list: ListEntry[]): void;
|
sendListResponse(list: ListEntry[]): void;
|
||||||
|
|
||||||
|
sendVoteStarted(): void;
|
||||||
|
sendVoteStats(msLeft: number, nrYes: number, nrNo: number): void;
|
||||||
|
sendVoteEnded(): void;
|
||||||
|
sendVoteCooldown(ms: number): void;
|
||||||
|
|
||||||
sendScreenResize(width: number, height: number): void;
|
sendScreenResize(width: number, height: number): void;
|
||||||
|
|
||||||
// Sends a rectangle update to the user.
|
// Sends a rectangle update to the user.
|
||||||
|
|||||||
Reference in New Issue
Block a user