How to make a filter partial match/wildcard?

Designing a filter? Get tips and advice from other users. Suggest new filter features here too.

Moderators: Moderators, Support

How to make a filter partial match/wildcard?

Postby nmX.CRIMENY » Mon Aug 24, 2009 9:21 pm

If I want a partial match, how do I write that in the logic textarea? Just how a wildcard could be used for *.jpg or thepicture.* is what I'm wanting to know how to do, and not necessarily exclusive to sv_hostname or similar, since I would like to use it for other server-side settings as well.
nmX.CRIMENY
Qtracker Registered Owner
Qtracker Registered Owner
 
Posts: 42
Joined: Wed Oct 03, 2007 10:42 pm

Re: How to make a filter partial match/wildcard?

Postby ron.mercer » Mon Aug 24, 2009 9:56 pm

nmX.CRIMENY wrote:If I want a partial match, how do I write that in the logic textarea? Just how a wildcard could be used for *.jpg or thepicture.* is what I'm wanting to know how to do, and not necessarily exclusive to sv_hostname or similar, since I would like to use it for other server-side settings as well.

You can use the find() function. It returns the position in the source string that your search string was found, so anything other than -1 means it was found.

Example:

source: "This is my server name"
search: "my"
logic: if find("This is my server name", "my") != -1
Ron Mercer
Qtracker

Image
User avatar
ron.mercer
Site Admin
 
Posts: 3196
Joined: Tue Dec 09, 2003 5:01 pm
Location: Ohio, USA

Re: How to make a filter partial match/wildcard?

Postby nmX.CRIMENY » Mon Aug 24, 2009 11:03 pm

Before you posted your example, I was trying something like this to display only the servers with a certain word in the server name:
if find("sv_hostname", "competition") == 1

...but I think I'm more confused now :(

I hate to be "that guy", but I'm not quite following. If I want to display only the servers whose names have the word competition in them somewhere, how would I write that? I must be misunderstanding the example, because the source has me confused and thinking that I need to know the source would already be named "the competition server", and then search for "competition" within it. I tried a few varieties based on the example you gave me, but I'm going horribly wrong somewhere--in some cases, all servers disappear; in others, nothing changes. And can the same function apply toward displaying only the servers whose map names contain certain characters? It must be going over my head because I've written small php scripts with find() that worked ok...argh, I'm embarrassed that I can't pick this up easily :/
nmX.CRIMENY
Qtracker Registered Owner
Qtracker Registered Owner
 
Posts: 42
Joined: Wed Oct 03, 2007 10:42 pm

Re: How to make a filter partial match/wildcard?

Postby ~Mr-Freeze~ » Tue Aug 25, 2009 4:33 am

Yeah its not that easy to understand I mostly guess /trial and error
ron could you explan find("source", "search", 0)
how the number on the end work's with -1 yet in the eg its 0 and that is not doing much

Think u just need the -1 and should work
Yeh the find will work for maps
Code: Select all
if find([$server_map], "mp") != -1
would only show maps with mp in them

off topic Nice update with the green folder when a filters on.
User avatar
~Mr-Freeze~
Qtracker Registered Owner
Qtracker Registered Owner
 
Posts: 127
Joined: Wed May 24, 2006 9:49 pm
Location: AuStRaLiA MaTe The LaNd DowN UndEr

Re: How to make a filter partial match/wildcard?

Postby ron.mercer » Tue Aug 25, 2009 10:38 am

~Mr-Freeze~ wrote:Yeah its not that easy to understand I mostly guess /trial and error
ron could you explan find("source", "search", 0)
how the number on the end work's with -1 yet in the eg its 0 and that is not doing much

Think u just need the -1 and should work
Yeh the find will work for maps
Code: Select all
if find([$server_map], "mp") != -1
would only show maps with mp in them

off topic Nice update with the green folder when a filters on.

Sure, for me it's pretty simple since it's a standard find function, but I could see why it would be confusing...

find(argument1=source string, argument2=search string, argument3=starting source string offset)

Keep in mind, this function returns a numeric value that indicates what position the search string was found in the source string. If it's not found, -1 is returned. And we'll ignore argument3 for now.

For your arguments, you can feed in whatever you want. It can be a string you provide, example: "this is my string", or it can be something that's pulled from server data which is a variable, example: [$server_name]. If it's a variable I look up the value of that variable, in this case the server name, and that's what I'll search through. You could do something stupid too and use a variable for both argument 1 and 2, not sure why you'd do that though but technically it's possible.

