From 8b54c9f5ea14142e15a8b1dbf809cb3e3a5a5d79 Mon Sep 17 00:00:00 2001 From: kremsy Date: Mon, 23 Dec 2013 16:14:03 +0100 Subject: [PATCH] added loadfile again, and pushed unpushed changes --- application/core/FileUtil.php | 46 ++++++++++++++++++++++ application/core/Maps/MapList.php | 5 ++- application/core/Players/Player.php | 4 +- application/core/Players/PlayerList.php | 4 ++ application/core/Players/PlayerManager.php | 26 ++++++++---- 5 files changed, 75 insertions(+), 10 deletions(-) diff --git a/application/core/FileUtil.php b/application/core/FileUtil.php index c9f1c41d..46f8e33c 100644 --- a/application/core/FileUtil.php +++ b/application/core/FileUtil.php @@ -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 * diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 9d5fb606..cfb1bda8 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -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); } diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index f454989a..9b87c8f4 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -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(); } /** diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index db4069c4..b35748ff 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -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); diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 99c88584..4b2e58bc 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -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'); } }