build config changes
All checks were successful
Galvanic Corrosion Cross-Compile / build (push) Successful in 1m50s
All checks were successful
Galvanic Corrosion Cross-Compile / build (push) Successful in 1m50s
* Commit hash shipped with builds
* Post & pre-build events
* Objective fixes
* Orientation challenge filler
* Custom Rooms base
- Currently cannot save rooms (CDN not set up)
* Moved root path to path.ts
* Room cloning
* Rewrote instances - the whole thing
* Relationships are still untested
* Charades Words
* AG Room fetch
* Private room matchmaking
* Socket fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* Galvanic Corrosion - Rec Room custom server for communities.
|
||||
<https://gitea.proxnet.dev/zombieb/galvanic-corrosion>
|
||||
Copyright (C) 2025 @zombieb (Discord / proxnet Gitea)
|
||||
Copyright (C) 2025 @zombieb (Discord / proxnet Gitea)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
@@ -34,10 +34,9 @@ import {
|
||||
import { SocketTarget } from "./targets/targetbase.ts";
|
||||
import { PlayerSocketSubscriptionTarget } from "./targets/SubscribeToPlayers.ts";
|
||||
import Presence from "../data/live/presence.ts";
|
||||
import Instances from "../data/live/instances.ts";
|
||||
import Matchmaking from "../data/live/base.ts";
|
||||
|
||||
const logmessages = true;
|
||||
const logmessages = false;
|
||||
|
||||
export class SignalRSocketHandler {
|
||||
|
||||
@@ -50,6 +49,8 @@ export class SignalRSocketHandler {
|
||||
|
||||
#PeriodicalId: number;
|
||||
|
||||
#killed = false;
|
||||
|
||||
constructor(socket: WebSocket, player: Profile) {
|
||||
|
||||
this.#socket = socket;
|
||||
@@ -62,6 +63,7 @@ export class SignalRSocketHandler {
|
||||
this.#Targets.set('SubscribeToPlayers', new PlayerSocketSubscriptionTarget(this));
|
||||
|
||||
this.#PeriodicalId = setInterval(async () => {
|
||||
if (this.#killed) return;
|
||||
if (this.#socket.readyState !== this.#socket.CLOSED) {
|
||||
const pres = await Presence.get(this.#profile);
|
||||
this.sendNotification("PresenceUpdate", await pres.export());
|
||||
@@ -69,9 +71,18 @@ export class SignalRSocketHandler {
|
||||
}
|
||||
}, 8000);
|
||||
|
||||
this.#socket.onclose = (ev) => {
|
||||
this.#log.d(`Close reason: ${ev.reason}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async #dispatchTarget<T = unknown>(target: string, args: unknown): Promise<TargetResult> {
|
||||
if (this.#killed) {
|
||||
const error = "Tried to dispatch socket target on dead socket";
|
||||
this.#log.w(error);
|
||||
return { type: TargetResultType.Failure, err: error };
|
||||
}
|
||||
const targetExec = this.#Targets.get(target);
|
||||
if (!targetExec) return { type: TargetResultType.NotATarget } as TargetResultNotATarget;
|
||||
else {
|
||||
@@ -152,6 +163,7 @@ export class SignalRSocketHandler {
|
||||
|
||||
destroy(sock: SignalRSocketHandler, internal: boolean | undefined = false) {
|
||||
return () => {
|
||||
sock.#killed = true;
|
||||
clearInterval(sock.#PeriodicalId);
|
||||
sock.sendRaw({ type: 7, error: "Socket closed" });
|
||||
if (!internal) sock.#socket.close();
|
||||
@@ -160,7 +172,7 @@ export class SignalRSocketHandler {
|
||||
|
||||
for (const target of sock.#Targets.values()) target.destroy();
|
||||
|
||||
Instances.removePlayerFromCurrentInstance(this.#profile);
|
||||
this.#profile.getInstance()?.removePlayer(this.#profile);
|
||||
Matchmaking.deleteLoginLock(this.#profile);
|
||||
}
|
||||
}
|
||||
@@ -174,13 +186,13 @@ export class SignalRSocketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
sendNotification(id: PushNotificationId | string, args: object) {
|
||||
sendNotification(id: PushNotificationId | string, args?: object) {
|
||||
const msg: SignalRMessage = {
|
||||
type: SignalMessageType.Invocation,
|
||||
target: "Notification",
|
||||
arguments: [JSON.stringify({
|
||||
Id: id,
|
||||
Msg: args
|
||||
Msg: args ? args : {}
|
||||
})]
|
||||
}
|
||||
this.sendRaw(msg);
|
||||
|
||||
Reference in New Issue
Block a user