fix fuck tonne bug
This commit is contained in:
parent
698fafb6ba
commit
ea011422f2
|
@ -17,22 +17,6 @@ export class Client {
|
|||
.join("");
|
||||
this.uniqWsID = crypto.randomUUID();
|
||||
}
|
||||
sendWelcome() {
|
||||
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());
|
||||
}
|
||||
|
|
25
src/Room.ts
25
src/Room.ts
|
@ -26,10 +26,15 @@ export class Room {
|
|||
}
|
||||
this.systemMessage("This is a development server. Instability may occur. Written by @fucksophie")
|
||||
}
|
||||
|
||||
private addToChatArray(chat: proto.ServerMessage_Chat) {
|
||||
this.chats.push(chat);
|
||||
if (this.chats.length > 150) this.chats.shift();
|
||||
}
|
||||
|
||||
systemMessage(message: string) {
|
||||
const system = Server.systemMessage(message);
|
||||
this.chats.push(system.chat!);
|
||||
|
||||
this.addToChatArray(system.chat!);
|
||||
this.particpiants.forEach((z) => {
|
||||
z.clients.forEach(g => {
|
||||
g.send(system);
|
||||
|
@ -54,7 +59,7 @@ export class Room {
|
|||
z.send(chatPacket);
|
||||
});
|
||||
|
||||
this.chats.push(chatPacket.chat!);
|
||||
this.addToChatArray(chatPacket.chat!);
|
||||
}
|
||||
|
||||
ban(ws: ServerWebSocket<Client>, minutes: number) {
|
||||
|
@ -86,8 +91,18 @@ export class Room {
|
|||
particpiant.addClient(ws.data);
|
||||
}
|
||||
|
||||
ws.data.sendWelcome();
|
||||
|
||||
ws.data.send(new proto.ServerMessage({
|
||||
event: proto.ServerMessage_EventType.WELCOME,
|
||||
welcome: {
|
||||
id: ws.data.id,
|
||||
name: particpiant.profile.name,
|
||||
color: particpiant.profile.color,
|
||||
room: ws.data.room!.name,
|
||||
owner: ws.data.room!.owner,
|
||||
chat: ws.data.room!.chats,
|
||||
role: particpiant.profile.role,
|
||||
},
|
||||
}));
|
||||
if (particpiant.clients.length <= 1) {
|
||||
//#region Annouce to everyone that the user has joined
|
||||
const joinMessage = new proto.ServerMessage({
|
||||
|
|
|
@ -43,9 +43,11 @@ export class Server {
|
|||
fetch(req, server) {
|
||||
let data;
|
||||
if (process.env.TRUST_PROXY) {
|
||||
data = req.headers.get("X-Forwarded-For")?.split(",")[0]?.trim()
|
||||
data = req.headers.get("X-Forwarded-For")?.split(",")[0]?.trim();
|
||||
if (!data) {
|
||||
console.log('Trust proxy is enabled, but XFF is empty. Spoofing / server issue?')
|
||||
console.log(
|
||||
"Trust proxy is enabled, but XFF is empty. Spoofing / server issue?"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (server.upgrade(req, { data })) {
|
||||
|
@ -125,9 +127,7 @@ export class Server {
|
|||
profile.commit();
|
||||
profile.emit("update");
|
||||
Server.wses.forEach((z) => {
|
||||
if (z.data.id == profile.id) {
|
||||
z?.data?.sendWelcome();
|
||||
}
|
||||
if (z.data.id == profile.id) z.close(6969);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -162,9 +162,7 @@ export class Server {
|
|||
profile.commit();
|
||||
profile.emit("update");
|
||||
Server.wses.forEach((z) => {
|
||||
if (z.data.id == profile.id) {
|
||||
z?.data?.sendWelcome();
|
||||
}
|
||||
if (z.data.id == profile.id) z.close(6969);
|
||||
});
|
||||
ws.data.send(
|
||||
Server.systemMessage(
|
||||
|
@ -182,9 +180,7 @@ export class Server {
|
|||
profile.commit();
|
||||
profile.emit("update");
|
||||
Server.wses.forEach((z) => {
|
||||
if (z.data.id == profile.id) {
|
||||
z?.data?.sendWelcome();
|
||||
}
|
||||
if (z.data.id == profile.id) z.close(6969);
|
||||
});
|
||||
|
||||
ws.data.send(
|
||||
|
@ -202,6 +198,7 @@ export class Server {
|
|||
if (!ws.data.room) return;
|
||||
const profile = Server.profiles.get(ws.data.id);
|
||||
if (!profile) return;
|
||||
if(!ws.data.room.owner) return;
|
||||
if (profile.role !== proto.Role.DEVELOPER) {
|
||||
if (ws.data.room.owner != ws.data.id) return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue