/** * login a valid character * @param Model\CharacterModel $characterModel * @return bool */ protected function loginByCharacter(Model\CharacterModel &$characterModel) { $login = false; if ($user = $characterModel->getUser()) { // set user/character data to session ------------------- $this->f3->set(self::SESSION_KEY_USER, ['ID' => $user->_id, 'NAME' => $user->name]); $dateTime = new \DateTime(); $this->f3->set(self::SESSION_KEY_CHARACTER, ['ID' => $characterModel->_id, 'NAME' => $characterModel->name, 'TIME' => $dateTime->getTimestamp()]); // save user login information --------------------------- $characterModel->touch('lastLogin'); $characterModel->save(); // write login log -------------------------------------- self::getLogger('LOGIN')->write(sprintf(self::LOG_LOGGED_IN, $user->_id, $user->name, $characterModel->_id, $characterModel->name)); $login = true; } return $login; }
/** * * @param Model\CharacterModel $character * @param Model\MapModel $map * @return Model\MapModel */ protected function updateMapData(Model\CharacterModel $character, Model\MapModel $map) { // update "map data" cache in case of map (system/connection) changes $clearMapDataCache = false; if (($mapScope = $map->getScope()) && $mapScope->name != 'none' && ($log = $character->getLog())) { // character is currently in a system $sameSystem = false; $sourceExists = true; $targetExists = true; // system coordinates $systemOffsetX = 130; $systemOffsetY = 0; $systemPosX = 0; $systemPosY = 30; $sourceSystemId = (int) $this->getF3()->get(User::SESSION_KEY_CHARACTER_PREV_SYSTEM_ID); $targetSystemId = (int) $log->systemId; if ($sourceSystemId) { $sourceSystem = null; $targetSystem = null; // check if source and target systems are equal // -> NO target system available if ($sourceSystemId === $targetSystemId) { // check if previous (solo) system is already on the map $sourceSystem = $map->getSystemByCCPId($sourceSystemId, ['active' => 1]); $sameSystem = true; } else { // check if previous (source) system is already on the map $sourceSystem = $map->getSystemByCCPId($sourceSystemId, ['active' => 1]); // -> check if system is already on this map $targetSystem = $map->getSystemByCCPId($targetSystemId, ['active' => 1]); } // if systems donĀ“t already exists on map -> get "blank" systems // -> required for system type check (e.g. wormhole, k-space) if (!$sourceSystem && $sourceSystemId) { $sourceExists = false; $sourceSystem = $map->getNewSystem($sourceSystemId); } else { // system exists -> add target to the "right" $systemPosX = $sourceSystem->posX + $systemOffsetX; $systemPosY = $sourceSystem->posY + $systemOffsetY; } if (!$sameSystem && !$targetSystem) { $targetExists = false; $targetSystem = $map->getNewSystem($targetSystemId); } $addSourceSystem = false; $addTargetSystem = false; $addConnection = false; switch ($mapScope->name) { case 'all': if ($sameSystem) { $addSourceSystem = true; } else { $addSourceSystem = true; $addTargetSystem = true; $addConnection = true; } break; case 'k-space': if ($sameSystem) { if (!$sourceSystem->isWormhole()) { $addSourceSystem = true; } } elseif (!$sourceSystem->isWormhole() || !$targetSystem->isWormhole()) { $addSourceSystem = true; $addTargetSystem = true; $addConnection = true; } break; case 'wh': default: if ($sameSystem) { if ($sourceSystem->isWormhole()) { $addSourceSystem = true; } } elseif ($sourceSystem->isWormhole() || $targetSystem->isWormhole()) { $addSourceSystem = true; $addTargetSystem = true; $addConnection = true; } elseif (!$sourceSystem->isWormhole() && !$targetSystem->isWormhole()) { // check distance between systems (in jumps) // -> if > 1 it is !very likely! a wormhole $routeController = new Route(); $routeController->initJumpData(); $route = $routeController->findRoute($sourceSystem->name, $targetSystem->name, 1); if (!$route['routePossible']) { $addSourceSystem = true; $addTargetSystem = true; $addConnection = true; } } break; } // save source system ------------------------------------------------------------------------------------- if ($addSourceSystem && $sourceSystem && !$sourceExists) { $sourceSystem = $map->saveSystem($sourceSystem, $systemPosX, $systemPosY, $character); // get updated maps object if ($sourceSystem) { $map = $sourceSystem->mapId; $sourceExists = true; $clearMapDataCache = true; // increase system position (prevent overlapping) $systemPosX = $sourceSystem->posX + $systemOffsetX; $systemPosY = $sourceSystem->posY + $systemOffsetY; } } // save target system ------------------------------------------------------------------------------------- if ($addTargetSystem && $targetSystem && !$targetExists) { $targetSystem = $map->saveSystem($targetSystem, $systemPosX, $systemPosY, $character); // get updated maps object if ($targetSystem) { $map = $targetSystem->mapId; $clearMapDataCache = true; $targetExists = true; } } // save connection ---------------------------------------------------------------------------------------- if ($addConnection && $sourceExists && $targetExists && $sourceSystem && $targetSystem && !$map->searchConnection($sourceSystem, $targetSystem)) { $connection = $map->getNewConnection($sourceSystem, $targetSystem); $connection = $map->saveConnection($connection); // get updated maps object if ($connection) { $map = $connection->mapId; $clearMapDataCache = true; } } } } if ($clearMapDataCache) { $this->clearMapDataCache($character); } return $map; }
/** * set/update logged in cookie by character model * -> store validation data in DB * @param Model\CharacterModel $character */ protected function setLoginCookie(Model\CharacterModel $character) { if ($this->getCookieState()) { $expireSeconds = (int) $this->getF3()->get('PATHFINDER.LOGIN.COOKIE_EXPIRE'); $expireSeconds *= 24 * 60 * 60; $timezone = new \DateTimeZone($this->getF3()->get('TZ')); $expireTime = new \DateTime('now', $timezone); // add cookie expire time $expireTime->add(new \DateInterval('PT' . $expireSeconds . 'S')); // unique "selector" -> to facilitate database look-ups (small size) // -> This is preferable to simply using the database id field, // which leaks the number of active users on the application $selector = bin2hex(mcrypt_create_iv(12, MCRYPT_DEV_URANDOM)); // generate unique "validator" (strong encryption) // -> plaintext set to user (cookie), hashed version of this in DB $size = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB); $validator = bin2hex(mcrypt_create_iv($size, MCRYPT_DEV_URANDOM)); // generate unique cookie token $token = hash('sha256', $validator); // get unique cookie name for this character $name = $character->getCookieName(); $authData = ['characterId' => $character, 'selector' => $selector, 'token' => $token, 'expires' => $expireTime->format('Y-m-d H:i:s')]; $authenticationModel = $character->rel('characterAuthentications'); $authenticationModel->copyfrom($authData); $authenticationModel->save(); $cookieValue = implode(':', [$selector, $validator]); // get cookie name -> save new one OR update existing cookie $cookieName = 'COOKIE.' . self::COOKIE_PREFIX_CHARACTER . '_' . $name; $this->getF3()->set($cookieName, $cookieValue, $expireSeconds); } }
/** * set new ingame waypoint * @param Model\CharacterModel $character * @param int $systemId * @param array $options * @return array */ public function setWaypoint(Model\CharacterModel $character, $systemId, $options = []) { $crestUrlParts = parse_url(self::getCrestEndpoint()); $waypointData = []; if ($crestUrlParts) { $accessToken = $character->getAccessToken(); $endpoints = $this->getEndpoints($accessToken); // get endpoint list for "ui" endpoints $uiEndpoints = $endpoint = $this->walkEndpoint($endpoints, $accessToken, ['decode', 'character', 'ui']); if (isset($uiEndpoints['setWaypoints']) && isset($uiEndpoints['setWaypoints']['href'])) { $endpointUrl = $uiEndpoints['setWaypoints']['href']; $systemEndpoint = self::getCrestEndpoint() . '/solarsystems/' . $systemId . '/'; // request body $content = ['clearOtherWaypoints' => (bool) $options['clearOtherWaypoints'], 'first' => (bool) $options['first'], 'solarSystem' => ['href' => $systemEndpoint, 'id' => (int) $systemId]]; $requestOptions = ['timeout' => self::CREST_TIMEOUT, 'method' => 'POST', 'user_agent' => $this->getUserAgent(), 'header' => ['Scope: characterNavigationWrite', 'Authorization: Bearer ' . $character->getAccessToken(), 'Host: ' . $crestUrlParts['host'], 'Content-Type: application/vnd.ccp.eve.PostWaypoint-v1+json;charset=utf-8'], 'content' => json_encode($content, JSON_UNESCAPED_SLASHES)]; $apiResponse = Lib\Web::instance()->request($endpointUrl, $requestOptions); if (isset($apiResponse['body'])) { $responseData = json_decode($apiResponse['body']); if (empty($responseData)) { $waypointData['systemId'] = (int) $systemId; } elseif (isset($responseData->message) && isset($responseData->key)) { // waypoint could not be set... $error = (object) []; $error->type = 'error'; $error->message = $responseData->key; $waypointData['error'] = $error; } } } } return $waypointData; }
/** * checks whether a character has access to this map or not * @param CharacterModel $characterModel * @return bool */ public function hasAccess(CharacterModel $characterModel) { $hasAccess = false; if (!$this->dry()) { // get all maps the user has access to // this includes corporation and alliance maps $maps = $characterModel->getMaps(); foreach ($maps as $map) { if ($map->id === $this->id) { $hasAccess = true; break; } } } return $hasAccess; }