Compare commits
No commits in common. "094aeb061c8c94008539ef25d0c1e811e7543695" and "1b89e6d555e27080e08d3791785a71f5fa56efbb" have entirely different histories.
094aeb061c
...
1b89e6d555
|
@ -17,22 +17,7 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
16
src/Room.ts
16
src/Room.ts
|
@ -86,8 +86,20 @@ export class Room {
|
||||||
particpiant.addClient(ws.data);
|
particpiant.addClient(ws.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.data.sendWelcome();
|
const welcome = new proto.ServerMessage({
|
||||||
|
event: proto.ServerMessage_EventType.WELCOME,
|
||||||
|
welcome: {
|
||||||
|
id: ws.data.id,
|
||||||
|
name: particpiant.profile.name,
|
||||||
|
color: particpiant.profile.color,
|
||||||
|
room: this.name,
|
||||||
|
owner: this.owner,
|
||||||
|
chat: this.chats,
|
||||||
|
role: particpiant.profile.role,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.data.send(welcome);
|
||||||
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({
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class Server {
|
||||||
static wses: ServerWebSocket<Client>[] = [];
|
static wses: ServerWebSocket<Client>[] = [];
|
||||||
static rooms = new Map<string, Room>();
|
static rooms = new Map<string, Room>();
|
||||||
static profiles = new Map<string, Profile>();
|
static profiles = new Map<string, Profile>();
|
||||||
|
|
||||||
static systemMessage(message: string): proto.ServerMessage {
|
static systemMessage(message: string): proto.ServerMessage {
|
||||||
return new proto.ServerMessage({
|
return new proto.ServerMessage({
|
||||||
event: proto.ServerMessage_EventType.CHAT,
|
event: proto.ServerMessage_EventType.CHAT,
|
||||||
|
@ -112,38 +112,23 @@ export class Server {
|
||||||
|
|
||||||
const args = decode.chat.split(" ");
|
const args = decode.chat.split(" ");
|
||||||
const command = args.shift();
|
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?.sendWelcome();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (profile.role == proto.Role.DEVELOPER) {
|
if (profile.role == proto.Role.DEVELOPER) {
|
||||||
if (command == "/ban") {
|
if (command == "/ban") {
|
||||||
const id = args[0];
|
const id = args[0];
|
||||||
if (getSiteBan(id)) return;
|
if(getSiteBan(id)) return;
|
||||||
addSiteBan(id);
|
addSiteBan(id);
|
||||||
|
|
||||||
Server.wses
|
Server.wses.filter(z => z.data.id == id).forEach(z => {
|
||||||
.filter((z) => z.data.id == id)
|
z.close(6969);
|
||||||
.forEach((z) => {
|
})
|
||||||
z.close(6969);
|
ws.data.send(Server.systemMessage('Banned ID ' + id + "."))
|
||||||
});
|
|
||||||
ws.data.send(Server.systemMessage("Banned ID " + id + "."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command == "/unban") {
|
if (command == "/unban") {
|
||||||
const id = args[0];
|
const id = args[0];
|
||||||
if (!getSiteBan(id)) return;
|
if(!getSiteBan(id)) return;
|
||||||
removeSiteBan(id);
|
removeSiteBan(id);
|
||||||
ws.data.send(Server.systemMessage("Unbanned ID " + id + "."));
|
ws.data.send(Server.systemMessage('Unbanned ID ' + id + "."))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command == "/unmod") {
|
if (command == "/unmod") {
|
||||||
|
@ -155,15 +140,9 @@ 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('Removed moderator status from ID ' + id + "."))
|
||||||
Server.systemMessage(
|
|
||||||
"Removed moderator status from ID " + id + "."
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command == "/mod") {
|
if (command == "/mod") {
|
||||||
|
@ -175,16 +154,9 @@ 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(Server.systemMessage('Added moderator status to ID ' + id + "."))
|
||||||
ws.data.send(
|
|
||||||
Server.systemMessage(
|
|
||||||
"Added moderator status to ID " + id + "."
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue