Fix kickban
This commit is contained in:
parent
e1937aea02
commit
d61eeac221
|
@ -147,10 +147,6 @@ export class Channel extends EventEmitter {
|
||||||
if (msg.message.startsWith("/")) {
|
if (msg.message.startsWith("/")) {
|
||||||
this.emit("command", msg, socket);
|
this.emit("command", msg, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.message == "debug") {
|
|
||||||
this.logger.info(socket.getUUID(), socket.currentChannelID);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
}
|
}
|
||||||
|
@ -660,7 +656,7 @@ export class Channel extends EventEmitter {
|
||||||
* @param _id User ID to ban
|
* @param _id User ID to ban
|
||||||
* @param t Time in millseconds to ban for
|
* @param t Time in millseconds to ban for
|
||||||
**/
|
**/
|
||||||
public kickban(_id: string, t: number = 1000 * 60 * 30, banner?: string) {
|
public async kickban(_id: string, t: number = 1000 * 60 * 30, banner?: string) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (t < 0 || t > 300 * 60 * 1000) return;
|
if (t < 0 || t > 300 * 60 * 1000) return;
|
||||||
|
|
||||||
|
@ -672,6 +668,20 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
if (!banChannel) return;
|
if (!banChannel) return;
|
||||||
|
|
||||||
|
// Check if they are on the server at all
|
||||||
|
let bannedPart: Participant | undefined;
|
||||||
|
const bannedUUIDs: string[] = [];
|
||||||
|
for (const sock of socketsBySocketID.values()) {
|
||||||
|
if (sock.getUserID() == _id) {
|
||||||
|
bannedUUIDs.push(sock.getUUID());
|
||||||
|
const part = sock.getParticipant();
|
||||||
|
|
||||||
|
if (part) bannedPart = part;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bannedPart) return;
|
||||||
|
|
||||||
let isBanned = this.bans.map(b => b.userId).includes(_id);
|
let isBanned = this.bans.map(b => b.userId).includes(_id);
|
||||||
let overwrite = false;
|
let overwrite = false;
|
||||||
|
|
||||||
|
@ -681,30 +691,33 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
let uuidsToKick: string[] = [];
|
let uuidsToKick: string[] = [];
|
||||||
|
|
||||||
for (const part of this.ppl) {
|
if (!overwrite) {
|
||||||
if (part._id !== _id) continue;
|
this.bans.push({
|
||||||
|
userId: _id,
|
||||||
|
startTime: now,
|
||||||
|
endTime: now + t
|
||||||
|
});
|
||||||
|
|
||||||
if (!overwrite) {
|
shouldUpdate = true;
|
||||||
this.bans.push({
|
} else {
|
||||||
userId: _id,
|
|
||||||
startTime: now,
|
for (const ban of this.bans) {
|
||||||
endTime: now + t
|
if (ban.userId !== _id) continue;
|
||||||
});
|
ban.startTime = now;
|
||||||
} else {
|
ban.endTime = now + t;
|
||||||
for (const ban of this.bans) {
|
|
||||||
if (ban.userId !== _id) continue;
|
|
||||||
ban.startTime = now;
|
|
||||||
ban.endTime = now + t;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uuidsToKick = [...uuidsToKick, ...part.uuids];
|
|
||||||
|
|
||||||
shouldUpdate = true;
|
shouldUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uuidsToKick = [...uuidsToKick, ...bannedUUIDs];
|
||||||
|
|
||||||
|
this.logger.debug("Banned UUIDs:", uuidsToKick);
|
||||||
|
|
||||||
for (const socket of socketsBySocketID.values()) {
|
for (const socket of socketsBySocketID.values()) {
|
||||||
if (uuidsToKick.includes(socket.getUUID())) {
|
this.logger.debug("Checking UUID:", socket.getUUID(), "| Result:", uuidsToKick.indexOf(socket.getUUID()) !== -1);
|
||||||
|
if (uuidsToKick.indexOf(socket.getUUID()) !== -1) {
|
||||||
socket.sendNotification({
|
socket.sendNotification({
|
||||||
title: "Notice",
|
title: "Notice",
|
||||||
text: `Banned from "${this.getID()}" for ${Math.floor(t / 1000 / 60)} minutes.`,
|
text: `Banned from "${this.getID()}" for ${Math.floor(t / 1000 / 60)} minutes.`,
|
||||||
|
@ -712,7 +725,14 @@ export class Channel extends EventEmitter {
|
||||||
target: "#room",
|
target: "#room",
|
||||||
class: "short"
|
class: "short"
|
||||||
});
|
});
|
||||||
socket.setChannel(banChannel.getID());
|
|
||||||
|
// If they are here, move them to the ban channel
|
||||||
|
const ch = socket.getCurrentChannel();
|
||||||
|
if (ch) {
|
||||||
|
this.logger.debug("Current channel:", ch.getID(), "| We are:", this.getID());
|
||||||
|
if (ch.getID() == this.getID())
|
||||||
|
socket.setChannel(banChannel.getID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -720,21 +740,30 @@ export class Channel extends EventEmitter {
|
||||||
this.emit("update", this);
|
this.emit("update", this);
|
||||||
|
|
||||||
if (typeof banner !== "undefined") {
|
if (typeof banner !== "undefined") {
|
||||||
this.sendNotification({
|
const p = this.getParticipantListUnsanitized().find(p => p._id == banner);
|
||||||
title: "Notice",
|
const minutes = Math.floor(t / 1000 / 60);
|
||||||
text: `${this.getParticipantListUnsanitized().find(p => p._id == banner)?.name} banned ${this.getParticipantListUnsanitized().find(p => p._id == _id)?.name} from the channel for ${Math.floor(t / 1000 / 60)} minutes.`,
|
|
||||||
duration: 7000,
|
|
||||||
target: "#room",
|
|
||||||
class: "short"
|
|
||||||
});
|
|
||||||
|
|
||||||
if (banner == _id) {
|
if (p && bannedPart) {
|
||||||
|
await this.sendChat({
|
||||||
|
m: "a",
|
||||||
|
message: `Banned ${bannedPart.name} from the channel for ${minutes} minutes.`
|
||||||
|
}, p);
|
||||||
this.sendNotification({
|
this.sendNotification({
|
||||||
title: "Certificate of Award",
|
title: "Notice",
|
||||||
text: `Let it be known that ${this.getParticipantListUnsanitized().find(p => p._id == banner)?.name} kickbanned him/her self.`,
|
text: `${p.name} banned ${bannedPart.name} from the channel for ${minutes} minutes.`,
|
||||||
duration: 7000,
|
duration: 7000,
|
||||||
target: "#room"
|
target: "#room",
|
||||||
|
class: "short"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (banner == _id) {
|
||||||
|
this.sendNotification({
|
||||||
|
title: "Certificate of Award",
|
||||||
|
text: `Let it be known that ${p.name} kickbanned him/her self.`,
|
||||||
|
duration: 7000,
|
||||||
|
target: "#room"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -785,6 +814,29 @@ export class Channel extends EventEmitter {
|
||||||
html: notif.html
|
html: notif.html
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async sendChat(msg: ServerEvents["a"], p: Participant) {
|
||||||
|
if (!msg.message) return;
|
||||||
|
|
||||||
|
if (msg.message.length > 512) return;
|
||||||
|
|
||||||
|
// Sanitize
|
||||||
|
msg.message = msg.message
|
||||||
|
.replace(/\p{C}+/gu, "")
|
||||||
|
.replace(/(\p{Mc}{5})\p{Mc}+/gu, "$1")
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
let outgoing: ClientEvents["a"] = {
|
||||||
|
m: "a",
|
||||||
|
a: msg.message,
|
||||||
|
t: Date.now(),
|
||||||
|
p: p
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sendArray([outgoing]);
|
||||||
|
this.chatHistory.push(outgoing);
|
||||||
|
await saveChatHistory(this.getID(), this.chatHistory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Channel;
|
export default Channel;
|
||||||
|
|
Loading…
Reference in New Issue