monorepo 버전 준비

## @strpc
기존 RPC를 package화

### @strpc/express
express의 middleware + router 결함

## @sammo
게임 전체
- server, client
- gateway_server, gateway_client
This commit is contained in:
2023-09-23 16:29:18 +00:00
parent 734e0cb7bf
commit e59f9a9659
197 changed files with 15458 additions and 3 deletions
@@ -0,0 +1,22 @@
import type { structure } from "@sammo/api_def/gateway";
import { StartSession } from "@sammo/server_util";
import { GET, type APIReturnType } from "@strpc/express";
import { declProcDecorators } from "@strpc/express/proc_decorator";
import { ReqGatewayLogin } from "../procDecorator/ReqGatewayLogin.js";
type BaseAPI = typeof structure.GetGameLoginToken;
type RType = APIReturnType<BaseAPI>;
export const GameLoginTokenSessionKey = "GameLoginToken";
export const GetGameLoginToken = GET<BaseAPI>()(declProcDecorators(
StartSession,
ReqGatewayLogin,
))(
async (query, ctx): RType => {
return {
result: false,
reason: 'NotYetImplemented',
};
}
);
@@ -0,0 +1,18 @@
import type { structure } from "@sammo/api_def/gateway";
import { StartSession } from "@sammo/server_util";
import { GET, type APIReturnType } from "@strpc/express";
import { declProcDecorators } from "@strpc/express/proc_decorator";
import { ReqGatewayLogin } from "../../procDecorator/ReqGatewayLogin.js";
type BaseAPI = typeof structure.Login.ReqNonce;
type RType = APIReturnType<BaseAPI>;
const argValidator = undefined;
export const ReqNonce = GET<BaseAPI>(argValidator)(declProcDecorators(
StartSession,
ReqGatewayLogin,
))(
(query, ctx): RType => {
throw new Error("Method not implemented.");
}
);
@@ -0,0 +1,62 @@
import type { structure } from "@sammo/api_def/gateway";
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 { delay } from "@sammo/util";
type BaseAPI = typeof structure.Login.LoginByID;
type RType = APIReturnType<BaseAPI>;
const LoginByIDReq = z.object({
id: z.string(),
password: z.string(),
});
export const LoginByID = POST<BaseAPI>(LoginByIDReq)(declProcDecorators(
StartSession,
))(
async (query, ctx, req, res): RType => {
const id = query.id;
const password = query.password;
//TODO: DB에서 뭔가 가져와야 함
await delay(1);
if (Math.random() < 0.3) {
return {
result: false,
reason: "로그인 실패",
reqOTP: false,
}
}
if (Math.random() < 0.5) {
return {
result: false,
reason: "OTP 인증 필요",
reqOTP: true,
}
}
const userID = 1;
const userName = "test";
const userLevel = 1;
const nextToken: [number, string] = [1, "1234567890"];
const loginCtx: GatewayLoginCtx = {
userID,
userName,
userLevel,
allowServerAction: new Map(),
allowGatewayAction: new Set(),
loginDate: new Date(),
}
ctx.session.setItem(loginCtxSessionKey, loginCtx);
return {
result: true,
nextToken,
}
});
@@ -0,0 +1,50 @@
import type { structure } from "@sammo/api_def/gateway";
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 { delay } from "@sammo/util";
type BaseAPI = typeof structure.Login.LoginByToken;
type RType = APIReturnType<BaseAPI>;
const LoginByTokenReq = z.object({
token_id: z.number(),
hashedToken: z.string(),
});
export const LoginByToken = POST<BaseAPI>(LoginByTokenReq)(declProcDecorators(
StartSession,
))
(async (query, ctx): RType => {
query.hashedToken;
ctx.session.clear();
await delay(1);
//무언가 로그인
//TODO: DB는 어디서 들고옴?
const userID = 1;
const userName = "test";
const userLevel = 1;
const nextToken: [number, string] = [1, "1234567890"];
const loginCtx: GatewayLoginCtx = {
userID,
userName,
userLevel,
allowServerAction: new Map(),
allowGatewayAction: new Set(),
loginDate: new Date(),
}
ctx.session.setItem(loginCtxSessionKey, loginCtx);
//throw new Error("Method not implemented.");
return {
result: true,
nextToken,
}
});
@@ -0,0 +1,30 @@
import type { structure } from "@sammo/api_def/gateway";
import { StartSession } from "@sammo/server_util";
import { GET, type APIReturnType } from "@strpc/express";
import { declProcDecorators } from "@strpc/express/proc_decorator";
type BaseAPI = typeof structure.Login.ReqNonce;
type RType = APIReturnType<BaseAPI>;
export const ReqNonceSessionKey = 'loginNonce';
export const ReqNonce = GET<BaseAPI>(undefined)(declProcDecorators(
StartSession,
))(
async (query, ctx): RType => {
const nonce = ctx.session.getItem<string>(ReqNonceSessionKey);
if (nonce !== undefined) {
return {
loginNonce: nonce,
result: true,
}
}
const newNonce = "1234567890";
ctx.session.setItem(ReqNonceSessionKey, newNonce);
return {
loginNonce: newNonce,
result: true,
}
}
)
@@ -0,0 +1,11 @@
import type { structure } from "@sammo/api_def/gateway";
import type { APINamespaceType } from "@strpc/express";
import { LoginByID } from "./LoginByID.js";
import { LoginByToken } from "./LoginByToken.js";
import { ReqNonce } from "./ReqNonce.js";
export const Login = {
LoginByID,
LoginByToken,
ReqNonce,
} satisfies APINamespaceType<typeof structure.Login>;
+9
View File
@@ -0,0 +1,9 @@
import type { structure } from "@sammo/api_def/gateway";
import { GetGameLoginToken } from "./GetGameLoginToken.js";
import { Login } from "./Login/index.js";
import type { APINamespaceType } from "@strpc/express";
export const sammoGatewayAPI = {
Login,
GetGameLoginToken
} satisfies APINamespaceType<typeof structure>;