Skip to content

Commit

Permalink
- BC Break: Required _PHP_ version changed >=7.1>=7.2
Browse files Browse the repository at this point in the history
- NEW "plugin API" for custom UI modules, closed exodus4d#913
- NEW live "Killstream" for killboard module, closed exodus4d#909
- NEW "custom layout" UI settings, closed exodus4d#470
  • Loading branch information
exodus4d committed Feb 1, 2020
1 parent c91bcbe commit 0c3d57e
Show file tree
Hide file tree
Showing 151 changed files with 32,261 additions and 21,653 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"latedef": false,

// Enforce line length to 100 characters
"maxlen": 200,
"maxlen": 220,

// Require capitalized names for constructor functions.
"newcap": true,
Expand Down
11 changes: 8 additions & 3 deletions app/Controller/Api/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function initData(\Base $f3){

// get program routes -------------------------------------------------------------------------------------
$return->routes = [
'ssoLogin' => $this->getF3()->alias( 'sso', ['action' => 'requestAuthorization'] )
'ssoLogin' => $this->getF3()->alias('sso', ['action' => 'requestAuthorization'])
];

// get third party APIs -----------------------------------------------------------------------------------
Expand All @@ -182,6 +182,11 @@ public function initData(\Base $f3){
'anoik' => Config::getPathfinderData('api.anoik')
];

// get Plugin config --------------------------------------------------------------------------------------
$return->plugin = [
'modules' => Config::getPluginConfig('modules')
];

// Character default config -------------------------------------------------------------------------------
$return->character = [
'autoLocationSelect' => (bool)Config::getPathfinderData('character.auto_location_select')
Expand Down Expand Up @@ -1065,7 +1070,7 @@ protected function updateMapByCharacter(Pathfinder\MapModel $map, Pathfinder\Cha
){
// check distance between systems (in jumps)
// -> if > 1 it is !very likely! a wormhole
$route = (new Route())->searchRoute($sourceSystem->systemId, $targetSystem->systemId, 1);
$route = (new Controller\Api\Rest\Route())->searchRoute($sourceSystem->systemId, $targetSystem->systemId, 1);

if(!$route['routePossible']){
$addSourceSystem = true;
Expand Down Expand Up @@ -1165,7 +1170,7 @@ protected function updateMapByCharacter(Pathfinder\MapModel $map, Pathfinder\Cha
// .. now we need to check jump distance between systems
// -> if > 1 it is !very likely! podded jump
if(empty($route)){
$route = (new Route())->searchRoute($sourceSystem->systemId, $targetSystem->systemId, 1);
$route = (new Controller\Api\Rest\Route())->searchRoute($sourceSystem->systemId, $targetSystem->systemId, 1);
}

if(!$route['routePossible']){
Expand Down
45 changes: 45 additions & 0 deletions app/Controller/Api/Rest/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,51 @@

class Connection extends AbstractRestController {

/**
* @param \Base $f3
* @param $params
* @throws \Exception
*/
public function get(\Base $f3, $params){
$requestData = $this->getRequestData($f3);
$connectionIds = array_map('intval', explode(',', (string)$params['id']));
$addData = (array)$requestData['addData'];
$filterData = (array)$requestData['filterData'];
$connectionData = [];

if($mapId = (int)$requestData['mapId']){
$activeCharacter = $this->getCharacter();

/**
* @var $map Pathfinder\MapModel
*/
$map = Pathfinder\AbstractPathfinderModel::getNew('MapModel');
$map->getById($mapId);

if($map->hasAccess($activeCharacter)){
$connections = $map->getConnections($connectionIds, 'wh');
foreach($connections as $connection){
$check = true;
$data = $connection->getData(in_array('signatures', $addData), in_array('logs', $addData));
// filter result
if(in_array('signatures', $filterData) && !$data->signatures){
$check = false;
}

if(in_array('logs', $filterData) && !$data->logs){
$check = false;
}

if($check){
$connectionData[] = $data;
}
}
}
}

$this->out($connectionData);
}

/**
* save a new connection or updates an existing (drag/drop) between two systems
* if a connection is changed (drag&drop) to another system. -> this function is called for update
Expand Down
41 changes: 9 additions & 32 deletions app/Controller/Api/Route.php → app/Controller/Api/Rest/Route.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 06.06.15
* Time: 03:34
*/

namespace Exodus4D\Pathfinder\Controller\Api;

namespace Exodus4D\Pathfinder\Controller\Api\Rest;


use Exodus4D\Pathfinder\Lib\Config;
use Exodus4D\Pathfinder\Controller;
use Exodus4D\Pathfinder\Controller\Ccp\Universe;
use Exodus4D\Pathfinder\Model\Pathfinder;

/**
* Routes controller
* Class Route
* @package Controller\Api
*/
class Route extends Controller\AccessController {
class Route extends AbstractRestController {


/**
* cache key for current Thera connections from eve-scout.com
Expand Down Expand Up @@ -739,8 +730,8 @@ private function getRouteCacheKey($mapIds, $systemFrom, $systemTo, $filterData =
* @param \Base $f3
* @throws \Exception
*/
public function search($f3){
$requestData = (array)$f3->get('POST');
public function post(\Base $f3){
$requestData = $this->getRequestData($f3);

$activeCharacter = $this->getCharacter();

Expand Down Expand Up @@ -861,20 +852,6 @@ public function search($f3){
}
}

echo json_encode($return);
$this->out($return);
}

}













}
112 changes: 112 additions & 0 deletions app/Controller/Api/Rest/SystemGraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php


namespace Exodus4D\Pathfinder\Controller\Api\Rest;

use Exodus4D\Pathfinder\Lib\Config;
use Exodus4D\Pathfinder\Model\Pathfinder;

class SystemGraph extends AbstractRestController {

/**
* cache key for HTTP response
*/
const CACHE_KEY_GRAPH = 'CACHED_SYSTEM_GRAPH_%s';

/**
* get graphs data for system(s)
* @param \Base $f3
* @param $params
* @throws \Exception
*/
public function get(\Base $f3, $params){
$requestData = $this->getRequestData($f3);
$systemIds = (array)$requestData['systemIds'];
$graphsData = [];

// valid response (data found) should be cached by server + client
$cacheResponse = false;

// number of log entries in each table per system (24 = 24h)
$logEntryCount = Pathfinder\AbstractSystemApiBasicModel::DATA_COLUMN_COUNT;

$ttl = 60 * 10;

// table names with system data
$logTables = [
'jumps' => 'SystemJumpModel',
'shipKills' => 'SystemShipKillModel',
'podKills' => 'SystemPodKillModel',
'factionKills' => 'SystemFactionKillModel'
];

$exists = false;

foreach($systemIds as $systemId){
$cacheKey = $this->getSystemGraphCacheKey($systemId);
if(!$exists = $f3->exists($cacheKey, $graphData)){
$graphData = [];
$cacheSystem = false;

foreach($logTables as $label => $className){
$systemLogModel = Pathfinder\AbstractSystemApiBasicModel::getNew($className);
$systemLogExists = false;

// 10min cache (could be up to 1h cache time)
$systemLogModel->getByForeignKey('systemId', $systemId);
if($systemLogModel->valid()){
$systemLogExists = true;
$cacheSystem = true;
$cacheResponse = true;
}

$systemLogData = $systemLogModel->getData();

// podKills share graph with shipKills -> skip
if($label != 'podKills'){
$graphData[$label]['logExists'] = $systemLogExists;
$graphData[$label]['updated'] = $systemLogData->updated;
}

$logValueCount = range(0, $logEntryCount - 1);
foreach($logValueCount as $i){
if($label == 'podKills'){
$graphData['shipKills']['data'][$i]['z'] = $systemLogData->values[$i];
}else{
$graphData[$label]['data'][] = [
'x' => ($logEntryCount - $i - 1) . 'h',
'y' => $systemLogData->values[$i]
];
}
}
}

if($cacheSystem){
$f3->set($cacheKey, $graphData, $ttl);
}
}else{
// server cache data exists -> client should cache as well
$cacheResponse = true;
}
$graphsData[$systemId] = $graphData;
}

if($cacheResponse){
// send client cache header
$f3->expire(Config::ttlLeft($exists, $ttl));
}

$this->out($graphsData);
}

// ----------------------------------------------------------------------------------------------------------------

/**
* get system graph cache key
* @param int $systemId
* @return string
*/
protected function getSystemGraphCacheKey(int $systemId): string {
return sprintf(self::CACHE_KEY_GRAPH, 'SYSTEM_' . $systemId);
}
}
97 changes: 0 additions & 97 deletions app/Controller/Api/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,103 +14,6 @@

class System extends Controller\AccessController {

// cache keys
const CACHE_KEY_GRAPH = 'CACHED_SYSTEM_GRAPH_%s';

/**
* get system graph cache key
* @param int $systemId
* @return string
*/
protected function getSystemGraphCacheKey(int $systemId): string {
return sprintf(self::CACHE_KEY_GRAPH, 'SYSTEM_' . $systemId);
}

/**
* get system log data from CCP API import
* system Kills, Jumps,....
* @param \Base $f3
* @throws \Exception
*/
public function graphData(\Base $f3){
$graphsData = [];
$systemIds = (array)$f3->get('GET.systemIds');

// valid response (data found) should be cached by server + client
$cacheResponse = false;

// number of log entries in each table per system (24 = 24h)
$logEntryCount = Pathfinder\AbstractSystemApiBasicModel::DATA_COLUMN_COUNT;

$ttl = 60 * 10;

// table names with system data
$logTables = [
'jumps' => 'SystemJumpModel',
'shipKills' => 'SystemShipKillModel',
'podKills' => 'SystemPodKillModel',
'factionKills' => 'SystemFactionKillModel'
];

$exists = false;

foreach($systemIds as $systemId){
$cacheKey = $this->getSystemGraphCacheKey($systemId);
if(!$exists = $f3->exists($cacheKey, $graphData)){
$graphData = [];
$cacheSystem = false;

foreach($logTables as $label => $className){
$systemLogModel = Pathfinder\AbstractSystemApiBasicModel::getNew($className);
$systemLogExists = false;

// 10min cache (could be up to 1h cache time)
$systemLogModel->getByForeignKey('systemId', $systemId);
if($systemLogModel->valid()){
$systemLogExists = true;
$cacheSystem = true;
$cacheResponse = true;
}

$systemLogData = $systemLogModel->getData();

// podKills share graph with shipKills -> skip
if($label != 'podKills'){
$graphData[$label]['logExists'] = $systemLogExists;
$graphData[$label]['updated'] = $systemLogData->updated;
}

$logValueCount = range(0, $logEntryCount - 1);
foreach($logValueCount as $i){
if($label == 'podKills'){
$graphData['shipKills']['data'][$i]['z'] = $systemLogData->values[$i];
}else{
$graphData[$label]['data'][] = [
'x' => ($logEntryCount - $i - 1) . 'h',
'y' => $systemLogData->values[$i]
];
}
}
}

if($cacheSystem){
$f3->set($cacheKey, $graphData, $ttl);
}
}else{
// server cache data exists -> client should cache as well
$cacheResponse = true;
}
$graphsData[$systemId] = $graphData;
}

if($cacheResponse){
// send client cache header
$f3->expire(Config::ttlLeft($exists, $ttl));
}

echo json_encode($graphsData);
}

/**
* set destination for system, station or structure
* @param \Base $f3
Expand Down
Loading

0 comments on commit 0c3d57e

Please sign in to comment.