Skip to content

Commit eaceeb3

Browse files
author
Ochii
committed
Reset users ready status when a room's match ends and send the new status to everyone in the room. Fixes #32
1 parent ecf89c6 commit eaceeb3

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cso2-master-server",
3-
"version": "0.8.7",
3+
"version": "0.8.8",
44
"repository": "github:Ochii/cso2-master-server",
55
"description": "A master server for Nexon's Counter-Strike: Online 2",
66
"author": "Luís Leite",

src/channel/channelmanager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class ChannelManager {
274274
// tell other room members about the new addition
275275
desiredRoom.recurseUsers((u: User): void => {
276276
if (u !== user) {
277-
desiredRoom.sendPlayerReadyStatusTo(user, u)
277+
desiredRoom.sendUserReadyStatusTo(user, u)
278278
desiredRoom.sendNewUserTo(u, user)
279279
}
280280
})

src/room/room.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,25 @@ export class Room {
441441
return newStatus
442442
}
443443

444+
/**
445+
* resets the ready status of ingame users
446+
* @returns true if reset successfully, false if not
447+
*/
448+
public resetIngameUsersReadyStatus(): boolean {
449+
for (const user of this.users) {
450+
const userInfo: RoomUser = this.usersInfo.get(user)
451+
452+
if (userInfo == null) {
453+
console.warn('resetIngameUsersReadyStatus: couldnt get userinfo')
454+
return false
455+
}
456+
457+
userInfo.ready = RoomReadyStatus.No
458+
}
459+
460+
return true
461+
}
462+
444463
/**
445464
* get's a room's status
446465
* @returns the room's status
@@ -814,24 +833,6 @@ export class Room {
814833
user.socket.send(reply)
815834
}
816835

817-
/**
818-
* send the room's data to the user that joined the room
819-
* @param user the player to send the other player's ready status
820-
* @param player the player whose ready status will be sent
821-
*/
822-
public sendPlayerReadyStatusTo(user: User, player: User): void {
823-
const status: RoomReadyStatus = this.getUserReadyStatus(player)
824-
825-
if (status == null) {
826-
console.warn('sendPlayerReadyStatusTo: couldnt get user "%s"\'s status (room "%s" room id %i)',
827-
user.userName, this.settings.roomName, this.id)
828-
return null
829-
}
830-
831-
const reply: Buffer = new OutRoomPacket(user.socket).setUserReadyStatus(player, status)
832-
user.socket.send(reply)
833-
}
834-
835836
/**
836837
* tell the user about a new user in the room
837838
* @param user the player to send the other player's ready status
@@ -851,7 +852,7 @@ export class Room {
851852
}
852853

853854
/**
854-
* tell the user about a new user in the room
855+
* send an user's ready status to another user
855856
* @param user the player to send the other player's ready status
856857
* @param player the player whose ready status will be sent
857858
*/
@@ -868,6 +869,16 @@ export class Room {
868869
user.socket.send(reply)
869870
}
870871

872+
/**
873+
* send everyone's ready status to an user
874+
* @param targetUser the user to send the info to
875+
*/
876+
public sendRoomUsersReadyStatusTo(targetUser: User): void {
877+
this.recurseUsers((u: User): void => {
878+
this.sendUserReadyStatusTo(targetUser, u)
879+
})
880+
}
881+
871882
/**
872883
* tell the user to connect to a host
873884
* @param user the user that will connect to the host

src/user/usermanager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ export class UserManager {
118118
currentRoom.settings.roomName, currentRoom.id)
119119

120120
currentRoom.setStatus(RoomStatus.Waiting)
121+
currentRoom.resetIngameUsersReadyStatus()
121122

122123
currentRoom.recurseUsers((u: User): void => {
124+
currentRoom.sendRoomUsersReadyStatusTo(u)
123125
currentRoom.sendGameEnd(u)
124126
})
125127

0 commit comments

Comments
 (0)