mIRC Homepage
Posted By: harl91 More socket help - 13/05/07 04:25 PM
I need some help with this socket script. What I need is on sock read, it finds any games that match its ip (%bot.ip) on tracker.winbolo.net:50005 , it sets the number of players %dead.players and port %dead.port.

If someone could help me get that far, it would be great!

Code:
alais deadgames {
  if (%trk.nick) .notice $nick Busy, try again later.
  else {
    set %trk.nick $nick
    sockopen winbolo tracker.winbolo.net 50005
  }
}
on *:sockopen:winbolo:{
  if ($sockerr) return
  var %d = sockwrite -n $sockname
  %d GET / HTTP/1.1
  %d Host: tracker.winbolo.net
  %d Accept: */*
  %d Connection: Close
}

on *:sockread:winbolo:{

}
alias trk {
  if ($isid) return $+(,$hget(tracker,$1),)
  hadd -m tracker $1-
}
Posted By: deegee Re: More socket help - 14/05/07 01:11 AM
I noticed that there can be several entries from the same address. This script only displays matching info to you, it doesn't set the vars. You can work from here I reckon. smile

Code:
; Note that your alias is mispelled as "alais"
alias deadgames {
  if %trk.nick { .notice $nick Busy, try again later. | return }
  set -e %trk.nick $nick
  sockopen winbolo tracker.winbolo.net 50005
}
on *:sockopen:winbolo:{
  if ($sockerr) return
  var %d = sockwrite -n $sockname
  %d GET / HTTP/1.0
  %d Host: tracker.winbolo.net
}
on *:sockread:winbolo:sockread &a | bwrite deadgames.txt -1 -1 &a
on *:sockclose:winbolo:{
  var %i = 1
  .fopen wb deadgames.txt
  while !$feof {
    .fseek -r wb /winbolo:\/\/ $+ %bot.ip $+ :/i
    if $fread(wb) { echo -a * Do whatever with: $striphtml($v1) }
  }
  .fclose wb
  .remove deadgames.txt
  unset %trk.nick
}
alias striphtml {
  var %return, %regex = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,,%return)
  return $remove(%return,&nbsp;,$chr(9),amp;)
}

Posted By: harl91 Re: More socket help - 14/05/07 03:01 PM
sweet thanks but there is something wrong
It only work half the time, and i keep getting this error:
/sockopen: 'winbolo' socket in use (line 816, script.ini)

in this code when i type /timer2 1 300 /deadgames
it should keep doing this every 5 minutes but it halts becuase of that /sockopen error.

Can someone fix please!

Code:
alias deadgames {
  if %trk.nick { .notice $nick Busy, try again later. | return }
  set -e %trk.nick $nick
  sockopen winbolo tracker.winbolo.net 50005
}
on *:sockopen:winbolo:{
  if ($sockerr) return
  var %d = sockwrite -n $sockname
  %d GET / HTTP/1.0
  %d Host: tracker.winbolo.net
}
on *:sockread:winbolo:sockread &a | bwrite deadgames.txt -1 -1 &a
on *:sockclose:winbolo:{
  var %i = 1
  .fopen wb deadgames.txt
  while !$feof {
    .fseek -r wb /winbolo:\/\/ $+ %bot.ip $+ :/i
    if $fread(wb) { 
      var %info = $striphtml($v1)
      tokenize 58 %info
      set %killport $left($3,5)
      set %play $right($left($5,2), -1)
      if (%play == 0) {
        var %nick1 = $wildtok( %used.ports, * $+ %killport $+ * , 1, 44)
        var %place = $findtok( %used.ports , %nick1 ,1 ,44)
        set %used.ports $deltok(%used.ports, %place, 44) 
        /run $mircdir $+ wonkaDSctl.exe quit %killport
        msg #winbolo $me AutoKilled %killport
      }
    }
  }
  timer2 1 300 /deadgames
  .fclose wb
  .remove deadgames.txt
  unset %trk.nick
}
alias striphtml {
  var %return, %regex = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,,%return)
  return $remove(%return,&nbsp;,$chr(9),amp;)


otherwise the times it works (like 1/4 times) it works fine. But that error is a hassel.
Posted By: harl91 Re: More socket help - 15/05/07 12:23 AM
basicaly what im asking is so that before the socket is opened, its closed WITHOUT any of the events on sockclose going off.
Posted By: chiram Re: More socket help - 17/05/07 08:36 PM
to treat the symptoms instead of the problem.. in your alias deadgames just add

if ($sock(winbolo)) { sockclose winbolo | unset %trk.nick }

and you won't get the error that the socket is in use, it also won't trigger the on sockclose event that is only when the socket is closed by the remote host. I added the unset %trk.nick to counter what i think is your odd method of deciding if it was trying to retrieve stats already.

not sure what the actual problem would be it seems that webserver sends all data when connection is opened before the "GET / HTTP/1.0" is sent so no need for that in script. And it seems the webserver closes connection instantly after sending that data. Possibly the server is having an issue and not sending data or closing the connection 1/4 times for you? If so treating the symptoms is fine..
© mIRC Discussion Forums