Skip to content

Commit

Permalink
feat: New Minecraft status rule
Browse files Browse the repository at this point in the history
  • Loading branch information
layou233 committed Jul 29, 2024
1 parent 05241e2 commit b7c5e0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions route/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func NewRule(logger *log.Logger, config *config.Rule, listMap map[string]set.Str
return NewMinecraftHostnameRule(config, listMap)
case "MinecraftPlayerName":
return NewMinecraftPlayerNameRule(config, listMap)
case "MinecraftStatus":
return NewMinecraftStatusRule(config)
}
if len(ruleRegistry) > 0 && strings.HasPrefix(config.Type, typeCustomPrefix) {
typeName := strings.TrimPrefix(config.Type, typeCustomPrefix)
Expand Down
27 changes: 27 additions & 0 deletions route/rule_minecraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/layou233/zbproxy/v3/adapter"
"github.com/layou233/zbproxy/v3/common/jsonx"
"github.com/layou233/zbproxy/v3/common/mcprotocol"
"github.com/layou233/zbproxy/v3/common/set"
"github.com/layou233/zbproxy/v3/config"
)
Expand Down Expand Up @@ -63,3 +64,29 @@ func (r *RuleMinecraftPlayerName) Match(metadata *adapter.Metadata) (match bool)
}
return
}

type RuleMinecraftStatus struct {
config *config.Rule
}

var _ Rule = (*RuleMinecraftStatus)(nil)

func NewMinecraftStatusRule(newConfig *config.Rule) (Rule, error) {
return &RuleMinecraftStatus{
config: newConfig,
}, nil
}

func (r *RuleMinecraftStatus) Config() *config.Rule {
return r.config
}

func (r *RuleMinecraftStatus) Match(metadata *adapter.Metadata) (match bool) {
if metadata.Minecraft != nil {
match = metadata.Minecraft.NextState == mcprotocol.NextStateStatus
}
if r.config.Invert {
match = !match
}
return
}

0 comments on commit b7c5e0f

Please sign in to comment.