* Unified profiles, rather than instantiating profiles every time we want to access one
* Socket and live instance changes * Possible problem with Deno's handling of sockets, compatibility issue with Node?
This commit is contained in:
@@ -11,10 +11,14 @@ function randomId(length: number) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Lots of this is redundant. The WebSocket request already contains an access token for the profile, but I'd
|
||||
// like to make sure that connectionIds are freed automatically.
|
||||
/**
|
||||
* Reserve `connectionId`s for each connected client, hand off to socket handler when complete or timed out
|
||||
*/
|
||||
export class SocketHandoff {
|
||||
|
||||
static all() {
|
||||
return Array.from(handoffs.values());
|
||||
}
|
||||
static generateId() {
|
||||
let id = randomId(48);
|
||||
while (handoffs.values().find(handoff => handoff.id == id)) id = randomId(48);
|
||||
@@ -32,19 +36,15 @@ export class SocketHandoff {
|
||||
this.id = SocketHandoff.generateId();
|
||||
|
||||
this.#timeout = setTimeout(() => {
|
||||
handoffs.delete(this);
|
||||
this.complete();
|
||||
});
|
||||
|
||||
handoffs.add(this);
|
||||
}
|
||||
|
||||
delete() {
|
||||
complete() {
|
||||
clearTimeout(this.#timeout);
|
||||
handoffs.delete(this);
|
||||
}
|
||||
|
||||
complete() {
|
||||
this.delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import WebSocket from "ws";
|
||||
import Profile from "../data/profiles.ts";
|
||||
import { IncomingMessage } from "node:http";
|
||||
import { Profile } from "../data/profiles.ts";
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
|
||||
export class SignalRSocketHandler {
|
||||
@@ -11,15 +10,13 @@ export class SignalRSocketHandler {
|
||||
#profile: Profile;
|
||||
|
||||
constructor(socket: WebSocket, player: Profile) {
|
||||
|
||||
|
||||
this.#socket = socket;
|
||||
this.#initLogSource();
|
||||
|
||||
this.#profile = player;
|
||||
|
||||
throw new Error("This will fail due to undefined access attempt. Debug this. Also, please unify profiles.");
|
||||
player.setSocketHandler(this);
|
||||
this.log.source += player.getId().toString();
|
||||
|
||||
// log: we connected!!
|
||||
|
||||
Deno.addSignalListener('SIGINT', this.destroy);
|
||||
|
||||
@@ -30,4 +27,17 @@ export class SignalRSocketHandler {
|
||||
Deno.removeSignalListener('SIGINT', this.destroy);
|
||||
}
|
||||
|
||||
async #initLogSource() {
|
||||
this.log.source += this.#profile.getId().toString();
|
||||
|
||||
this.log.i(`Player '${(await this.#profile.export())?.username}' (${this.#profile.getId()}) created hub socket`);
|
||||
|
||||
this.#socket.on('open', () => {
|
||||
this.log.d(`hello world`)
|
||||
});
|
||||
this.#socket.on('message', data => {
|
||||
this.log.d(data.toString());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user