mIRC Homepage
Posted By: fallen248 ftp checker problems - 17/05/05 02:59 PM
Ok so i attempted to take this script i had already written to check an ftp and apply it to all the ftps on a list. However it still seems to stop after the first one. All the variables in this script are fine i just need help with the actual script. the ftp checking part if someone could please help me to correct it i would greatly appreciate it.


on *:TEXT:!chkall:?:{
if ($nick isop %channame) {
/set %identchk $readini(%usersfile, $nick, Status)
if (%identchk > 1) || (%identchk == $null) {
.timer $+ $rand(200, 50000) 1 2 /msg $nick Y ou must identify with the bot before using this command.
/halt
} else {
if $2 == rewt { /notice %nick Im sorry but that ftp is local to me and cannot be checked. }
/remove downusers
/set %total $ini(%sitesfile, 0)
/set %errorchk 0
/inc %total 1
/set %count 1
while (%count != %total) {
/set %nick $nick
/set %check $ini(%sitesfile, %count)
/set %ftpusername $readini(%sitesfile, %check, User)
/set %ftppassword $readini(%sitesfile, %check, Notes)
/set %ftpipaddress $readini(%sitesfile, %check, IP)
/set %ftpport $readini(%sitesfile, %check, Port)
/set %ftppassword $remove(%ftppassword,Password: )
/sockopen ftpcheck %ftpipaddress %ftpport
}
}
}

on 1:sockopen:ftpcheck:{
if ($sockerr > 0) {
.timer $+ $rand(200, 50000) 1 2 /msg %nick Connection failed to %check
/set %temp.22 $readini(%sitesfile, %check, Catagory)
/set %temp.22 $readini(%sitesfile, %check, Catagory)
if (Down isin %temp.22) {
/writeini -n %usersfile %check Status 3

} else
if ($nick ishop %channame) || ($nick isvoice %channame) {
/writeini -n %sitesfile %check OldCategory %temp.22
/writeini -n %sitesfile %check Catagory Down
/writeini -n %usersfile %check Status 3

}
}
/sockwrite -n ftpcheck USER %ftpusername
/sockwrite -n ftpcheck PASS %ftppassword
}

on *:sockread:ftpcheck:{
if ($sockerr > 0) return
:nextread
sockread %temp
if ($sockbr == 0) return
if (%temp == $null) %temp = -

if (denied isin %temp) {
.timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
/sockclose ftpcheck
/set %temp.22 $readini(%sitesfile, %check, Catagory)
if (Down isin %temp.22) {
/writeini -n %usersfile %check Status 3

}
else {
/writeini -n %sitesfile %check OldCategory %temp.22
/writeini -n %sitesfile %check Catagory Down
/writeini -n %usersfile %check Status 3

}

}

if (logged in isin %temp) {
.timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
/sockclose ftpcheck
.timer $+ $rand(200, 50000) 1 2 /msg %nick %check $+ 's FTP Is Up!
if ($readini(%usersfile, %check, Status) == 3) {
/set %temp.23 $readini(%sitesfile, %check, OldCategory)
/writeini -n %sitesfile %check Catagory %temp.23
/writeini -n %usersfile %check Status 2

}

}

if (incorrect isin %temp) {
.timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
/sockclose ftpcheck
/set %temp.22 $readini(%sitesfile, %check, Catagory)
if (Down isin %temp.22) {
/writeini -n %usersfile %check Status 3
/halt
} else {
/writeini -n %sitesfile %check OldCategory %temp.22
/writeini -n %sitesfile %check Catagory Down
/writeini -n %usersfile %check Status 3
}

}
if (too many isin %temp) {
.timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
.timer $+ $rand(200, 50000) 1 2 /msg %nick %check $+ 's FTP Is Up!
if ($readini(%usersfile, %check, Status) == 3) {
/set %temp.23 $readini(%sitesfile, %check, OldCategory)
/writeini -n %sitesfile %check Catagory %temp.23
/writeini -n %usersfile %check Status 2

}
/sockclose ftpcheck

}
echo 4 %temp
goto nextread
}


also i know category is spelled wrong, im going to correct that. smile
Posted By: fallen248 Re: ftp checker problems - 19/05/05 04:20 AM
anybody?
Posted By: DaveC Re: ftp checker problems - 19/05/05 07:22 AM
There are several problems with this, also the way you displayed it without any [ code ] & [ /code ] markers sure didnt help you to get any help, makes it real hard to read with it all against one wall.

Anyway, problems i saw.
(1) on *:TEXT:!chkall:?: ~~ event is missing a final close } thus all the other stuff is part of it and not events of there own. the code being in your first event doesnt run since you have an error before that, see problem (2)

