automatic role updating
This commit is contained in:
parent
1b89e6d555
commit
d6b20082ea
|
@ -17,7 +17,22 @@ export class Client {
|
|||
.join("");
|
||||
this.uniqWsID = crypto.randomUUID();
|
||||
}
|
||||
|
||||
updateRole() {
|
||||
const profile = Server.profiles.get(this.id)
|
||||
if(!profile) return;
|
||||
this.send(new proto.ServerMessage({
|
||||
event: proto.ServerMessage_EventType.WELCOME,
|
||||
welcome: {
|
||||
id: this.id,
|
||||
name: profile.name,
|
||||
color: profile.color,
|
||||
room: this.room!.name,
|
||||
owner: this.room!.owner,
|
||||
chat: this.room!.chats,
|
||||
role: profile.role,
|
||||
},
|
||||
}));
|
||||
}
|
||||
send(message: proto.ServerMessage) {
|
||||
this.ws.send(message.toBinary());
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export class Server {
|
|||
static wses: ServerWebSocket<Client>[] = [];
|
||||
static rooms = new Map<string, Room>();
|
||||
static profiles = new Map<string, Profile>();
|
||||
|
||||
|
||||
static systemMessage(message: string): proto.ServerMessage {
|
||||
return new proto.ServerMessage({
|
||||
event: proto.ServerMessage_EventType.CHAT,
|
||||
|
@ -112,23 +112,38 @@ export class Server {
|
|||
|
||||
const args = decode.chat.split(" ");
|
||||
const command = args.shift();
|
||||
|
||||
if (decode.chat == process.env.HASH) {
|
||||
profile.role = proto.Role.DEVELOPER;
|
||||
profile.commit();
|
||||
profile.emit("update");
|
||||
Server.wses.forEach((z) => {
|
||||
if (z.data.id == profile.id) {
|
||||
z?.data?.updateRole();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.role == proto.Role.DEVELOPER) {
|
||||
if (command == "/ban") {
|
||||
const id = args[0];
|
||||
if(getSiteBan(id)) return;
|
||||
if (getSiteBan(id)) return;
|
||||
addSiteBan(id);
|
||||
|
||||
Server.wses.filter(z => z.data.id == id).forEach(z => {
|
||||
z.close(6969);
|
||||
})
|
||||
ws.data.send(Server.systemMessage('Banned ID ' + id + "."))
|
||||
Server.wses
|
||||
.filter((z) => z.data.id == id)
|
||||
.forEach((z) => {
|
||||
z.close(6969);
|
||||
});
|
||||
ws.data.send(Server.systemMessage("Banned ID " + id + "."));
|
||||
return;
|
||||
}
|
||||
if (command == "/unban") {
|
||||
const id = args[0];
|
||||
if(!getSiteBan(id)) return;
|
||||
if (!getSiteBan(id)) return;
|
||||
removeSiteBan(id);
|
||||
ws.data.send(Server.systemMessage('Unbanned ID ' + id + "."))
|
||||
ws.data.send(Server.systemMessage("Unbanned ID " + id + "."));
|
||||
return;
|
||||
}
|
||||
if (command == "/unmod") {
|
||||
|
@ -140,9 +155,15 @@ export class Server {
|
|||
profile.commit();
|
||||
profile.emit("update");
|
||||
Server.wses.forEach((z) => {
|
||||
if (z.data.id == profile.id) z.close(6969);
|
||||
if (z.data.id == profile.id) {
|
||||
z?.data?.updateRole();
|
||||
}
|
||||
});
|
||||
ws.data.send(Server.systemMessage('Removed moderator status from ID ' + id + "."))
|
||||
ws.data.send(
|
||||
Server.systemMessage(
|
||||
"Removed moderator status from ID " + id + "."
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (command == "/mod") {
|
||||
|
@ -154,9 +175,16 @@ export class Server {
|
|||
profile.commit();
|
||||
profile.emit("update");
|
||||
Server.wses.forEach((z) => {
|
||||
if (z.data.id == profile.id) z.close(6969);
|
||||
if (z.data.id == profile.id) {
|
||||
z?.data?.updateRole();
|
||||
}
|
||||
});
|
||||
ws.data.send(Server.systemMessage('Added moderator status to ID ' + id + "."))
|
||||
|
||||
ws.data.send(
|
||||
Server.systemMessage(
|
||||
"Added moderator status to ID " + id + "."
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue