public static function GetHandler($rawPacket) { if (XTParser::IsValid($rawPacket)) { $arrPacket = XTParser::ParseRaw($rawPacket); if (isset($arrPacket[1])) { $strHandler = $arrPacket[1]; return $strHandler; } } return false; }
public function recv() { if (!$this->usingProxy) { // If we're not using a proxy, we're going to use the ordinary socket_ functions $arrSockets = array($this->resSocket); $intChanged = socket_select($arrSockets, $arrWrite, $arrExcept, 30); if ($intChanged == 0) { echo 'Haven\'t received any data within the past 30 seconds', chr(10); $strData = $this->recv(); return $strData; } $mixReceived = @socket_recv($this->resSocket, $strData, 8192, 0); if ($mixReceived === 0) { socket_shutdown($this->resSocket); echo 'Failed to login', chr(10), die; } while (strpos($strData, chr(0)) === false) { @socket_recv($this->resSocket, $strMissing, 8192, 0); $strData .= $strMissing; } } else { // Otherwise we're going to use the file handler functions built-in to PHP $strData = $this->proxyObject->ph_read(); } if (XTParser::IsValid($strData) && !empty($this->arrListeners)) { $arrData = explode(chr(0), $strData); array_pop($arrData); foreach ($arrData as $strPacket) { if (XTParser::IsValid($strPacket)) { $arrPacket = XTParser::ParseRaw($strPacket); if (!empty($arrPacket)) { $strHandler = $arrPacket[1]; if (array_key_exists($strHandler, $this->arrListeners)) { foreach ($this->arrListeners[$strHandler] as $mixCallable) { call_user_func($mixCallable, $arrPacket); } } } $strData = $strPacket; } } } return $strData; }
$username = $_POST["username"]; $password = $_POST["password"]; spl_autoload_register(function ($strClass) { require_once sprintf('Penguin/%s.php', $strClass); }); $objPenguin = new Penguin(); global $itemid; $objPenguin->addListener("jr", function ($packet) use($objPenguin) { $objPenguin->addItem($_POST["itemid"]); }); $objPenguin->addListener("ai", function ($packet) { echo "Successfully added item ", "\n"; die; }); $objPenguin->addListener("e", function ($packet) use($objPenguin) { die($objPenguin->arrErrors[$packet[3]]["Description"]); }); try { $objPenguin->login($username, $password); $objPenguin->joinServer('Sled'); } catch (ConnectionException $objException) { die; } $objPenguin->joinRoom(805); while (true) { $strData = $objPenguin->recv(); if (XTParser::IsValid($strData)) { // echo $strData, chr(10); } } }