[add] login
This commit is contained in:
parent
8a3e93e5d8
commit
6cc42d3c54
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -12,8 +12,8 @@
|
||||
"address": "127.0.0.1:9229/87f42d5b-97bf-4d25-a4d7-37306985459a",
|
||||
"port": 9229,
|
||||
"localRoot": "${workspaceFolder}",
|
||||
// "remoteRoot": "D:/Project/Test/Test_Web/GuessWhoIAmS",
|
||||
"remoteRoot": "E:/Project/Test/Test_NodeJS/GuessWhoIAmS",
|
||||
"remoteRoot": "D:/Project/Test/Test_Web/GuessWhoIAmS",
|
||||
// "remoteRoot": "E:/Project/Test/Test_NodeJS/GuessWhoIAmS",
|
||||
// "remoteRoot": "/volume1/homes/JianMiau/www/line-bot-ts",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
|
@ -10,9 +10,9 @@
|
||||
"build": "tsrpc-cli build",
|
||||
"doc": "tsrpc-cli doc",
|
||||
"test": "mocha test/**/*.test.ts",
|
||||
"api": "tsrpc-cli api && tsrpc-cli proto",
|
||||
"proto": "tsrpc-cli proto",
|
||||
"sync": "tsrpc-cli sync",
|
||||
"api": "tsrpc-cli api"
|
||||
"sync": "tsrpc-cli sync"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^8.2.3",
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { ApiCall, BaseConnection } from "tsrpc";
|
||||
import Lobby from "../component/Lobby/Lobby";
|
||||
import { ReqAccountLogin, ResAccountLogin } from "../shared/protocols/PtlAccountLogin";
|
||||
import { ReqLogin, ResLogin } from "../../shared/protocols/account/PtlLogin";
|
||||
|
||||
export default async function (call: ApiCall<ReqAccountLogin, ResAccountLogin>) {
|
||||
export default async function (call: ApiCall<ReqLogin, ResLogin>) {
|
||||
// Error
|
||||
if (!call.req.name) {
|
||||
call.error('Name is empty')
|
||||
@ -16,6 +15,5 @@ export default async function (call: ApiCall<ReqAccountLogin, ResAccountLogin>)
|
||||
console.log(`name: ${name} is Login`)
|
||||
conn.UserId = sn
|
||||
conn.NickName = name
|
||||
Lobby.AddConns(conn)
|
||||
call.succ(0)
|
||||
}
|
@ -9,7 +9,6 @@ export default class Lobby {
|
||||
//#region private
|
||||
|
||||
private static conns: BaseConnection[] = [];
|
||||
private static serialNumber: number = 0
|
||||
|
||||
//#endregion
|
||||
|
||||
@ -27,6 +26,16 @@ export default class Lobby {
|
||||
this.conns.push(conn)
|
||||
}
|
||||
|
||||
/** DelConns */
|
||||
public static DelConns(conn: BaseConnection): void {
|
||||
for (let i = 0; i < this.conns.length; i++) {
|
||||
if (this.conns[i] === conn) {
|
||||
this.conns.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /** List */
|
||||
// public static List(req: INetResponse<RpcLobbyListRequest>): void {
|
||||
// const data = []
|
||||
|
@ -15,11 +15,12 @@ export default class Room {
|
||||
|
||||
//#region public
|
||||
|
||||
public RoomId: number = 0
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region private
|
||||
|
||||
private roomId: number = 0
|
||||
private conns: BaseConnection[] = [];
|
||||
|
||||
//#endregion
|
||||
@ -31,7 +32,7 @@ export default class Room {
|
||||
*/
|
||||
constructor() {
|
||||
// 给每个新房间生成一个唯一的 ID
|
||||
this.roomId = ++Room.maxRoomId;
|
||||
this.RoomId = ++Room.maxRoomId;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
20
src/index.ts
20
src/index.ts
@ -2,13 +2,14 @@ import dayjs from "dayjs";
|
||||
import "dayjs/locale/zh-tw";
|
||||
import dotenv from "dotenv";
|
||||
import * as path from "path";
|
||||
import { WsServer } from "tsrpc";
|
||||
import { BaseConnection, WsServer } from "tsrpc";
|
||||
import Lobby from "./component/Lobby/Lobby";
|
||||
import User from "./component/User/User";
|
||||
import { BaseEnumerator } from "./Engine/CatanEngine/CoroutineV2/Core/BaseEnumerator";
|
||||
import "./Engine/CatanEngine/CSharp/String";
|
||||
import "./Engine/Utils/CCExtensions/ArrayExtension";
|
||||
import "./Engine/Utils/CCExtensions/NumberExtension";
|
||||
import { serviceProto } from './shared/protocols/serviceProto';
|
||||
import { serviceProto, ServiceType } from './shared/protocols/serviceProto';
|
||||
|
||||
BaseEnumerator.Init();
|
||||
dayjs.locale("zh-tw")
|
||||
@ -26,8 +27,21 @@ export const server = new WsServer(serviceProto, {
|
||||
async function init() {
|
||||
await server.autoImplementApi(path.resolve(__dirname, 'api'));
|
||||
|
||||
// TODO
|
||||
// Prepare something... (e.g. connect the db)
|
||||
// server.flows.postConnectFlow.push((conn) => {
|
||||
// Lobby.AddConns(conn);
|
||||
// });
|
||||
server.flows.postConnectFlow.push((conn: BaseConnection<ServiceType>) => {
|
||||
Lobby.AddConns(conn)
|
||||
console.log(`${conn.ip} is connected`)
|
||||
return conn;
|
||||
});
|
||||
server.flows.postDisconnectFlow.push((flow) => {
|
||||
const { conn, reason } = flow;
|
||||
Lobby.DelConns(conn)
|
||||
console.log(`${conn.ip} is disconnected`)
|
||||
return flow;
|
||||
});
|
||||
};
|
||||
|
||||
// Entry function
|
||||
|
@ -1,38 +1,38 @@
|
||||
import type { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
export default <TsrpcConfig>{
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api', // API dir
|
||||
docDir: 'docs', // API documents dir
|
||||
ptlTemplate: { baseFile: 'src/shared/protocols/base.ts' },
|
||||
// msgTemplate: { baseFile: 'src/shared/protocols/base.ts' },
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api', // API dir
|
||||
docDir: 'docs', // API documents dir
|
||||
ptlTemplate: { baseFile: 'src/shared/protocols/base.ts' },
|
||||
// msgTemplate: { baseFile: 'src/shared/protocols/base.ts' },
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../GuessWhoIAm/src/shared',
|
||||
type: 'copy' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user