Update admin messages that change user data to skip rate limit checks
This commit is contained in:
parent
c970faa928
commit
2a73ac0af2
|
@ -18,6 +18,7 @@ lobbyRegexes:
|
||||||
- ^lobby[0-9][0-9]$
|
- ^lobby[0-9][0-9]$
|
||||||
- ^lobby[0-9]$
|
- ^lobby[0-9]$
|
||||||
- ^lobby$
|
- ^lobby$
|
||||||
|
- ^lobbyNaN$
|
||||||
- ^test/.+$
|
- ^test/.+$
|
||||||
lobbyBackdoor: lolwutsecretlobbybackdoor
|
lobbyBackdoor: lolwutsecretlobbybackdoor
|
||||||
fullChannel: test/awkward
|
fullChannel: test/awkward
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
ServerEvents,
|
ServerEvents,
|
||||||
IChannelInfo,
|
IChannelInfo,
|
||||||
Notification,
|
Notification,
|
||||||
UserFlags
|
UserFlags,
|
||||||
} from "../util/types";
|
} from "../util/types";
|
||||||
import type { Socket } from "../ws/Socket";
|
import type { Socket } from "../ws/Socket";
|
||||||
import { validateChannelSettings } from "./settings";
|
import { validateChannelSettings } from "./settings";
|
||||||
|
@ -18,7 +18,7 @@ import { ChannelList } from "./ChannelList";
|
||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
import { saveChatHistory, getChatHistory } from "../data/history";
|
import { saveChatHistory, getChatHistory } from "../data/history";
|
||||||
import { mixin } from "../util/helpers";
|
import { mixin } from "../util/helpers";
|
||||||
import { readUser } from "../data/user";
|
import { User } from "@prisma/client";
|
||||||
|
|
||||||
interface CachedKickban {
|
interface CachedKickban {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
@ -45,6 +45,7 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
public logger: Logger;
|
public logger: Logger;
|
||||||
public bans = new Array<CachedKickban>();
|
public bans = new Array<CachedKickban>();
|
||||||
|
public cursorCache = new Array<{ x: string | number; y: string | number; id: string }>();
|
||||||
|
|
||||||
public crown?: Crown;
|
public crown?: Crown;
|
||||||
|
|
||||||
|
@ -66,8 +67,6 @@ export class Channel extends EventEmitter {
|
||||||
// Validate settings in set
|
// Validate settings in set
|
||||||
// Set the verified settings
|
// Set the verified settings
|
||||||
|
|
||||||
this.logger.debug("lobby me?", this.isLobby());
|
|
||||||
|
|
||||||
if (!this.isLobby()) {
|
if (!this.isLobby()) {
|
||||||
if (set) {
|
if (set) {
|
||||||
//this.logger.debug("Passed settings:", set);
|
//this.logger.debug("Passed settings:", set);
|
||||||
|
@ -172,6 +171,101 @@ export class Channel extends EventEmitter {
|
||||||
this.on("command", (msg, socket) => {
|
this.on("command", (msg, socket) => {
|
||||||
// TODO commands
|
// TODO commands
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.on("user data update", (user: User) => {
|
||||||
|
try {
|
||||||
|
if (typeof user.name !== "string") return;
|
||||||
|
if (typeof user.color !== "string") return;
|
||||||
|
if (typeof user.id !== "string") return;
|
||||||
|
if (typeof user.tag !== "undefined" && typeof user.tag !== "string") return;
|
||||||
|
if (typeof user.flags !== "undefined" && typeof user.flags !== "string") return;
|
||||||
|
|
||||||
|
let tag;
|
||||||
|
let flags;
|
||||||
|
|
||||||
|
try {
|
||||||
|
tag = JSON.parse(user.tag);
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
|
try {
|
||||||
|
flags = JSON.parse(user.flags);
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
|
for (const p of this.ppl) {
|
||||||
|
if (p._id !== user.id) continue;
|
||||||
|
|
||||||
|
p._id = user.id;
|
||||||
|
p.name = user.name;
|
||||||
|
p.color = user.color;
|
||||||
|
p.tag = tag;
|
||||||
|
p.flags = flags;
|
||||||
|
|
||||||
|
let found;
|
||||||
|
|
||||||
|
for (const cursor of this.cursorCache) {
|
||||||
|
if (cursor.id == p.id) {
|
||||||
|
found = cursor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let x: string | number = "0.00";
|
||||||
|
let y: string | number = "-10.00";
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
x = found.x;
|
||||||
|
y = found.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendArray(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
m: "p",
|
||||||
|
_id: p._id,
|
||||||
|
name: p.name,
|
||||||
|
color: p.color,
|
||||||
|
id: p.id,
|
||||||
|
x: x,
|
||||||
|
y: y
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit("update", this);
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(err);
|
||||||
|
this.logger.warn("Unable to update user");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("cursor", (pos: { x: string | number; y: string | number; id: string }) => {
|
||||||
|
let found;
|
||||||
|
|
||||||
|
for (const cursor of this.cursorCache) {
|
||||||
|
if (cursor.id == pos.id) {
|
||||||
|
found = cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
// Cache the cursor pos
|
||||||
|
this.cursorCache.push(pos);
|
||||||
|
} else {
|
||||||
|
// Edit the cache
|
||||||
|
found.x = pos.x;
|
||||||
|
found.y = pos.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendArray([
|
||||||
|
{
|
||||||
|
m: "m",
|
||||||
|
id: pos.id,
|
||||||
|
// not type safe
|
||||||
|
x: pos.x as string,
|
||||||
|
y: pos.y as string
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +296,7 @@ export class Channel extends EventEmitter {
|
||||||
* Determine whether this channel is a lobby with the name "lobby" in it
|
* Determine whether this channel is a lobby with the name "lobby" in it
|
||||||
*/
|
*/
|
||||||
public isTrueLobby() {
|
public isTrueLobby() {
|
||||||
if (this.getID().match("^lobby[0-9][0-9]$") && this.getID().match("^lobby[1-9]$")) return true;
|
if (this.getID().match("^lobby[0-9][0-9]$") && this.getID().match("^lobby[0-9]$") && this.getID().match("^lobby$"), "^lobbyNaN$") return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ export const config = loadConfig<ChannelConfig>("config/channels.yml", {
|
||||||
visible: true
|
visible: true
|
||||||
},
|
},
|
||||||
// Here's a terrifying fact: Brandon used parseInt to check lobby names
|
// Here's a terrifying fact: Brandon used parseInt to check lobby names
|
||||||
lobbyRegexes: ["^lobby[0-9][0-9]$", "^lobby[0-9]$", "^lobby$", "^test/.+$"],
|
lobbyRegexes: ["^lobby[0-9][0-9]$", "^lobby[0-9]$", "^lobby$", "^lobbyNaN$", "^test/.+$"],
|
||||||
lobbyBackdoor: "lolwutsecretlobbybackdoor",
|
lobbyBackdoor: "lolwutsecretlobbybackdoor",
|
||||||
fullChannel: "test/awkward",
|
fullChannel: "test/awkward",
|
||||||
sendLimit: false,
|
sendLimit: false,
|
||||||
|
|
|
@ -318,14 +318,13 @@ export class Socket extends EventEmitter {
|
||||||
const part = this.getParticipant();
|
const part = this.getParticipant();
|
||||||
if (!part) return;
|
if (!part) return;
|
||||||
|
|
||||||
ch.sendArray([
|
let pos = {
|
||||||
{
|
x: this.cursorPos.x,
|
||||||
m: "m",
|
y: this.cursorPos.y,
|
||||||
id: part.id,
|
id: this.getParticipantID()
|
||||||
x: this.cursorPos.x,
|
};
|
||||||
y: this.cursorPos.y
|
|
||||||
}
|
ch.emit("cursor", pos);
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCurrentChannel() {
|
public getCurrentChannel() {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
import { ChannelList } from "../../../../channel/ChannelList";
|
||||||
import { readUser, updateUser } from "../../../../data/user";
|
import { readUser, updateUser } from "../../../../data/user";
|
||||||
import { ServerEventListener } from "../../../../util/types";
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
import { findSocketsByUserID } from "../../../Socket";
|
import { Logger } from "../../../../util/Logger";
|
||||||
|
|
||||||
export const color: ServerEventListener<"color"> = {
|
export const color: ServerEventListener<"color"> = {
|
||||||
id: "color",
|
id: "color",
|
||||||
callback: async (msg, socket) => {
|
callback: async (msg, socket) => {
|
||||||
// I'm not allowed to use this feature on MPP.net for a really stupid reason
|
|
||||||
// Nevermind, fishing bot has color again
|
|
||||||
const id = msg._id;
|
const id = msg._id;
|
||||||
const color = msg.color;
|
const color = msg.color;
|
||||||
|
|
||||||
|
@ -19,9 +18,8 @@ export const color: ServerEventListener<"color"> = {
|
||||||
user.color = color;
|
user.color = color;
|
||||||
await updateUser(id, user);
|
await updateUser(id, user);
|
||||||
|
|
||||||
const toUpdate = findSocketsByUserID(id);
|
for (const ch of ChannelList.getList()) {
|
||||||
toUpdate.forEach(s => {
|
ch.emit("user data update", user);
|
||||||
s.userset(undefined, msg.color, true);
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ChannelList } from "../../../../channel/ChannelList";
|
||||||
import { readUser, updateUser } from "../../../../data/user";
|
import { readUser, updateUser } from "../../../../data/user";
|
||||||
import { ServerEventListener } from "../../../../util/types";
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
import { findSocketsByUserID } from "../../../Socket";
|
import { findSocketsByUserID } from "../../../Socket";
|
||||||
|
@ -18,9 +19,8 @@ export const name: ServerEventListener<"name"> = {
|
||||||
user.name = name;
|
user.name = name;
|
||||||
await updateUser(id, user);
|
await updateUser(id, user);
|
||||||
|
|
||||||
const toUpdate = findSocketsByUserID(id);
|
for (const ch of ChannelList.getList()) {
|
||||||
toUpdate.forEach(s => {
|
ch.emit("user data update", user);
|
||||||
s.userset(msg.name, undefined, true);
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ChannelList } from "../../../../channel/ChannelList";
|
||||||
import { readUser, updateUser } from "../../../../data/user";
|
import { readUser, updateUser } from "../../../../data/user";
|
||||||
import { Logger } from "../../../../util/Logger";
|
import { Logger } from "../../../../util/Logger";
|
||||||
import { ServerEventListener } from "../../../../util/types";
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
|
@ -39,6 +40,10 @@ export const user_flag: ServerEventListener<"user_flag"> = {
|
||||||
sock.setUserFlag(msg.key, msg.value);
|
sock.setUserFlag(msg.key, msg.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const ch of ChannelList.getList()) {
|
||||||
|
ch.emit("user data update", user);
|
||||||
|
}
|
||||||
|
|
||||||
// socket.getCurrentChannel()?.logger.debug("socks:", socks);
|
// socket.getCurrentChannel()?.logger.debug("socks:", socks);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue