duhhhhhhhh
This commit is contained in:
@@ -4,7 +4,8 @@ import { type ConsoleItem, ConsoleItemSchema } from "./zod.ts";
|
||||
import Server from "../../server.ts";
|
||||
import { getSourceAddress } from "../../../util/net.ts";
|
||||
import { consoleSockets } from "../../../main.ts";
|
||||
import chalk from "npm:chalk@^5.3.0";
|
||||
import chalk from "chalk";
|
||||
import { CommandSenderType } from "../../commands/cmdtypes.ts";
|
||||
|
||||
export default class SocketConsoleHandler {
|
||||
|
||||
@@ -55,7 +56,7 @@ export default class SocketConsoleHandler {
|
||||
if (!zodParsed.success) this.destroy();
|
||||
|
||||
else if (zodParsed.data.e == ConsoleEvent.Command) {
|
||||
const data = await Server.Commands.dispatch(...zodParsed.data.d.split(' '));
|
||||
const data = await Server.Commands.dispatch({ type: CommandSenderType.Console }, ...zodParsed.data.d.split(' '));
|
||||
if (data instanceof Error) throw data;
|
||||
|
||||
this.send(ConsoleEvent.Message, chalk.gray(`> ${chalk.yellow(data)}`));
|
||||
|
||||
@@ -18,6 +18,8 @@ import { SocketTarget } from "./targets/targetbase.ts";
|
||||
import type Profile from "../../profiles/profile.ts";
|
||||
import { detailedLog } from "../../../main.ts";
|
||||
import { PlayerSocketSubscriptionTarget } from "./targets/SubscribeToPlayers.ts";
|
||||
import Server from "../../server.ts";
|
||||
import { PresenceUpdateEvent } from "../../presence/events/PresenceUpdateEvent.ts";
|
||||
|
||||
const logmessages = true;
|
||||
|
||||
@@ -32,6 +34,10 @@ export class SignalRSocketHandler {
|
||||
|
||||
#killed = false;
|
||||
|
||||
#presCb = (ev: PresenceUpdateEvent) => {
|
||||
if (ev.profile == this.#profile) this.sendNotification("PresenceUpdate", ev.presence.export());
|
||||
}
|
||||
|
||||
constructor(socket: WebSocket, player: Profile) {
|
||||
|
||||
this.#socket = socket;
|
||||
@@ -69,6 +75,8 @@ export class SignalRSocketHandler {
|
||||
}
|
||||
|
||||
async #onMessage(message: Message) {
|
||||
this.#profile.Matchmaking.updateLastSeen();
|
||||
|
||||
if (message.kind == MessageKind.Protocol) {
|
||||
this.sendRaw({});
|
||||
return;
|
||||
@@ -130,6 +138,8 @@ export class SignalRSocketHandler {
|
||||
}
|
||||
});
|
||||
|
||||
Server.on('presence.update', this.#presCb);
|
||||
|
||||
this.#socket.addEventListener('close', this.destroy(this, true));
|
||||
}
|
||||
|
||||
@@ -137,10 +147,12 @@ export class SignalRSocketHandler {
|
||||
return (ev: CloseEvent) => {
|
||||
handler.#killed = true;
|
||||
|
||||
Server.off('presence.update', this.#presCb);
|
||||
|
||||
let errorReason = "Socket closed by server";
|
||||
this.#log.d(`Socket close code: ${ev.code}`);
|
||||
if (ev.reason.includes('Bye!')) errorReason = "Socket closed by client request";
|
||||
|
||||
|
||||
handler.sendRaw({ type: 7, error: errorReason });
|
||||
|
||||
if (!internal) handler.#socket.close();
|
||||
|
||||
@@ -6,7 +6,7 @@ export class PlayerSocketSubscriptionTarget extends SocketTarget {
|
||||
#ids: number[] = [];
|
||||
|
||||
override zod = z.object({
|
||||
PlayerIds: z.array(z.number().nonnegative().max(2_147_483_647))
|
||||
PlayerIds: z.array(z.number().nonnegative().max(Math.pow(2, 31)))
|
||||
});
|
||||
|
||||
override exec(...ids: number[]) {
|
||||
|
||||
Reference in New Issue
Block a user