update pianoverse

This commit is contained in:
Soph :3 2024-08-27 20:40:34 +03:00
parent 9969a17590
commit 213ab89b7e
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
3 changed files with 42 additions and 38 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -9,6 +9,6 @@
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"pianoverse": "git+https://git.sad.ovh/sophie/pianoverse#f83eddf063a2610a605024f5d4fedde83b4fb83e" "pianoverse": "^2.0.0"
} }
} }

View file

@ -79,6 +79,7 @@ export class Server {
if (typeof message == "string") return; if (typeof message == "string") return;
if (!ws.data) return; if (!ws.data) return;
//@ts-expect-error
const decode = proto.ClientMessage.fromBinary(message); const decode = proto.ClientMessage.fromBinary(message);
if (decode.event == CEventType.KICK) { if (decode.event == CEventType.KICK) {
@ -132,6 +133,46 @@ export class Server {
if (!player.data.room) return; if (!player.data.room) return;
player.data.room.ban(player, decode.ban!.minutes); player.data.room.ban(player, decode.ban!.minutes);
} }
if(decode.event == CEventType.UNMOD) {
let eventSenderProfile = Server.profiles.get(ws.data.id);
if (!eventSenderProfile) return;
if(eventSenderProfile.role == proto.Role.USER) return;
const profile = Server.profiles.get(decode.unmod);
if (!profile) return;
if (profile.role !== proto.Role.MODERATOR) return;
profile.role = proto.Role.USER;
profile.commit();
profile.emit("update");
Server.wses.forEach((z) => {
if (z.data.id == profile.id) z.close(6969);
});
ws.data.send(
Server.systemMessage(
"Removed moderator status from ID " + decode.unmod + "."
)
);
return;
}
if (decode.event == CEventType.MOD) {
let eventSenderProfile = Server.profiles.get(ws.data.id);
if (!eventSenderProfile) return;
if(eventSenderProfile.role == proto.Role.USER) return;
const profile = Server.profiles.get(decode.mod);
if (!profile) return;
if (profile.role == proto.Role.MODERATOR) return;
profile.role = proto.Role.MODERATOR;
profile.commit();
profile.emit("update");
Server.wses.forEach((z) => {
if (z.data.id == profile.id) z.close(6969);
});
ws.data.send(
Server.systemMessage("Added moderator status to ID " + decode.mod + ".")
);
return;
}
//#region All of these packets just regurgiated info //#region All of these packets just regurgiated info
if (decode.event == CEventType.CHAT) { if (decode.event == CEventType.CHAT) {
let profile = Server.profiles.get(ws.data.id); let profile = Server.profiles.get(ws.data.id);
@ -171,43 +212,6 @@ export class Server {
ws.data.send(Server.systemMessage("Unbanned ID " + id + ".")); ws.data.send(Server.systemMessage("Unbanned ID " + id + "."));
return; return;
} }
if (command == "/unmod") {
const id = args[0];
const profile = Server.profiles.get(id);
if (!profile) return;
if (profile.role !== proto.Role.MODERATOR) return;
profile.role = proto.Role.USER;
profile.commit();
profile.emit("update");
Server.wses.forEach((z) => {
if (z.data.id == profile.id) z.close(6969);
});
ws.data.send(
Server.systemMessage(
"Removed moderator status from ID " + id + "."
)
);
return;
}
if (command == "/mod") {
const id = args[0];
const profile = Server.profiles.get(id);
if (!profile) return;
if (profile.role == proto.Role.MODERATOR) return;
profile.role = proto.Role.MODERATOR;
profile.commit();
profile.emit("update");
Server.wses.forEach((z) => {
if (z.data.id == profile.id) z.close(6969);
});
ws.data.send(
Server.systemMessage(
"Added moderator status to ID " + id + "."
)
);
return;
}
} }
ws.data.room!.chat(ws, decode.chat); ws.data.room!.chat(ws, decode.chat);