(2) while (%count != %total) ~~ this loop does not advance the %count value, it is not incremented at the end of the loop, this normally causes a endless loop, however you dont get one becuase of problem (3)

(3) /sockopen ftpcheck %ftpipaddress %ftpport ~~ wheather problem (2) was fixed or not, you cant sockopen ftpcheck a second time, as your already using it from the first site. This error well stop the script and save you from problem (2) endless loop

(4) Overall ~~ The concept you have attempted is to open all the sites at once, and then process them, This well not work even if u assigned sepearte socket names, since you then refrence %check from the TEXT event, which you have already changed.

I have taken a shoot at fixing this, I dont think it well be perfect, but it might send you in the right direction.
I renamed the socket to "ftpcheck>$nick>%check" as a cheap method of passing them values to the socket events and as a way to make unique socket names.

I also remarked up a few lines i noticed.

Code:
on *:TEXT:!chkall:?:{
  if ($nick isop %channame) {
    /set %identchk $readini(%usersfile, $nick, Status)
    if (%identchk > 1) || (%identchk == $null) {
      .timer $+ $rand(200, 50000) 1 2 /msg $nick  Y ou must identify with the bot before using this command.
      /halt
    } 
    else {
      ;if $2 == rewt { /notice $nick Im sorry but that ftp is local to me and cannot be checked. }
      ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----[ this cant happen as there is no $2 in this event ]
      /remove downusers
      /set %total $ini(%sitesfile, 0)
      /set %errorchk 0
      /inc %total 1
      /set %count 1
      while (%count < %total) {
        /set %check $ini(%sitesfile, %count)
        /set %ftpipaddress $readini(%sitesfile, %check, IP)
        /set %ftpport $readini(%sitesfile, %check, Port)
        /sockopen $+(ftpcheck>,$nick,>,%check) %ftpipaddress %ftpport
        inc %count
      }
    }
  }
}
on 1:sockopen:ftpcheck>*:{
  var %nick =  $gettok($sockname,2,$asc(>))
  var %check = $gettok($sockname,3,$asc(>))
  if ($sockerr > 0) {
    .timer $+ $rand(200, 50000) 1 2 /msg %nick Connection failed to %check
    /set %temp.22 $readini(%sitesfile, %check, Catagory)
    /set %temp.22 $readini(%sitesfile, %check, Catagory)
    if (Down isin %temp.22) {
      /writeini -n %usersfile %check Status 3
    } 
    else {
      if ($nick ishop %channame) || ($nick isvoice %channame) {
        ;-^^^^^----------------------^^^^^--------------------------[ I dont know if this is ment to be $nick which is likely to be $me for this event, or nick ]
        /writeini -n %sitesfile %check OldCategory %temp.22
        /writeini -n %sitesfile %check Catagory Down
        /writeini -n %usersfile %check Status 3
      }
    }
  }
  else {
    /set %ftpusername $readini(%sitesfile, %check, User)
    /set %ftppassword $readini(%sitesfile, %check, Notes)
    /set %ftppassword $remove(%ftppassword,Password: )
    /sockwrite -n $sockname USER %ftpusername
    /sockwrite -n $sockname PASS %ftppassword
  }
}
on *:sockread:ftpcheck>*:{
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  if (denied isin %temp) {
    .timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
    /sockclose $sockname
    /set %temp.22 $readini(%sitesfile, %check, Catagory)
    if (Down isin %temp.22) {
      /writeini -n %usersfile %check Status 3
    } 
    else {
      /writeini -n %sitesfile %check OldCategory %temp.22
      /writeini -n %sitesfile %check Catagory Down
      /writeini -n %usersfile %check Status 3
    }
  }
  if (logged in isin %temp)   {
    .timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp 
    /sockclose $sockname
    .timer $+ $rand(200, 50000) 1 2 /msg %nick %check $+ 's FTP Is Up!
    if ($readini(%usersfile, %check, Status) == 3) {
      /set %temp.23 $readini(%sitesfile, %check, OldCategory)
      /writeini -n %sitesfile %check Catagory %temp.23
      /writeini -n %usersfile %check Status 2
    }
  }
  if (incorrect isin %temp) {
    .timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
    /sockclose $sockname
    /set %temp.22 $readini(%sitesfile, %check, Catagory)
    if (Down isin %temp.22) {
      /writeini -n %usersfile %check Status 3
      /halt
      } else {
      /writeini -n %sitesfile %check OldCategory %temp.22
      /writeini -n %sitesfile %check Catagory Down
      /writeini -n %usersfile %check Status 3
    }
  }
  if (too many isin %temp) {
    .timer $+ $rand(200, 50000) 1 2 /msg %nick returned: %temp
    .timer $+ $rand(200, 50000) 1 2 /msg %nick %check $+ 's FTP Is Up!
    if ($readini(%usersfile, %check, Status) == 3) {
      /set %temp.23 $readini(%sitesfile, %check, OldCategory)
      /writeini -n %sitesfile %check Catagory %temp.23
      /writeini -n %usersfile %check Status 2
    }
    /sockclose $sockname
  }
  echo 4 %temp
  goto nextread
}


