From df1c6a83fce428772aa4a3042705f3ce65374e92 Mon Sep 17 00:00:00 2001 From: ppeb Date: Mon, 16 Sep 2024 02:33:43 -0500 Subject: [PATCH] Send kick and ban reasons to players --- api/ban.go | 15 ++++++++++----- api/kick.go | 16 +++++++++++++++- database/login.go | 1 + database/user.go | 1 + gpcm/kick.go | 15 +++++++++++++++ gpcm/login.go | 11 ++++++++++- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/api/ban.go b/api/ban.go index 125eab8..411fcb9 100644 --- a/api/ban.go +++ b/api/ban.go @@ -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) diff --git a/api/kick.go b/api/kick.go index 64d1e72..6990e9f 100644 --- a/api/kick.go +++ b/api/kick.go @@ -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) diff --git a/database/login.go b/database/login.go index f0c2418..c152987 100644 --- a/database/login.go +++ b/database/login.go @@ -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 diff --git a/database/user.go b/database/user.go index 9bec502..c268a9b 100644 --- a/database/user.go +++ b/database/user.go @@ -40,6 +40,7 @@ type User struct { LastName string Restricted bool RestrictedDeviceId uint32 + BanReason string OpenHost bool LastInGameSn string LastIPAddress string diff --git a/gpcm/kick.go b/gpcm/kick.go index 8a3c712..080380c 100644 --- a/gpcm/kick.go +++ b/gpcm/kick.go @@ -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, + }) + } +} diff --git a/gpcm/login.go b/gpcm/login.go index 7b931b6..49080ab 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -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{