[add] Lobby Create

This commit is contained in:
建喵 2023-08-29 17:57:36 +08:00
parent 81ca68d81f
commit f7559a5f27
7 changed files with 44 additions and 27 deletions

View File

@ -81,9 +81,9 @@ export default class Client {
if (true) {
//@ts-ignore
if (req.Data != null && req.Data != undefined && req.Data != NaN) {
console.log(`[RPC] 傳送client資料:(${req.WS.clientCount}): ${req.Method}(${JSON.stringify(req.Data)})`)
console.log(`[RPC] 傳送client資料:(${this.clientCount}): ${req.Method}(${JSON.stringify(req.Data)})`)
} else {
console.log(`[RPC] 傳送client資料:(${req.WS.clientCount}): ${req.Method}()`)
console.log(`[RPC] 傳送client資料:(${this.clientCount}): ${req.Method}()`)
}
}

View File

@ -12,8 +12,10 @@ export default class MainControlData {
if (req.IsValid) {
switch (req.Method) {
case "lobby.list":
Lobby.GetList(req);
// GiftData.Instance?.AddCommonList(resp.Data)
Lobby.List(req);
break
case "lobby.create":
Lobby.Create(req);
break
default:
// if (GameMain.Instance && GameMain.Instance.node && GameMain.Instance.node.parent) {

View File

@ -2,7 +2,7 @@ import Client from "../../../../Client/Client"
export interface INetResponse<TResponse> {
readonly Method: string
readonly WS: Client
readonly WS?: Client
readonly Status: number
readonly Data: TResponse
readonly IsValid?: boolean

View File

@ -1,18 +1,13 @@
import Client from "../../../Client/Client"
import { INetResponse } from "./Core/INetResponse"
export abstract class NetResponse implements INetResponse<any> {
protected data: any = undefined
protected method: string = ""
protected ws: Client = undefined
protected status: number = undefined
get Method(): string {
return this.method
}
get WS(): Client {
return this.ws
}
get Status(): number {
return this.status
}
@ -20,9 +15,8 @@ export abstract class NetResponse implements INetResponse<any> {
return this.data
}
constructor(ws: Client, data: any, status: number = 0) {
this.ws = ws
this.data = data
constructor(data: any = undefined, status: number = 0) {
this.data = data ?? ""
this.status = status
}
}

View File

@ -1,4 +1,4 @@
import { LobbyListRequest } from "../define/Request/LobbyRequest";
import { LobbyCreateRequest, LobbyListRequest } from "../define/Request/LobbyRequest";
import { INetResponse } from "../Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import Room from "../Room/Room";
@ -10,22 +10,30 @@ export default class Lobby {
//#region private
private static list: Room[] = []
private static serialNumber: number = 0
//#endregion
//#region Custom
/** GetList */
public static GetList(req: INetResponse<any>): void {
let resp: LobbyListRequest = new LobbyListRequest(req.WS, this.list, 0)
public static List(req: INetResponse<any>): void {
const data = []
for (let i = 0; i < this.list.length; i++) {
const room = this.list[i];
data.push(room.SerialNumber)
}
const resp: LobbyListRequest = new LobbyListRequest(data, 0)
req.WS.SendClient(resp)
}
/** Create */
public static Create(req: INetResponse<any>): void {
let room = new Room()
const room: Room = new Room(Lobby.serialNumber, req.WS)
Lobby.serialNumber++;
this.list.push(room)
//
const resp: LobbyCreateRequest = new LobbyCreateRequest()
req.WS.SendClient(resp)
}
/** Join */

View File

@ -1,12 +1,19 @@
import BaseSingleton from "../Engine/Utils/Singleton/BaseSingleton"
import Client from "../Client/Client"
/**
* Room
*/
export default class Room extends BaseSingleton<Room>() {
export default class Room {
//#region public
public SerialNumber: number = 0
//#endregion
//#region private
private wsArr: Client[] = []
//#endregion
@ -15,9 +22,9 @@ export default class Room extends BaseSingleton<Room>() {
/**
*
*/
constructor() {
super()
constructor(serialNumber: number, ws: Client) {
this.SerialNumber = serialNumber
this.wsArr.push(ws)
}
//#endregion

View File

@ -1,13 +1,19 @@
import { NetResponse } from "../../Engine/CatanEngine/NetManagerV2/NetResponse"
import Room from "../../Room/Room"
// #region Request
export type RpcLobbyListRequest = Room[]
export type RpcLobbyListRequest = any[]
export class LobbyListRequest extends NetResponse {
protected data: RpcLobbyListRequest = undefined
protected data: RpcLobbyListRequest
protected method: string = "lobby.list"
constructor(data: RpcLobbyListRequest = undefined, status: number = 0) { super(data, status) }
}
export type RpcLobbyCreateRequest = undefined
export class LobbyCreateRequest extends NetResponse {
protected data: RpcLobbyListRequest
protected method: string = "lobby.create"
constructor(data: RpcLobbyCreateRequest = undefined, status: number = 0) { super(data, status) }
}
// #endregion