mIRC Home    About    Download    Register    News    Help

Print Thread
#220804 29/04/10 06:55 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
You can search through sockets with $sock(*,n) why not have a way to search through the sockets with $sock(/pattern/,n,t) where /pattern/ is the regex pattern, n being the Nth match, and t being $true/1/etc to denote that it's a regex match

Last edited by FroggieDaFrog; 29/04/10 06:55 PM.

I am SReject
My Stuff
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
I guess the same reason most identifiers with the exception of $read (which is looking for *data*, not unique identifiers) don't allow regex matches- think $timer, $comchan, etc. There's no real need for this. If your socknames are too complex for a simple wildcard match then your socknames are too complex IMO. Do you have any real world use cases where a regex match would be necessary?


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #220846 01/05/10 01:59 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
SRBnc.AUTH.6554641
SRBnc.AUTH.username.655568
SRBnc.AUTH.username2.65544687
+a bunch more SRBnc.AUTH.Usernames.ticks

lets say I have these and I want to move through the sockets looking for ban/swear usernames. i'd have to loop through all sockets, then reg ex match them


And to be honest. I'd like to see all the /sock commands br able to regex match, as it can with *?

Last edited by FroggieDaFrog; 01/05/10 02:02 AM.

I am SReject
My Stuff
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Just use a loop over $sock(srbnc.auth.*). All you have is an extra step of adding "if ($regex(...))" to your loop body, which isn't a big deal.

Here's what your suggestion would look like:
Code:
; fictional regex syntax
var %i = 1
while ($sock(^srbnc.auth.(bad|word|here),%i,r)) {
  var %sock = $v1
  do_something_with_sock %sock
  inc %i
}


Here's what it looks like now:
Code:
; valid syntax
var %i = 1
while ($sock(srbnc.auth.*,%i)) {
  var %sock = $v1, %name = $gettok($v1,3,46)
  if ($regex(%name,/^(bad|word|here)$/)) do_something_with_sock %sock
  inc %i
}


Hardly a difference. Why is builtin support necessary again?

Windows allows a maximum number of a few hundred open sockets at a time, so looping over the extra sockets isn't a perf issue. Adding this kind of support to /sock* commands would be equally unnecessary, as you should really not be sending data to arbitrary sockets by an arbitrary name match. Rather, *if* you do, you're hitting a weird edge case and you should be able to deal with the few extra lines of code.

Of course, why you need to search your list of sockets for bad words *after* the sockets have opened is beyond me. If you want to find all the sockets that match banned usernames do so before you /sockopen (or ON SOCKOPEN) and match the socket name individually.

I still see no real benefit to regular expressions here, just extra implementation complexity. Allowing regular expression matches in $sock and /sock would require mIRC to add special switches to differentiate regular expressions from wildcard matches which would add to complexity, confusion and would ultimately be underused. Again, regular expressions are for "searching". If you need to "search" your sockets, you're doing *something* wrong.

And of course, you can always add your own aliases to do the above for $sock and all /sock commands.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I'm not sure regex is needed here at all:

Code:
alias smellysocks {
  var %i = 1, %words = bad words here, %sock
  while ($sock(srbnc.auth.*,%i)) {
    %sock = $v1
    if ($istok(%words,$gettok(%sock,3,46),32)) { do_stuff_with %sock }
    inc %i
  }
}


Or if you want to match badword "sing" in username "singing" (for example) rather than exact words only, just change $istok to $matchtok


Link Copied to Clipboard