diff --git a/bun.lockb b/bun.lockb index 5cf5264..65d1cbd 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 0ae9210..3daf86d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,6 @@ }, "type": "module", "dependencies": { - "pianoverse": "git+https://git.sad.ovh/sophie/pianoverse#f83eddf063a2610a605024f5d4fedde83b4fb83e" + "pianoverse": "^2.0.0" } } \ No newline at end of file diff --git a/src/Server.ts b/src/Server.ts index 63ce17a..e206616 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -79,6 +79,7 @@ export class Server { if (typeof message == "string") return; if (!ws.data) return; + //@ts-expect-error const decode = proto.ClientMessage.fromBinary(message); if (decode.event == CEventType.KICK) { @@ -132,6 +133,46 @@ export class Server { if (!player.data.room) return; 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 if (decode.event == CEventType.CHAT) { let profile = Server.profiles.get(ws.data.id); @@ -171,43 +212,6 @@ export class Server { ws.data.send(Server.systemMessage("Unbanned ID " + id + ".")); 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);