wip
This commit is contained in:
@@ -61,7 +61,6 @@ export const structure = {
|
||||
token_id: number,
|
||||
}, AutoLoginResponse, AutoLoginFailed>(),
|
||||
ReqNonce: GET<AutoLoginNonceResponse, AutoLoginFailed>(),
|
||||
test: GET<{result: true, hello:'world'}>(),
|
||||
},
|
||||
GetGameLoginToken: GET<{
|
||||
result: true,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@sammo/game_logic": "workspace:^",
|
||||
"@sammo/util": "workspace:^",
|
||||
"@strpc/def": "workspace:^",
|
||||
"bootstrap": "^5.3.1",
|
||||
@@ -30,6 +31,7 @@
|
||||
"vue-router": "^4.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node20": "^20.1.2",
|
||||
"@types/lodash-es": "^4.17.9",
|
||||
"@types/node": "^20.6.3",
|
||||
"@vue/eslint-config-prettier": "^8.0.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "@tsconfig/node18/tsconfig.json",
|
||||
"extends": "@tsconfig/node20/tsconfig.json",
|
||||
"include": [
|
||||
"vite.config.*",
|
||||
"vitest.config.*",
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
"vue-router": "^4.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node20": "^20.1.2",
|
||||
"@types/lodash-es": "^4.17.9",
|
||||
"@types/node": "^20.6.3",
|
||||
"@vue/eslint-config-prettier": "^8.0.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "@tsconfig/node18/tsconfig.json",
|
||||
"extends": "@tsconfig/node20/tsconfig.json",
|
||||
"include": [
|
||||
"vite.config.*",
|
||||
"vitest.config.*",
|
||||
|
||||
@@ -15,13 +15,23 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@sammo/api_def": "workspace:^",
|
||||
"@sammo/crypto": "workspace:^",
|
||||
"@sammo/server_util": "workspace:^",
|
||||
"@sammo/util": "workspace:^",
|
||||
"@strpc/express": "workspace:^",
|
||||
"date-fns": "^2.30.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"mongoose": "^7.4.3"
|
||||
"express": "^4.18.2",
|
||||
"express-session": "^1.17.3",
|
||||
"lodash-es": "^4.17.21",
|
||||
"mongoose": "^7.4.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"tslib": "^2.6.2",
|
||||
"zod": "^3.22.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/express-session": "^1.17.7",
|
||||
"@types/node": "^20.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ export const LoginByID = POST<BaseAPI>(LoginByIDReq)(declProcDecorators(
|
||||
userID,
|
||||
userName,
|
||||
userLevel,
|
||||
allowServerAction: new Set(),
|
||||
allowServerAction: new Map(),
|
||||
allowGatewayAction: new Set(),
|
||||
loginDate: new Date(),
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ import { StartSession } from "@sammo/server_util";
|
||||
import { POST, type APIReturnType } from "@strpc/express";
|
||||
import { declProcDecorators } from "@strpc/express/proc_decorator";
|
||||
import { z } from "zod";
|
||||
import { loginCtxSessionKey, type GatewayLoginCtx } from "../../procDecorator/ReqGatewayLogin.js";
|
||||
import { loginCtxSessionKey, type GatewayLoginCtx } from "@/procDecorator/ReqGatewayLogin.js";
|
||||
import { delay } from "@sammo/util";
|
||||
|
||||
type BaseAPI = typeof structure.Login.LoginByToken;
|
||||
type RType = APIReturnType<BaseAPI>;
|
||||
@@ -16,7 +17,7 @@ const LoginByTokenReq = z.object({
|
||||
export const LoginByToken = POST<BaseAPI>(LoginByTokenReq)(declProcDecorators(
|
||||
StartSession,
|
||||
))
|
||||
(async (query, ctx) => {
|
||||
(async (query, ctx): RType => {
|
||||
query.hashedToken;
|
||||
ctx.session.clear();
|
||||
|
||||
@@ -33,6 +34,7 @@ export const LoginByToken = POST<BaseAPI>(LoginByTokenReq)(declProcDecorators(
|
||||
userName,
|
||||
userLevel,
|
||||
allowServerAction: new Map(),
|
||||
allowGatewayAction: new Set(),
|
||||
loginDate: new Date(),
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,9 @@ import type { APINamespaceType } from "@strpc/express";
|
||||
import { LoginByID } from "./LoginByID.js";
|
||||
import { LoginByToken } from "./LoginByToken.js";
|
||||
import { ReqNonce } from "./ReqNonce.js";
|
||||
import { test } from "./test.js";
|
||||
|
||||
export const Login = {
|
||||
LoginByID,
|
||||
LoginByToken,
|
||||
ReqNonce,
|
||||
test,
|
||||
} satisfies APINamespaceType<typeof structure.Login>;
|
||||
@@ -31,7 +31,7 @@ function generateConfig() {
|
||||
return {
|
||||
port: parseInt(process.env['SERVER_PORT'] ?? "3001"),
|
||||
sessionSecret: unwrap(process.env['SESSION_SECRET']),
|
||||
apiRootPath: process.env['API_ROOT_PATH'] ?? '/api/gateway',
|
||||
apiRootPath: process.env['API_ROOT_PATH'] ?? '/api',
|
||||
} as const;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ export type {
|
||||
ServerActionType,
|
||||
UserIDType,
|
||||
IUser,
|
||||
} from "./schema/User.ts";
|
||||
} from "./schema/User.js";
|
||||
|
||||
export type {
|
||||
ILoginToken
|
||||
} from "./schema/LoginToken.ts";
|
||||
} from "./schema/LoginToken.js";
|
||||
@@ -1,7 +0,0 @@
|
||||
import 'dotenv/config';
|
||||
import { unwrap } from "@sammo/util";
|
||||
|
||||
export const gatewayConfig = {
|
||||
sessionSecret: unwrap(process.env.GATEWAY_SESSION_SECRET),
|
||||
port: Number(unwrap(process.env.GATEWAY_PORT)),
|
||||
};
|
||||
@@ -1,15 +1,15 @@
|
||||
import './dotenv.js'
|
||||
import { ownConfig } from './dotenv.js';
|
||||
import 'reflect-metadata';
|
||||
import gatewayDB from './connectDB.js';
|
||||
import express, { type Request, type Response } from "express"
|
||||
import session from "express-session";
|
||||
import { buildAPISystem } from '@strpc/express/generator';
|
||||
//import { sammoGatewayAPI } from './api/index.js';
|
||||
import { unwrap } from '@sammo/util';;
|
||||
import { gatewayConfig } from './gatewayConfig.js';
|
||||
|
||||
import { sammoGatewayAPI } from './api/index.js';
|
||||
import { unwrap } from '@sammo/util';
|
||||
|
||||
|
||||
const gatewayConfig = ownConfig();
|
||||
|
||||
gatewayDB.then(async (gatewayDB) => {
|
||||
// create express app
|
||||
@@ -22,7 +22,7 @@ gatewayDB.then(async (gatewayDB) => {
|
||||
}))
|
||||
//app.set('etag', false);
|
||||
|
||||
//app.use('/gateway_api', buildAPISystem(sammoGatewayAPI));
|
||||
app.use('/gateway_api', buildAPISystem(sammoGatewayAPI));
|
||||
|
||||
// start express server
|
||||
app.listen(gatewayConfig.port)
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../../@strpc/express"
|
||||
},
|
||||
{
|
||||
"path": "../api_def"
|
||||
},
|
||||
{
|
||||
"path": "../util"
|
||||
},
|
||||
|
||||
@@ -29,7 +29,9 @@
|
||||
"zod": "^3.22.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sammo/gateway": "workspace:^",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/express-session": "^1.17.7",
|
||||
"@sammo/gateway_server": "workspace:^",
|
||||
"@types/node": "^20.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { StateIncrementer } from '@sammo/server_util';
|
||||
import SchemaSequence from './schema/SchemaSequence.js';
|
||||
import { InvalidArgument } from '@sammo/util';
|
||||
|
||||
export function MongoSequenceFactory(collectionName: string): StateIncrementer{
|
||||
|
||||
return async (increase: number) => {
|
||||
if(increase <= 0){
|
||||
throw new InvalidArgument('increase must be > 0');
|
||||
}
|
||||
increase = Math.ceil(increase);
|
||||
|
||||
const result = await SchemaSequence.findOneAndUpdate({
|
||||
collectionName,
|
||||
}, {
|
||||
$inc: {
|
||||
nextSeq: increase,
|
||||
},
|
||||
}, {
|
||||
upsert: true,
|
||||
new: true,
|
||||
});
|
||||
return result.nextSeq;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dotenv/config';
|
||||
import { connect, Mongoose } from "mongoose";
|
||||
import { unwrap } from './util/unwrap.js';
|
||||
import { unwrap } from '@sammo/util';
|
||||
|
||||
const dbConfig = {
|
||||
host: unwrap(process.env.GAME_DB_HOST),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import { resolve } from "node:path";
|
||||
|
||||
export const rootPath = resolve(resolve(), '../..');
|
||||
@@ -0,0 +1,49 @@
|
||||
import dotenv from 'dotenv';
|
||||
import { rootPath } from './constPath.js';
|
||||
import { unwrap } from '@sammo/util';
|
||||
|
||||
let init = false;
|
||||
const dirPath = rootPath
|
||||
console.log(rootPath);
|
||||
|
||||
function initDotEnv() {
|
||||
if (process.env['NODE_ENV'] == 'production') {
|
||||
dotenv.config({ path: `${dirPath}/.env.production.local` });
|
||||
dotenv.config({ path: `${dirPath}/.env.local` });
|
||||
dotenv.config({ path: `${dirPath}/.env.production` });
|
||||
}
|
||||
else {
|
||||
dotenv.config({ path: `${dirPath}/.env.development.local` });
|
||||
dotenv.config({ path: `${dirPath}/.env.local` });
|
||||
dotenv.config({ path: `${dirPath}/.env.development` });
|
||||
}
|
||||
dotenv.config();
|
||||
init = true;
|
||||
}
|
||||
|
||||
if (!init) {
|
||||
initDotEnv();
|
||||
}
|
||||
|
||||
let _ownConfig: ReturnType<typeof generateConfig>|undefined = undefined;
|
||||
|
||||
function generateConfig() {
|
||||
return {
|
||||
port: parseInt(process.env['SERVER_PORT'] ?? "3001"),
|
||||
sessionSecret: unwrap(process.env['SESSION_SECRET']),
|
||||
gatewayHost: unwrap(process.env.GATEWAY_HOST),
|
||||
gatewayPort: Number(unwrap(process.env.GATEWAY_PORT)),
|
||||
apiRootPath: process.env['API_ROOT_PATH'] ?? '/api',
|
||||
} as const;
|
||||
}
|
||||
|
||||
export function serverConfig() {
|
||||
if(_ownConfig !== undefined){
|
||||
return _ownConfig;
|
||||
}
|
||||
if(!init){
|
||||
initDotEnv();
|
||||
}
|
||||
_ownConfig = generateConfig();
|
||||
return _ownConfig;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { SessionCtx } from "@sammo/server_util";
|
||||
import type { LoginCtx } from "./ReqLogin.js";
|
||||
import type { SessionCtx } from "./StartSession.js";
|
||||
import type { ProcDecoratorGenerator } from "./base.js";
|
||||
import type { ProcDecoratorGenerator } from "@strpc/express/proc_decorator";
|
||||
|
||||
export type GameLoginCtx = {
|
||||
generalID: number;
|
||||
@@ -12,11 +12,11 @@ export function ReqGameLogin<Q extends LoginCtx & SessionCtx>(): ProcDecoratorGe
|
||||
return async (ctx) => {
|
||||
//NOTE: 게임 서버별로 gameLoginCtx를 따로 가져야 하는가?
|
||||
let gameLoginCtx = ctx.session.getItem<GameLoginCtx>(`gameLoginCtx`);
|
||||
if(gameLoginCtx){
|
||||
if(gameLoginCtx.gameLoginDate >= ctx.loginDate){
|
||||
if (gameLoginCtx) {
|
||||
if (gameLoginCtx.gameLoginDate >= ctx.loginDate) {
|
||||
return [{
|
||||
result: true,
|
||||
},{
|
||||
}, {
|
||||
...gameLoginCtx,
|
||||
...ctx,
|
||||
}];
|
||||
@@ -25,11 +25,12 @@ export function ReqGameLogin<Q extends LoginCtx & SessionCtx>(): ProcDecoratorGe
|
||||
}
|
||||
|
||||
//TODO: DB에서 generalID를 가져오는 로직
|
||||
|
||||
return [{
|
||||
result: false,
|
||||
type: 'Required GameLogin',
|
||||
info: 'NotYetImplemented'
|
||||
}, ctx];
|
||||
}, {
|
||||
...ctx
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ServerActionType } from "../schema/gateway/User.js";
|
||||
import type { SessionCtx } from "./StartSession.js";
|
||||
import type { ProcDecorator } from "./base.js";
|
||||
import type { SessionCtx } from "@sammo/server_util";
|
||||
import type { ProcDecorator } from "@strpc/express/proc_decorator";
|
||||
import type { ServerActionType } from "@sammo/gateway_server/exports"
|
||||
|
||||
export type LoginCtx = {
|
||||
userID: number;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Schema, model, Types } from 'mongoose';
|
||||
|
||||
interface ISchemaSequence {
|
||||
_id: Types.ObjectId;
|
||||
|
||||
collectionName: string;
|
||||
nextSeq: number;
|
||||
}
|
||||
|
||||
export const SchemaSequence = new Schema<ISchemaSequence>({
|
||||
collectionName: { type: String, required: true },
|
||||
nextSeq: {
|
||||
type: Number, required: true,
|
||||
get: (v: number) => Math.ceil(v),
|
||||
set: (v: number) => Math.ceil(v),
|
||||
default: 0,
|
||||
},
|
||||
|
||||
}, { autoIndex: true, autoCreate: true })
|
||||
.index({ collectionName: 1 }, { unique: true })
|
||||
;
|
||||
|
||||
export default model<ISchemaSequence>('SchemaSequence', SchemaSequence);
|
||||
@@ -3,6 +3,9 @@
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
@@ -17,5 +20,11 @@
|
||||
{
|
||||
"path": "../server_util"
|
||||
},
|
||||
{
|
||||
"path": "../api_def"
|
||||
},
|
||||
{
|
||||
"path": "../gateway_server"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"@strpc/express": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express-session": "^1.17.7",
|
||||
"lodash-es": "^4.17.21"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Empty, ProcDecoratorGenerator } from "@strpc/express/proc_decorator";
|
||||
import { type Session, type SessionData } from "express-session";
|
||||
import type { Session, SessionData } from "express-session";
|
||||
|
||||
export type SessionCtx = {
|
||||
session: {
|
||||
|
||||
Reference in New Issue
Block a user