mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2003
Posts: 18
H
H0BB1T Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Mar 2003
Posts: 18
Im trying to make a script that checks the userid of those joining my channel, but i cant make it work. perhaps one of you can help me:

on *:JOIN:#:/who $nick

raw 352:*:{
set %ID $3
set %IDnick $6
if ( ~ isin %ID ) && ( $len( %ID ) > 8 ) && ( %ID isalpha ) && ( $islower(%ID) == $true ) {
ping %IDnick
echo 12 -s %IDnick has this userid : 4 %ID
}
halt
}
raw 315:*: /halt

any clues about why doesnt it work?

Joined: May 2003
Posts: 2,265
P
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
change $islower(%id) == $true to %id islower


new username: tidy_trax
Joined: Mar 2003
Posts: 18
H
H0BB1T Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Mar 2003
Posts: 18
still doesnt work

Joined: May 2003
Posts: 2,265
P
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
raw 352:*:{
set %ID *!* $+ $3 $+ @ $+ $4
set %IDnick $6
if (~* iswm %ID) && ($len(%ID) > 8) && (%ID isalpha) && (%ID islower) {
ping %IDnick
echo 12 -s %IDnick has this userid : 4 %ID
}
halt
}
raw 315:*: /halt


new username: tidy_trax
Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
Lose all the variables for a start.
Code:
if ($chr(126) isin $3) && ($islower($3)) && ($3 isalpha) && ($len($3) > 8) {
  ctcp $6 PING
  echo -s 12 $6 has this userid:4 $3
}
You haven't shown any code to explain why the variables need to be set so unless you want to store that information for another purpose it is just slowing down the script for no reason.

Also: $chr(126) = "~"

Joined: Mar 2003
Posts: 18
H
H0BB1T Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Mar 2003
Posts: 18
I copied the code in a fresh mirc, and still it doesnt work confused

Joined: May 2003
Posts: 2,265
P
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
perhaps because because all of the if ~ isin and if isupper's dont match the address?


new username: tidy_trax
Joined: Dec 2002
Posts: 191
N
Vogon poet
Offline
Vogon poet
N
Joined: Dec 2002
Posts: 191
~ isn't an alphabet character

//echo -ag $iif(~ isalpha,yes,no)

Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
It's because there is a conflict. Serves me right for testing it on a server that doesn't check for ident.

