API: Add baninfo endpoint
Some checks failed
Build CI / build (push) Has been cancelled
golangci-lint / lint (push) Has been cancelled

This commit is contained in:
Palapeli
2026-04-22 13:34:21 -04:00
parent 9005b4795d
commit 4d92f7bf0c
6 changed files with 296 additions and 64 deletions

View File

@@ -29,10 +29,31 @@ const (
WHERE has_ban = true
AND (profile_id = $2
OR (allow_default_keys = FALSE AND ng_device_id && (SELECT * FROM known_ng_device_ids))
OR last_ip_address = $3
OR ($3 != '' AND last_ip_address = $3)
OR ($4 != '' AND last_ip_address = $4))
AND (ban_expires IS NULL OR ban_expires > $5)
ORDER BY ban_tos DESC LIMIT 1`
SearchUserBanInfo = `
WITH known_ng_device_ids AS (
WITH RECURSIVE device_tree AS (
SELECT unnest(ng_device_id) AS device_id
FROM users
WHERE allow_default_keys = FALSE AND $1 != 0 AND ng_device_id && array[$1]::bigint[]
UNION
SELECT unnest(ng_device_id)
FROM users
JOIN device_tree dt
ON allow_default_keys = FALSE AND ng_device_id && array[dt.device_id]
) SELECT array_agg(DISTINCT device_id) FROM device_tree
) SELECT has_ban, ban_tos, ban_issued, ban_expires, ban_reason, ng_device_id, profile_id, gsbrcd, last_ingamesn
FROM users
WHERE has_ban = true
AND (profile_id = $2
OR (allow_default_keys = FALSE AND ng_device_id && (SELECT * FROM known_ng_device_ids))
OR ($3 != '' AND last_ip_address = $3)
OR ($4 != '' AND last_ip_address = $4))
ORDER BY ban_expires DESC LIMIT 1`
)
var (

View File

@@ -155,3 +155,18 @@ func (c *Connection) UnbanUser(profileId uint32) bool {
_, err := c.pool.Exec(c.ctx, DisableUserBan, profileId)
return err == nil
}
func (c *Connection) SearchUserBan(profileId uint32, ngDeviceId uint32, ipAddress string, lastIpAddress string) (
tos bool, issued time.Time, expires time.Time, reason string, bannedProfileId uint32, gsbrCode string, inGameName string, err error) {
row := c.pool.QueryRow(c.ctx, SearchUserBanInfo, ngDeviceId, profileId, ipAddress, lastIpAddress)
var hasBan bool
var bannedNgDeviceId []uint32
err = row.Scan(&hasBan, &tos, &issued, &expires, &reason, &bannedNgDeviceId, &bannedProfileId, &gsbrCode, &inGameName)
if err == nil && !hasBan {
err = errors.New("no ban found")
}
if len(gsbrCode) > 4 {
gsbrCode = gsbrCode[:4]
}
return tos, issued, expires, reason, bannedProfileId, gsbrCode, inGameName, err
}