String are just a collection of characters, and each character has a position that starts at 0 and increments by one. So look at this:

Code: Select all
This is an example string
0000000000111111111122222
0123456789012345678901234

I put the numbers below it to make it easy to determine the position of any given character. For example, "is" starts at 5, "example" starts at 11, and the last character "g" is at 24.

Here are some example return values:

find("This is an example string", "example") returns 11
find("This is an example string", "string") returns 19
find("This is an example string", "this") returns 0
find("This is an example string", "t") returns 0
find("This is an example string", "n") returns 9 (find the first occurance)
find("This is an example string", " ") returns 4 (finds the first occurance)
find("This is an example string", " is") returns 4
find("This is an example string", "is") returns 5
find("This is an example string", "duck") returns -1

You'll notice that the comparisons are not case sensitive, so I used "t" and not "T" in one of the examples.

I hope this makes sense and helps, if not I'll try again...
Ron Mercer
Qtracker

Image
User avatar
ron.mercer
Site Admin
 
Posts: 3196
Joined: Tue Dec 09, 2003 5:01 pm
Location: Ohio, USA

Re: How to make a filter partial match/wildcard?

Postby nmX.CRIMENY » Tue Aug 25, 2009 11:33 am

I now understand the return values and why -1 is used. Thanks!

My filter is displaying 1, sometimes 2, servers that are unrelated to the filter and none of the appropriate ones for some reason. Here's the full text of the .qtf file:

Code: Select all
description FTWgl Servers
version 1.0
game UrbanTerror
author
comments
email
homepage
directory
filename
commandline
active 0
if find("[$sv_hostname]", "FTWgl.com") != -1


Where am I going wrong? Urban Terror's server.cfg uses sv_hostname, but Qtracker properties display both hostname and sv_hostname; I've tried both with no luck.
nmX.CRIMENY
Qtracker Registered Owner
Qtracker Registered Owner
 
Posts: 42
Joined: Wed Oct 03, 2007 10:42 pm

Re: How to make a filter partial match/wildcard?

Postby ron.mercer » Tue Aug 25, 2009 12:49 pm

nmX.CRIMENY wrote:I now understand the return values and why -1 is used. Thanks!

My filter is displaying 1, sometimes 2, servers that are unrelated to the filter and none of the appropriate ones for some reason. Here's the full text of the .qtf file:

Code: Select all
description FTWgl Servers
version 1.0
game UrbanTerror
author
comments
email
homepage
directory
filename
commandline
active 0
if find("[$sv_hostname]", "FTWgl.com") != -1


Where am I going wrong? Urban Terror's server.cfg uses sv_hostname, but Qtracker properties display both hostname and sv_hostname; I've tried both with no luck.

Try this instead:

if find([$server_name], "FTWgl.com") != -1

Anything that looks like [$] is a Qtracker variable. You can see all the different variables that can be used from the Insert menu (green arrow in toolbar), select one and it will insert the correct variable text for you.

If you're looking for a rule, that Qtracker doesn't have a variable for, you would use the rule function, like so:

if find(rule("sv_hostname"), "FTWgl.com") != -1

In the above example, the rule() function is called first to obtain the value of the specific server rule. So the string that is returned is what will be passed to the find() function as argument1.
Ron Mercer
Qtracker

Image
User avatar
ron.mercer
Site Admin
 
Posts: 3196
Joined: Tue Dec 09, 2003 5:01 pm
Location: Ohio, USA

Re: How to make a filter partial match/wildcard?

Postby nmX.CRIMENY » Tue Aug 25, 2009 3:35 pm

Excellent! I now have a very firm grasp of how this flows and how to nest them into more complex filtering. This will be very handy for working with yet-to-be-released versions of games/mods that I'm beta testing. Thank you much =]
nmX.CRIMENY
Qtracker Registered Owner
Qtracker Registered Owner
 
Posts: 42
Joined: Wed Oct 03, 2007 10:42 pm

Re: How to make a filter partial match/wildcard?

Postby signa » Wed Aug 26, 2009 9:18 am

Thanks for explaining all. That was something that always confused me. :oops:
User avatar
signa
Qtracker Registered Owner
Qtracker Registered Owner
 
Posts: 690
Joined: Mon Oct 17, 2005 10:22 pm
Location: Detroit


Return to Filters

Who is online

Users browsing this forum: No registered users and 2 guests