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