westor

Worldtracker v1.0 for Joseph

Jul 13th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 6.22 KB | None | 0 0
  1. ; Fixed by westor on 14/07/2017 02:00
  2.  
  3. alias -l active_channels return #test_chan
  4. alias -l mynick return Announcer
  5. alias -l ignored_worlds return
  6. alias -l show_country return 1
  7. alias -l show_class return 1
  8. alias -l show_pvp return 1
  9. alias -l show_clan return 1
  10. alias -l show_total_players return 1
  11.  
  12. on $*:text:/^!tracker +(off|stop)/iS:$($active_channels): {
  13.   if ($nick !isop #) || ($me !== $mynick) return
  14.   if ($timer(worldcheck)) { .timerworldcheck off | .timerworldmsg off }
  15.   if ($window(@rb_output)) { window -c @rb_output }
  16.   cleanup wtracker
  17.   cleanup checkpop
  18.   msg $active_channels Tracker was killed by $nick $+ .
  19. }
  20.  
  21. on $*:text:/^!tracker +(\d+) +(\d+)/Si:$($active_channels):{
  22.   if ($nick !isop #) || ($me !== $mynick) return
  23.   var %diff $regml(1)
  24.   var %secs = $regml(2)
  25.  
  26.   trackstart %diff %secs
  27. }
  28.  
  29. alias trackstart {
  30.   ;/trackstart <difference> <interval>
  31.  
  32.   var %diff $1, %secs $2
  33.  
  34.   ;avoid hammering the server, any more frequently wouldn't be very useful anyway
  35.   if (%secs <= 10) var %secs 10
  36.  
  37.   ;if the difference is too low the bot might have more lines to send than flood limits allow
  38.   if (%diff <= 10) var %diff 10
  39.  
  40.   if (!$hget(wtracker)) { hmake wtracker 300 | hadd wtracker silent 1 }
  41.   hadd wtracker diff %diff
  42.  
  43.   .timerworldcheck 0 %secs checkpop
  44.   .timerworldmsg 0 3 re_msg
  45.   msg $active_channels Tracker booted up by $iif($nick, $nick, $me) checking for a difference of %diff players every $duration(%secs) $+ .
  46.  
  47. }
  48.  
  49. alias checkpop {
  50.   if ($sock(checkpop).to > 10) cleanup checkpop
  51.   elseif ($sock(checkpop)) return
  52.   sockopen checkpop oldschool.runescape.com 80
  53. }
  54.  
  55.  
  56.  
  57. ;<SReject>
  58. on *:sockopen:checkpop:{
  59.   if ($sockerr) {
  60.     echo -st World tracker sockopen sockerr: $sock($sockname).wsmsg
  61.     cleanup $sockname
  62.   }
  63.   else {
  64.     var %n = sockwrite -nt $sockname
  65.     %n GET /slu HTTP/1.1
  66.     %n Host: oldschool.runescape.com
  67.     %n Connection: close
  68.     %n Cache-control: no-cache
  69.     %n
  70.  
  71.     var %age $calc($ctime - $hget(wtracker, time))
  72.     hadd wtracker time $ctime
  73.     if (!$hget(wtracker,silent)) { hadd wtracker silent $iif(%age > 600, $true, $false) }
  74.   }
  75. }
  76. on *:SOCKWRITE:checkpop:{
  77.   if ($sockerr) {
  78.     echo -st World tracker sockwrite sockerr: $sock($sockname).wsmsg
  79.     cleanup $sockname
  80.   }
  81. }
  82. on *:SOCKREAD:checkpop:{
  83.   if ($sockerr) {
  84.     echo -st World tracker sockread sockerr: $sock($sockname).wsmsg
  85.     cleanup $sockname
  86.   }
  87.   else {
  88.     noop $hget($sockname, data, &data)
  89.     sockread $sock($sockname).rq &read
  90.     bcopy &data $calc($bvar(&data, 0) +1) &read 1 -1
  91.     hadd -mb $sockname data &data
  92.   }
  93. }
  94. on *:SOCKCLOSE:checkpop:{
  95.   if ($sockerr) {
  96.     echo -st World tracker sockclose sockerr: $sock($sockname).wsmsg
  97.   }
  98.   elseif (!$hget($sockname, data, &data)) {
  99.     echo -st World tracker parse error: No Data recieved
  100.   }
  101.  
  102.   ;; find end of headers
  103.   elseif ($bfind(&data, 1, 13 10 13 10)) {
  104.     var %body_start = $calc($v1 + 4)
  105.  
  106.     ;; check response status
  107.     ;echo -s >> $bvar(&data, 1, 12).text
  108.  
  109.     if (HTTP/1.1 200 ?* !iswmcs $bvar(&data, 1, 14).text) {
  110.       echo -st World tracker parse error: Server Response $bvar(&data, 1, $bfind(&data, 1, 13 10)).text
  111.     }
  112.     else {
  113.  
  114.       ;; find the <tbody tag and clip everything before it
  115.       var %table_start = $bfind(&data, %body_start, <tbody)
  116.       bcopy -c &data 1 &data %table_start -1
  117.  
  118.       ;; find the </tbody tag and clip everything after it
  119.       var %table_end = $calc($bfind(&data, 1, </tbody) + 7)
  120.       bcopy -c &data 1 &data 1 %table_end
  121.  
  122.       ;; write to file
  123.       bwrite checkpop.txt 0 -1 &data
  124.       filter -fk checkpop.txt check_filter *
  125.       .copy -fo checkpop.txt checkpop_OLD.txt
  126.       .remove checkpop.txt
  127.       unset %checkpop_*
  128.       if ($hget(wtracker,silent)) { hdel wtracker silent }
  129.     }
  130.   }
  131.   else {
  132.     echo -st World tracker parse error: Invalid response(No header truncation)
  133.   }
  134.   cleanup $sockname
  135. }
  136.  
  137.  
  138. alias -l cleanup {
  139.   if ($sock($1)) sockclose $1
  140.   if ($hget($1)) hfree $1
  141.   unset %checkpop_*
  142. }
  143. ;</SReject>
  144. alias -l check_filter {
  145.   tokenize 32 $fixtab($strip($1-))
  146.   ;echo -a IS: $1-
  147.  
  148.   if (</tr> isin $1-) && (%checkpop_world) && (%checkpop_players) && ($timer(worldmsg)) {
  149.     var %w = @rb_output
  150.     if (!$window(%w)) { window -h %w }
  151.  
  152.     var %old = $hget(wtracker,%checkpop_world)
  153.     var %diff $calc(%checkpop_players - %old)
  154.  
  155.     ; echo -a World %checkpop_world $+ : % $+ old = %old ---- % $+ diff = %diff ---- % $+ checkpop_players = %checkpop_players ---- $!hget(wtracker,diff) = $hget(wtracker,diff)
  156.  
  157.     hadd wtracker %checkpop_world %checkpop_players
  158.  
  159.     if (!$hget(wtracker, silent)) && (!$istok($ignored_worlds, %checkpop_world, 44)) && (%diff !== %old) && ($abs(%diff) >= $hget(wtracker,diff)) {
  160.       aline -n %w World: %checkpop_world $+($chr(3), $iif($left(%diff,1) == -, 04, 03+), %diff, $chr(3)) $iif($show_total_players,( $+ %checkpop_players $+ )) $iif(%checkpop_class, $+ $v1) $iif(%checkpop_country, - $v1) $iif(%checkpop_pvp, - $v1) $iif(%checkpop_clan, - $v1)
  161.     }
  162.  
  163.     unset %checkpop_*
  164.   }
  165.   if (<tr isin $1-) && (--pvp isin $1-) && ($show_pvp) { set %checkpop_pvp (7PVP) }
  166.   if (<a id='* iswm $1-) && (*class='* iswm $1-) && (*href='* iswm $1-) {
  167.     var %n = $remove($1-,</a>)
  168.     set %checkpop_world $gettok(%n,$numtok(%n,32),32)
  169.   }
  170.   if ($regex($1-, /(\d+) players<\/td/i)) { set %checkpop_players $regml(1) }
  171.   if (*country* iswm $1-) && ($show_country) { set %checkpop_country (6 $+ $nohtml($1-) $+ ) }
  172.   if (*'>Members</td>* iswm $1-) && ($show_class) { set %checkpop_class (2P2P) }
  173.   if (*'>Free</td>* iswm $1-) && ($show_class) { set %checkpop_class (5F2P) }
  174.   if (*--country* !iswm $1-) && ($show_clan) && (*--type* !iswm $1-) && (*players</td>* !iswm $1-) && (*</td>* iswm $1-) && (*__row-cell* iswm $1-) {
  175.     var %clan = $nohtml($1-)
  176.     if (%clan !== -) { set %checkpop_clan (10 $+ %clan $+ ) }
  177.   }
  178. }
  179.  
  180. alias -l fixtab { return $replace($1-,$chr(9),$chr(32),$chr(10),$chr(32),$chr(13),$chr(32)) }
  181. alias -l nohtml { return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,) }
  182. alias re_msg {
  183.   var %w = @rb_output
  184.   if (!$window(%w)) || (!$line(%w,0)) || (!$timer(worldcheck)) || (!$timer(worldmsg)) { return }
  185.   var %l = $line(%w,1)
  186.   if (%l) { dline %w 1 | .msg $active_channels %l }
  187. }
Add Comment
Please, Sign In to add comment