sessionInfo = []; return $this; } protected function __construct() { $this->set('userID', -1); $this->set('userName', 'Dummy'); $this->set('ip', '127.0.0.1'); $this->set('time', time()); $this->set('userGrade', '-1'); $this->set('acl', '[]'); $this->set('reqOTP', false); $this->set('tokenValidUntil', '2999-12-31 23:59:59'); } public function setReadOnly(): static { $this->writeClosed = true; return $this; } protected function set(string $name, $value) { $this->sessionInfo[$name] = $value; } public function __get(string $name) { if ($name == 'generalID') { if (!class_exists('\\sammo\\UniqueConst')){ return null; } return $this->get(UniqueConst::$serverID.static::GAME_KEY_GENERAL_ID); } if ($name == 'generalName') { if (!class_exists('\\sammo\\UniqueConst')){ return null; } return $this->get(UniqueConst::$serverID.static::GAME_KEY_GENERAL_NAME); } return $this->get($name); } protected function get(string $name) { return $this->sessionInfo[$name] ?? null; } public function loginGame(&$result = null): static { $userID = $this->userID; if (!$userID) { if ($result !== null) { $result = false; } return $this; } if (!class_exists('\\sammo\\UniqueConst')) { if ($result !== null) { $result = false; } return $this; } $serverID = UniqueConst::$serverID; $loginDate = $this->get($serverID.static::GAME_KEY_DATE); $generalID = $this->get($serverID.static::GAME_KEY_GENERAL_ID); $generalName = $this->get($serverID.static::GAME_KEY_GENERAL_NAME); $deadTime = $this->get($serverID.static::GAME_KEY_EXPECTED_DEADTIME); $now = time(); if ( $generalID && $generalName && $loginDate && $deadTime && $loginDate + 1800 > $now && $deadTime > $now ) { //로그인 정보는 30분간 유지한다. if ($result !== null) { $result = true; } return $this; } if ($generalID || $generalName || $loginDate || $deadTime) { $this->logoutGame(); } $generalID = -1; $generalName = 'DummyGeneral'; $deadTime = $now+60*60*24; $this->set($serverID.static::GAME_KEY_DATE, $now); $this->set($serverID.static::GAME_KEY_GENERAL_ID, $generalID); $this->set($serverID.static::GAME_KEY_GENERAL_NAME, $generalName); $this->set($serverID.static::GAME_KEY_EXPECTED_DEADTIME, $deadTime); return $this; } public function __destruct() { } }