diff --git a/application/.idea/workspace.xml b/application/.idea/workspace.xml index a5f92084..0a7d7e65 100644 --- a/application/.idea/workspace.xml +++ b/application/.idea/workspace.xml @@ -37,7 +37,7 @@ - + @@ -64,7 +64,34 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -89,7 +116,6 @@ - @@ -291,7 +318,7 @@ - + @@ -350,41 +377,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -427,13 +419,6 @@ - - - - - - - @@ -457,9 +442,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/application/core/playerHandler.php b/application/core/playerHandler.php index bbce5f85..36b25f20 100644 --- a/application/core/playerHandler.php +++ b/application/core/playerHandler.php @@ -24,6 +24,7 @@ class playerHandler { $this->mc = $mc; $this->playerList = array(); $this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCONNECT, $this, 'playerConnect'); + $this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect'); } @@ -41,6 +42,7 @@ class playerHandler { * @param $player */ public function playerConnect($player){ + //TODO: Welcome Message?, on mc restart not all players listed, no relay support yet $this->mc->client->query('GetDetailedPlayerInfo', $player[0]); $this->addPlayer(new Player($this->mc->client->getResponse())); $player = $this->playerList[$player[0]]; @@ -48,12 +50,36 @@ class playerHandler { $this->mc->chat->sendChat('$ff0New Player: '. $player->nickname . '$z $ff0Nation:$fff ' . $player->nation . ' $ff0Ladder: $fff' . $player->ladderrank); } } + + /** + * Handles a playerDisconnect + * @param $player + */ + public function playerDisconnect($player){ + $player = $this->removePlayer($player[0]); + $played = TOOLS::formatTime(time() - $player->created); + $this->mc->chat->sendChat($player->nickname . '$z $ff0has left the game. Played:$fff ' . $played); + } + + + /** + * Gets a Player from the Playerlist + * @param $login + * @return null + */ + public function getPlayer($login){ + if (isset($this->playerList[$login])) + return $this->playerList[$login]; + else + return null; + } + /** * Adds a player to the PlayerList * @param Player $player * @return bool */ - public function addPlayer(Player $player){ + private function addPlayer(Player $player){ if($player != null){ $this->playerList[$player->login] = $player; return true; @@ -61,4 +87,18 @@ class playerHandler { return false; } } + /** + * Removes a Player from the PlayerList + * @param $login + * @return Player $player + */ + private function removePlayer($login){ + if(isset($this->playerList[$login])){ + $player = $this->playerList[$login]; + unset($this->playerList[$login]); + } else { + $player = null; + } + return $player; + } } \ No newline at end of file diff --git a/application/core/tools.php b/application/core/tools.php index 76d959b7..ae57ffbf 100644 --- a/application/core/tools.php +++ b/application/core/tools.php @@ -140,6 +140,16 @@ class Tools { return $format; } + /** + * Formats the given time (seconds) to hh:mm:ss + * + * @param int $time + * @return string + */ + public static function formatTimeH($seconds) { + return gmdate("H:i:s", $seconds); + } + /** * Convert given data to real boolean * diff --git a/rsa b/rsa new file mode 100644 index 00000000..e69de29b