Skip to content

Commit 5e4acb1

Browse files
author
Ochii
committed
Allow users to toggle ready status during the countdown, update room status when game starts and ends, don't send game results window to users waiting in lobby. Fixes #32 and #46
1 parent eaceeb3 commit 5e4acb1

File tree

7 files changed

+91
-37
lines changed

7 files changed

+91
-37
lines changed

src/channel/channelmanager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,6 @@ export class ChannelManager {
328328
return false
329329
}
330330

331-
if (currentRoom.isGlobalCountdownInProgress()) {
332-
console.warn('user "%s" tried toggle ready status, although it isn\'t in any', user.userName)
333-
return false
334-
}
335-
336331
const readyStatus: RoomReadyStatus = currentRoom.toggleUserReadyStatus(user)
337332

338333
if (readyStatus == null) {
@@ -394,9 +389,12 @@ export class ChannelManager {
394389

395390
room.stopCountdown()
396391
room.setStatus(RoomStatus.Ingame)
392+
room.setUserIngame(host, true)
397393

398394
room.recurseNonHostUsers((u: User): void => {
395+
room.sendRoomStatusTo(u)
399396
if (room.isUserReady(u) === true) {
397+
room.setUserIngame(u, true)
400398
room.sendConnectHostTo(u, host)
401399
room.sendGuestDataTo(host, u)
402400
}
@@ -412,6 +410,8 @@ export class ChannelManager {
412410
private handleUserGameStart(user: User, room: Room): void {
413411
const host: User = room.host
414412

413+
room.sendRoomStatusTo(user)
414+
room.setUserIngame(user, true)
415415
room.sendConnectHostTo(user, host)
416416
room.sendGuestDataTo(host, user)
417417

src/packets/in/room/updatesettings.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Uint64LE } from 'int64-buffer'
22

33
import { InPacketBase } from 'packets/in/packet'
44

5+
import { RoomStatus } from 'room/room'
6+
57
/**
68
* a host's request to change a room's settings
79
* @class InRoomUpdateSettings
@@ -48,7 +50,7 @@ export class InRoomUpdateSettings {
4850
public weaponRestrictions: number
4951
// end of flags & 0x2000
5052
// flags & 0x4000
51-
public unk20: number
53+
public status: RoomStatus
5254
// end of flags & 0x4000
5355
// flags & 0x8000
5456
public unk21: number
@@ -103,7 +105,7 @@ export class InRoomUpdateSettings {
103105
public unk39: number
104106
// end of flags & 0x20000000
105107
// flags & 0x40000000
106-
public unk40: number
108+
public isIngame: boolean
107109
// end of flags & 0x40000000
108110
// flags & 0x80000000
109111
public startMoney: number
@@ -185,7 +187,7 @@ export class InRoomUpdateSettings {
185187
this.weaponRestrictions = inPacket.readUInt8()
186188
}
187189
if (lowFlag & 0x4000) {
188-
this.unk20 = inPacket.readUInt8()
190+
this.status = inPacket.readUInt8()
189191
}
190192
if (lowFlag & 0x8000) {
191193
this.unk21 = inPacket.readUInt8()
@@ -252,7 +254,7 @@ export class InRoomUpdateSettings {
252254
}
253255

254256
if (lowFlag & 0x40000000) {
255-
this.unk40 = inPacket.readUInt8()
257+
this.isIngame = inPacket.readUInt8() as unknown as boolean
256258
}
257259

258260
if (lowFlag & 0x80000000) {

src/packets/out/room/updatesettings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class OutRoomUpdateSettings {
7676
outPacket.writeUInt8(this.settings.weaponRestrictions)
7777
}
7878
if (lowFlag & 0x4000) {
79-
outPacket.writeUInt8(this.settings.unk20)
79+
outPacket.writeUInt8(this.settings.status)
8080
}
8181
if (lowFlag & 0x8000) {
8282
outPacket.writeUInt8(this.settings.unk21)
@@ -143,7 +143,7 @@ export class OutRoomUpdateSettings {
143143
}
144144

145145
if (lowFlag & 0x40000000) {
146-
outPacket.writeUInt8(this.settings.unk40)
146+
outPacket.writeUInt8(this.settings.isIngame as unknown as number)
147147
}
148148

149149
if (lowFlag & 0x80000000) {
@@ -219,7 +219,7 @@ export class OutRoomUpdateSettings {
219219
if (this.settings.weaponRestrictions != null) {
220220
lowFlag |= 0x2000
221221
}
222-
if (this.settings.unk20 != null) {
222+
if (this.settings.status != null) {
223223
lowFlag |= 0x4000
224224
}
225225
if (this.settings.unk21 != null
@@ -276,7 +276,7 @@ export class OutRoomUpdateSettings {
276276
lowFlag |= 0x20000000
277277
}
278278

279-
if (this.settings.unk40 != null) {
279+
if (this.settings.isIngame != null) {
280280
lowFlag |= 0x40000000
281281
}
282282

src/room/room.ts

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ export class Room {
136136
private emptyRoomCallback: (emptyRoom: Room, channel: Channel) => void
137137
private parentChannel: Channel
138138

139-
private status: RoomStatus
140-
141139
private countingDown: boolean
142140
private countdown: number
143141

@@ -154,8 +152,6 @@ export class Room {
154152

155153
this.settings = new RoomSettings(options)
156154

157-
this.status = RoomStatus.Waiting
158-
159155
this.countingDown = false
160156
this.countdown = defaultCountdownNum
161157

@@ -375,6 +371,26 @@ export class Room {
375371
return userInfo.ready === RoomReadyStatus.Yes
376372
}
377373

374+
/**
375+
* is the user ingame?
376+
* @param user the target user
377+
*/
378+
public isUserIngame(user: User): boolean {
379+
if (this.hasUser(user) === false) {
380+
console.warn('isUserIngame: user "%s" not found!', user.userName)
381+
return false
382+
}
383+
384+
const userInfo: RoomUser = this.usersInfo.get(user)
385+
386+
if (userInfo == null) {
387+
console.warn('isUserIngame: couldnt get "%s"\'s userinfo', user.userName)
388+
return false
389+
}
390+
391+
return userInfo.isIngame
392+
}
393+
378394
/**
379395
* checks if the room's users are ready
380396
* @returns true if everyone is ready, false if not
@@ -409,6 +425,27 @@ export class Room {
409425
userInfo.team = newTeam
410426
}
411427

428+
/**
429+
* set's an user's ingame status
430+
* @param user the target user
431+
* @param ingame the new ingame status
432+
*/
433+
public setUserIngame(user: User, ingame: boolean): void {
434+
if (this.hasUser(user) === false) {
435+
console.warn('setUserIngame: user "%s" not found!', user.userName)
436+
return
437+
}
438+
439+
const userInfo: RoomUser = this.usersInfo.get(user)
440+
441+
if (userInfo == null) {
442+
console.warn('setUserIngame: couldnt get "%s"\'s userinfo', user.userName)
443+
return null
444+
}
445+
446+
userInfo.isIngame = ingame
447+
}
448+
412449
/**
413450
* toggles the user's room ready status
414451
* @param user the user's object
@@ -465,23 +502,16 @@ export class Room {
465502
* @returns the room's status
466503
*/
467504
public getStatus(): RoomStatus {
468-
return this.status
505+
return this.settings.status
469506
}
470507

471508
/**
472509
* set a room's status
473510
* @param newStatus the new room's status
474511
*/
475512
public setStatus(newStatus: RoomStatus): void {
476-
this.status = newStatus
477-
}
478-
479-
/**
480-
* is the countdown request user a host and can it start a global countdown?
481-
* @param user the user that requested the countdown
482-
*/
483-
public canCountdown(user: User): boolean {
484-
return user === this.host && this.status === RoomStatus.Waiting
513+
this.settings.status = newStatus
514+
this.settings.isIngame = newStatus === RoomStatus.Ingame
485515
}
486516

487517
/**
@@ -743,9 +773,9 @@ export class Room {
743773
this.settings.unk18 = newSettings.unk18
744774
updatedSet.unk18 = newSettings.unk18
745775
}
746-
if (newSettings.unk20 != null) {
747-
this.settings.unk20 = newSettings.unk20
748-
updatedSet.unk20 = newSettings.unk20
776+
if (newSettings.status != null) {
777+
this.settings.status = newSettings.status
778+
updatedSet.status = newSettings.status
749779
}
750780
if (newSettings.unk21 != null) {
751781
this.settings.unk21 = newSettings.unk21
@@ -803,9 +833,9 @@ export class Room {
803833
this.settings.unk39 = newSettings.unk39
804834
updatedSet.unk39 = newSettings.unk39
805835
}
806-
if (newSettings.unk40 != null) {
807-
this.settings.unk40 = newSettings.unk40
808-
updatedSet.unk40 = newSettings.unk40
836+
if (newSettings.isIngame != null) {
837+
this.settings.isIngame = newSettings.isIngame
838+
updatedSet.isIngame = newSettings.isIngame
809839
}
810840
if (newSettings.unk43 != null) {
811841
this.settings.unk43 = newSettings.unk43
@@ -961,6 +991,20 @@ export class Room {
961991
user.socket.send(resultReply)
962992
}
963993

994+
/**
995+
* send an user its current room's status
996+
* @param user the target user
997+
*/
998+
public sendRoomStatusTo(user: User): void {
999+
const settings: RoomSettings = new RoomSettings()
1000+
settings.status = this.settings.status
1001+
settings.isIngame = this.settings.isIngame
1002+
1003+
const statusReply: Buffer =
1004+
new OutRoomPacket(user.socket).updateSettings(settings)
1005+
user.socket.send(statusReply)
1006+
}
1007+
9641008
/**
9651009
* handle max players setting's update event
9661010
* @param newMaxPlayers the requested new max players number

src/room/roomsettings.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IRoomOptions, RoomGamemode, RoomTeamBalance } from 'room/room'
1+
import { IRoomOptions, RoomGamemode, RoomStatus, RoomTeamBalance } from 'room/room'
22

33
export class RoomSettings {
44
public roomName: string
@@ -16,13 +16,15 @@ export class RoomSettings {
1616
public respawnTime: number
1717
public teamBalanceType: RoomTeamBalance
1818
public weaponRestrictions: number
19+
public status: RoomStatus
1920
public hltvEnabled: number
2021
public mapCycleType: number
2122
public multiMaps: number[]
2223
public areBotsEnabled: boolean
2324
public botDifficulty: number
2425
public numCtBots: number
2526
public numTrBots: number
27+
public isIngame: boolean
2628

2729
public unk00: number
2830
public unk01: number
@@ -33,7 +35,6 @@ export class RoomSettings {
3335
public unk13: number
3436
public unk17: number
3537
public unk18: number
36-
public unk20: number
3738
public unk21: number
3839
public unk23: number
3940
public unk24: number
@@ -48,7 +49,6 @@ export class RoomSettings {
4849
public unk37: number
4950
public unk38: number
5051
public unk39: number
51-
public unk40: number
5252
public unk43: number
5353
public unk45: number
5454

@@ -72,12 +72,14 @@ export class RoomSettings {
7272
this.respawnTime = options.respawnTime ? options.respawnTime : 3
7373
this.teamBalanceType = options.teamBalance ? options.teamBalance : 0
7474
this.weaponRestrictions = options.weaponRestrictions ? options.weaponRestrictions : 0
75+
this.status = RoomStatus.Waiting
7576
this.hltvEnabled = options.hltvEnabled ? options.hltvEnabled : 0
7677
this.mapCycleType = 1
7778
this.multiMaps = []
7879
this.areBotsEnabled = false
7980
this.numCtBots = 0
8081
this.numTrBots = 0
8182
this.botDifficulty = 0
83+
this.isIngame = false
8284
}
8385
}

src/room/roomuser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { RoomReadyStatus, RoomTeamNum } from 'room/room'
77
export class RoomUser {
88
public team: RoomTeamNum
99
public ready: RoomReadyStatus
10+
public isIngame: boolean
1011

1112
constructor(team: RoomTeamNum, ready: RoomReadyStatus) {
1213
this.team = team
1314
this.ready = ready
15+
this.isIngame = false
1416
}
1517
}

src/user/usermanager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ export class UserManager {
121121
currentRoom.resetIngameUsersReadyStatus()
122122

123123
currentRoom.recurseUsers((u: User): void => {
124+
currentRoom.sendRoomStatusTo(u)
124125
currentRoom.sendRoomUsersReadyStatusTo(u)
125-
currentRoom.sendGameEnd(u)
126+
if (currentRoom.isUserIngame(u) === true) {
127+
currentRoom.sendGameEnd(u)
128+
currentRoom.setUserIngame(u, false)
129+
}
126130
})
127131

128132
return true

0 commit comments

Comments
 (0)