11package gpcm
22
3- import "wwfc/common"
3+ import (
4+ "strconv"
5+ "time"
6+ "wwfc/common"
7+ "wwfc/qr2"
8+ )
9+
10+ // Expects a global mutex to be locked
11+ // This function will return all sessions that are matched with the player `profileID`
12+ func getSessionsMatchedWithPlayer (gameName string , profileID uint32 ) []* GameSpySession {
13+
14+ var matchedPlayers []* GameSpySession
15+
16+ // Check if the user is part of a group
17+ var foundGroup * qr2.GroupInfo
18+ groups := qr2 .GetGroups ([]string {gameName }, []string {}, false )
19+ for _ , group := range groups {
20+ for _ , playerInfo := range group .Players {
21+ pid , err := strconv .ParseUint (playerInfo .ProfileID , 10 , 32 )
22+ if err == nil {
23+ if uint32 (pid ) == profileID {
24+ foundGroup = & group
25+ break
26+ }
27+ }
28+ }
29+ }
30+
31+ // If the user is part of a group, send a kick order to all players in the group
32+ if foundGroup != nil {
33+ for _ , playerInfo := range foundGroup .Players {
34+ pid , err := strconv .ParseUint (playerInfo .ProfileID , 10 , 32 )
35+ if err == nil {
36+ if session , exists := sessions [uint32 (pid )]; exists {
37+ matchedPlayers = append (matchedPlayers , session )
38+ }
39+ }
40+ }
41+ }
42+
43+ return matchedPlayers
44+ }
445
546func kickPlayer (profileID uint32 , reason string ) {
647 if session , exists := sessions [profileID ]; exists {
@@ -31,12 +72,23 @@ func kickPlayer(profileID uint32, reason string) {
3172 return
3273 }
3374
75+ players := getSessionsMatchedWithPlayer (session .GameName , profileID )
3476 session .replyError (GPError {
3577 ErrorCode : ErrConnectionClosed .ErrorCode ,
3678 ErrorString : "The player was kicked from the server. Reason: " + reason ,
3779 Fatal : true ,
3880 WWFCMessage : errorMessage ,
3981 })
82+
83+ // After 3 seconds, send kick order to all players in the group
84+ // This is to prevent the restricted player from staying in the group if he ignores the GPCM kick
85+ go func (players []* GameSpySession ) {
86+ time .AfterFunc (3 * time .Second , func () {
87+ for _ , player := range players {
88+ qr2 .OrderKickFromGroup (player .User .ProfileId , profileID )
89+ }
90+ })
91+ }(players )
4092 }
4193}
4294
@@ -52,12 +104,23 @@ func KickPlayerCustomMessage(profileID uint32, reason string, message WWFCErrorM
52104 defer mutex .Unlock ()
53105
54106 if session , exists := sessions [profileID ]; exists {
107+ players := getSessionsMatchedWithPlayer (session .GameName , profileID )
55108 session .replyError (GPError {
56109 ErrorCode : ErrConnectionClosed .ErrorCode ,
57110 ErrorString : "The player was kicked from the server. Reason: " + reason ,
58111 Fatal : true ,
59112 WWFCMessage : message ,
60113 Reason : reason ,
61114 })
115+
116+ // After 3 seconds, send kick order to all players in the group
117+ // This is to prevent the restricted player from staying in the group if he ignores the GPCM kick
118+ go func (players []* GameSpySession ) {
119+ time .AfterFunc (3 * time .Second , func () {
120+ for _ , player := range players {
121+ qr2 .OrderKickFromGroup (player .User .ProfileId , profileID )
122+ }
123+ })
124+ }(players )
62125 }
63126}
0 commit comments