Verification: clan tag setting, GroupVerify 0.3.0 wording
Root sets GroupVerify's clan_tag (the scoreboard tag CS2-Tags gives verified players without a rank) next to the Steam group. Validated like the plugin (12 UTF-16 units, no quotes, ; or \), saved to gv_settings and sent as css_gv_clantag when the plugin is loaded. Only changed fields are sent. GroupVerify 0.3.0 checks players with the Steam Web API as they join, so the group list is now "Confirmed group members" with first/last confirmed dates.
This commit is contained in:
parent
9e4bc63201
commit
3c62874f91
6 changed files with 102 additions and 17 deletions
|
|
@ -9,6 +9,8 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf16"
|
||||
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/live"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/steam"
|
||||
|
|
@ -127,6 +129,7 @@ type verifyStatusView struct {
|
|||
GroupID string `json:"groupId"`
|
||||
Active bool `json:"active"`
|
||||
Shown bool `json:"shown"`
|
||||
ClanTag string `json:"clanTag"`
|
||||
Timezone string `json:"timezone"`
|
||||
ReloadSeconds int `json:"reloadSeconds"`
|
||||
GroupMembers int `json:"groupMembers"`
|
||||
|
|
@ -153,6 +156,7 @@ func (s *Server) adminVerify(w http.ResponseWriter, r *http.Request, id *Identit
|
|||
view := verifyStatusView{
|
||||
Tables: true, Plugin: info.Plugin, Version: info.Version,
|
||||
Enabled: info.Settings.Enabled, GroupID: info.Settings.GroupID, Active: info.Settings.Active(), Shown: info.Shown(),
|
||||
ClanTag: info.Settings.ClanTag,
|
||||
Timezone: loc.String(), ReloadSeconds: info.Settings.ReloadSeconds,
|
||||
CanOverride: id.Has(verifyOverridePerm), CanConfigure: id.Has("@css/root"),
|
||||
}
|
||||
|
|
@ -304,12 +308,30 @@ func isClanID(n uint64) bool {
|
|||
return n>>56 == 1 && (n>>52)&0xF == 7 && n&0xFFFFFFFF != 0
|
||||
}
|
||||
|
||||
// saveVerifySettings turns GroupVerify on or off or changes its group: {enabled?, groupId?}. Saved
|
||||
// clanTagMax matches GroupVerify (and Steam's own group tags). It counts UTF-16 units, as C# does.
|
||||
const clanTagMax = 12
|
||||
|
||||
// validClanTag is GroupVerify's rule, plus no backslashes, which the console would mangle.
|
||||
func validClanTag(tag string) bool {
|
||||
if len(utf16.Encode([]rune(tag))) > clanTagMax {
|
||||
return false
|
||||
}
|
||||
for _, r := range tag {
|
||||
if unicode.IsControl(r) || r == '"' || r == ';' || r == '\\' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// saveVerifySettings turns GroupVerify on or off, or changes its group or clan tag:
|
||||
// {enabled?, groupId?, clanTag?}. Saved
|
||||
// to gv_settings, then, when the plugin is loaded, sent as its own command so it applies at once.
|
||||
func (s *Server) saveVerifySettings(w http.ResponseWriter, r *http.Request, id *Identity, x *staffIndex) {
|
||||
var req struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
GroupID *string `json:"groupId"`
|
||||
ClanTag *string `json:"clanTag"`
|
||||
}
|
||||
if err := readJSON(r, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, err.Error())
|
||||
|
|
@ -319,7 +341,7 @@ func (s *Server) saveVerifySettings(w http.ResponseWriter, r *http.Request, id *
|
|||
fail(w, http.StatusForbidden, "Only Root can change GroupVerify's settings.")
|
||||
return
|
||||
}
|
||||
if req.Enabled == nil && req.GroupID == nil {
|
||||
if req.Enabled == nil && req.GroupID == nil && req.ClanTag == nil {
|
||||
fail(w, http.StatusBadRequest, "Nothing to change.")
|
||||
return
|
||||
}
|
||||
|
|
@ -342,6 +364,18 @@ func (s *Server) saveVerifySettings(w http.ResponseWriter, r *http.Request, id *
|
|||
g = strconv.FormatUint(n, 10)
|
||||
changes = append(changes, change{"group_id64", g, "css_gv_group " + g})
|
||||
}
|
||||
if req.ClanTag != nil {
|
||||
tag := strings.TrimSpace(*req.ClanTag)
|
||||
if !validClanTag(tag) {
|
||||
fail(w, http.StatusBadRequest, fmt.Sprintf("A clan tag is at most %d characters, without quotes, ; or \\.", clanTagMax))
|
||||
return
|
||||
}
|
||||
cmd := `css_gv_clantag "` + tag + `"`
|
||||
if tag == "" {
|
||||
cmd = "css_gv_clantag -"
|
||||
}
|
||||
changes = append(changes, change{"clan_tag", tag, cmd})
|
||||
}
|
||||
if req.Enabled != nil {
|
||||
c := change{"enabled", "0", "css_gv_disable"}
|
||||
if *req.Enabled {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue