That's a spicy meatball
* APIUtils additions * Socket and web server listen on dedicated ports (see denoland/deno socket issue created by ZombieB1309 on GitHub) * Coach and Server created automatically (untested) * Profile content functions split into 'managers' * Progression temporary implementation * Settings placed into profile content manager * Relationships and messages return temporary empty array * Socket targets defined, message delivery to target, exec returned (goes unused for now)
This commit is contained in:
@@ -6,7 +6,6 @@ import { Config } from "./config.ts";
|
||||
import { AuthType, User, UserTokenFormat } from "./data/users.ts";
|
||||
import UnifiedProfile, { ProfileTokenFormat } from "./data/profiles.ts";
|
||||
import z from "zod";
|
||||
import { IncomingMessage } from "node:http";
|
||||
|
||||
const config = Config.getConfig();
|
||||
|
||||
@@ -25,6 +24,11 @@ export function createRouter(path: string) {
|
||||
return router;
|
||||
}
|
||||
|
||||
export function setCacheAllowed(_rq: express.Request, rs: express.Response, nxt: express.NextFunction) {
|
||||
rs.setHeader("Cache-Control", 'public');
|
||||
nxt();
|
||||
}
|
||||
|
||||
export function generateRandomString(length: number) {
|
||||
const characters =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
@@ -132,14 +136,14 @@ export function getSrcIpDefault(rq: express.Request): string {
|
||||
|
||||
return typeof rq.ip === "undefined" ? "(unknown source)" : rq.ip;
|
||||
}
|
||||
export function getSrcIpDefaultRaw(rq: IncomingMessage) {
|
||||
const cfIp = rq.headers['cf-connecting-ip'];
|
||||
export function getSrcIpDefaultDeno(req: Request, info: Deno.ServeHandlerInfo<Deno.NetAddr>) {
|
||||
const cfIp = req.headers.get('cf-connecting-ip');
|
||||
if (cfIp) return cfIp;
|
||||
|
||||
const xrIp = rq.headers['x-real-ip'];
|
||||
const xrIp = req.headers.get('x-real-ip');
|
||||
if (xrIp) return xrIp;
|
||||
|
||||
return rq.socket.remoteAddress ? rq.socket.remoteAddress : "(unknown source)";
|
||||
return info.remoteAddr.hostname;
|
||||
}
|
||||
|
||||
export function statusResponse(code: number) {
|
||||
@@ -277,11 +281,12 @@ export async function Authentication(
|
||||
}
|
||||
|
||||
const valid = ![ // used to contain more conditions, now is only 1
|
||||
decodedToken.iss == `${config.web.securepublichost ? 'https' : 'http'}://${config.web.publichost}`,
|
||||
decodedToken.iss == `${config.web.api.securepublichost ? 'https' : 'http'}://${config.web.api.publichost}`,
|
||||
].includes(false);
|
||||
if (valid) {
|
||||
if (decodedToken.typ == AuthType.Web) rs.locals.user = new User(decodedToken.sub);
|
||||
else if (decodedToken.typ == AuthType.Game) rs.locals.profile = UnifiedProfile.get(decodedToken.sub);
|
||||
rs.locals.token = token;
|
||||
|
||||
nxt();
|
||||
} else {
|
||||
@@ -294,6 +299,18 @@ export async function Authentication(
|
||||
}
|
||||
}
|
||||
|
||||
export function AuthenticationType(type: AuthType) {
|
||||
return (_rq: express.Request, rs: express.Response, nxt: express.NextFunction) => {
|
||||
const profile = rs.locals.profile;
|
||||
const user = rs.locals.user;
|
||||
|
||||
if ((type == AuthType.Game && !profile) || (type == AuthType.Web && !user)) {
|
||||
rs.json(genericResponseFormat(true, 'Wrong authentication type provided.'));
|
||||
return;
|
||||
} else nxt();
|
||||
}
|
||||
}
|
||||
|
||||
export type NoBody = Record<string | number | symbol, never>;
|
||||
|
||||
export * as APIUtils from "./apiutils.ts";
|
||||
|
||||
Reference in New Issue
Block a user