-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Session manager(WIP). Related to #16
- Loading branch information
Lem()nTea_
committed
Nov 29, 2014
1 parent
a2512dc
commit a4e309b
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace ifteam\CustomPacket; | ||
|
||
use pocketmine\Player; | ||
use pocketmine\Server; | ||
|
||
class SessionManager { | ||
|
||
private static $instance; | ||
private $session = array(); | ||
private $log = 'Server::getInstance()->getLogger()->debug'; | ||
|
||
public function __construct(){ | ||
self::$instance = $this; | ||
} | ||
|
||
public static function getInstance(){ | ||
return self::$instance; | ||
} | ||
|
||
public function add(Player $player, $ip, $port){ | ||
if($player->getAddress() !== $ip): Server::getInstance()->getLogger()->warning('Player '.$player->getName().' attempted to connect to CustomPacket server with invalid IP!'); return; endif; | ||
$this->session[$player->getName()]['ip'] = $ip; | ||
$this->session[$player->getName()]['port'] = $port; | ||
$this->log($player->getName().' ('.$ip.')connected to CustomPacket server on port '. $port); | ||
} | ||
|
||
public function close($key){ | ||
if(isset($this->session[$key])): $this->session[$key] = NULL; $this->log('Player '. $key. 'disconnected from CustomPacket Server'); endif; //faster freeing memory without garbage collector | ||
} | ||
|
||
public function getSessionData($key){ | ||
return isset($this->session[$key]) ? $this->session[$key] : false; | ||
} | ||
|
||
} | ||
?> |