Battlefield 2 server informer

By Daveoh on Jun 09, 2006

This grabs information about a BF2 server and displays it to the channel requested from.
Requires IP and port number formatted as IP:port.
Includes name, players, ranking and password status, booster pack, map and ping.

;Battlefield 2 server informer
;Made by Daveoh on Quakenet @ #kidswithguns
;Thanks to game-monitor.com for providing server stats!
;Edit to how seen fit, but please include these first four lines :)

on *:TEXT:!bf2query*:#:{ if (%bf2query.spam) { halt } | set -u10 %bf2query.spam 1
  if ($1- == !bf2query) { msg $chan Usage: !bf2query IP:PORT | halt }
  unset %bf2query.*
  if (c isincs $chan($chan).mode) { set %bf2query.spacer $chr(124) } | else { set %bf2query.spacer $+(,$chr(124),) }
  if ($sock(bf2query)) { msg $chan Socket in use, attempting to close... | sockclose bf2query | if ($sock(bf2query)) msg $chan Unable to close socket, halting... | halt }
  set %bf2query.ip $2
  set %bf2query.chan $chan
  set %bf2query.1 1
  sockopen bf2query game-monitor.com 80
}
on *:sockopen:bf2query:{ 
  sockwrite -n $sockname GET $iif(%bf2query.loc,%bf2query.loc,$+(/GameServer/,%bf2query.ip,/)) HTTP/1.0
  sockwrite -n $sockname Host: game-monitor.com
  sockwrite -n $sockname user-agent: Mozilla/??
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname $crlf
}
on 1:sockread:bf2query:{
  :nextread
  if ($sockerr > 0) return
  sockread %temp
  if ($sockbr == 0) return
  ;if (%temp) echo @temp %temp
  if ($len(%temp) < 250) { var %temp = $remove(%temp,   ) }

  if (Location:* iswm %temp) { set %bf2query.loc $gettok(%temp,2,32) }
  if (<b>Server Not in Database:</b> == %temp) { msg %bf2query.chan Sorry, server not in database | unset %bf2query.* | sockclose bf2query | halt }
  if (<td colspan="2"><b>Game:</b>* iswm %temp && BattleField 2 !isin %temp) { msg %bf2query.chan Error: This is not a Battlefield 2 server | unset %bf2query.* | sockclose bf2query | halt } 

  if (<tr><th width="20%">Server Variable</th><th width="80%">Value</th></tr> == %temp && %bf2query.1 == $null) { set %bf2query.allowvars 1 }
  if (average_latency isin %temp && %bf2query.allowvars) { set %bf2query.ping $remove($gettok(%temp,4,47),td><td>,<) }
  if (bf2_mapsize isin %temp && %bf2query.allowvars) { set %bf2query.mapsize $remove($gettok(%temp,4,47),td><td>,<) }
  if (bf2_ranked isin %temp && %bf2query.allowvars) { set %bf2query.ranked $remove($gettok(%temp,4,47),td><td>,<) }
  if (bf2_reservedslots isin %temp && %bf2query.allowvars) { set %bf2query.reserved $remove($gettok(%temp,4,47),td><td>,<) }
  if (booster_pack isin %temp && %bf2query.allowvars) { set %bf2query.booster $remove($gettok(%temp,4,47),td><td>,<) }
  if (hostname isin %temp && %bf2query.allowvars) { set %bf2query.hostname $remove($gettok(%temp,7-,62),</td></tr) }
  if (mapname isin %temp && %bf2query.allowvars) { set %bf2query.mapname $remove($gettok(%temp,4,47),td><td>,<) }
  if (maxplayers isin %temp && %bf2query.allowvars) { set %bf2query.maxplayers $remove($gettok(%temp,4,47),td><td>,<) }
  if (numplayers isin %temp && %bf2query.allowvars) { set %bf2query.numplayers $remove($gettok(%temp,4,47),td><td>,<) }
  if (password isin %temp && %bf2query.allowvars) { set %bf2query.password $remove($gettok(%temp,4,47),td><td>,<) | set %bf2query.done 1 }

  if (%bf2query.done == 1) { msg %bf2query.chan Hostname: %bf2query.hostname %bf2query.spacer $iif(%bf2query.ranked,Ranked,Unranked) & $iif(%bf2query.password == 0,public,passworded) %bf2query.spacer $iif(%bf2query.booster,Booster pack: %bf2query.booster %bf2query.spacer) Players: %bf2query.numplayers $+ / $+ %bf2query.maxplayers ( $+ %bf2query.reserved $+ ) %bf2query.spacer Map: %bf2query.mapname ( $+ %bf2query.mapsize $+ ) %bf2query.spacer Ping: %bf2query.ping | unset %bf2query.* | sockclose bf2query | halt }

  goto nextread
}
on 1:sockclose:bf2query:{
  if (%bf2query.1 == 1) { unset %bf2query.1 | if ($sock(bf2query)) sockclose bf2query | sockopen bf2query game-monitor.com 80 }
}

Comments

Sign in to comment.
Daveoh   -  Jun 10, 2006

Script updated: Changes depending on channel mode and contains number of reserved slots

 Respond  
ubermensch   -  Jun 10, 2006

This is good :) It cannot be used in +c channels because of some small colour formatting, but I expect this can be removed.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.