Jump to content
Sign in to follow this  
xSkaSchY

UDP Socket Query

Recommended Posts

Hello Guys,

im currently working on a new server monitoring plus web interface for a linux dedicated server.

As soon it is possible i'll release a demo version.

At this point of work i have a problem while fetching some player informations via udp sockets.

Is it possible to get the player-id?

Any suggestions?

Greetigs Toby

Share this post


Link to post
Share on other sites

there no way of grabbing the player-id via a server query.

the only option is parsing the logfile.

Share this post


Link to post
Share on other sites

hey jerry,

yes i currently use this way, but thats not the finest. smile_o.gif

Share this post


Link to post
Share on other sites

if i might ask, what do you use for parsing the logs?

i have some unfinished python scripts that eventually would be part of a remote server tool.

Do you wrote your tool in python or maybe perl?

Share this post


Link to post
Share on other sites

i write the GUI in PHP, and some scripts in bash, like start / stop.

For parsing i use php too. its a very powerful language.

by the way: the log file, server_console.log, r only up-to-date if the server restarts sad_o.gif No live logs?

Share this post


Link to post
Share on other sites

I'm very interresting to know what are commands you sent to the dedicated server to get players names and others infos, port query... etc...

are there theses informations somewhere ?

Thanks a lot wink_o.gif

Share this post


Link to post
Share on other sites

Here is a small sample:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

<?php

$sHostaddr = '62.75.129.36';

$iPort = 2302;

if ($iWaittime < 500) $iWaittime = 500;

if ($iWaittime > 2000) $iWaittime = 2000;

$iWaittime = doubleval($iWaittime / 1000.0);

$rConnection = @fsockopen('udp://' . $sHostaddr, $iPort, &$iErrorNo, &$sErrorStr);

if (!$rConnection) {

die('Socket Error [' . $sHostaddr . ':' . $iPort. '] [' . $iErrorNo . '] - ' . $sErrorStr);

}

socket_set_blocking($rConnection, true);

$sCommand = pack("c*",0xFE,0xFD,0x00,0x04,0x05,0x06,0x07,0xFF,0xFF,0xFF);

$sSignature = pack("c*",0x00,0x04,0x05,0x06,0x07);

$sHead = "player_\x00team_\x00score_\x00deaths_\x00\x00";

fwrite($rConnection, $sCommand, strlen($sCommand));

$iStarttime = microtime(true);

$iDataLenght = 0;

$sServerdata = '';

do {

$sServerdata .= fgetc($rConnection);

$iDataLenght++;

$aMetaData = stream_get_meta_data($rConnection);

if (microtime(true) > ($iStarttime + $iWaittime)) {

$this->errmsg="contime";

fclose($rConnection);

return false;

}

} while ($aMetaData["unread_bytes"]);

$sServerdata = substr($sServerdata,strlen($sSignature));

$sGEnd = strpos($sServerdata, $sHead);

$sGInfo = substr($sServerdata, 0, $sGEnd);

$aGInfo = explode("\x00", $sGInfo);

$sPEnd = strlen($sServerdata);

$sPInfo = substr($sServerdata, $sGEnd+strlen($sHead), $sPEnd);

$aPInfo = explode("\x00",$sPInfo);

for ($i = 0; $i < count($aGInfo); $i = $i + 2) {

$sKey = $aGInfo[$i];

if ($i + 1 >= count($aGInfo)) break;

$sData = $aGInfo[$i+1];

if ($sKey != "\x00" && !empty($sData))

$aServerdata[$sKey] = $sData;

}

for ($i = 0; $i < count($aPInfo); $i=$i+4) {

$sName = $aPInfo[$i];

if (!empty($sName)) {

$aServerdata['player'][] = array(

"name" => $sName,

"team" => $aPInfo[$i+1],

"score" => $aPInfo[$i+2],

"deaths" => $aPInfo[$i+3]

);

}

}

print '<pre>';

print_r($aServerdata);

print '</pre>';

?>

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×