[add] Lobby Create
This commit is contained in:
parent
81ca68d81f
commit
f7559a5f27
@ -81,9 +81,9 @@ export default class Client {
|
|||||||
if (true) {
|
if (true) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (req.Data != null && req.Data != undefined && req.Data != NaN) {
|
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 {
|
} else {
|
||||||
console.log(`[RPC] 傳送client資料:(${req.WS.clientCount}): ${req.Method}()`)
|
console.log(`[RPC] 傳送client資料:(${this.clientCount}): ${req.Method}()`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,10 @@ export default class MainControlData {
|
|||||||
if (req.IsValid) {
|
if (req.IsValid) {
|
||||||
switch (req.Method) {
|
switch (req.Method) {
|
||||||
case "lobby.list":
|
case "lobby.list":
|
||||||
Lobby.GetList(req);
|
Lobby.List(req);
|
||||||
// GiftData.Instance?.AddCommonList(resp.Data)
|
break
|
||||||
|
case "lobby.create":
|
||||||
|
Lobby.Create(req);
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
// if (GameMain.Instance && GameMain.Instance.node && GameMain.Instance.node.parent) {
|
// if (GameMain.Instance && GameMain.Instance.node && GameMain.Instance.node.parent) {
|
||||||
|
@ -2,7 +2,7 @@ import Client from "../../../../Client/Client"
|
|||||||
|
|
||||||
export interface INetResponse<TResponse> {
|
export interface INetResponse<TResponse> {
|
||||||
readonly Method: string
|
readonly Method: string
|
||||||
readonly WS: Client
|
readonly WS?: Client
|
||||||
readonly Status: number
|
readonly Status: number
|
||||||
readonly Data: TResponse
|
readonly Data: TResponse
|
||||||
readonly IsValid?: boolean
|
readonly IsValid?: boolean
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import Client from "../../../Client/Client"
|
|
||||||
import { INetResponse } from "./Core/INetResponse"
|
import { INetResponse } from "./Core/INetResponse"
|
||||||
|
|
||||||
export abstract class NetResponse implements INetResponse<any> {
|
export abstract class NetResponse implements INetResponse<any> {
|
||||||
protected data: any = undefined
|
protected data: any = undefined
|
||||||
protected method: string = ""
|
protected method: string = ""
|
||||||
protected ws: Client = undefined
|
|
||||||
protected status: number = undefined
|
protected status: number = undefined
|
||||||
|
|
||||||
get Method(): string {
|
get Method(): string {
|
||||||
return this.method
|
return this.method
|
||||||
}
|
}
|
||||||
get WS(): Client {
|
|
||||||
return this.ws
|
|
||||||
}
|
|
||||||
get Status(): number {
|
get Status(): number {
|
||||||
return this.status
|
return this.status
|
||||||
}
|
}
|
||||||
@ -20,9 +15,8 @@ export abstract class NetResponse implements INetResponse<any> {
|
|||||||
return this.data
|
return this.data
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(ws: Client, data: any, status: number = 0) {
|
constructor(data: any = undefined, status: number = 0) {
|
||||||
this.ws = ws
|
this.data = data ?? ""
|
||||||
this.data = data
|
|
||||||
this.status = status
|
this.status = status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 { INetResponse } from "../Engine/CatanEngine/NetManagerV2/Core/INetResponse";
|
||||||
import Room from "../Room/Room";
|
import Room from "../Room/Room";
|
||||||
|
|
||||||
@ -10,22 +10,30 @@ export default class Lobby {
|
|||||||
//#region private
|
//#region private
|
||||||
|
|
||||||
private static list: Room[] = []
|
private static list: Room[] = []
|
||||||
|
private static serialNumber: number = 0
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Custom
|
//#region Custom
|
||||||
|
|
||||||
/** GetList */
|
/** GetList */
|
||||||
public static GetList(req: INetResponse<any>): void {
|
public static List(req: INetResponse<any>): void {
|
||||||
let resp: LobbyListRequest = new LobbyListRequest(req.WS, this.list, 0)
|
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)
|
req.WS.SendClient(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create */
|
/** Create */
|
||||||
public static Create(req: INetResponse<any>): void {
|
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)
|
this.list.push(room)
|
||||||
//
|
const resp: LobbyCreateRequest = new LobbyCreateRequest()
|
||||||
|
req.WS.SendClient(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Join */
|
/** Join */
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
import BaseSingleton from "../Engine/Utils/Singleton/BaseSingleton"
|
import Client from "../Client/Client"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Room
|
* Room
|
||||||
*/
|
*/
|
||||||
export default class Room extends BaseSingleton<Room>() {
|
export default class Room {
|
||||||
|
|
||||||
|
//#region public
|
||||||
|
|
||||||
|
public SerialNumber: number = 0
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
//#region private
|
//#region private
|
||||||
|
|
||||||
|
private wsArr: Client[] = []
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@ -15,9 +22,9 @@ export default class Room extends BaseSingleton<Room>() {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor(serialNumber: number, ws: Client) {
|
||||||
super()
|
this.SerialNumber = serialNumber
|
||||||
|
this.wsArr.push(ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
import { NetResponse } from "../../Engine/CatanEngine/NetManagerV2/NetResponse"
|
import { NetResponse } from "../../Engine/CatanEngine/NetManagerV2/NetResponse"
|
||||||
import Room from "../../Room/Room"
|
|
||||||
|
|
||||||
// #region Request
|
// #region Request
|
||||||
|
|
||||||
export type RpcLobbyListRequest = Room[]
|
export type RpcLobbyListRequest = any[]
|
||||||
|
|
||||||
export class LobbyListRequest extends NetResponse {
|
export class LobbyListRequest extends NetResponse {
|
||||||
protected data: RpcLobbyListRequest = undefined
|
protected data: RpcLobbyListRequest
|
||||||
protected method: string = "lobby.list"
|
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
|
// #endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user