mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-09-30 19:16:36 -05:00
API: Add baninfo endpoint
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user