Send kick and ban reasons to players

This commit is contained in:
ppeb 2024-09-16 02:33:43 -05:00
parent e12944ccab
commit df1c6a83fc
No known key found for this signature in database
GPG Key ID: CC147AD1B3D318D0
6 changed files with 52 additions and 7 deletions

View File

@ -94,11 +94,16 @@ func handleBanImpl(w http.ResponseWriter, r *http.Request) (*database.User, bool
return nil, false, "Failed to ban user", http.StatusInternalServerError
}
if req.Tos {
gpcm.KickPlayer(req.Pid, "banned")
} else {
gpcm.KickPlayer(req.Pid, "restricted")
}
gpcm.KickPlayerCustomMessage(req.Pid, req.Reason, gpcm.WWFCErrorMessage{
ErrorCode: 22002,
MessageRMC: map[byte]string{
gpcm.LangEnglish: "" +
"You have been banned from Retro WFC\n" +
"Reason: " + req.Reason + "\n" +
"Error Code: %[1]d\n" +
"Support Info: NG%08[2]x",
},
})
var message string
user, success := database.GetProfile(pool, ctx, req.Pid)

View File

@ -41,6 +41,7 @@ func HandleKick(w http.ResponseWriter, r *http.Request) {
type KickRequestSpec struct {
Secret string
Reason string
Pid uint32
}
@ -66,7 +67,20 @@ func handleKickImpl(w http.ResponseWriter, r *http.Request) (*database.User, boo
return nil, false, "pid missing or 0 in request", http.StatusBadRequest
}
gpcm.KickPlayer(req.Pid, "moderator_kick")
if req.Reason == "" {
return nil, false, "Missing kick reason in request", http.StatusBadRequest
}
gpcm.KickPlayerCustomMessage(req.Pid, "moderator_kick", gpcm.WWFCErrorMessage{
ErrorCode: 22004,
MessageRMC: map[byte]string{
gpcm.LangEnglish: "" +
"You have been kicked from\n" +
"Retro WFC by a moderator.\n" +
"Reason: " + req.Reason + "\n" +
"Error Code: %[1]d",
},
})
var message string
user, success := database.GetProfile(pool, ctx, req.Pid)

View File

@ -172,6 +172,7 @@ func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsb
var bannedDeviceIdList []uint32
timeNow := time.Now()
err = pool.QueryRow(ctx, SearchUserBan, user.NgDeviceId, user.ProfileId, ipAddress, *lastIPAddress, timeNow).Scan(&banExists, &banTOS, &bannedDeviceIdList)
if err != nil {
if err != pgx.ErrNoRows {
return User{}, err

View File

@ -40,6 +40,7 @@ type User struct {
LastName string
Restricted bool
RestrictedDeviceId uint32
BanReason string
OpenHost bool
LastInGameSn string
LastIPAddress string

View File

@ -49,3 +49,18 @@ func KickPlayer(profileID uint32, reason string) {
kickPlayer(profileID, reason)
}
// Exists because the above function is used in too many places to be updated easily
func KickPlayerCustomMessage(profileID uint32, reason string, message WWFCErrorMessage) {
mutex.Lock()
defer mutex.Unlock()
if session, exists := sessions[profileID]; exists {
session.replyError(GPError{
ErrorCode: ErrConnectionClosed.ErrorCode,
ErrorString: "The player was kicked from the server. Reason: " + reason,
Fatal: true,
WWFCMessage: message,
})
}
}

View File

@ -476,7 +476,16 @@ func (g *GameSpySession) performLoginWithDatabase(userId uint64, gsbrCode string
ErrorCode: ErrLogin.ErrorCode,
ErrorString: "The profile is banned from the service.",
Fatal: true,
WWFCMessage: WWFCMsgProfileBannedTOS,
WWFCMessage: WWFCErrorMessage{
ErrorCode: 22002,
MessageRMC: map[byte]string{
LangEnglish: "" +
"You are banned from Retro WFC\n" +
"Reason: " + user.BanReason + "\n" +
"Error Code: %[1]d\n" +
"Support Info: NG%08[2]x",
},
},
})
} else {
g.replyError(GPError{