Compare commits
No commits in common. "bac593dcef6e1ea10e0588a1660f1b70269dfa7f" and "9fcc3864c05df59cd585b950377cca26b5c9bd76" have entirely different histories.
bac593dcef
...
9fcc3864c0
|
@ -31,7 +31,7 @@ import {
|
|||
getSavedChannel,
|
||||
saveChannel
|
||||
} from "../data/channel";
|
||||
import { forceloadChannel } from "./forceload";
|
||||
import { forceloadChannel } from "./forceLoad";
|
||||
|
||||
interface CachedKickban {
|
||||
userId: string;
|
||||
|
@ -91,8 +91,7 @@ export class Channel extends EventEmitter {
|
|||
const data = {
|
||||
id: info._id,
|
||||
settings: JSON.stringify(info.settings),
|
||||
flags: JSON.stringify(this.flags),
|
||||
forceload: this.stays
|
||||
flags: JSON.stringify(this.flags)
|
||||
};
|
||||
|
||||
//this.logger.debug("Channel data to save:", data);
|
||||
|
@ -206,7 +205,6 @@ export class Channel extends EventEmitter {
|
|||
}
|
||||
|
||||
private alreadyBound = false;
|
||||
private destroyTimeout: Timer | undefined;
|
||||
|
||||
private bindEventListeners() {
|
||||
if (this.alreadyBound) return;
|
||||
|
@ -216,12 +214,6 @@ export class Channel extends EventEmitter {
|
|||
this.logger.info("Loaded chat history");
|
||||
|
||||
this.on("update", (self, uuid) => {
|
||||
// Propogate channel flags intended to be updated
|
||||
if (typeof this.flags.owner_id === "string") {
|
||||
this.settings.owner_id = this.flags.owner_id;
|
||||
}
|
||||
|
||||
// this.logger.debug("update");
|
||||
// Send updated info
|
||||
for (const socket of socketsByUUID.values()) {
|
||||
for (const p of this.ppl) {
|
||||
|
@ -241,20 +233,13 @@ export class Channel extends EventEmitter {
|
|||
|
||||
if (this.ppl.length === 0 && !this.stays) {
|
||||
if (config.channelDestroyTimeout) {
|
||||
this.destroyTimeout = setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
this.destroy();
|
||||
}, config.channelDestroyTimeout);
|
||||
} else {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
this.ppl.length > 0 &&
|
||||
typeof this.destroyTimeout !== "undefined"
|
||||
) {
|
||||
clearTimeout(this.destroyTimeout);
|
||||
}
|
||||
});
|
||||
|
||||
const BANNED_WORDS = ["AMIGHTYWIND", "CHECKLYHQ"];
|
||||
|
@ -685,7 +670,7 @@ export class Channel extends EventEmitter {
|
|||
|
||||
if (p) {
|
||||
// Give the crown back
|
||||
this.giveCrown(p, true, true);
|
||||
this.giveCrown(p, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -731,8 +716,7 @@ export class Channel extends EventEmitter {
|
|||
// Broadcast a channel update so everyone subscribed to the channel list can see the new user count
|
||||
//this.emit("update", this, socket.getUUID());
|
||||
//this.logger.debug("Update from join");
|
||||
// this.emit("update", this);
|
||||
socket.sendChannelUpdate(this.getInfo(), this.getParticipantList());
|
||||
this.emit("update", this);
|
||||
|
||||
//this.logger.debug("Settings:", this.settings);
|
||||
if (this.settings.owner_id === part._id) {
|
||||
|
@ -746,8 +730,7 @@ export class Channel extends EventEmitter {
|
|||
*/
|
||||
public leave(socket: Socket) {
|
||||
// this.logger.debug("Leave called");
|
||||
const part = socket.getParticipant();
|
||||
if (!part) return;
|
||||
const part = socket.getParticipant() as IParticipant;
|
||||
|
||||
let dupeCount = 0;
|
||||
for (const s of socketsByUUID.values()) {
|
||||
|
@ -763,22 +746,18 @@ export class Channel extends EventEmitter {
|
|||
if (dupeCount === 1) {
|
||||
const p = this.ppl.find(p => p.id === socket.getParticipantID());
|
||||
|
||||
let hadCrown = false;
|
||||
|
||||
if (p) {
|
||||
this.ppl.splice(this.ppl.indexOf(p), 1);
|
||||
|
||||
if (this.crown) {
|
||||
if (this.crown.participantId === p.id) {
|
||||
// Channel owner left, reset crown timeout
|
||||
hadCrown = true;
|
||||
this.chown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast bye
|
||||
if (!hadCrown)
|
||||
this.sendArray([
|
||||
{
|
||||
m: "bye",
|
||||
|
@ -787,7 +766,7 @@ export class Channel extends EventEmitter {
|
|||
]);
|
||||
|
||||
//this.logger.debug("Update from leave");
|
||||
// this.emit("update", this);
|
||||
this.emit("update", this);
|
||||
} else {
|
||||
for (const p of this.ppl) {
|
||||
if (!p.uuids.includes(socket.getUUID())) continue;
|
||||
|
@ -967,7 +946,6 @@ export class Channel extends EventEmitter {
|
|||
*/
|
||||
public destroy() {
|
||||
if (this.destroyed) return;
|
||||
|
||||
this.destroyed = true;
|
||||
|
||||
if (this.ppl.length > 0) {
|
||||
|
@ -1021,7 +999,7 @@ export class Channel extends EventEmitter {
|
|||
this.crown.time = Date.now();
|
||||
|
||||
if (update) {
|
||||
// this.logger.debug("Update from giveCrown");
|
||||
//this.logger.debug("Update from giveCrown");
|
||||
this.emit("update", this);
|
||||
}
|
||||
}
|
||||
|
@ -1330,8 +1308,6 @@ export class Channel extends EventEmitter {
|
|||
val: TChannelFlags[K]
|
||||
) {
|
||||
this.flags[key] = val;
|
||||
this.logger.debug("Updating channel flag " + key + " to", val);
|
||||
this.emit("update", this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1394,11 +1370,6 @@ export class Channel extends EventEmitter {
|
|||
).toFixed(2)}M`
|
||||
);
|
||||
}
|
||||
|
||||
public setForceload(enable: boolean) {
|
||||
this.stays = enable;
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
||||
export default Channel;
|
||||
|
|
|
@ -14,15 +14,9 @@ const logger = new Logger("Channel Forceloader");
|
|||
*/
|
||||
export function forceloadChannel(id: string) {
|
||||
try {
|
||||
const existing = ChannelList.getChannel(id);
|
||||
if (existing) {
|
||||
logger.info("Keeping", id, "forceloaded");
|
||||
existing.setForceload(true);
|
||||
} else {
|
||||
logger.info("Forceloading", id);
|
||||
new Channel(id, undefined, undefined, undefined, true);
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
// If you don't load the server first, bun will literally segfault
|
||||
import "./ws/server";
|
||||
import { loadForcedStartupChannels } from "./channel/forceload";
|
||||
import { loadForcedStartupChannels } from "./channel/forceLoad";
|
||||
import { Logger } from "./util/Logger";
|
||||
// docker hates this next one
|
||||
import { startReadline } from "./util/readline";
|
||||
|
|
|
@ -281,11 +281,6 @@ declare interface IncomingSocketEvents {
|
|||
_id: string;
|
||||
};
|
||||
|
||||
unforceload: {
|
||||
m: "unforceload";
|
||||
_id: string;
|
||||
};
|
||||
|
||||
ch_flag: {
|
||||
m: "ch_flag";
|
||||
_id?: string;
|
||||
|
|
|
@ -861,7 +861,7 @@ export class Socket extends EventEmitter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Allow custom messages to be sent and received from this socket
|
||||
* Start sending this socket the list of channels periodically
|
||||
**/
|
||||
public subscribeToCustom() {
|
||||
if (this.isSubscribedToCustom) return;
|
||||
|
@ -869,7 +869,7 @@ export class Socket extends EventEmitter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Disallow custom messages to be sent and received from this socket
|
||||
* Stop sending this socket the list of channels periodically
|
||||
**/
|
||||
public unsubscribeFromCustom() {
|
||||
if (!this.isSubscribedToCustom) return;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { Logger } from "~/util/Logger";
|
||||
import { ChannelList } from "../../../../channel/ChannelList";
|
||||
import { ServerEventListener, TChannelFlags } from "../../../../util/types";
|
||||
|
||||
const logger = new Logger("Channel flag input");
|
||||
|
||||
export const ch_flag: ServerEventListener<"ch_flag"> = {
|
||||
id: "ch_flag",
|
||||
callback: async (msg, socket) => {
|
||||
|
@ -20,7 +17,7 @@ export const ch_flag: ServerEventListener<"ch_flag"> = {
|
|||
if (typeof msg.key !== "string") return;
|
||||
if (typeof msg.value === "undefined") return;
|
||||
|
||||
const ch = ChannelList.getChannel(chid);
|
||||
const ch = ChannelList.getList().find(c => c.getID() == chid);
|
||||
if (!ch) return;
|
||||
|
||||
ch.setFlag(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { forceloadChannel } from "~/channel/forceload";
|
||||
import { ServerEventListener } from "~/util/types";
|
||||
import { forceloadChannel } from "../../../../channel/forceLoad";
|
||||
import { ServerEventListener } from "../../../../util/types";
|
||||
|
||||
export const forceload: ServerEventListener<"forceload"> = {
|
||||
id: "forceload",
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
import { forceloadChannel, unforceloadChannel } from "~/channel/forceload";
|
||||
import { ServerEventListener } from "~/util/types";
|
||||
|
||||
export const unforceload: ServerEventListener<"unforceload"> = {
|
||||
id: "unforceload",
|
||||
callback: async (msg, socket) => {
|
||||
// Unforceload channel
|
||||
if (typeof msg._id !== "string") return;
|
||||
|
||||
unforceloadChannel(msg._id);
|
||||
}
|
||||
};
|
|
@ -1,20 +1,17 @@
|
|||
import { EventGroup, eventGroups } from "../../events";
|
||||
import { admin_chat } from "./handlers/admin_chat";
|
||||
import { ch_flag } from "./handlers/ch_flag";
|
||||
import { clear_chat } from "./handlers/clear_chat";
|
||||
|
||||
export const EVENT_GROUP_ADMIN = new EventGroup("admin");
|
||||
|
||||
import { color } from "./handlers/color";
|
||||
import { eval_msg } from "./handlers/eval";
|
||||
import { forceload } from "./handlers/forceload";
|
||||
import { move } from "./handlers/move";
|
||||
import { name } from "./handlers/name";
|
||||
import { notification } from "./handlers/notification";
|
||||
import { rename_channel } from "./handlers/rename_channel";
|
||||
import { restart } from "./handlers/restart";
|
||||
import { tag } from "./handlers/tag";
|
||||
import { unforceload } from "./handlers/unforceload";
|
||||
import { user_flag } from "./handlers/user_flag";
|
||||
|
||||
// EVENT_GROUP_ADMIN.add(color);
|
||||
|
@ -32,10 +29,7 @@ EVENT_GROUP_ADMIN.addMany(
|
|||
rename_channel,
|
||||
admin_chat,
|
||||
eval_msg,
|
||||
tag,
|
||||
ch_flag,
|
||||
forceload,
|
||||
unforceload
|
||||
tag
|
||||
);
|
||||
|
||||
eventGroups.push(EVENT_GROUP_ADMIN);
|
||||
|
|
|
@ -17,9 +17,6 @@ import { kickban } from "./handlers/kickban";
|
|||
import { bye } from "./handlers/bye";
|
||||
import { chown } from "./handlers/chown";
|
||||
import { unban } from "./handlers/unban";
|
||||
import { plus_custom } from "./handlers/+custom";
|
||||
import { minus_custom } from "./handlers/-custom";
|
||||
import { custom } from "./handlers/custom";
|
||||
|
||||
// Imagine not having an "addMany" function...
|
||||
|
||||
|
@ -51,10 +48,7 @@ EVENTGROUP_USER.addMany(
|
|||
kickban,
|
||||
unban,
|
||||
bye,
|
||||
chown,
|
||||
plus_custom,
|
||||
minus_custom,
|
||||
custom
|
||||
chown
|
||||
);
|
||||
|
||||
eventGroups.push(EVENTGROUP_USER);
|
||||
|
|
Loading…
Reference in New Issue