[mod] Room
This commit is contained in:
parent
2568a95cc4
commit
8a3e93e5d8
@ -6,7 +6,7 @@ export default async function (call: ApiCall<ReqLobbyList, ResLobbyList>) {
|
|||||||
const data: any[] = []
|
const data: any[] = []
|
||||||
for (let i = 0; i < Lobby.Room.length; i++) {
|
for (let i = 0; i < Lobby.Room.length; i++) {
|
||||||
const room = Lobby.Room[i]
|
const room = Lobby.Room[i]
|
||||||
data.push(room.SerialNumber)
|
data.push(room.RoomId)
|
||||||
}
|
}
|
||||||
call.succ(data)
|
call.succ(data)
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import Client from "../Client/Client"
|
import { BaseConnection } from "tsrpc";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Room
|
* Room
|
||||||
@ -7,13 +8,19 @@ export default class Room {
|
|||||||
|
|
||||||
//#region public
|
//#region public
|
||||||
|
|
||||||
public SerialNumber: number = 0
|
static maxRoomId: number = 0;
|
||||||
|
static rooms: { [roomId: number]: Room } = {};
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region public
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region private
|
//#region private
|
||||||
|
|
||||||
private wsArr: Client[] = []
|
private roomId: number = 0
|
||||||
|
private conns: BaseConnection[] = [];
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@ -22,9 +29,9 @@ export default class Room {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
constructor(serialNumber: number, ws: Client) {
|
constructor() {
|
||||||
this.SerialNumber = serialNumber
|
// 给每个新房间生成一个唯一的 ID
|
||||||
this.wsArr.push(ws)
|
this.roomId = ++Room.maxRoomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -32,11 +39,8 @@ export default class Room {
|
|||||||
//#region Custom
|
//#region Custom
|
||||||
|
|
||||||
/** Join */
|
/** Join */
|
||||||
public Join(ws: Client): void {
|
public Join(conn: BaseConnection): void {
|
||||||
this.wsArr.forEach(otherWS => {
|
this.conns.push(conn);
|
||||||
// otherWS.SendClient()
|
|
||||||
})
|
|
||||||
this.wsArr.push(ws)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user