From: <lu...@us...> - 2008-12-24 02:33:50
|
Revision: 8681 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=8681&view=rev Author: luke-jr Date: 2008-12-24 02:33:46 +0000 (Wed, 24 Dec 2008) Log Message: ----------- some auth support (not working completely yet) ->do* to send messages by type func Modified Paths: -------------- private/wrtlprnft/serverinfo.php Modified: private/wrtlprnft/serverinfo.php =================================================================== --- private/wrtlprnft/serverinfo.php 2008-12-21 18:34:32 UTC (rev 8680) +++ private/wrtlprnft/serverinfo.php 2008-12-24 02:33:46 UTC (rev 8681) @@ -487,6 +487,10 @@ } function connection($host, $port=4534) { + $this->host = $host; + $this->hostip = gethostbyname($host); + $this->port = $port; + connection::$current = $this; $this->sock = fsockopen('udp://' . $host . ':' . $port . ''); $this->connectiontime = microtime(true); @@ -552,6 +556,7 @@ case 20: $cont = $this->handleFreeID ($msg); break; case 220: $cont = $this->handleNewTeam ($msg); break; case 24: $cont = $this->handleNetSync ($msg); break; + case 40: $cont = $this->handleAuthRequest ($msg); break; default: if(connection::$debug) print_r($msg); } } @@ -625,6 +630,13 @@ $this->onChat($playerid, $text); return true; } + function doChat($text) { + $msg = nMessage::makeMsg(200); + $msg->writeshort($this->playerid); + $msg->writeString($text); + $this->send($msg); + return true; + } function onSync($timeout, $sync_sn_netObjects, $c_sync) { $msg = nMessage::makeMsg(27); $msg->writeshort($c_sync); @@ -706,6 +718,68 @@ } return true; } + function handleAuthRequest($msg) { + $scrambled = ''; + for ($i = 7; $i >= 0; --$i) + { + $x = $msg->readshort(); + $low = $x & 255; + $high = ($x - $low) >> 8; + + $scrambled .= "$low$high"; + } + + $user = $msg->readstring(); + $tmsg = $msg->readstring(); + + /* BROKEN: + $method = "bmd5"; + $prefix = ""; + $suffix = ""; + if (!$msg->end()) + { + $method = $msg->readstring(); + $prefix = $msg->readstring(); + $suffix = $msg->readstring(); + } + echo "Method: $method\nPrefix: $prefix\nSuffix: $suffix\n"; + */ + + $info = array( + 'scrambled' => $scrambled, + 'user' => $user, + 'message' => $tmsg, + ); + + $this->onAuthRequest($info); + return true; + } + function onAuthRequest($info) { + } + function doAuthAnswer(&$info) { + switch ($info['method']) { + case 'bmd5': + case '': + $info['scrambled'] = md5(md5($info['password']) . pack('H*', $info['scrambled'])); + break; + default: + return false; + } + + $msg = nMessage::makeMsg(41); + for ($i = 7; $i >= 0; --$i) + $msg->writeshort($info['scrambled'][i << 1] + ($info['scrambled'][(i << 1) + 1] << 8)); + $msg->writeString($info['user']); + $msg->writebool($info['aborted']); + if (!isset($info['automatic'])) + $info['automatic'] = true; + $msg->writebool($info['automatic']); + if (!isset($info['server'])) + $info['server'] = $this->hostip . ':' . $this->port; + $msg->writeString($info['server']); + $this->send($msg); + return true; + } } class bot extends connection { @@ -726,10 +800,8 @@ $this->playerid = $p->id; $this->gotPlayer = true; - $msg = nMessage::makeMsg(200); - $msg->writeshort($this->playerid); - $msg->writeString($this->message); - $this->send($msg); + $this->doChat($this->message); + $this->logout(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |