2024-10-21 23:38:34 +08:00
|
|
|
package rule
|
2022-09-10 14:09:47 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ RuleItem = (*ClashModeItem)(nil)
|
|
|
|
|
|
|
|
type ClashModeItem struct {
|
|
|
|
router adapter.Router
|
|
|
|
mode string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewClashModeItem(router adapter.Router, mode string) *ClashModeItem {
|
|
|
|
return &ClashModeItem{
|
|
|
|
router: router,
|
2023-08-24 21:52:38 +08:00
|
|
|
mode: mode,
|
2022-09-10 14:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
|
|
|
|
clashServer := r.router.ClashServer()
|
|
|
|
if clashServer == nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-24 21:52:38 +08:00
|
|
|
return strings.EqualFold(clashServer.Mode(), r.mode)
|
2022-09-10 14:09:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ClashModeItem) String() string {
|
|
|
|
return "clash_mode=" + r.mode
|
|
|
|
}
|