|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
So basically my game server post the new seeds for BattleField 2 so people can play on my server now I usually pick up from mIRC from topic a random num lenght of 16 what I mean is
Welcome to #BF2 I currently have 2 open servers up for gameplay NO ABUSE OR Automatic KICK! (BF2:11) 01 93 93 93 01 01 30 20 00 10 01 01 02 02 03 04 (BF2:32) 01 93 93 01 33 39 91 31 57 75 98 18 29 10 39 19 Have FUN
so I pick up these numbers just like that by using
%t = $chan(#).topic
$remove($gettok(%t,$+($calc($findtok(%t,(BF2:11),1,32) + 1),-,$calc($findtok(%t,(BF2:11),1,32) + 16)),32),$chr(32))
so It would be the LENGHT of 16 bytes without any issues BUT.. What if... instead of (BF2:11) 16lenght key it became (BF2:11)16 lenght key having no space between the first byte and the "Gettok/Findtok" it wouldnt work I need to find a way in which I can get both of these ALPHA NUM numbers keeping in mine that (BF2:XX) XX could be any number depending on which Connection to server I have.
So again the method I have on top only works if (BF2:11) 16 lenght is seperated otherwise it fails.
and BTW to even make it more harder sometimes (BF2:11) will have a : beside it like (BF2:11): so its not always 100% static making it hard to use GETTOK routines
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Try this in place of your current $remove line:
$gettok($gettok($remove($wildtok(%t,*BF2:11*,1,32) $+ $remove($gettok(%t,$+($calc($findtok(%t,$wildtok(%t,*BF2:11*,1,32),1,32) + 1),-,$calc($findtok(%t,$wildtok(%t,*BF2:11*,1,32),1,32) + 16)),32),$chr(32)),:),2,41),1,40) It should work for all situations: (BF2:11) 01 02 ... (BF2:11)01 02 ... (BF2:11): 01 02 ... (BF2:11):01 02 ...
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
As a note, it's probably faster with regex, but I still haven't taken the time to try and figure that out. ![smile smile](/images/graemlins/mirc/smile.gif)
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
Here's another solution. Although it's dependent on the two instances of (BF:XX) being part of the topic and no other occurances of the ( and ) characters. I don't know if that's a potential problem for you, but given the format you posted, it's another solution none the less.
$remove($gettok($gettok(%t,2,41),1,40),$chr(32),:)
Doesn't matter what XX is or if a : or space is present (both are removed as you can see in the code). As long as the topic stays in the same or similar format, it should always work.
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
I already thought of that solution and it doesnt work because : might not be that it might be ; in the future know what i mean
the WILDtok routine works perfect for what I want and im sure REGEX would be quicker but in this case im not looking for speed im looking for it to do what I want it to do and Riamus certainly posted what I wanted in a long form yes but a flawless method to top it.
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Yes, I considered using the ()'s and 2 $gettok's to accomplish the task, but if another parentheses was in the topic, it would mess it all up, so I went with the $wildtok method instead. It's longer, but less likely to get messed up.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
alias BF.getkey {
var %r = $regex(BF,$1-,/\(BF2:11\)[:\s]*((?:\d+\s+)+)/i)
return $regml(BF,1)
}
Sample usage:
alias showkey {
;$1 = channel
var %topic = $chan($$1).topic
if ($BF.getkey(%topic) != $null) echo 3 -a Key- $v1
else echo 4 -a No Key Found
}
/showkey #your_chan Matches all the given formats, (BF2:11) 01 02.. (BF2:11)01 02.. (BF2:11): 01 02.. (BF2:11):01 02.. -genius_at_work
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
See, I knew regex would look nicer. ![laugh laugh](/images/graemlins/mirc/laugh.gif) genius_at_work: If you have time, would you be willing to explain how that works for me. I suppose now isn't a bad time to start learning at least a little regex. ![smile smile](/images/graemlins/mirc/smile.gif)
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
/\(BF2:11\)[:\s]*((?:\d+\s+)+)/i
/ Specifies there is a pattern within. I've also seen #'s use, but / being more common.
\(BF2:11\) This looks for the text "(BF2:11)". Regex uses things like hypens, parenthesis, and backslashes for its syntax. As such, the parenthesis must be escaped using a backslash (same for hyphen, etc.)
[:\s]*
The [] are grouping brackets, and specify to look for "items contained within", meaning "in these braces are the only characters you should be looking for". The : was a possible character, and so was a space (the \s represents space characters). The trailing * means is may or may not be present. You could also use + to represent there must be atleast one of these characters.
((?:\d+\s+)+) The outer parenthesis specify this is a group we are looking for, and the contained items will be the value of our $regml result(s).
The inner parenthesis (because the first characters are "?:") are non-grouping. Don't seperate this set of parethesis off as its own return value, only use it for sake of containment. And what is it containing? The pattern for <number><space> (\d is digit, \s is again space). The +'s (as i mentioned) mean 1 or more. This set of parenthesis are trailed by another plus meaning repeat this pattern; look for a string of <number><space>.
i The i flag stands for case-insensitive. mainly for the BF found in the pattern.
-KingTomato
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Ok, that makes sense. But what stops it from displaying the second group of 16 numbers? What indicates that it should stop after 16 numbers (or when it reaches the next parentheses)?
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
Unless the g modifier is used, the regex will find only the first match to the pattern and stop. If it were used (you would place it before or after the i modifier above), then the second set of numbers would be referenced by $regml(BF,2).
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
The regex stops matching simply because the next (BF..) part is not a digit. If you wanted to limit the match to 16 sets of digits, you could replace the last + with {16} . In regex {n,m} indicates that the preceeding character/class must repeat a minimum of n times and a maximum of m times. The ,m is optional, and if excluded, indicates that exactly n repetitions must exist.
-genius_at_work
|
|
|
|
|