handle deleted users on reload

fixes #42
This commit is contained in:
HF 2023-03-13 10:26:30 +01:00
parent 73ae694ef1
commit 81133c90aa
2 changed files with 18 additions and 8 deletions

View File

@ -61,14 +61,9 @@ class User {
userlvl; // number
constructor() {
// if id = 0 -> unregistered
this.id = 0;
this.regUser = null;
this.resetRegUser();
this.ip = '127.0.0.1';
this.ipSub = this.ip;
this.channels = {};
this.blocked = [];
this.userlvl = 0;
}
async initialize(id, ip = null, regUser = null) {
@ -91,6 +86,15 @@ class User {
}
}
resetRegUser() {
// if id = 0 -> unregistered
this.id = 0;
this.regUser = null;
this.channels = {};
this.blocked = [];
this.userlvl = 0;
}
setRegUser(reguser) {
this.regUser = reguser;
this.id = reguser.id;
@ -154,7 +158,13 @@ class User {
async reload() {
if (!this.regUser) return;
await this.regUser.reload();
try {
await this.regUser.reload();
} catch (e) {
// user got deleted
this.resetRegUser();
return;
}
this.setRegUser(this.regUser);
}

View File

@ -372,9 +372,9 @@ class SocketServer {
reloadUser(name) {
this.wss.clients.forEach(async (ws) => {
if (ws.user.name === name) {
await ws.user.reload();
const buffer = dehydrateChangeMe();
ws.send(buffer);
await ws.user.reload();
}
});
}