This commit is contained in:
Hri7566 2024-09-19 11:51:10 -04:00
parent 8c8af2edcc
commit 9fcc3864c0
9 changed files with 78 additions and 22 deletions

View File

@ -149,6 +149,8 @@ export class Channel extends EventEmitter {
// Copy default settings
mixin(this.settings, config.defaultSettings);
if (owner_id) this.settings.owner_id = owner_id;
if (!this.isLobby()) {
if (set) {
// Copied from changeSettings below
@ -717,6 +719,9 @@ export class Channel extends EventEmitter {
this.emit("update", this);
//this.logger.debug("Settings:", this.settings);
if (this.settings.owner_id === part._id) {
this.giveCrown(part, true, true);
}
}
/**
@ -889,6 +894,20 @@ export class Channel extends EventEmitter {
const part = socket.getParticipant();
if (!part) return;
pianoPartID = part.id;
const flags = socket.getUserFlags();
if (flags) {
// Is crownsolo on?
if (
this.settings.crownsolo &&
this.crown &&
!(flags.admin || flags.mod)
) {
// Do they have the crown?
if (part.id !== this.crown.participantId) return;
}
}
}
const clientMsg: OutgoingSocketEvents["n"] = {

View File

@ -1,6 +1,6 @@
import { ChannelList } from "~/channel/ChannelList";
import { bus } from "./bus";
import type { ClientEvents, ServerEvents } from "~/util/types";
import type { OutgoingSocketEvents, IncomingSocketEvents } from "~/util/types";
import { socketsByUUID, type Socket } from "~/ws/Socket";
export function loadBehaviors() {
@ -12,7 +12,7 @@ export function loadBehaviors() {
bus.on("ls", () => {});
bus.on("custom", (msg: ServerEvents["custom"], sender: Socket) => {
bus.on("custom", (msg: IncomingSocketEvents["custom"], sender: Socket) => {
if (typeof msg !== "object") return;
if (typeof msg.data === "undefined") return;
if (typeof msg.target !== "object") return;
@ -52,7 +52,7 @@ export function loadBehaviors() {
m: "custom",
data: msg.data,
p: sender.getUserID()
} as ClientEvents["custom"]
} as OutgoingSocketEvents["custom"]
]);
}
} else if (msg.target.mode === "ids") {
@ -65,7 +65,7 @@ export function loadBehaviors() {
m: "custom",
data: msg.data,
p: sender.getUserID()
} as ClientEvents["custom"]
} as OutgoingSocketEvents["custom"]
]);
}
} else if (msg.target.mode === "subscribed") {
@ -74,7 +74,7 @@ export function loadBehaviors() {
m: "custom",
data: msg.data,
p: sender.getUserID()
} as ClientEvents["custom"]
} as OutgoingSocketEvents["custom"]
]);
}
}

View File

@ -30,7 +30,7 @@ export class Gateway {
public isTokenValid = false; // implemented
// Their user agent, if sent
public userAgent = ""; // TODO
public userAgent = ""; // partially implemented
// Whether they have moved their cursor
public hasCursorMoved = false; // implemented

View File

@ -6,13 +6,24 @@ export const userset: ServerEventListener<"userset"> = {
callback: async (msg, socket) => {
// Change username/color
if (!socket.rateLimits?.chains.userset.attempt()) return;
if (typeof msg.set.name !== "string" && typeof msg.set.color !== "string") return;
if (
typeof msg.set.name !== "string" &&
typeof msg.set.color !== "string"
)
return;
if (typeof msg.set.name == "string") {
const user = socket.getUser();
if (!user) return;
if (typeof msg.set.name == "string" && msg.set.name !== user.name) {
socket.gateway.hasChangedName = true;
}
if (typeof msg.set.color == "string" && config.enableColorChanging) {
if (
typeof msg.set.color == "string" &&
msg.set.color !== user.color &&
config.enableColorChanging
) {
socket.gateway.hasChangedColor = true;
}

View File

@ -1,6 +1,5 @@
// This is some convoluted dark magic I copied from some old mpp server I wrote
// No fucking clue where it came from or how it works internally, but I typedefized it
// It's just a bunch of rate limits in a chain... like a RateLimitChain...... hmmmm.......
// Replicated note quota class from client
// with types!
export class NoteQuota {
public allowance = 8000;
public max = 24000;

View File

@ -14,10 +14,14 @@ export const adminLimits: RateLimitConstructorList = {
"-ls": () => new RateLimit(config.admin.normal["-ls"]),
chown: () => new RateLimit(config.admin.normal.chown),
"+custom": () => new RateLimit(config.admin.normal["+custom"]),
"-custom": () => new RateLimit(config.admin.normal["-custom"]),
hi: () => new RateLimit(config.admin.normal.hi),
bye: () => new RateLimit(config.admin.normal.bye),
devices: () => new RateLimit(config.admin.normal.devices),
"admin message": () => new RateLimit(config.admin.normal["admin message"])
"admin message": () =>
new RateLimit(config.admin.normal["admin message"])
},
chains: {
userset: () =>
@ -28,12 +32,17 @@ export const adminLimits: RateLimitConstructorList = {
chset: () =>
new RateLimitChain(
config.admin.chains.chset.num,
config.admin.chains.userset.interval
config.admin.chains.chset.interval
),
n: () =>
new RateLimitChain(
config.admin.chains.n.num,
config.admin.chains.userset.interval
config.admin.chains.n.interval
),
custom: () =>
new RateLimitChain(
config.admin.chains.custom.num,
config.admin.chains.custom.interval
)
}
};

View File

@ -14,10 +14,14 @@ export const crownLimits: RateLimitConstructorList = {
"-ls": () => new RateLimit(config.crown.normal["-ls"]),
chown: () => new RateLimit(config.crown.normal.chown),
"+custom": () => new RateLimit(config.crown.normal["+custom"]),
"-custom": () => new RateLimit(config.crown.normal["-custom"]),
hi: () => new RateLimit(config.crown.normal.hi),
bye: () => new RateLimit(config.crown.normal.bye),
devices: () => new RateLimit(config.crown.normal.devices),
"admin message": () => new RateLimit(config.crown.normal["admin message"])
"admin message": () =>
new RateLimit(config.crown.normal["admin message"])
},
chains: {
userset: () =>
@ -28,12 +32,17 @@ export const crownLimits: RateLimitConstructorList = {
chset: () =>
new RateLimitChain(
config.crown.chains.chset.num,
config.crown.chains.userset.interval
config.crown.chains.chset.interval
),
n: () =>
new RateLimitChain(
config.crown.chains.n.num,
config.crown.chains.userset.interval
config.crown.chains.n.interval
),
custom: () =>
new RateLimitChain(
config.crown.chains.custom.num,
config.crown.chains.custom.interval
)
}
};

View File

@ -14,10 +14,14 @@ export const userLimits: RateLimitConstructorList = {
"-ls": () => new RateLimit(config.user.normal["-ls"]),
chown: () => new RateLimit(config.user.normal.chown),
"+custom": () => new RateLimit(config.user.normal["+custom"]),
"-custom": () => new RateLimit(config.user.normal["-custom"]),
hi: () => new RateLimit(config.user.normal.hi),
bye: () => new RateLimit(config.user.normal.bye),
devices: () => new RateLimit(config.user.normal.devices),
"admin message": () => new RateLimit(config.user.normal["admin message"])
"admin message": () =>
new RateLimit(config.user.normal["admin message"])
},
chains: {
userset: () =>
@ -28,12 +32,17 @@ export const userLimits: RateLimitConstructorList = {
chset: () =>
new RateLimitChain(
config.user.chains.chset.num,
config.user.chains.userset.interval
config.user.chains.chset.interval
),
n: () =>
new RateLimitChain(
config.user.chains.n.num,
config.user.chains.userset.interval
config.user.chains.n.interval
),
custom: () =>
new RateLimitChain(
config.user.chains.custom.num,
config.user.chains.custom.num
)
}
};

View File

@ -15,7 +15,7 @@ const logger = new Logger("WebSocket Server");
// ip -> timestamp
// for checking if they visited the site and are also connected to the websocket
const httpIpCache = new Map<string, number>();
export const httpIpCache = new Map<string, number>();
interface IFrontendConfig {
topButtons: "original" | "none";