From 722e2fa695b84a96b89c69c7b1bc4e908c47910e Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 9 Nov 2013 21:35:43 +0100 Subject: [PATCH] improved playerhandler --- application/.idea/workspace.xml | 78 ++-- application/core/chat.php | 4 +- application/core/core.php | 10 +- application/core/player.php | 634 ++--------------------------- application/core/playerHandler.php | 12 +- 5 files changed, 84 insertions(+), 654 deletions(-) diff --git a/application/.idea/workspace.xml b/application/.idea/workspace.xml index f2d8d094..a5f92084 100644 --- a/application/.idea/workspace.xml +++ b/application/.idea/workspace.xml @@ -26,7 +26,7 @@ - + @@ -34,19 +34,19 @@ - + - + - + - + @@ -64,7 +64,7 @@ - + @@ -100,11 +100,11 @@ @@ -350,13 +350,6 @@ - - - - - - - @@ -420,13 +413,6 @@ - - - - - - - @@ -434,9 +420,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -445,21 +459,7 @@ - - - - - - - - - - - - - - - + diff --git a/application/core/chat.php b/application/core/chat.php index 61f1c3d5..22272c92 100644 --- a/application/core/chat.php +++ b/application/core/chat.php @@ -38,10 +38,10 @@ class Chat { public function sendChat($message, $login = null, $prefix = false) { if (!$this->mc->client) return false; if ($login === null) { - return $this->mc->client->query('ChatSendServerMessage', ($prefix ? $this->prefix : '') . $message); + return $this->mc->client->query('ChatSendServerMessage', '$z' . ($prefix ? $this->prefix : '') . $message . '$z'); } else { - return $this->mc->client->query('ChatSendServerMessageToLogin', ($prefix ? $this->prefix : '') . $message, $login); + return $this->mc->client->query('ChatSendServerMessageToLogin', '$z' . ($prefix ? $this->prefix : '') . $message . '$z', $login); } } diff --git a/application/core/core.php b/application/core/core.php index 4ed6fa73..47812bf9 100644 --- a/application/core/core.php +++ b/application/core/core.php @@ -184,7 +184,11 @@ class ManiaControl { if (!$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!')) { trigger_error("Couldn't announce ManiaControl. " . $this->getClientErrorText()); } - + + //get PlayerList + $this->client->query('GetPlayerList', 300, 0, 2); + $this->playerHandler->addPlayerList($this->client->getResponse()); + // OnInit $this->callbacks->onInit(); @@ -307,10 +311,6 @@ class ManiaControl { } } } - - $this->client->query('GetPlayerList', 300, 0, 2); - $this->playerHandler->addPlayerList($this->client->getResponse()); - } /** diff --git a/application/core/player.php b/application/core/player.php index 53ec022f..5eabe333 100644 --- a/application/core/player.php +++ b/application/core/player.php @@ -11,57 +11,46 @@ namespace ManiaControl; class Player { /** - * Private properties + * public properties */ - private $id; - private $pid; - private $login; - private $nickname; - private $teamname; - private $ip; - private $client; - private $ipport; - private $zone; - private $continent; - private $nation; - //private $prevstatus; - private $isspectator; - private $isofficial; - private $language; - private $avatar; - private $teamid; - private $unlocked; - private $ladderrank; - private $ladderscore; - private $created; - private $wins; - private $newwins; - private $timeplayed; - private $maplist; - private $playerlist; - private $msgs; - private $pmbuf; - private $mutelist; - private $mutebuf; - private $style; - private $panels; - private $panelbg; - private $speclogin; - private $dedirank; - private $disconnectionreason; + public $id; //Internal Id from ManiaControl + public $pid; //Id from dedicated Server + public $login; + public $nickname; + public $teamname; + public $ip; + public $client; + public $ipport; + public $zone; + public $continent; + public $nation; + //public $prevstatus; + public $isSpectator; + public $isOfficial; + public $language; + public $avatar; + public $teamid; + public $unlocked; + public $ladderrank; + public $ladderscore; + public $created; + //TODO: usefull construct player without rpc info? //TODO: isBot properti + //TODO: add all attributes like, allies, clublink ... just make vardump on rpc infos public function __construct($rpc_infos = null){ + if ($rpc_infos) { - $this->pid = $rpc_infos['PlayerId']; $this->login = $rpc_infos['Login']; $this->nickname = $rpc_infos['NickName']; + $this->pid = $rpc_infos['PlayerId']; + $this->teamid = $rpc_infos['TeamId']; $this->ipport = $rpc_infos['IPAddress']; $this->ip = preg_replace('/:\d+/', '', $rpc_infos['IPAddress']); // strip port //$this->prevstatus = false; - $this->isspectator = $rpc_infos['IsSpectator']; - $this->isofficial = $rpc_infos['IsInOfficialMode']; + $this->isSpectator = $rpc_infos['IsSpectator']; + $this->isOfficial = $rpc_infos['IsInOfficialMode']; $this->teamname = $rpc_infos['LadderStats']['TeamName']; $this->zone = substr($rpc_infos['Path'], 6); // strip 'World|' $zones = explode('|', $rpc_infos['Path']); @@ -90,7 +79,6 @@ class Player { $this->client = $rpc_infos['ClientVersion']; $this->language = $rpc_infos['Language']; $this->avatar = $rpc_infos['Avatar']['FileName']; - $this->teamid = $rpc_infos['TeamId']; $this->created = time(); } else { // set defaults @@ -100,8 +88,8 @@ class Player { $this->ipport = ''; $this->ip = ''; //$this->prevstatus = false; - $this->isspectator = false; - $this->isofficial = false; + $this->isSpectator = false; + $this->isOfficial = false; $this->teamname = ''; $this->zone = ''; $this->continent = ''; @@ -111,566 +99,6 @@ class Player { $this->created = 0; } } - - /** - * @param mixed $avatar - */ - public function setAvatar($avatar) - { - $this->avatar = $avatar; - } - - /** - * @return mixed - */ - public function getAvatar() - { - return $this->avatar; - } - - /** - * @param mixed $client - */ - public function setClient($client) - { - $this->client = $client; - } - - /** - * @return mixed - */ - public function getClient() - { - return $this->client; - } - - /** - * @param string $continent - */ - public function setContinent($continent) - { - $this->continent = $continent; - } - - /** - * @return string - */ - public function getContinent() - { - return $this->continent; - } - - /** - * @param int $created - */ - public function setCreated($created) - { - $this->created = $created; - } - - /** - * @return int - */ - public function getCreated() - { - return $this->created; - } - - /** - * @param mixed $dedirank - */ - public function setDedirank($dedirank) - { - $this->dedirank = $dedirank; - } - - /** - * @return mixed - */ - public function getDedirank() - { - return $this->dedirank; - } - - /** - * @param mixed $disconnectionreason - */ - public function setDisconnectionreason($disconnectionreason) - { - $this->disconnectionreason = $disconnectionreason; - } - - /** - * @return mixed - */ - public function getDisconnectionreason() - { - return $this->disconnectionreason; - } - - /** - * @param mixed $id - */ - public function setId($id) - { - $this->id = $id; - } - - /** - * @return mixed - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $ip - */ - public function setIp($ip) - { - $this->ip = $ip; - } - - /** - * @return string - */ - public function getIp() - { - return $this->ip; - } - - /** - * @param string $ipport - */ - public function setIpport($ipport) - { - $this->ipport = $ipport; - } - - /** - * @return string - */ - public function getIpport() - { - return $this->ipport; - } - - /** - * @param boolean $isofficial - */ - public function setIsofficial($isofficial) - { - $this->isofficial = $isofficial; - } - - /** - * @return boolean - */ - public function getIsofficial() - { - return $this->isofficial; - } - - /** - * @param boolean $isspectator - */ - public function setIsspectator($isspectator) - { - $this->isspectator = $isspectator; - } - - /** - * @return boolean - */ - public function getIsspectator() - { - return $this->isspectator; - } - - /** - * @param int $ladderrank - */ - public function setLadderrank($ladderrank) - { - $this->ladderrank = $ladderrank; - } - - /** - * @return int - */ - public function getLadderrank() - { - return $this->ladderrank; - } - - /** - * @param int $ladderscore - */ - public function setLadderscore($ladderscore) - { - $this->ladderscore = $ladderscore; - } - - /** - * @return int - */ - public function getLadderscore() - { - return $this->ladderscore; - } - - /** - * @param mixed $language - */ - public function setLanguage($language) - { - $this->language = $language; - } - - /** - * @return mixed - */ - public function getLanguage() - { - return $this->language; - } - - /** - * @param string $login - */ - public function setLogin($login) - { - $this->login = $login; - } - - /** - * @return string - */ - public function getLogin() - { - return $this->login; - } - - /** - * @param mixed $maplist - */ - public function setMaplist($maplist) - { - $this->maplist = $maplist; - } - - /** - * @return mixed - */ - public function getMaplist() - { - return $this->maplist; - } - - /** - * @param mixed $msgs - */ - public function setMsgs($msgs) - { - $this->msgs = $msgs; - } - - /** - * @return mixed - */ - public function getMsgs() - { - return $this->msgs; - } - - /** - * @param mixed $mutebuf - */ - public function setMutebuf($mutebuf) - { - $this->mutebuf = $mutebuf; - } - - /** - * @return mixed - */ - public function getMutebuf() - { - return $this->mutebuf; - } - - /** - * @param mixed $mutelist - */ - public function setMutelist($mutelist) - { - $this->mutelist = $mutelist; - } - - /** - * @return mixed - */ - public function getMutelist() - { - return $this->mutelist; - } - - /** - * @param string $nation - */ - public function setNation($nation) - { - $this->nation = $nation; - } - - /** - * @return string - */ - public function getNation() - { - return $this->nation; - } - - /** - * @param mixed $newwins - */ - public function setNewwins($newwins) - { - $this->newwins = $newwins; - } - - /** - * @return mixed - */ - public function getNewwins() - { - return $this->newwins; - } - - /** - * @param string $nickname - */ - public function setNickname($nickname) - { - $this->nickname = $nickname; - } - - /** - * @return string - */ - public function getNickname() - { - return $this->nickname; - } - - /** - * @param mixed $panelbg - */ - public function setPanelbg($panelbg) - { - $this->panelbg = $panelbg; - } - - /** - * @return mixed - */ - public function getPanelbg() - { - return $this->panelbg; - } - - /** - * @param mixed $panels - */ - public function setPanels($panels) - { - $this->panels = $panels; - } - - /** - * @return mixed - */ - public function getPanels() - { - return $this->panels; - } - - /** - * @param int $pid - */ - public function setPid($pid) - { - $this->pid = $pid; - } - - /** - * @return int - */ - public function getPid() - { - return $this->pid; - } - - /** - * @param mixed $playerlist - */ - public function setPlayerlist($playerlist) - { - $this->playerlist = $playerlist; - } - - /** - * @return mixed - */ - public function getPlayerlist() - { - return $this->playerlist; - } - - /** - * @param mixed $pmbuf - */ - public function setPmbuf($pmbuf) - { - $this->pmbuf = $pmbuf; - } - - /** - * @return mixed - */ - public function getPmbuf() - { - return $this->pmbuf; - } - - /** - * @param mixed $speclogin - */ - public function setSpeclogin($speclogin) - { - $this->speclogin = $speclogin; - } - - /** - * @return mixed - */ - public function getSpeclogin() - { - return $this->speclogin; - } - - /** - * @param mixed $style - */ - public function setStyle($style) - { - $this->style = $style; - } - - /** - * @return mixed - */ - public function getStyle() - { - return $this->style; - } - - /** - * @param mixed $teamid - */ - public function setTeamid($teamid) - { - $this->teamid = $teamid; - } - - /** - * @return mixed - */ - public function getTeamid() - { - return $this->teamid; - } - - /** - * @param string $teamname - */ - public function setTeamname($teamname) - { - $this->teamname = $teamname; - } - - /** - * @return string - */ - public function getTeamname() - { - return $this->teamname; - } - - /** - * @param mixed $timeplayed - */ - public function setTimeplayed($timeplayed) - { - $this->timeplayed = $timeplayed; - } - - /** - * @return mixed - */ - public function getTimeplayed() - { - return $this->timeplayed; - } - - /** - * @param mixed $unlocked - */ - public function setUnlocked($unlocked) - { - $this->unlocked = $unlocked; - } - - /** - * @return mixed - */ - public function getUnlocked() - { - return $this->unlocked; - } - - /** - * @param mixed $wins - */ - public function setWins($wins) - { - $this->wins = $wins; - } - - /** - * @return mixed - */ - public function getWins() - { - return $this->wins; - } - - /** - * @param string $zone - */ - public function setZone($zone) - { - $this->zone = $zone; - } - - /** - * @return string - */ - public function getZone() - { - return $this->zone; - } } ?> \ No newline at end of file diff --git a/application/core/playerHandler.php b/application/core/playerHandler.php index 67ef39c7..bbce5f85 100644 --- a/application/core/playerHandler.php +++ b/application/core/playerHandler.php @@ -37,15 +37,17 @@ class playerHandler { } } /** - * Handels a playerConnect + * Handles a playerConnect * @param $player */ public function playerConnect($player){ - error_log("test"); $this->mc->client->query('GetDetailedPlayerInfo', $player[0]); $this->addPlayer(new Player($this->mc->client->getResponse())); - $this->mc->chat->sendChat("test"); - } + $player = $this->playerList[$player[0]]; + if($player->pid != 0){ //Player 0 = server + $this->mc->chat->sendChat('$ff0New Player: '. $player->nickname . '$z $ff0Nation:$fff ' . $player->nation . ' $ff0Ladder: $fff' . $player->ladderrank); + } + } /** * Adds a player to the PlayerList * @param Player $player @@ -53,7 +55,7 @@ class playerHandler { */ public function addPlayer(Player $player){ if($player != null){ - $this->playerList[$player->getLogin()] = $player; + $this->playerList[$player->login] = $player; return true; }else{ return false;