diff --git a/README-Install.md b/README-Install.md index 0e1dc35..6dfdeb5 100644 --- a/README-Install.md +++ b/README-Install.md @@ -108,6 +108,7 @@ Dependencies * (Optional) iconv extension (`iconv.so`) * (Optional) intl extension (`intl.so`) * (Optional) APC (or APCu for PHP >= 5.5) extension (`apc.so`) + * (Optional) Stomp extension (`stomp.so`) * PostgreSQL >= 9.0 diff --git a/UPDATING b/UPDATING index 3af80c4..38e8671 100644 --- a/UPDATING +++ b/UPDATING @@ -1,3 +1,9 @@ +staging +======= + +The [eve_kill] section has been added to config.ini. If you want to +import Eve-Kill data, you need to install the Stomp extension. + v0.13.3, released 2014-12-13 ============================ diff --git a/bin/cache_top_kills b/bin/cache_top_kills index be934bd..898ee8b 100755 --- a/bin/cache_top_kills +++ b/bin/cache_top_kills @@ -1,7 +1,7 @@ #!/usr/bin/env php + * Copyright (C) 2013, 2015 Romain "Artefact2" Dalmaso * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -22,6 +22,12 @@ namespace Osmium\CLI\CacheTopKills; require __DIR__.'/../inc/root.php'; require \Osmium\ROOT.'/inc/ajax-common.php'; +echo "Purging old kills…\n"; +\Osmium\Db\query_params( + 'DELETE FROM osmium.recentkillsdna WHERE killtime < $1', + array(time() - 7*86400) +); + echo "Caching groupdna…\n"; $q = \Osmium\Db\query_params( diff --git a/bin/cron.hourly b/bin/cron.hourly index 2bc828c..138da7f 100755 --- a/bin/cron.hourly +++ b/bin/cron.hourly @@ -11,7 +11,6 @@ require __DIR__.'/../inc/cron.php'; function() { passthru('./bin/update_lscores'); passthru('./bin/prune_cache'); - passthru('./bin/fetch_zkillboard_json'); passthru('./bin/cache_top_kills'); }, 20 * 60, diff --git a/bin/eve_kill_stomp_client b/bin/eve_kill_stomp_client new file mode 100755 index 0000000..3bd8b59 --- /dev/null +++ b/bin/eve_kill_stomp_client @@ -0,0 +1,136 @@ +#!/usr/bin/env php + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Osmium\CLI\EveKillStompClient; + +require __DIR__.'/../inc/root.php'; + +if(!\Osmium\get_ini_setting('enable_eve_kill')) { + echo "Eve-Kill support is not enabled in config.ini.\n"; + die(); +} + +/* XXX: daemonize me! */ +/* XXX: mention me in README-Install */ + +/* The zKillboard documentation doesn't say if the dates are in UTC, + * but they probably are */ +date_default_timezone_set('UTC'); + +$d = \Osmium\Db\prepare('delkill', 'DELETE FROM recentkillsdna WHERE killid = $1'); +$i = \Osmium\Db\prepare( + 'inskill', + 'INSERT INTO recentkillsdna (killid, killtime, dna, groupdna, solarsystemid, + characterid, charactername, corporationid, corporationname, allianceid, alliancename) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)' +); + +if($d === false || $i === false) { + fprintf(STDERR, "pgsql error\n"); + die(1); +} + +/* Not a typo. This allows the script to continue running after read + * timeouts. */ +while(true) try { + $stomp = new \Stomp( + \Osmium\get_ini_setting('eve_kill_stomp_uri'), + \Osmium\get_ini_setting('eve_kill_stomp_user'), + \Osmium\get_ini_setting('eve_kill_stomp_pass') + ); + + $stomp->setReadTimeout(5); + /* XXX: what do the options mean? */ + $stomp->subscribe('/topic/kills', [ + 'id' => \Osmium\get_ini_setting('eve_kill_stomp_id').'-'.gethostname(), + 'persistent' => 'true', + 'ack' => 'client', + 'prefetch-count' => 1, + ]); + + while($frame = $stomp->readFrame()) { + $stomp->ack($frame->headers['message-id']); + + $k = json_decode($frame->body, true); + if(json_last_error() !== JSON_ERROR_NONE || $k === false) { + throw new \Exception((string)$frame->body); + continue; + } + + if(!isset($k['killID']) || $k['killID'] <= 0) continue; + + $dna = $k['victim']['shipTypeID']; + + foreach($k['items'] as $item) { + $f = (int)$item['flag']; + if(!( + /* See invflags */ + ($f >= 11 && $f <= 34) /* Low, medium, high slots */ + || ($f >= 92 && $f <= 99) /* Rig slots */ + || ($f >= 125 && $f <= 132) /* Subsystem slots */ + || ($f === 87) /* Drone bay */ + || ($f === 88) /* Booster */ + || ($f === 89) /* Implant */ + )) { + continue; + } + + $typeid = (int)$item['typeID']; + $qty = (int)$item['qtyDropped'] + (int)$item['qtyDestroyed']; + if($qty === 0) continue; + $dna .= ':'.$typeid.';'.$qty; + } + + $dna .= '::'; + + $dna = \Osmium\Fit\mangle_dna($dna); + $gdna = \Osmium\Fit\uniquify_dna($dna); + + if($dna === false || $gdna === false) { + continue; + } + + $d = \Osmium\Db\execute('delkill', array($k['killID'])); + $i = \Osmium\Db\execute( + 'inskill', + array( + $k['killID'], + strtotime($k['killTime']), + $dna, + $gdna, + $k['solarSystemID'], + $k['victim']['characterID'], + $k['victim']['characterName'], + $k['victim']['corporationID'], + $k['victim']['corporationName'], + $k['victim']['allianceID'] > 0 ? $k['victim']['allianceID'] : null, + $k['victim']['allianceID'] > 0 ? $k['victim']['allianceName'] : null, + ) + ); + + if($d === false || $i === false) throw new \Exception('pgsql failure'); + + echo '.'; + } +} catch(\Exception $e) { + ob_start(); + var_dump($e); + fprintf(STDERR, ob_get_clean()); + die(1); +} diff --git a/bin/sanity_check b/bin/sanity_check index 1519845..88b79fa 100755 --- a/bin/sanity_check +++ b/bin/sanity_check @@ -1,7 +1,7 @@ #!/usr/bin/env php + * Copyright (C) 2013, 2014, 2015 Romain "Artefact2" Dalmaso * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -89,8 +89,11 @@ foreach(array( check_func($func); } -check_ext('dom'); -check_method('DOMImplementation', 'createDocument'); +check_ext('dom', CHECK_REQUIRED); +check_method('DOMImplementation', 'createDocument', CHECK_REQUIRED); + +check_ext('stomp'); +check_method('Stomp', 'ack'); check_ext('intl'); check_method('Normalizer', 'normalize'); @@ -99,9 +102,11 @@ check_method('Normalizer', 'normalize'); @include_once 'HTMLPurifier.auto.php'; check_method('HTMLPurifier', 'purify', CHECK_REQUIRED); -check('for HTMLPurifier >= '.MIN_HP_VER, function() { - return array(version_compare(HTMLPurifier::VERSION, MIN_HP_VER, '>='), HTMLPurifier::VERSION); -}, CHECK_REQUIRED); +if(class_exists('HTMLPurifier')) { + check('for HTMLPurifier >= '.MIN_HP_VER, function() { + return array(version_compare(HTMLPurifier::VERSION, MIN_HP_VER, '>='), HTMLPurifier::VERSION); + }, CHECK_REQUIRED); +} check('whether config.ini exists', function() { $ini = __DIR__.'/../config.ini'; diff --git a/config-example.ini b/config-example.ini index e13f739..6241d99 100644 --- a/config-example.ini +++ b/config-example.ini @@ -254,3 +254,14 @@ ccp_oauth_root="https://sisilogin.testeveonline.com" ; Given to you by CCP. ccp_oauth_clientid="" ccp_oauth_secret="" + +[eve_kill] + +; Use Eve-Kill data to display flavors of the week and popular +; alliance doctrines on the homepage. +enable_eve_kill=Off + +eve_kill_stomp_id=osmium +eve_kill_stomp_uri=tcp://eve-kill.net:61613 +eve_kill_stomp_user=guest +eve_kill_stomp_pass=guest