added loadfile again, and pushed unpushed changes

This commit is contained in:
kremsy 2013-12-23 16:14:03 +01:00
parent 27aac6842e
commit 8b54c9f5ea
5 changed files with 75 additions and 10 deletions

View File

@ -8,7 +8,53 @@ namespace ManiaControl;
* @author steeffeen & kremsy
*/
abstract class FileUtil {
/**
* Load a remote file
*
* @param string $url
* @return string || null
*/
public static function loadFile($url) {
if (!$url) {
return null;
}
$urlData = parse_url($url);
$port = (isset($urlData['port']) ? $urlData['port'] : 80);
$fsock = fsockopen($urlData['host'], $port);
stream_set_timeout($fsock, 3);
$query = 'GET ' . $urlData['path'] . ' HTTP/1.0' . PHP_EOL;
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
$query .= 'Content-Type: UTF-8' . PHP_EOL;
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
$query .= PHP_EOL;
fwrite($fsock, $query);
$buffer = '';
$info = array('timed_out' => false);
while (!feof($fsock) && !$info['timed_out']) {
$buffer .= fread($fsock, 1024);
$info = stream_get_meta_data($fsock);
}
fclose($fsock);
if ($info['timed_out'] || !$buffer) {
return null;
}
if (substr($buffer, 9, 3) != "200") {
return null;
}
$result = explode("\r\n\r\n", $buffer, 2);
if (count($result) < 2) {
return null;
}
return $result[1];
}
/**
* Load config xml-file
*

View File

@ -294,6 +294,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
break;
}
//TODO pages
//render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
}
@ -328,7 +331,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->manialinkManager->labelLine($frame,$array);
//TODO detailed mx info page with link to mxo
//TODO action detailed map info
//TODO later add buttons for jukebox, admin control buttons (remove map, change to map)
//TODO side switch
@ -341,6 +343,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player
*/
public function closeWidget(array $callback, Player $player) {
//TODO update player things
$this->maniaControl->manialinkManager->closeWidget($player);
}

View File

@ -71,7 +71,7 @@ class Player {
* @return bool
*/
// TODO: check for bot players
public function isFakePlayer() {
public function isFakePlayer() { //TODO Bot have also positive pids, so this is useless, just stringmatch *fake
return ($this->pid <= 0);
}
@ -86,7 +86,7 @@ class Player {
if (isset($pathParts[3])) {
return $pathParts[3];
}
return "";
return $this->getCountry();
}
/**

View File

@ -159,6 +159,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$countryQuad->setX($x + 88);
$countryQuad->setSize(4,4);
$countryQuad->setZ(-0.1);
//TODO mousover show locations in descript bar
//Level Quad
$rightQuad = new Quad_BgRaceScore2();
@ -205,6 +207,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Buddy);
$playerQuad->setSize(3.8,3.8);
//$playerQuad->setAction(self::ACTION_FORCE_BLUE . "." .$listPlayer->login);
//TODO special player thing
$redQuad = new Quad_Emblems();
$playerFrame->add($redQuad);

View File

@ -119,18 +119,25 @@ class PlayerManager implements CallbackListener {
$this->maniaControl->client->query('GetDetailedPlayerInfo', $login);
$playerInfo = $this->maniaControl->client->getResponse();
$player = new Player($playerInfo);
var_dump($player);
//if($player->isFakePlayer())
//return;
$this->addPlayer($player);
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
$string = array(0 => 'New Player', 1 => '$0f0Operator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
$nickname = Formatter::stripCodes($player->nickname); // TODO: strip codes without colour codes like in serverviewer
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
//$nickname = Formatter::stripCodes($player->nickname); // TODO: strip codes without colour codes like in serverviewer
//TODO standart notification colour from settings or something
$this->maniaControl->chat->sendChat(
'$ff0' . $string[$player->authLevel] . ': $fff' . $nickname . '$z $ff0Nation:$fff ' . $player->getCountry() .
' $ff0Ladder: $fff' . $player->ladderRank);
'$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined');
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION,$player->login);
}
$this->maniaControl->log('Player joined: ' . $player->login . " / " . $player->nickname . " Nation: " . $player->getCountry() . " IP: " .$player->ipAddress);
$this->maniaControl->log('Player joined: ' . $player->login . " / " . $player->nickname . " Nation:" . $player->getCountry() . " IP: " .$player->ipAddress);
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERJOINED, array(self::CB_PLAYERJOINED, $player));
@ -143,14 +150,19 @@ class PlayerManager implements CallbackListener {
*/
public function playerDisconnect(array $callback) {
$login = $callback[1][0];
//TODO check for fakeplayers
$player = $this->removePlayer($login);
//if($player->isFakePlayer())
//return;
$played = Formatter::formatTimeH(time() - $player->joinTime);
$this->maniaControl->log("Player left: " . $player->login . " / " . $player->nickname . " Playtime: " . $played);
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $ff0has left the game. Played:$fff ' . $played);
//$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $ff0left the game. Played:$fff ' . $played);
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game');
}
}