fix(hwid): keep a subscription's device limit while its client is disabled

effectiveHwidLimitForSubID took the limit over enabled clients only. A
client switched off for expiry, quota or by hand therefore had no limit
at all, while the subscription body is still served for disabled
clients, so any number of devices registered and stayed past the
renewal.

The limit now follows the subId whatever the enable flag, and the gate,
the slot status and the trim keep sharing that one query.
This commit is contained in:
MHSanaei
2026-11-01 08:39:50 +01:00
parent bd36053356
commit f8ceede46f
2 changed files with 46 additions and 2 deletions
+4 -2
View File
@@ -92,10 +92,12 @@ func normalizeHwidRequest(req HwidRequest) HwidRequest {
}
}
// The subscription body is built for disabled clients too, so an expired,
// depleted or suspended client must keep holding the limit of its subId.
func effectiveHwidLimitForSubID(tx *gorm.DB, subID string) (int, error) {
var limit int
err := tx.Model(&model.ClientRecord{}).
Where("sub_id = ? AND enable = ?", subID, true).
Where("sub_id = ?", subID).
Select("COALESCE(MAX(limit_hwid), 0)").
Scan(&limit).Error
return limit, err
@@ -216,7 +218,7 @@ func trackUnlimitedHwid(db *gorm.DB, subID string, req HwidRequest) {
}
// HwidSlotStatusForSubID is SELECT-only: it must never write client_hwids or
// last_seen. Enabled-clients scope mirrors the gate, so limit == limit enforced.
// last_seen. It shares the gate's limit query, so limit == limit enforced.
func (s *ClientService) HwidSlotStatusForSubID(subID string) (status HwidSlotStatus, found bool, err error) {
subID = strings.TrimSpace(subID)
if subID == "" {