Add user-specific staff options (kick, ban, ipgrab, etc)
This commit is contained in:
parent
5186233293
commit
04c51508a8
1 changed files with 61 additions and 2 deletions
63
src/index.js
63
src/index.js
|
@ -181,6 +181,7 @@ class CollabVMClient {
|
||||||
}
|
}
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
user.element = tr;
|
user.element = tr;
|
||||||
|
if (rank !== 0) userModOptions(user.username, tr, td);
|
||||||
userlist.appendChild(tr);
|
userlist.appendChild(tr);
|
||||||
}
|
}
|
||||||
onlineusercount.innerText = users.length;
|
onlineusercount.innerText = users.length;
|
||||||
|
@ -306,6 +307,11 @@ class CollabVMClient {
|
||||||
buttons.clearQueue.style.display = "inline-block";
|
buttons.clearQueue.style.display = "inline-block";
|
||||||
buttons.endTurn.style.display = "inline-block";
|
buttons.endTurn.style.display = "inline-block";
|
||||||
}
|
}
|
||||||
|
users.forEach((u) => userModOptions(u.username, u.element, u.element.children[0]));
|
||||||
|
break;
|
||||||
|
case "19":
|
||||||
|
// Got IP
|
||||||
|
this.eventemitter.emit('ip', {username: msgArr[2], ip: msgArr[3]});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -394,7 +400,22 @@ class CollabVMClient {
|
||||||
reboot: () => this.socket.send(guacutils.encode(["admin", "10", this.node])),
|
reboot: () => this.socket.send(guacutils.encode(["admin", "10", this.node])),
|
||||||
clearQueue: () => this.socket.send(guacutils.encode(["admin", "17", this.node])),
|
clearQueue: () => this.socket.send(guacutils.encode(["admin", "17", this.node])),
|
||||||
bypassTurn: () => this.socket.send(guacutils.encode(["admin", "20"])),
|
bypassTurn: () => this.socket.send(guacutils.encode(["admin", "20"])),
|
||||||
endTurn: () => this.socket.send(guacutils.encode(["admin", "16", users[0].username])),
|
endTurn: (user) => this.socket.send(guacutils.encode(["admin", "16", user])),
|
||||||
|
ban: (user) => this.socket.send(guacutils.encode(["admin", "12", user])),
|
||||||
|
kick: (user) => this.socket.send(guacutils.encode(["admin", "15", user])),
|
||||||
|
renameUser: (user, newname) => this.socket.send(guacutils.encode(["admin", "18", user, newname])),
|
||||||
|
mute: (user, mutestate) => this.socket.send(guacutils.encode(["admin", "14", user, mutestate])),
|
||||||
|
getip: (user) => {
|
||||||
|
if (users.find(u => u.username === user) === undefined) return;
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
var unbind = this.eventemitter.on('ip', (args) => {
|
||||||
|
if (args.username !== user) return;
|
||||||
|
unbind();
|
||||||
|
res(args.ip);
|
||||||
|
});
|
||||||
|
this.socket.send(guacutils.encode(["admin", "19", user]));
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function multicollab(url) {
|
function multicollab(url) {
|
||||||
|
@ -441,6 +462,44 @@ function chatMessage(username, msg) {
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
chatList.appendChild(tr);
|
chatList.appendChild(tr);
|
||||||
}
|
}
|
||||||
|
function userModOptions(user, tr, td) {
|
||||||
|
tr.classList.add("dropdown");
|
||||||
|
td.classList.add("dropdown-toggle");
|
||||||
|
td.setAttribute("data-bs-toggle", "dropdown");
|
||||||
|
td.setAttribute("role", "button");
|
||||||
|
td.setAttribute("aria-expanded", "false");
|
||||||
|
var ul = document.createElement("ul");
|
||||||
|
ul.classList = "dropdown-menu dropdown-menu-dark table-dark text-light";
|
||||||
|
|
||||||
|
if (perms.bypassturn) addUserDropdownItem(ul, "End Turn", () => vm.admin.endTurn(user));
|
||||||
|
if (perms.ban) addUserDropdownItem(ul, "Ban", () => vm.admin.ban(user));
|
||||||
|
if (perms.kick) addUserDropdownItem(ul, "Kick", () => vm.admin.kick(user));
|
||||||
|
if (perms.rename) addUserDropdownItem(ul, "Rename", () => {
|
||||||
|
var newname = window.prompt(`Enter new username for ${user}`);
|
||||||
|
if (newname == null) return;
|
||||||
|
vm.admin.renameUser(user, newname)
|
||||||
|
});
|
||||||
|
if (perms.mute) {
|
||||||
|
addUserDropdownItem(ul, "Temporary Mute", () => vm.admin.mute(user, 0));
|
||||||
|
addUserDropdownItem(ul, "Indefinite Mute", () => vm.admin.mute(user, 1));
|
||||||
|
addUserDropdownItem(ul, "Unmute", () => vm.admin.mute(user, 2));
|
||||||
|
}
|
||||||
|
if (perms.grabip) addUserDropdownItem(ul, "Get IP", async () => {
|
||||||
|
var ip = await vm.admin.getip(user);
|
||||||
|
alert(ip);
|
||||||
|
});
|
||||||
|
tr.appendChild(ul);
|
||||||
|
}
|
||||||
|
function addUserDropdownItem(ul, text, func) {
|
||||||
|
var li = document.createElement("li");
|
||||||
|
var a = document.createElement("a");
|
||||||
|
a.href = "#";
|
||||||
|
a.classList.add("dropdown-item");
|
||||||
|
a.innerHTML = text;
|
||||||
|
a.addEventListener('click', func);
|
||||||
|
li.appendChild(a);
|
||||||
|
ul.appendChild(li);
|
||||||
|
}
|
||||||
async function openVM(url, node) {
|
async function openVM(url, node) {
|
||||||
if (connected) return;
|
if (connected) return;
|
||||||
connected = true;
|
connected = true;
|
||||||
|
@ -498,7 +557,7 @@ buttons.restore.addEventListener('click', () => vm.admin.restore());
|
||||||
buttons.reboot.addEventListener('click', () => vm.admin.reboot());
|
buttons.reboot.addEventListener('click', () => vm.admin.reboot());
|
||||||
buttons.clearQueue.addEventListener('click', () => vm.admin.clearQueue());
|
buttons.clearQueue.addEventListener('click', () => vm.admin.clearQueue());
|
||||||
buttons.bypassTurn.addEventListener('click', () => vm.admin.bypassTurn());
|
buttons.bypassTurn.addEventListener('click', () => vm.admin.bypassTurn());
|
||||||
buttons.endTurn.addEventListener('click', () => vm.admin.endTurn());
|
buttons.endTurn.addEventListener('click', () => vm.admin.endTurn(users[0]));
|
||||||
// Login
|
// Login
|
||||||
var usernameClick = false;
|
var usernameClick = false;
|
||||||
usernameSpan.addEventListener('click', () => {
|
usernameSpan.addEventListener('click', () => {
|
||||||
|
|
Loading…
Reference in a new issue