Jump to content

Home

Looking for Server Query Info


MyKell

Recommended Posts

This does not directly affect JA Coding, but seems like the most likely place to post...

 

I am working on an RCON program for JKA. I host 3 servers and monitor a couple other and have found the current RCON programs are just not enough.

 

I have a working RCON program based off RCON Commander from SEVERAL years ago. I have rewritten (not converted) in vb.net. I have a snappy display and can send and received RCON commands.

 

I would like to add monitoring area similar to what RCON Unlimited uses. From what I understand, RCON Unlimited queries the server for non RCON server info or configstrings. It returns a line to text in a format like this:

 

\sv_maxclents\20\sv_hostname\Jedi Knight\

 

I am very unsure of the info I would send the server or even where I would send it. I have been told I have to query a master server such as gamespy and I have been told I have to query the server directly.

 

Can anyone point me in the right direction? I have looked, but I am unsure how to proceed.

 

I am a medium programmer with HEAVY focus on inventory databases and accounting software. This game query stuff is new to me. Any code help in vb6 or vb.net would be wonderfull.

 

Thank you

Link to comment
Share on other sites

are you looking into doing it for PHP/ Perl or something else?

 

if php here's an example getstatus function which u can use:

 

function getstatus($server, $port = 29070)
{
   if (!($fd = @fsockopen("udp://$server", $port, $errno, $errstr, 3)))
       return FALSE;

   stream_set_timeout($fd, 3, 0);

   # challenge?

   fwrite($fd, "\xff\xff\xff\xffgetstatus " . rand());

   # getstatus reply should always come as a single (possibly
   # fragmented) datagram
   if (!($buf = @fread($fd, 4096))) {
       echo("Server is not responding<br>\n");
       return FALSE;
   }

   $parts = explode("\n", $buf);

   if ($parts[0] != "\xff\xff\xff\xffstatusResponse") {
       echo("bad response<br>\n");
       return FALSE;
   }

   # build an array of all the serverinfo keys
   $infostring = explode("\\", $parts[1]);
   array_shift($infostring);

   $side = 0;

   while (list($idx, $str) = each($infostring)) {
       if ($side == 0)
           $key = $str;
       else
           $info[$key] = $str;

       $side ^= 1;
   }

   # build an array of all the players
   # start by shifting off the response header and the serverinfo
   array_shift($parts);
   array_shift($parts);


   # and then looping through what's left
   while (list($idx, $str) = each($parts)) {
       if ($str == "")
           break;

       $playerparts = explode("\"", $str);
       $playerinfo = $playerparts[0];
       $name = $playerparts[1];

       $scoreping = explode(" ", $playerinfo);
       $score = $scoreping[0];
       $ping = $scoreping[1];

       $playerlist[$idx]['slot'] = $slot;
       $playerlist[$idx]['team'] = $team;
       $playerlist[$idx]['score'] = $score;
       $playerlist[$idx]['ping'] = $ping;
       $playerlist[$idx]['name'] = $name;
   }

   return array(info => $info, players => $playerlist);
}

 

u basically call something like this above all the printing stuff:

 

$ip = "your.ip.goes.here";
$port = "29070";
$status = getstatus($ip, $port);

 

to get a cvar u would do something like this:

<?php printf("%s", $status['info']['sv_hostname']); ?>

 

because there isnt another easy way to do this here's my example way of getting player count (not sure its 100% correct)

 

<?php
if ($status['players']) {
       uasort($status['players'], sort_by_score_desc);

	$playercount=0;
	while (list($idx, $curplayer) = each($status['players'])) {
		$playercount++;
   	}
	$status['info']['sv_currentclients']=$playercount;
}
?>

 

(just print out the sv_currentclients cvar if u use this method)

 

 

basically this is how i print out players:

 

       <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
        <tr>
          <td align="left"><font size="2" color="#EEEEEE"><b><u>Players</u></b></font></td>
          <td width="30" align="center"><font size="2" color="#EEEEEE"><b><u>Score</u></b></font></td>
          <td width="30" align="center"><font size="2" color="#EEEEEE"><b><u>Ping</u></b></font></td>
        </tr>

	<?php
if ($status['players']) {
       uasort($status['players'], sort_by_score_desc);

	while (list($idx, $curplayer) = each($status['players'])) {
       printf(" <tr>\n<td align=left><font size=2>%s</font></td><td width=30 align=center><font size=2>%d</font></td><td width=30 align=center><font size=2>%d</font></td></tr>\n",
           $curplayer['name'],
           $curplayer['score'],
           $curplayer['ping']);
   	}
}
	?>
      </table>

 

now,,, you might want to colorize say the hostname or player names so:

 

<?php
$osp_colors = array(
   0 => "#666666", // to show black text on black bg...
   //0 => "#000000",
   1 => "#ff0000",
   2 => "#00ff00",
   3 => "#ffff00",
   4 => "#0000ff",
   5 => "#00ffff",
   6 => "#ff00ff",
   7 => "#ffffff", // maybe change this if you use a white bg
   8 => "#ff7f00",
   9 => "#7f7f7f",
   10 => "#bfbfbf",
   11 => "#bfbfbf",
   12 => "#007f00",
   13 => "#7f7f00",
   14 => "#00007f",
   15 => "#7f0000",
   16 => "#7f3f00",
   17 => "#ff9919",
   18 => "#007f7f",
   19 => "#7f007f",
   20 => "#007fff",
   21 => "#7f00ff",
   22 => "#3399cc",
   23 => "#ccffcc",
   24 => "#006633",
   25 => "#ff0033",
   26 => "#b21919",
   27 => "#993300",
   28 => "#cc9933",
   29 => "#999933",
   30 => "#ffffbf",
   31 => "#ffff7f"
);

function colorize($text)
{
   global $osp_colors;

   $curcolor = -1;
   $nextcolor = 7;

   for ($x = 0; $x < strlen($text); $x++) {
       if ($text[$x] == '^' && $text[$x + 1] != '^') {
           $nextcolor = (ord($text[$x + 1]) + 16) & 31;
           $x++;
           continue;
       }
       if ($curcolor != $nextcolor) {
           if ($curcolor != -1)
               $buf .= "</font>";
           $curcolor = $nextcolor;
           $buf .= sprintf("<font color=\"%s\">", $osp_colors[$curcolor]);

       }
	//$chars = "¤";
       $buf .= htmlspecialchars($text[$x]);
   }

   if ($curcolor != -1)
       $buf .= "</font>";
   return $buf;
}

 

just do something like this:

 

<?php printf("%s", colorize($status['info']['sv_hostname'])); ?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...