fix username bug for real this time

This commit is contained in:
elijahr2411 2023-02-15 15:23:32 -05:00
parent 4ea7557285
commit b4fbd6cb20

View file

@ -69,8 +69,10 @@ class CollabVMClient {
#url; #url;
#captcha = false; #captcha = false;
captchaToken; captchaToken;
constructor(url) { isMainSocket;
constructor(url, isMainSocket) {
this.#url = url; this.#url = url;
this.isMainSocket = isMainSocket;
} }
connect(hcaptchatoken) { connect(hcaptchatoken) {
this.captchaToken = hcaptchatoken; this.captchaToken = hcaptchatoken;
@ -170,7 +172,7 @@ class CollabVMClient {
this.eventemitter.emit('captcha', false); this.eventemitter.emit('captcha', false);
} }
case "chat": case "chat":
if (!connected) return; if (!connected || !this.isMainSocket) return;
for (var i = 1; i < msgArr.length; i += 2) { for (var i = 1; i < msgArr.length; i += 2) {
chatMessage(msgArr[i], msgArr[i+1]) chatMessage(msgArr[i], msgArr[i+1])
} }
@ -217,7 +219,7 @@ class CollabVMClient {
alert("That username has been blacklisted."); alert("That username has been blacklisted.");
break; break;
} }
if (!connected) return; if (!connected || !this.isMainSocket) return;
var u = users.find(u => u.username === window.username); var u = users.find(u => u.username === window.username);
if (u) { if (u) {
u.username = msgArr[3]; u.username = msgArr[3];
@ -234,14 +236,14 @@ class CollabVMClient {
user.element.children[0].innerHTML = msgArr[3]; user.element.children[0].innerHTML = msgArr[3];
break; break;
case "adduser": case "adduser":
if (!connected) return; if (!connected || !this.isMainSocket) return;
for (var i = 2; i < msgArr.length; i += 2) { for (var i = 2; i < msgArr.length; i += 2) {
this.addUser(msgArr[i], msgArr[i+1]); this.addUser(msgArr[i], msgArr[i+1]);
} }
onlineusercount.innerText = users.length; onlineusercount.innerText = users.length;
break; break;
case "remuser": case "remuser":
if (!connected) return; if (!connected || !this.isMainSocket) return;
for (var i = 2; i < msgArr.length; i++) { for (var i = 2; i < msgArr.length; i++) {
var user = users.find(u => u.username == msgArr[i]); var user = users.find(u => u.username == msgArr[i]);
users.splice(users.indexOf(user), 1); users.splice(users.indexOf(user), 1);
@ -599,7 +601,7 @@ class CollabVMClient {
} }
function multicollab(url) { function multicollab(url) {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
var vm = new CollabVMClient(url); var vm = new CollabVMClient(url, false);
await vm.connect(); await vm.connect();
var list = await vm.list(); var list = await vm.list();
vm.disconnect(); vm.disconnect();
@ -715,7 +717,7 @@ async function openVM(url, node) {
token = await doCaptcha(vm.captcha); token = await doCaptcha(vm.captcha);
} }
window.location.href = "#" + node; window.location.href = "#" + node;
vm = new CollabVMClient(url); vm = new CollabVMClient(url, true);
await vm.connect(token); await vm.connect(token);
await vm.connectToVM(node); await vm.connectToVM(node);
vmlist.style.display = "none"; vmlist.style.display = "none";