Some last things...
. you dont need to put / on the front of commands ie: /sockopen and sockopen in a script is the same. / and // are only needed from the mirc command prompt.
. use dont use set %value 1234 if you dont need that value saved outside the running script use var %value = 1234 this way it exists only during the running script (note the = in the var usage)
. .timer $+ rand(200,50000) migth as well just be .timer as a timer well create a free number to use, you really should not be using numbers as timer names anyway, if you must do it do this .timer. $+ rand(200,50000) this way the "name" of the timer well be ex .2345 which is not a number.
. I dont really see the purpose of delaying the MSG to the nick for 2 seconds anyway
Posted By: fallen248 Re: ftp checker problems - 19/05/05 05:23 PM
ok, this seems to work with only one problem. each time i run it. it seems to not change the responce once an ftp is found up. for instance here is a portion of one of the outputs

infinite's FTP Is Up!
Connection failed to notc4
infinite's FTP Is Up!
returned: 230 User logged in, proceed.
infinite's FTP Is Up!
returned: 230 User EWG logged in.
Connection failed to HeadHntR
returned: 230 User ftp logged in.
infinite's FTP Is Up!
returned: 230 User ftpx logged in.
infinite's FTP Is Up!
infinite's FTP Is Up!
infinite's FTP Is Up!
returned: 230 User xptf logged in.
returned: 220-4 users logged in within the last 24 hours.
returned: 230 User test logged in.

so all users that come back as Up it list's as infinite it seems...here is a portion of a second output:

Connection failed to FukYea
Connection failed to HeadHntR
punk-roc's FTP Is Up!
punk-roc's FTP Is Up!
punk-roc's FTP Is Up!
returned: 230 User ftpx logged in.
punk-roc's FTP Is Up!
returned: 230 User xptf logged in.
returned: 230 User ftp logged in.
returned: 230 User logged in, proceed.
returned: 530 Login or Password incorrect.
punk-roc's FTP Is Up!
returned: 230 User test logged in.

in that one puk-roc keeps being repeated as the users nick
Posted By: DaveC Re: ftp checker problems - 20/05/05 07:45 AM
Opps!

locate

Code:
on *:sockread:ftpcheck>*:{


and replace with

Code:
on *:sockread:ftpcheck>*:{
  var %nick =  $gettok($sockname,2,$asc(>))
  var %check = $gettok($sockname,3,$asc(>))


i forgot to add the creating of these in the socketread event, they need to be extracted from the socketname the same as they were in the sockopen event.
© mIRC Discussion Forums