The "~" is not classed as an alphanumeric character so the script cannot check for isalpha and the ~ at the same time. I suggest the following change:
Code:
if ($chr(126) isin $3) && ($islower($3)) && ($remove($3,$chr(126)) isalpha) && ($len($3) > 8) {
  ctcp $6 PING
  echo -s 12 $6 has this userid:4 $3
}
I changed ($3 isalpha) to ($remove($3,$chr(126)). This excludes the ~ when checking for alpha characters.

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Excuse me for butting in, but ...

Why are you /who-ing the user on JOIN? The user's $address contains the information you need. If you prefer, you can even
Code:

[color:#840017]var %uid = $gettok($address, 1, 64)[/color]

to separate the userid (ident) from the host ($site). If the only reason you are using /who is to get their nickname and their userid, you are seriously wasting your time. You're building in lag into your script for no apparent reason.

Next point: ALL of the conditions you have in your IF statement MUST be true in order for you to see your script do anything whatsoever. That means that:
  1. ~ must be in at least one place in the userid;
  2. the entire userid must be in lower case;
  3. the userid must be only alphabet characters, no numbers or other characters are to be allowed (corrected version with $remove); and finally,
  4. the length of the userid must be greater than 8 characters in length.
Item d, by itself, might rule out a lot of nicks from ever triggering your PING + echo. Maximum userid length on most IRCds I've ever seen is 10 characters (to include the ~). Most IRCds allow at least numbers in addition to letters. ALL of the above MUST be true or nothing will visibly happen. Are you certain that is what you want? All of those conditions to be true (retain the &&)? Or perhaps if any of them are true (switch the && to ||)?

Perhaps a more sane version of the same code could look similar to this:
Code:

on ^*:JOIN:#:{
  [color:#840017]
  ;  Separate out the userid for multiple uses
  ;[/color]
  var %uid = $gettok($address, 1, 64)
  [color:#840017]
  ;  Color the userid portion bright blue and leave the rest of the join line alone.
  ;[/color]
  echo $color(join) -it $chan * Joins: $nick $+($chr(40),$chr(3),12,%uid,$chr(3),@,$site,$chr(41))
  [color:#840017]
  ;  Use the IF statements to decide whether or not to PING the joining nick or not.
  ;[/color]
  if ((~* iswm %uid) || ($islower(%uid)) || ($len(%uid) > 5) || ($remove(%uid, ~) isalphanum)) $&
    ctcp $nick PING
 
}

* Joins: NickName ([color:#8888FF]~userid@IP12-34-56-78.host.com)[/color]


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
Why are you /who-ing the user on JOIN?

Good point though I overlooked that when I saw all the messy code with global vars.

BTW: Welcome back. grin

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Thanx. laugh


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Mar 2003
Posts: 18
H
H0BB1T Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Mar 2003
Posts: 18
First of all I would like to apologize, since i should have told you first what was this script for before asking about the code. That way you could help me better to find the correct and more efficient way to doing it. Im still learning about this, and sometimes there are better ways to solve a same trouble.
This script was designed to spot the drones as the join channel. Im sure you all know of the troubles we are having to deal with in most of the networks. These drones, infected computers that join IRC to help to spread the infection, usually have the same caractherisitics:
- gibberish userid ( randomly choosen ) of more than 9 characters and unidentified with the server ( ~ )
- alpha userid, no numbers
- all in lowercase
My idea was to create a script to watch them as they join the channel, and then query them to check if they are really "there", or they are drones.
Now that you know why do i need this script for, perhaps you can help me built a more efficient one. So far Watchdog's modifications have solved the trouble and now script works ( thx btw smile ), but perhaps as you mentioned in your reply , there is a better way to do it.
I will be more than happy to go on learning from you all smile

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Here's an idea:
Code:

[color:#840017]
;  If you're not opped, this script will not fire; you couldn't possibly do anything about it if
;  you weren't opped in that channel, so why bother looking?
;  [/color]
on ^@*:JOIN:#:{

  [color:#840017]
  ;  If the userid:
  ;  · starts with a ~
  ;  · is all lower-case alphabetical characters only
  ;  · 8 or 9 characters after the ~
  ;  [/color]
  if ($regex($address, /^(~[a-z]{8,9})@.*$/)) {

    [color:#840017]
    ;  Then reformat the join line to reflect a possible drone join
    ;  [color:#2B5932]* [color:#FF0000][Possible Drone][/color] Joins: Nickname ([color:#FF0000]~abwgohety[/color]@12-34-56-78.host.com)[/color]
    ;  [/color]
    echo $color(join) -it $chan * $+($chr(3),$color(ctcp),[Possible Drone],$chr(3)) $&
      Joins: $nick $+($chr(40),$chr(3),$color(ctcp),$regml(1),$chr(3),@,$site,$chr(41))
    haltdef

    [color:#840017]
    ;  Add their nick to the channel's entry in PossibleDrones.ini to be removed by their
    ;  departure from the channel or by their response to the CTCP VERSION sent them in the next
    ;  step. Using the ctime as the value allows you to check later how long it's been since you
    ;  asked for their version reply (in effect, pinging and VERSIONing at the same time).
    ;  [/color]
    writeini PossibleDrones.ini $chan $nick $ctime

    [color:#840017]
    ;  Quietly send them a CTCP VERSION, which is blocked on clients only by ignoring all CTCPs 
    ;  and slightly less likely to be scripted in on drones.
    ;  [/color]
    .ctcp $nick VERSION
  }
}
  [color:#840017]
;  Now we'll need something to capture the VERSION reply, if there is any.
;  [/color]
on *:CTCPREPLY:VERSION*:{

  [color:#840017]
  ;  %i will be the loop index through $chan(), if necessary.
  ;  %ctime will be used to calculate their ping time from the value stored in the ini file.
  ;  [/color]
  var %i = 1, %ctime = $ctime

  [color:#840017]
  ;  If the userid matches a possible drone, then check each channel and echo out the All-Clear
  ;  for this user.
  ;  [/color]
  if $regex($address, /^(~[a-z]{8,9})@.*$/) {

    [color:#840017]
    ;  Check each channel
    ;  [/color]
    while $chan(%i) {

      [color:#840017]
      ;  Store the current channel in a variable since it will be used past another if statement
      ;  and therefore $ifmatch will be overwritten with a new value.
      ;  [/color]
      var %chan = $ifmatch

      [color:#840017]
      ;  If there is a value stored for this $nick for this %chan, retrieve it
      ;  [/color]
      if ($readini(PossibleDrones.ini, %chan, $nick)) {

        [color:#840017]
        ;  Echo out their ping and version reply
        ;  [/color]
        echo $color(info2) -it %chan * Possible drone $&
          replied in $duration($calc(%ctime - $ifmatch)) «» $2-

        [color:#840017]
        ;  Remove this entry from the ini file.
        ;  [/color]
        .remini PossibleDrones.ini %chan $nick
      }

      [color:#840017]
      ;  Go to the next channel.
      ;  [/color]
      inc %i
    }
  }
}
 [color:#840017]
;  Script self-cleanup
;
;  For every non-me user leaving the channel, either through part, kick or quit:
;  [/color]
on !*:PART:#:{
  [color:#840017]
  ;  If this user matches a possible drone...
  ;  [/color]
  if ($regex($address, /^(~[a-z]{8,9})@.*$/)) {

    [color:#840017]
    ;  Remove their channel/nick entry from the ini file.
    ;  [/color]
    .remini PossibleDrones.ini $chan $nick
  }
}
on !*:KICK:#:{
   [color:#840017]
  ;  If this user matches a possible drone...
  ;  [/color]
  if ($regex($address, /^(~[a-z]{8,9})@.*$/)) {

    [color:#840017]
    ;  Remove their channel/nick entry from the ini file.
    ;  [/color]
    .remini PossibleDrones.ini $chan $nick
  }
}
on !*:QUIT:{

  [color:#840017]
  ;  If this user does not match a possible drone, then stop processing.
  ;  [/color]
  if (!$regex($address, /^(~[a-z]{8,9})@.*$/)) halt

  [color:#840017]
  ;  Otherwise, %i will be the loop index for the common channels.
  ;  [/color]
  var %i = 1

  [color:#840017]
  ;  For each channel you share,
  ;  [/color]
  while $comchan(%i,$nick) {

    [color:#840017]
    ;  Try to remove their entry, whether present or not.
    ;  [/color]
    .remini PossibleDrones.ini $ifmatch $nick

    [color:#840017]
    ;  Go to the next channel.
    ;  [/color]
    inc %i
  }
}

 [color:#840017]
;  If you deop yourself, remove the entries for that channel from the ini file.
;  [/color]
on me:*:DEOP:#: if ($opnick == $me) remini PossibleDrones.ini $chan

 [color:#840017]
;  If you part a channel, remove the entries for that channel from the ini file.
;  [/color]
on me:*:PART:#: remini PossibleDrones.ini $chan

 [color:#840017]
;  If you exit mIRC, remove the entire ini file.
;  [/color]
on *:EXIT: .remove PossibleDrones.ini

Just some thoughts I had in passing how it might be done. You could do much the same thing using a hash table entry using something like network•nick = $ctime #chan1 #chan2 #chan3 to make it multi-network aware, though most likely with drones, it won't matter regardless. Most of their nicks and the channels they go to won't repeat anywhere anyway.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Mar 2003
Posts: 18
H
H0BB1T Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Mar 2003
Posts: 18
thx for the tip smile


Link Copied to Clipboard