organize
This commit is contained in:
parent
0eedef4f20
commit
2332aa5810
36
README.md
36
README.md
|
@ -66,27 +66,27 @@ This has always been the future intention of this project.
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- Change `socketsBySocketID` to `socketsByUUID`
|
- [ ] Channel data saving (I forget what this means)
|
||||||
- Channel data saving
|
- [ ] Token generation
|
||||||
- Permission groups and permissions
|
- [ ] Permission groups and permissions
|
||||||
- Probable permission groups: owner, admin, mod, trialmod, default
|
- [x] Probable permission groups: owner, admin, mod, trialmod, default
|
||||||
- Setup tags for each permission group
|
- [ ] Setup tags for each permission group
|
||||||
- MPP.com data message
|
- [ ] MPP.com data message
|
||||||
- Implement based on `spooky.js` given there is no official documentation
|
- Implement based on `spooky.js` given there is no official documentation
|
||||||
- No cussing setting
|
- [ ] No cussing setting
|
||||||
- Full server-wide event bus
|
- [ ] Full server-wide event bus
|
||||||
- Channel events
|
- [ ] Channel events
|
||||||
- Socket events
|
- [ ] Socket events
|
||||||
- User data events
|
- [ ] User data events
|
||||||
- Permission-related events
|
- [ ] Permission-related events
|
||||||
- Redo ratelimits
|
- [ ] Redo ratelimits
|
||||||
- Redo all of the validations with Zod
|
- [ ] Redo all of the validations with Zod
|
||||||
- This probably means making Zod schemas for every single message type
|
- This probably means making Zod schemas for every single message type
|
||||||
- Also user and channel data
|
- Also user and channel data
|
||||||
- Test every frontend
|
- [ ] Test every frontend
|
||||||
- Test fishing bot
|
- [ ] Test fishing bot
|
||||||
- Remote console
|
- [ ] Remote console
|
||||||
- Modify frontend to use templating
|
- [ ] Modify frontend to use templating
|
||||||
|
|
||||||
## Backlog/Notes
|
## Backlog/Notes
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
owner:
|
||||||
|
- clearChat
|
||||||
|
- vanish
|
||||||
|
- chsetAnywhere
|
||||||
|
- chownAnywhere
|
||||||
|
- usersetOthers
|
||||||
|
- siteBan
|
||||||
|
- siteBanAnyReason
|
||||||
|
- siteBanAnyDuration
|
||||||
|
|
||||||
admin:
|
admin:
|
||||||
- clearChat
|
- clearChat
|
||||||
- vanish
|
- vanish
|
||||||
|
@ -7,3 +17,19 @@ admin:
|
||||||
- siteBan
|
- siteBan
|
||||||
- siteBanAnyReason
|
- siteBanAnyReason
|
||||||
- siteBanAnyDuration
|
- siteBanAnyDuration
|
||||||
|
|
||||||
|
mod:
|
||||||
|
- clearChat
|
||||||
|
- vanish
|
||||||
|
- chsetAnywhere
|
||||||
|
- chownAnywhere
|
||||||
|
- usersetOthers
|
||||||
|
- siteBan
|
||||||
|
- siteBanAnyReason
|
||||||
|
|
||||||
|
trialmod:
|
||||||
|
- clearChat
|
||||||
|
- vanish
|
||||||
|
- chsetAnywhere
|
||||||
|
- chownAnywhere
|
||||||
|
- siteBan
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
import { Logger } from "../util/Logger";
|
import { Logger } from "../util/Logger";
|
||||||
import type {
|
import type {
|
||||||
ChannelSettingValue,
|
|
||||||
IChannelSettings,
|
IChannelSettings,
|
||||||
ClientEvents,
|
OutgoingSocketEvents,
|
||||||
Participant,
|
Participant,
|
||||||
ServerEvents,
|
IncomingSocketEvents,
|
||||||
IChannelInfo,
|
IChannelInfo,
|
||||||
Notification,
|
Notification,
|
||||||
UserFlags,
|
UserFlags,
|
||||||
|
@ -57,7 +56,7 @@ export class Channel extends EventEmitter {
|
||||||
private settings: Partial<IChannelSettings>;
|
private settings: Partial<IChannelSettings>;
|
||||||
private ppl = new Array<ExtraPart>();
|
private ppl = new Array<ExtraPart>();
|
||||||
|
|
||||||
public chatHistory = new Array<ClientEvents["a"]>();
|
public chatHistory = new Array<OutgoingSocketEvents["a"]>();
|
||||||
|
|
||||||
private async loadChatHistory() {
|
private async loadChatHistory() {
|
||||||
try {
|
try {
|
||||||
|
@ -242,7 +241,7 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
const BANNED_WORDS = ["AMIGHTYWIND", "CHECKLYHQ"];
|
const BANNED_WORDS = ["AMIGHTYWIND", "CHECKLYHQ"];
|
||||||
|
|
||||||
this.on("a", async (msg: ServerEvents["a"], socket: Socket) => {
|
this.on("a", async (msg: IncomingSocketEvents["a"], socket: Socket) => {
|
||||||
try {
|
try {
|
||||||
if (typeof msg.message !== "string") return;
|
if (typeof msg.message !== "string") return;
|
||||||
|
|
||||||
|
@ -284,7 +283,7 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
const part = socket.getParticipant() as Participant;
|
const part = socket.getParticipant() as Participant;
|
||||||
|
|
||||||
const outgoing: ClientEvents["a"] = {
|
const outgoing: OutgoingSocketEvents["a"] = {
|
||||||
m: "a",
|
m: "a",
|
||||||
a: msg.message,
|
a: msg.message,
|
||||||
t: Date.now(),
|
t: Date.now(),
|
||||||
|
@ -847,8 +846,8 @@ export class Channel extends EventEmitter {
|
||||||
* Send messages to everyone in this channel
|
* Send messages to everyone in this channel
|
||||||
* @param arr List of events to send to clients
|
* @param arr List of events to send to clients
|
||||||
*/
|
*/
|
||||||
public sendArray<EventID extends keyof ClientEvents>(
|
public sendArray<EventID extends keyof OutgoingSocketEvents>(
|
||||||
arr: ClientEvents[EventID][],
|
arr: OutgoingSocketEvents[EventID][],
|
||||||
blockPartID?: string
|
blockPartID?: string
|
||||||
) {
|
) {
|
||||||
const sentSocketIDs = new Array<string>();
|
const sentSocketIDs = new Array<string>();
|
||||||
|
@ -875,7 +874,7 @@ export class Channel extends EventEmitter {
|
||||||
* @param socket Socket that is sending notes
|
* @param socket Socket that is sending notes
|
||||||
* @returns undefined
|
* @returns undefined
|
||||||
*/
|
*/
|
||||||
public playNotes(msg: ServerEvents["n"], socket?: Socket) {
|
public playNotes(msg: IncomingSocketEvents["n"], socket?: Socket) {
|
||||||
if (this.isDestroyed()) return;
|
if (this.isDestroyed()) return;
|
||||||
let pianoPartID = usersConfig.adminParticipant.id;
|
let pianoPartID = usersConfig.adminParticipant.id;
|
||||||
|
|
||||||
|
@ -885,7 +884,7 @@ export class Channel extends EventEmitter {
|
||||||
pianoPartID = part.id;
|
pianoPartID = part.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientMsg: ClientEvents["n"] = {
|
const clientMsg: OutgoingSocketEvents["n"] = {
|
||||||
m: "n",
|
m: "n",
|
||||||
n: msg.n,
|
n: msg.n,
|
||||||
t: msg.t,
|
t: msg.t,
|
||||||
|
@ -1230,7 +1229,7 @@ export class Channel extends EventEmitter {
|
||||||
* @param msg Chat message event to send
|
* @param msg Chat message event to send
|
||||||
* @param p Participant who is "sending the message"
|
* @param p Participant who is "sending the message"
|
||||||
**/
|
**/
|
||||||
public async sendChat(msg: ServerEvents["a"], p: Participant) {
|
public async sendChat(msg: IncomingSocketEvents["a"], p: Participant) {
|
||||||
if (!msg.message) return;
|
if (!msg.message) return;
|
||||||
|
|
||||||
if (msg.message.length > 512) return;
|
if (msg.message.length > 512) return;
|
||||||
|
@ -1241,7 +1240,7 @@ export class Channel extends EventEmitter {
|
||||||
.replace(/(\p{Mc}{5})\p{Mc}+/gu, "$1")
|
.replace(/(\p{Mc}{5})\p{Mc}+/gu, "$1")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
const outgoing: ClientEvents["a"] = {
|
const outgoing: OutgoingSocketEvents["a"] = {
|
||||||
m: "a",
|
m: "a",
|
||||||
a: msg.message,
|
a: msg.message,
|
||||||
t: Date.now(),
|
t: Date.now(),
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import EventEmitter from "events";
|
||||||
|
|
||||||
|
class EventBus extends EventEmitter {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const eventBus = new EventBus();
|
|
@ -107,7 +107,7 @@ declare interface Crown {
|
||||||
endPos: Vector2;
|
endPos: Vector2;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface ServerEvents {
|
declare interface IncomingSocketEvents {
|
||||||
hi: {
|
hi: {
|
||||||
m: "hi";
|
m: "hi";
|
||||||
token?: string;
|
token?: string;
|
||||||
|
@ -209,7 +209,7 @@ declare interface ServerEvents {
|
||||||
"admin message": {
|
"admin message": {
|
||||||
m: "admin message";
|
m: "admin message";
|
||||||
password: string;
|
password: string;
|
||||||
msg: ServerEvents[keyof ServerEvents];
|
msg: IncomingSocketEvents[keyof IncomingSocketEvents];
|
||||||
};
|
};
|
||||||
|
|
||||||
b: {
|
b: {
|
||||||
|
@ -310,7 +310,7 @@ declare interface ServerEvents {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface ClientEvents {
|
declare interface OutgoingSocketEvents {
|
||||||
a: {
|
a: {
|
||||||
m: "a";
|
m: "a";
|
||||||
a: string;
|
a: string;
|
||||||
|
@ -407,11 +407,11 @@ declare interface ClientEvents {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventID = ServerEvents[keyof ServerEvents]["m"];
|
type EventID = IncomingSocketEvents[keyof IncomingSocketEvents]["m"];
|
||||||
|
|
||||||
declare type ServerEventListener<E extends EventID> = {
|
declare type ServerEventListener<E extends EventID> = {
|
||||||
id: E;
|
id: E;
|
||||||
callback: (msg: ServerEvents[E], socket: Socket) => Promise<void>;
|
callback: (msg: IncomingSocketEvents[E], socket: Socket) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
declare type Vector2<T = number> = {
|
declare type Vector2<T = number> = {
|
||||||
|
|
|
@ -9,9 +9,9 @@ import EventEmitter from "events";
|
||||||
import type {
|
import type {
|
||||||
IChannelInfo,
|
IChannelInfo,
|
||||||
IChannelSettings,
|
IChannelSettings,
|
||||||
ClientEvents,
|
OutgoingSocketEvents,
|
||||||
Participant,
|
Participant,
|
||||||
ServerEvents,
|
IncomingSocketEvents,
|
||||||
UserFlags,
|
UserFlags,
|
||||||
Vector2,
|
Vector2,
|
||||||
Notification,
|
Notification,
|
||||||
|
@ -295,8 +295,8 @@ export class Socket extends EventEmitter {
|
||||||
* Send this socket an array of messages
|
* Send this socket an array of messages
|
||||||
* @param arr Array of messages to send
|
* @param arr Array of messages to send
|
||||||
**/
|
**/
|
||||||
public sendArray<EventID extends keyof ClientEvents>(
|
public sendArray<EventID extends keyof OutgoingSocketEvents>(
|
||||||
arr: ClientEvents[EventID][]
|
arr: OutgoingSocketEvents[EventID][]
|
||||||
) {
|
) {
|
||||||
if (this.isDestroyed() || !this.ws) return;
|
if (this.isDestroyed() || !this.ws) return;
|
||||||
this.ws.send(JSON.stringify(arr));
|
this.ws.send(JSON.stringify(arr));
|
||||||
|
@ -646,7 +646,7 @@ export class Socket extends EventEmitter {
|
||||||
* Make this socket play a note in the channel they are in
|
* Make this socket play a note in the channel they are in
|
||||||
* @param msg Note message from client
|
* @param msg Note message from client
|
||||||
**/
|
**/
|
||||||
public playNotes(msg: ServerEvents["n"]) {
|
public playNotes(msg: IncomingSocketEvents["n"]) {
|
||||||
const ch = this.getCurrentChannel();
|
const ch = this.getCurrentChannel();
|
||||||
if (!ch) return;
|
if (!ch) return;
|
||||||
ch.playNotes(msg, this);
|
ch.playNotes(msg, this);
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import type { EventID, ServerEventListener, ServerEvents } from "../util/types";
|
import type {
|
||||||
|
EventID,
|
||||||
|
ServerEventListener,
|
||||||
|
IncomingSocketEvents
|
||||||
|
} from "../util/types";
|
||||||
|
|
||||||
export class EventGroup {
|
export class EventGroup {
|
||||||
public eventList = new Array<ServerEventListener<any>>();
|
public eventList = new Array<ServerEventListener<any>>();
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
import { Socket } from "../../../Socket";
|
import { Socket } from "../../../Socket";
|
||||||
import { ServerEventListener, ServerEvents } from "../../../../util/types";
|
import {
|
||||||
|
ServerEventListener,
|
||||||
|
IncomingSocketEvents
|
||||||
|
} from "../../../../util/types";
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/64509631/is-there-a-regex-to-match-all-unicode-emojis
|
// https://stackoverflow.com/questions/64509631/is-there-a-regex-to-match-all-unicode-emojis
|
||||||
const emojiRegex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
|
const emojiRegex =
|
||||||
|
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
|
||||||
|
|
||||||
function populateSocketChatGatewayFlags(msg: ServerEvents["a"], socket: Socket) {
|
function populateSocketChatGatewayFlags(
|
||||||
|
msg: IncomingSocketEvents["a"],
|
||||||
|
socket: Socket
|
||||||
|
) {
|
||||||
socket.gateway.hasSentChatMessage = true;
|
socket.gateway.hasSentChatMessage = true;
|
||||||
|
|
||||||
if (msg.message.toUpperCase() == msg.message) {
|
if (msg.message.toUpperCase() == msg.message) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { getUserPermissions } from "~/data/permissions";
|
||||||
import { Logger } from "~/util/Logger";
|
import { Logger } from "~/util/Logger";
|
||||||
import { getMOTD } from "~/util/motd";
|
import { getMOTD } from "~/util/motd";
|
||||||
import { createToken, getToken, validateToken } from "~/util/token";
|
import { createToken, getToken, validateToken } from "~/util/token";
|
||||||
import type { ServerEventListener, ServerEvents } from "~/util/types";
|
import type { ServerEventListener, IncomingSocketEvents } from "~/util/types";
|
||||||
import type { Socket } from "~/ws/Socket";
|
import type { Socket } from "~/ws/Socket";
|
||||||
import { config, usersConfigPath } from "~/ws/usersConfig";
|
import { config, usersConfigPath } from "~/ws/usersConfig";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue