diff --git a/.eslintignore b/.eslintignore index d813ca5..317aa18 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ src/utils -src/Engine \ No newline at end of file +src/Engine +src/shared/protocols/serviceProto.ts \ No newline at end of file diff --git a/src/api/room/ApiCreate.ts b/src/api/room/ApiCreate.ts index 202d7f5..1f6aa26 100644 --- a/src/api/room/ApiCreate.ts +++ b/src/api/room/ApiCreate.ts @@ -4,8 +4,9 @@ import { ReqCreate, ResCreate } from "../../shared/protocols/room/PtlCreate"; import { ServiceType } from "../../shared/protocols/serviceProto"; export default async function (call: ApiCall) { + const { type } = call.req; const conn: BaseConnection = call.conn; - const room: Room = new Room(); + const room: Room = new Room(type); room.Join(conn); conn.Room = room; call.succ(room.RoomId); diff --git a/src/api/room/ApiJoin.ts b/src/api/room/ApiJoin.ts index 20d2bc2..95e6750 100644 --- a/src/api/room/ApiJoin.ts +++ b/src/api/room/ApiJoin.ts @@ -1,5 +1,6 @@ import { ApiCall, BaseConnection } from "tsrpc"; import Room from "../../component/Room/Room"; +import { EGameType } from "../../shared/protocols/define/enum"; import { ReqJoin, ResJoin } from "../../shared/protocols/room/PtlJoin"; import { ServiceType } from "../../shared/protocols/serviceProto"; @@ -12,9 +13,9 @@ export default async function (call: ApiCall) { call.error("房間已滿"); return; } - room.Join(conn); + const type: EGameType = room.Join(conn); conn.Room = room; - call.succ(room.ConnCount()); + call.succ([room.ConnCount(), type]); if (room.ConnCount() >= 2) { room.GotoGame(); diff --git a/src/component/Room/Room.ts b/src/component/Room/Room.ts index e1852da..410993b 100644 --- a/src/component/Room/Room.ts +++ b/src/component/Room/Room.ts @@ -1,8 +1,9 @@ import { BaseConnection, WsConnection } from "tsrpc"; import { server } from "../.."; import { RandomEx } from "../../Engine/Utils/Number/RandomEx"; -import { EGameState } from "../../shared/protocols/define/enum"; +import { EGameState, EGameType } from "../../shared/protocols/define/enum"; import { MsgChangeState } from "../../shared/protocols/room/MsgChangeState"; +import { MsgGoToGame } from "../../shared/protocols/room/MsgGoToGame"; import { ServiceType } from "../../shared/protocols/serviceProto"; import { sleep } from "../../utils"; import { RoomConnData } from "./RoomUtils"; @@ -32,6 +33,8 @@ export default class Room { private connData: Map, RoomConnData> = new Map(); + private type: EGameType; + //#endregion //#region Lifecycle @@ -39,10 +42,11 @@ export default class Room { /** * */ - constructor() { + constructor(type: EGameType) { // 给每个新房间生成一个唯一的 ID this.RoomId = ++Room.maxRoomId; Room.rooms[this.RoomId] = this; + this.type = type; } //#endregion @@ -68,7 +72,8 @@ export default class Room { /** GotoGame */ public GotoGame(): void { - server.broadcastMsg("room/GoToGame", 0, []>this.conns); + let data: MsgGoToGame = this.type; + server.broadcastMsg("room/GoToGame", data, []>this.conns); } /** @@ -211,13 +216,14 @@ export default class Room { } /** Join */ - public Join(conn: BaseConnection): void { + public Join(conn: BaseConnection): EGameType { this.conns.push(conn); const data: RoomConnData = { state: undefined, answer: undefined, }; this.connData.set(conn, data); + return this.type; } /** GameOver */