fix fuck tonne bug
This commit is contained in:
parent
698fafb6ba
commit
ea011422f2
|
@ -17,22 +17,6 @@ export class Client {
|
||||||
.join("");
|
.join("");
|
||||||
this.uniqWsID = crypto.randomUUID();
|
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) {
|
send(message: proto.ServerMessage) {
|
||||||
this.ws.send(message.toBinary());
|
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")
|
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) {
|
systemMessage(message: string) {
|
||||||
const system = Server.systemMessage(message);
|
const system = Server.systemMessage(message);
|
||||||
this.chats.push(system.chat!);
|
this.addToChatArray(system.chat!);
|
||||||
|
|
||||||
this.particpiants.forEach((z) => {
|
this.particpiants.forEach((z) => {
|
||||||
z.clients.forEach(g => {
|
z.clients.forEach(g => {
|
||||||
g.send(system);
|
g.send(system);
|
||||||
|
@ -54,7 +59,7 @@ export class Room {
|
||||||
z.send(chatPacket);
|
z.send(chatPacket);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chats.push(chatPacket.chat!);
|
this.addToChatArray(chatPacket.chat!);
|
||||||
}
|
}
|
||||||
|
|
||||||
ban(ws: ServerWebSocket<Client>, minutes: number) {
|
ban(ws: ServerWebSocket<Client>, minutes: number) {
|
||||||
|
@ -86,8 +91,18 @@ export class Room {
|
||||||
particpiant.addClient(ws.data);
|
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) {
|
if (particpiant.clients.length <= 1) {
|
||||||
//#region Annouce to everyone that the user has joined
|
//#region Annouce to everyone that the user has joined
|
||||||
const joinMessage = new proto.ServerMessage({
|
const joinMessage = new proto.ServerMessage({
|
||||||
|
|
|
@ -42,10 +42,12 @@ export class Server {
|
||||||
// #region WS upgrading
|
// #region WS upgrading
|
||||||
fetch(req, server) {
|
fetch(req, server) {
|
||||||
let data;
|
let data;
|
||||||
if(process.env.TRUST_PROXY) {
|
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) {
|
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 })) {
|
if (server.upgrade(req, { data })) {
|
||||||
|
@ -125,9 +127,7 @@ export class Server {
|
||||||
profile.commit();
|
profile.commit();
|
||||||
profile.emit("update");
|
profile.emit("update");
|
||||||
Server.wses.forEach((z) => {
|
Server.wses.forEach((z) => {
|
||||||
if (z.data.id == profile.id) {
|
if (z.data.id == profile.id) z.close(6969);
|
||||||
z?.data?.sendWelcome();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -162,9 +162,7 @@ export class Server {
|
||||||
profile.commit();
|
profile.commit();
|
||||||
profile.emit("update");
|
profile.emit("update");
|
||||||
Server.wses.forEach((z) => {
|
Server.wses.forEach((z) => {
|
||||||
if (z.data.id == profile.id) {
|
if (z.data.id == profile.id) z.close(6969);
|
||||||
z?.data?.sendWelcome();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
ws.data.send(
|
ws.data.send(
|
||||||
Server.systemMessage(
|
Server.systemMessage(
|
||||||
|
@ -182,9 +180,7 @@ export class Server {
|
||||||
profile.commit();
|
profile.commit();
|
||||||
profile.emit("update");
|
profile.emit("update");
|
||||||
Server.wses.forEach((z) => {
|
Server.wses.forEach((z) => {
|
||||||
if (z.data.id == profile.id) {
|
if (z.data.id == profile.id) z.close(6969);
|
||||||
z?.data?.sendWelcome();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.data.send(
|
ws.data.send(
|
||||||
|
@ -202,6 +198,7 @@ export class Server {
|
||||||
if (!ws.data.room) return;
|
if (!ws.data.room) return;
|
||||||
const profile = Server.profiles.get(ws.data.id);
|
const profile = Server.profiles.get(ws.data.id);
|
||||||
if (!profile) return;
|
if (!profile) return;
|
||||||
|
if(!ws.data.room.owner) return;
|
||||||
if (profile.role !== proto.Role.DEVELOPER) {
|
if (profile.role !== proto.Role.DEVELOPER) {
|
||||||
if (ws.data.room.owner != ws.data.id) return;
|
if (ws.data.room.owner != ws.data.id) return;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +302,7 @@ export class Server {
|
||||||
},
|
},
|
||||||
open(ws: ServerWebSocket<Client>) {
|
open(ws: ServerWebSocket<Client>) {
|
||||||
let ip: string = ws.remoteAddress;
|
let ip: string = ws.remoteAddress;
|
||||||
if(process.env.TRUST_PROXY) ip = ws.data as unknown as string;
|
if (process.env.TRUST_PROXY) ip = ws.data as unknown as string;
|
||||||
|
|
||||||
const client = new Client(ws, ip);
|
const client = new Client(ws, ip);
|
||||||
if (getSiteBan(client.id)) {
|
if (getSiteBan(client.id)) {
|
||||||
|
|
Loading…
Reference in a new issue