mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-07-01 23:41:23 -05:00
ServerBrowser: Custom handling of Mario Kart Wii filters
This commit is contained in:
parent
3e7f4ed342
commit
698cdb8bd8
|
|
@ -82,7 +82,7 @@ func filterServers(servers []map[string]string, queryGame string, expression str
|
|||
continue
|
||||
}
|
||||
|
||||
ret, err := filter.Eval(tree, server)
|
||||
ret, err := filter.Eval(tree, server, queryGame)
|
||||
if err != nil {
|
||||
logging.Error(ModuleName, "Error evaluating filter:", err.Error())
|
||||
return []map[string]string{}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,17 @@ package filter
|
|||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type expression struct {
|
||||
ast *TreeNode
|
||||
context map[string]string
|
||||
ast *TreeNode
|
||||
context map[string]string
|
||||
queryGame string
|
||||
}
|
||||
|
||||
// Bug(zdebeer): functions is eval from right to left instead from left to right.
|
||||
func Eval(basenode *TreeNode, context map[string]string) (value int64, err error) {
|
||||
func Eval(basenode *TreeNode, context map[string]string, queryGame string) (value int64, err error) {
|
||||
defer func() {
|
||||
if str := recover(); str != nil {
|
||||
value = 0
|
||||
|
|
@ -20,7 +22,7 @@ func Eval(basenode *TreeNode, context map[string]string) (value int64, err error
|
|||
}
|
||||
}()
|
||||
|
||||
this := &expression{basenode, context}
|
||||
this := &expression{basenode, context, queryGame}
|
||||
return this.eval(basenode), nil
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +118,12 @@ func (this *expression) evalEquals(args []*TreeNode) int64 {
|
|||
case cnt < 2:
|
||||
panic("operator missing arguments")
|
||||
case cnt == 2:
|
||||
if n, ok := args[0].Value.(*IdentityToken); ok {
|
||||
if n.Name == "rk" && this.queryGame == "mariokartwii" {
|
||||
return this.evalEqualsRK(this.getString(args[1]))
|
||||
}
|
||||
}
|
||||
|
||||
if this.getString(args[0]) == this.getString(args[1]) {
|
||||
return 1
|
||||
}
|
||||
|
|
@ -131,6 +139,25 @@ func (this *expression) evalEquals(args []*TreeNode) int64 {
|
|||
}
|
||||
}
|
||||
|
||||
// Operator override
|
||||
func (this *expression) evalEqualsRK(value string) int64 {
|
||||
rk := this.context["rk"]
|
||||
// Check and remove regional searches due to the limited player count
|
||||
// China (ID 6) gets a pass because it was never released
|
||||
if len(rk) == 4 && (strings.HasPrefix(rk, "vs_") || strings.HasPrefix(rk, "bt_")) && rk[3] >= '0' && rk[3] < '6' {
|
||||
rk = rk[:2]
|
||||
}
|
||||
|
||||
if len(value) == 4 && (strings.HasPrefix(value, "vs_") || strings.HasPrefix(value, "bt_")) && value[3] >= '0' && value[3] < '6' {
|
||||
value = value[:2]
|
||||
}
|
||||
|
||||
if rk == value {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *expression) evalNotEquals(args []*TreeNode) int64 {
|
||||
cnt := len(args)
|
||||
switch {
|
||||
|
|
@ -208,6 +235,13 @@ func (this *expression) evalMathOperator(fn func(int64, int64) int64, args []*Tr
|
|||
case cnt < 2:
|
||||
panic("operator missing arguments")
|
||||
case cnt == 2:
|
||||
if n, ok := args[0].Value.(*IdentityToken); ok {
|
||||
// Remove VR search due to the limited player count
|
||||
if (n.Name == "ev" || n.Name == "eb") && this.queryGame == "mariokartwii" {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
return fn(this.getNumber(args[0]), this.getNumber(args[1]))
|
||||
default:
|
||||
answ := fn(this.getNumber(args[0]), this.getNumber(args[1]))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user