dedimania continue

This commit is contained in:
kremsy
2014-02-16 22:38:14 +01:00
committed by Steffen Schröder
parent deb08cfbd0
commit 6affb6825b
6 changed files with 335 additions and 33 deletions

View File

@ -41,10 +41,23 @@ class AsynchronousFileReader {
foreach($this->sockets as $key => &$socket) {
/** @var SocketStructure $socket */
$socket->streamBuffer .= fread($socket->socket, 4096);
//$socket->streamBuffer .= fgets($socket->socket, 4096);
//var_dump($socket->streamBuffer);
/* $meta = stream_get_meta_data($socket->socket);
while($meta["unread_bytes"] > 0){
var_dump("test");
$socket->streamBuffer .= fgets($socket->socket, 4096);
$meta = stream_get_meta_data($socket->socket);
var_dump($meta);
}
var_dump($meta);
exit();*/
if (feof($socket->socket) || time() > ($socket->creationTime + self::SOCKET_TIMEOUT)) {
fclose($socket->socket);
unset($this->sockets[$key]);
$result = "";
$error = 0;
if (time() > ($socket->creationTime + self::SOCKET_TIMEOUT)) {
@ -84,15 +97,36 @@ class AsynchronousFileReader {
}
$header = $this->parseHeader($resultArray[0]);
if (isset($header["transfer-encoding"])) {
$result = $this->decode_chunked($resultArray[1]);
} else {
$result = $resultArray[1];
}
return $result;
return $this->decompressData($header, $result);
}
/**
* Checks if the data is Compressed and uncompress it
*
* @param $header
* @param $data
* @return string
*/
private function decompressData($header, $data) {
if (isset($header["content-encoding"])) {
switch($header["content-encoding"]) {
case "gzip":
case "gzip;":
return gzdecode($data);
case "deflate":
case "deflate;":
return gzinflate($data);
}
}
return $data;
}
/**
* Decode Chunks
@ -134,6 +168,58 @@ class AsynchronousFileReader {
}
/**
* Send Data via POST Method
*
* @param $url
* @param $function
* @param $content
* @param string $contentType
* @return bool|null
*/
public function postData($url, $function, $content, $compressed = false, $contentType = 'UTF-8') {
if (!is_callable($function)) {
$this->maniaControl->log("Function is not callable");
return false;
}
if (!$url) {
return null;
}
$urlData = parse_url($url);
$port = (isset($urlData['port']) ? $urlData['port'] : 80);
$socket = @fsockopen($urlData['host'], $port, $errno, $errstr, 4);
if (!$socket) {
return false;
}
$query = 'POST ' . $urlData['path'] . ' HTTP/1.1' . PHP_EOL;
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
$query .= 'Accept-Charset: utf-8' . PHP_EOL;
$query .= 'Accept-Encoding: gzip, deflate' . PHP_EOL;
//$query .= 'Content-Encoding: gzip' . PHP_EOL;
$query .= 'Content-Type: text/xml; charset=utf-8;' . PHP_EOL;
$query .= 'Keep-Alive: 300' . PHP_EOL;
$query .= 'Connection: Keep-Alive' . PHP_EOL;
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
$query .= 'Content-Length: ' . strlen($content) . PHP_EOL . PHP_EOL;
$query .= $content . PHP_EOL;
fwrite($socket, $query);
$success = stream_set_blocking($socket, 0);
if (!$success) {
return false;
}
$socketStructure = new SocketStructure($url, $socket, $function);
array_push($this->sockets, $socketStructure);
return true;
}
/**
* Load a remote file
*

View File

@ -24,6 +24,7 @@ class Map {
public $mapType = '';
public $mapStyle = '';
public $nbCheckpoints = -1;
public $nbLaps = -1;
/** @var MXMapInfo $mx */
public $mx = null;
public $authorLogin = '';
@ -57,6 +58,7 @@ class Map {
$this->mapType = $mpMap->mapType;
$this->mapStyle = $mpMap->mapStyle;
$this->nbCheckpoints = $mpMap->nbCheckpoints;
$this->nbLaps = $mpMap->nbLaps;
$this->authorNick = $this->authorLogin;
}

View File

@ -377,6 +377,7 @@ class MapManager implements CallbackListener {
if (array_key_exists($rpcMap->uId, $this->maps)) {
$this->currentMap = $this->maps[$rpcMap->uId];
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
$this->currentMap->nbLaps = $rpcMap->nbLaps;
return true;
}
$map = $this->initializeMap($rpcMap);

View File

@ -225,7 +225,7 @@ class Server implements CallbackListener {
case 1:
return 'Rounds';
case 2:
return 'TimeAttack';
return 'Timeattack';
case 3:
return 'Team';
case 4:
@ -306,7 +306,7 @@ class Server implements CallbackListener {
}
// Server not yet in given status - Wait for it...
$waitBegin = time();
$maxWaitTime = 20;
$maxWaitTime = 30;
$lastStatus = $response->name;
$this->maniaControl->log("Waiting for server to reach status {$statusCode}...");
$this->maniaControl->log("Current Status: {$lastStatus}");