improved player class

This commit is contained in:
kremsy 2013-11-09 22:08:06 +01:00
parent 722e2fa695
commit c9ab3fe799
4 changed files with 128 additions and 51 deletions

View File

@ -37,7 +37,7 @@
<file leaf-file-name="playerHandler.php" pinned="false" current="true" current-in-tab="true"> <file leaf-file-name="playerHandler.php" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/core/playerHandler.php"> <entry file="file://$PROJECT_DIR$/core/playerHandler.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="46" column="50" selection-start="1102" selection-end="1102" vertical-scroll-proportion="0.53782505" vertical-offset="242" max-vertical-offset="1088"> <state line="68" column="7" selection-start="1941" selection-end="1941" vertical-scroll-proportion="0.7234042" vertical-offset="459" max-vertical-offset="1768">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -64,7 +64,34 @@
<file leaf-file-name="core.php" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="core.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/core/core.php"> <entry file="file://$PROJECT_DIR$/core/core.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="187" column="24" selection-start="4232" selection-end="4232" vertical-scroll-proportion="-5.5" vertical-offset="2761" max-vertical-offset="6817"> <state line="187" column="24" selection-start="4232" selection-end="4232" vertical-scroll-proportion="-41.82895" vertical-offset="0" max-vertical-offset="6817">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="commands.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/core/commands.php">
<provider selected="true" editor-type-id="text-editor">
<state line="99" column="27" selection-start="2928" selection-end="2928" vertical-scroll-proportion="170.65384" vertical-offset="6120" max-vertical-offset="11730">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="stats.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/core/stats.php">
<provider selected="true" editor-type-id="text-editor">
<state line="20" column="0" selection-start="268" selection-end="268" vertical-scroll-proportion="152.5" vertical-offset="4305" max-vertical-offset="5151">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="tools.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/core/tools.php">
<provider selected="true" editor-type-id="text-editor">
<state line="154" column="6" selection-start="3963" selection-end="3963" vertical-scroll-proportion="-22.615385" vertical-offset="2030" max-vertical-offset="4352">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -89,7 +116,6 @@
<component name="IdeDocumentHistory"> <component name="IdeDocumentHistory">
<option name="changedFiles"> <option name="changedFiles">
<list> <list>
<option value="$PROJECT_DIR$/plugins/chatlog.plugin.php" />
<option value="$PROJECT_DIR$/core/database.ManiaControl.php" /> <option value="$PROJECT_DIR$/core/database.ManiaControl.php" />
<option value="$PROJECT_DIR$/core/manialinkIdHandler.php" /> <option value="$PROJECT_DIR$/core/manialinkIdHandler.php" />
<option value="$PROJECT_DIR$/core/core.ManiaControl.php" /> <option value="$PROJECT_DIR$/core/core.ManiaControl.php" />
@ -103,15 +129,16 @@
<option value="$PROJECT_DIR$/core/callbacks.php" /> <option value="$PROJECT_DIR$/core/callbacks.php" />
<option value="$PROJECT_DIR$/core/chat.php" /> <option value="$PROJECT_DIR$/core/chat.php" />
<option value="$PROJECT_DIR$/core/core.php" /> <option value="$PROJECT_DIR$/core/core.php" />
<option value="$PROJECT_DIR$/core/playerHandler.php" />
<option value="$PROJECT_DIR$/core/player.php" /> <option value="$PROJECT_DIR$/core/player.php" />
<option value="$PROJECT_DIR$/core/playerHandler.php" />
<option value="$PROJECT_DIR$/core/tools.php" />
</list> </list>
</option> </option>
</component> </component>
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" /> <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" />
<component name="ProjectFrameBounds"> <component name="ProjectFrameBounds">
<option name="x" value="376" /> <option name="x" value="247" />
<option name="y" value="13" /> <option name="y" value="29" />
<option name="width" value="1936" /> <option name="width" value="1936" />
<option name="height" value="1056" /> <option name="height" value="1056" />
</component> </component>
@ -291,7 +318,7 @@
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="376" y="13" width="1936" height="1056" extended-state="0" /> <frame x="247" y="29" width="1936" height="1056" extended-state="0" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
@ -350,41 +377,6 @@
</breakpoint-manager> </breakpoint-manager>
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/core/authentication.php">
<provider selected="true" editor-type-id="text-editor">
<state line="96" column="74" selection-start="2314" selection-end="2321" vertical-scroll-proportion="-6.3157897" vertical-offset="1152" max-vertical-offset="1853">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/manialinkIdHandler.php">
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="5" selection-start="306" selection-end="306" vertical-scroll-proportion="-12.423077" vertical-offset="0" max-vertical-offset="748">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/commands.php">
<provider selected="true" editor-type-id="text-editor">
<state line="20" column="33" selection-start="0" selection-end="21192" vertical-scroll-proportion="0.4122682" vertical-offset="51" max-vertical-offset="11730">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/stats.php">
<provider selected="true" editor-type-id="text-editor">
<state line="20" column="0" selection-start="268" selection-end="268" vertical-scroll-proportion="0.3566334" vertical-offset="90" max-vertical-offset="5151">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ManiaControl.php">
<provider selected="true" editor-type-id="text-editor">
<state line="26" column="0" selection-start="623" selection-end="623" vertical-scroll-proportion="0.5885486" vertical-offset="0" max-vertical-offset="751">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/server.php"> <entry file="file://$PROJECT_DIR$/core/server.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="241" column="9" selection-start="5767" selection-end="5767" vertical-scroll-proportion="0.5021398" vertical-offset="3745" max-vertical-offset="6579"> <state line="241" column="9" selection-start="5767" selection-end="5767" vertical-scroll-proportion="0.5021398" vertical-offset="3745" max-vertical-offset="6579">
@ -427,13 +419,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/core/core.php">
<provider selected="true" editor-type-id="text-editor">
<state line="187" column="24" selection-start="4232" selection-end="4232" vertical-scroll-proportion="-5.5" vertical-offset="2761" max-vertical-offset="6817">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/chat.php"> <entry file="file://$PROJECT_DIR$/core/chat.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="47" column="7" selection-start="976" selection-end="976" vertical-scroll-proportion="-9.653846" vertical-offset="548" max-vertical-offset="1547"> <state line="47" column="7" selection-start="976" selection-end="976" vertical-scroll-proportion="-9.653846" vertical-offset="548" max-vertical-offset="1547">
@ -457,9 +442,51 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/core/core.php">
<provider selected="true" editor-type-id="text-editor">
<state line="187" column="24" selection-start="4232" selection-end="4232" vertical-scroll-proportion="-41.82895" vertical-offset="0" max-vertical-offset="6817">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plugins/oldstructure/records.plugin.php">
<provider selected="true" editor-type-id="text-editor">
<state line="1200" column="7" selection-start="37957" selection-end="37957" vertical-scroll-proportion="0.5579196" vertical-offset="19928" max-vertical-offset="20774">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plugins/oldstructure/obstacle.plugin.php">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="-0.024822695" vertical-offset="21" max-vertical-offset="1173">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/commands.php">
<provider selected="true" editor-type-id="text-editor">
<state line="99" column="27" selection-start="2928" selection-end="2928" vertical-scroll-proportion="170.65384" vertical-offset="6120" max-vertical-offset="11730">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/stats.php">
<provider selected="true" editor-type-id="text-editor">
<state line="20" column="0" selection-start="268" selection-end="268" vertical-scroll-proportion="152.5" vertical-offset="4305" max-vertical-offset="5151">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/tools.php">
<provider selected="true" editor-type-id="text-editor">
<state line="154" column="6" selection-start="3963" selection-end="3963" vertical-scroll-proportion="-22.615385" vertical-offset="2030" max-vertical-offset="4352">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core/playerHandler.php"> <entry file="file://$PROJECT_DIR$/core/playerHandler.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="46" column="50" selection-start="1102" selection-end="1102" vertical-scroll-proportion="0.53782505" vertical-offset="242" max-vertical-offset="1088"> <state line="68" column="7" selection-start="1941" selection-end="1941" vertical-scroll-proportion="0.7234042" vertical-offset="459" max-vertical-offset="1768">
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@ -24,6 +24,7 @@ class playerHandler {
$this->mc = $mc; $this->mc = $mc;
$this->playerList = array(); $this->playerList = array();
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCONNECT, $this, 'playerConnect'); $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 * @param $player
*/ */
public function playerConnect($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->mc->client->query('GetDetailedPlayerInfo', $player[0]);
$this->addPlayer(new Player($this->mc->client->getResponse())); $this->addPlayer(new Player($this->mc->client->getResponse()));
$player = $this->playerList[$player[0]]; $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); $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 * Adds a player to the PlayerList
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
public function addPlayer(Player $player){ private function addPlayer(Player $player){
if($player != null){ if($player != null){
$this->playerList[$player->login] = $player; $this->playerList[$player->login] = $player;
return true; return true;
@ -61,4 +87,18 @@ class playerHandler {
return false; 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;
}
} }

View File

@ -140,6 +140,16 @@ class Tools {
return $format; 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 * Convert given data to real boolean
* *

0
rsa Normal file
View File