11package gpcm
22
33import (
4- "strconv"
54 "time"
65 "wwfc/common"
76 "wwfc/qr2"
87)
98
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- }
45-
469func kickPlayer (profileID uint32 , reason string ) {
4710 if session , exists := sessions [profileID ]; exists {
4811 errorMessage := WWFCMsgKickedGeneric
@@ -72,24 +35,21 @@ func kickPlayer(profileID uint32, reason string) {
7235 return
7336 }
7437
75- players := getSessionsMatchedWithPlayer (session .GameName , profileID )
7638 session .replyError (GPError {
7739 ErrorCode : ErrConnectionClosed .ErrorCode ,
7840 ErrorString : "The player was kicked from the server. Reason: " + reason ,
7941 Fatal : true ,
8042 WWFCMessage : errorMessage ,
8143 })
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 )
9244 }
45+
46+ // After 3 seconds, send kick order to all players
47+ // This is to prevent the restricted player from staying in the group if he ignores the GPCM kick
48+ go func () {
49+ time .AfterFunc (3 * time .Second , func () {
50+ qr2 .OrderKickFromGroups (profileID )
51+ })
52+ }()
9353}
9454
9555func KickPlayer (profileID uint32 , reason string ) {
@@ -104,23 +64,20 @@ func KickPlayerCustomMessage(profileID uint32, reason string, message WWFCErrorM
10464 defer mutex .Unlock ()
10565
10666 if session , exists := sessions [profileID ]; exists {
107- players := getSessionsMatchedWithPlayer (session .GameName , profileID )
10867 session .replyError (GPError {
10968 ErrorCode : ErrConnectionClosed .ErrorCode ,
11069 ErrorString : "The player was kicked from the server. Reason: " + reason ,
11170 Fatal : true ,
11271 WWFCMessage : message ,
11372 Reason : reason ,
11473 })
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 )
12574 }
75+
76+ // After 3 seconds, send kick order to all players
77+ // This is to prevent the restricted player from staying in the group if he ignores the GPCM kick
78+ go func () {
79+ time .AfterFunc (3 * time .Second , func () {
80+ qr2 .OrderKickFromGroups (profileID )
81+ })
82+ }()
12683}
0 commit comments