Fix match clash mode

This commit is contained in:
世界
2024-11-13 17:06:34 +08:00
parent e18b527eaa
commit 2be7482e32
3 changed files with 13 additions and 7 deletions

View File

@@ -1,25 +1,33 @@
package rule
import (
"context"
"strings"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing/service"
)
var _ RuleItem = (*ClashModeItem)(nil)
type ClashModeItem struct {
ctx context.Context
clashServer adapter.ClashServer
mode string
}
func NewClashModeItem(clashServer adapter.ClashServer, mode string) *ClashModeItem {
func NewClashModeItem(ctx context.Context, mode string) *ClashModeItem {
return &ClashModeItem{
clashServer: clashServer,
mode: mode,
ctx: ctx,
mode: mode,
}
}
func (r *ClashModeItem) Start() error {
r.clashServer = service.FromContext[adapter.ClashServer](r.ctx)
return nil
}
func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
if r.clashServer == nil {
return false