This repository has been archived on 2026-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
Files
galvanic-corrosion/src/db.ts
zombieb c920dbe88a Many changes. Commit before I break down.
- Authentication middleware uses Zod
- PhotonRegionId in config
- DB key changes and additions
- WebSocket for SignalR mock
- Presence additions
  * Needs modification for playerIds (do not store `Profile` in a set, this will cause sync issues)
- Profile settings
- Profile Device Class
- Zod properly checks for issuer in token
- Room scene type bug
- Setting key import started
- Instancing changes
- PlayerReporting API route
- Deduplicated auth/connect/token
- match/player/login begin
- WebSocket hands off connection to SignalR handler
2025-03-27 00:44:58 -04:00

83 lines
2.1 KiB
TypeScript

import { Redis } from "ioredis";
import * as Config from "./config.ts";
import Logging from "@proxnet/undead-logging";
import chalk from "npm:chalk@^5.3.0";
const log = new Logging("Redis");
const config = Config.getConfig();
if (typeof config == "undefined") {
log.e(`Cannot start: Redis configuration failed`);
Deno.exit(1);
}
let shuttingDown = false;
Deno.addSignalListener("SIGINT", () => {
if (shuttingDown) return;
shuttingDown = true;
log.n("Disconnecting from Redis");
Database.quit();
});
export const Database = new Redis({
port: config.redis.port,
host: config.redis.host,
username: config.redis.username == "" ? undefined : config.redis.username,
password: config.redis.password == "" ? undefined : config.redis.password,
db: config.redis.db,
lazyConnect: true,
});
Database.on("connect", async () => {
log.i(`Connected to Redis`);
if (Deno.args.includes("--db-flush")) {
await Database.flushall(() => {
log.w(`${chalk.inverse("The database was flushed.")}`);
});
}
});
Database.on("connecting", () => {
log.n("Connecting to Redis..");
});
Database.on("error", (err) => {
log.e(`Redis error: ${err.stack}`);
});
export function buildKey(...args: string[]) {
return args.join(":");
}
export const KeyGroups = {
Config: {
Root: "config",
Dynamic: "dynamic",
Game: "game",
},
Content: {
Root: "content",
Images: "images",
Rooms: "rooms",
},
Profile_Usernames: "profile-usernames",
Profiles: {
Root: "profiles",
Username: "username",
ProfileImage: "profileImage",
Junior: "isJunior",
Platforms: "platforms",
DisplayName: "displayName",
Settings: "settings",
DeviceClass: "deviceClass",
},
Operators: "operators",
Users: {
Root: "users",
Profiles: "profiles",
Pubkey: "pubkey",
Nonces: "nonces",
AssociatedPlatforms: "associatedPlatforms",
AssociatedDeviceIds: "associatedDeviceIds",
AssociatedIps: "associatedIps",
},
};
export * as Redis from "./db.ts";