Documentation
ΒΆ
Index ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
View Source
var Plugin = proxy.Plugin{ Name: "StonyPerms", Init: func(ctx context.Context, p *proxy.Proxy) error { log := logr.FromContextOrDiscard(ctx) configPath := filepath.Join("config", "stonyperms.toml") cfg, err := LoadConfig(configPath) if err != nil { log.Error(err, "Failed to load stonyperms.toml, using defaults") cfg = &Config{ DefaultGroup: "default", StorageType: "json", StorageDir: "config/stonyperms", ApplyGatePermissions: true, ApplyServerContexts: true, EnableAuditLog: true, } } store, err := storage.NewJSONStorage(cfg.StorageDir) if err != nil { return err } mgr, err := manager.New(store) if err != nil { return err } globalManager.Store(mgr) var serverContexts sync.Map if cfg.ApplyGatePermissions { event.Subscribe(p.Event(), 0, func(e *proxy.PermissionsSetupEvent) { subj := e.Subject() if pl, ok := subj.(proxy.Player); ok { uid := uuid.UUID(pl.ID()) _ = mgr.GetOrCreateUser(uid, pl.Username()) e.SetFunc(mgr.GatePermissionFunc(uid, func() map[string]string { ctxs := make(map[string]string) if cfg.ApplyServerContexts { if val, ok := serverContexts.Load(pl.ID()); ok { if sName, ok := val.(string); ok && sName != "" { ctxs["server"] = sName } } else if s := pl.CurrentServer(); s != nil { ctxs["server"] = s.Server().ServerInfo().Name() } } return ctxs })) } }) } if cfg.ApplyServerContexts { event.Subscribe(p.Event(), 0, func(e *proxy.ServerPostConnectEvent) { if s := e.Player().CurrentServer(); s != nil { serverContexts.Store(e.Player().ID(), s.Server().ServerInfo().Name()) } }) } event.Subscribe(p.Event(), 0, func(e *proxy.DisconnectEvent) { serverContexts.Delete(e.Player().ID()) }) command.RegisterCommands(p, mgr) if !p.Config().RequireBuiltinCommandPermissions { log.Info("NOTE: Gate's 'requireBuiltinCommandPermissions' is set to false in config.yml. Built-in proxy commands (/server, /send, /glist) will bypass permissions until enabled.") } uCount, gCount, tCount, _ := mgr.Stats() log.Info("StonyPerms successfully initialized", "users", uCount, "groups", gCount, "tracks", tCount, "storage", cfg.StorageType, "gate_hooks", cfg.ApplyGatePermissions, ) return nil }, }
Plugin is the primary Gate proxy plugin entrypoint for StonyPerms.
Functions ΒΆ
func GetManager ΒΆ
GetManager returns the active StonyPerms Manager instance, allowing other plugins to query permissions & metadata.
Types ΒΆ
type Config ΒΆ
type Config struct {
DefaultGroup string `toml:"default_group"`
StorageType string `toml:"storage_type"`
StorageDir string `toml:"storage_dir"`
ApplyGatePermissions bool `toml:"apply_gate_permissions"`
ApplyServerContexts bool `toml:"apply_server_contexts"`
EnableAuditLog bool `toml:"enable_audit_log"`
}
Config represents the top-level StonyPerms configuration.
func LoadConfig ΒΆ
LoadConfig loads the config from filePath or writes default configuration if missing.
Click to show internal directories.
Click to hide internal directories.