This commit is contained in:
Hri7566 2024-09-16 12:49:37 -04:00
parent 0eedef4f20
commit 2332aa5810
10 changed files with 90 additions and 45 deletions

View File

@ -66,27 +66,27 @@ This has always been the future intention of this project.
## TODO
- Change `socketsBySocketID` to `socketsByUUID`
- Channel data saving
- Permission groups and permissions
- Probable permission groups: owner, admin, mod, trialmod, default
- Setup tags for each permission group
- MPP.com data message
- [ ] Channel data saving (I forget what this means)
- [ ] Token generation
- [ ] Permission groups and permissions
- [x] Probable permission groups: owner, admin, mod, trialmod, default
- [ ] Setup tags for each permission group
- [ ] MPP.com data message
- Implement based on `spooky.js` given there is no official documentation
- No cussing setting
- Full server-wide event bus
- Channel events
- Socket events
- User data events
- Permission-related events
- Redo ratelimits
- Redo all of the validations with Zod
- [ ] No cussing setting
- [ ] Full server-wide event bus
- [ ] Channel events
- [ ] Socket events
- [ ] User data events
- [ ] Permission-related events
- [ ] Redo ratelimits
- [ ] Redo all of the validations with Zod
- This probably means making Zod schemas for every single message type
- Also user and channel data
- Test every frontend
- Test fishing bot
- Remote console
- Modify frontend to use templating
- [ ] Test every frontend
- [ ] Test fishing bot
- [ ] Remote console
- [ ] Modify frontend to use templating
## Backlog/Notes

BIN
bun.lockb

Binary file not shown.

View File

@ -1,3 +1,13 @@
owner:
- clearChat
- vanish
- chsetAnywhere
- chownAnywhere
- usersetOthers
- siteBan
- siteBanAnyReason
- siteBanAnyDuration
admin:
- clearChat
- vanish
@ -7,3 +17,19 @@ admin:
- siteBan
- siteBanAnyReason
- siteBanAnyDuration
mod:
- clearChat
- vanish
- chsetAnywhere
- chownAnywhere
- usersetOthers
- siteBan
- siteBanAnyReason
trialmod:
- clearChat
- vanish
- chsetAnywhere
- chownAnywhere
- siteBan

View File

@ -1,11 +1,10 @@
import EventEmitter from "events";
import { Logger } from "../util/Logger";
import type {
ChannelSettingValue,
IChannelSettings,
ClientEvents,
OutgoingSocketEvents,
Participant,
ServerEvents,
IncomingSocketEvents,
IChannelInfo,
Notification,
UserFlags,
@ -57,7 +56,7 @@ export class Channel extends EventEmitter {
private settings: Partial<IChannelSettings>;
private ppl = new Array<ExtraPart>();
public chatHistory = new Array<ClientEvents["a"]>();
public chatHistory = new Array<OutgoingSocketEvents["a"]>();
private async loadChatHistory() {
try {
@ -242,7 +241,7 @@ export class Channel extends EventEmitter {
const BANNED_WORDS = ["AMIGHTYWIND", "CHECKLYHQ"];
this.on("a", async (msg: ServerEvents["a"], socket: Socket) => {
this.on("a", async (msg: IncomingSocketEvents["a"], socket: Socket) => {
try {
if (typeof msg.message !== "string") return;
@ -284,7 +283,7 @@ export class Channel extends EventEmitter {
const part = socket.getParticipant() as Participant;
const outgoing: ClientEvents["a"] = {
const outgoing: OutgoingSocketEvents["a"] = {
m: "a",
a: msg.message,
t: Date.now(),
@ -847,8 +846,8 @@ export class Channel extends EventEmitter {
* Send messages to everyone in this channel
* @param arr List of events to send to clients
*/
public sendArray<EventID extends keyof ClientEvents>(
arr: ClientEvents[EventID][],
public sendArray<EventID extends keyof OutgoingSocketEvents>(
arr: OutgoingSocketEvents[EventID][],
blockPartID?: string
) {
const sentSocketIDs = new Array<string>();
@ -875,7 +874,7 @@ export class Channel extends EventEmitter {
* @param socket Socket that is sending notes
* @returns undefined
*/
public playNotes(msg: ServerEvents["n"], socket?: Socket) {
public playNotes(msg: IncomingSocketEvents["n"], socket?: Socket) {
if (this.isDestroyed()) return;
let pianoPartID = usersConfig.adminParticipant.id;
@ -885,7 +884,7 @@ export class Channel extends EventEmitter {
pianoPartID = part.id;
}
const clientMsg: ClientEvents["n"] = {
const clientMsg: OutgoingSocketEvents["n"] = {
m: "n",
n: msg.n,
t: msg.t,
@ -1230,7 +1229,7 @@ export class Channel extends EventEmitter {
* @param msg Chat message event to send
* @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.length > 512) return;
@ -1241,7 +1240,7 @@ export class Channel extends EventEmitter {
.replace(/(\p{Mc}{5})\p{Mc}+/gu, "$1")
.trim();
const outgoing: ClientEvents["a"] = {
const outgoing: OutgoingSocketEvents["a"] = {
m: "a",
a: msg.message,
t: Date.now(),

9
src/event/bus.ts Normal file
View File

@ -0,0 +1,9 @@
import EventEmitter from "events";
class EventBus extends EventEmitter {
constructor() {
super();
}
}
export const eventBus = new EventBus();

10
src/util/types.d.ts vendored
View File

@ -107,7 +107,7 @@ declare interface Crown {
endPos: Vector2;
}
declare interface ServerEvents {
declare interface IncomingSocketEvents {
hi: {
m: "hi";
token?: string;
@ -209,7 +209,7 @@ declare interface ServerEvents {
"admin message": {
m: "admin message";
password: string;
msg: ServerEvents[keyof ServerEvents];
msg: IncomingSocketEvents[keyof IncomingSocketEvents];
};
b: {
@ -310,7 +310,7 @@ declare interface ServerEvents {
};
}
declare interface ClientEvents {
declare interface OutgoingSocketEvents {
a: {
m: "a";
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> = {
id: E;
callback: (msg: ServerEvents[E], socket: Socket) => Promise<void>;
callback: (msg: IncomingSocketEvents[E], socket: Socket) => Promise<void>;
};
declare type Vector2<T = number> = {

View File

@ -9,9 +9,9 @@ import EventEmitter from "events";
import type {
IChannelInfo,
IChannelSettings,
ClientEvents,
OutgoingSocketEvents,
Participant,
ServerEvents,
IncomingSocketEvents,
UserFlags,
Vector2,
Notification,
@ -295,8 +295,8 @@ export class Socket extends EventEmitter {
* Send this socket an array of messages
* @param arr Array of messages to send
**/
public sendArray<EventID extends keyof ClientEvents>(
arr: ClientEvents[EventID][]
public sendArray<EventID extends keyof OutgoingSocketEvents>(
arr: OutgoingSocketEvents[EventID][]
) {
if (this.isDestroyed() || !this.ws) return;
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
* @param msg Note message from client
**/
public playNotes(msg: ServerEvents["n"]) {
public playNotes(msg: IncomingSocketEvents["n"]) {
const ch = this.getCurrentChannel();
if (!ch) return;
ch.playNotes(msg, this);

View File

@ -1,4 +1,8 @@
import type { EventID, ServerEventListener, ServerEvents } from "../util/types";
import type {
EventID,
ServerEventListener,
IncomingSocketEvents
} from "../util/types";
export class EventGroup {
public eventList = new Array<ServerEventListener<any>>();

View File

@ -1,10 +1,17 @@
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
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;
if (msg.message.toUpperCase() == msg.message) {

View File

@ -2,7 +2,7 @@ import { getUserPermissions } from "~/data/permissions";
import { Logger } from "~/util/Logger";
import { getMOTD } from "~/util/motd";
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 { config, usersConfigPath } from "~/ws/usersConfig";