Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- /* 2018-02
- apt install php-cli php-curl
- https://github.com/zKillboard/zKillboard/wiki/API-(Killmails)
- https://esi.evetech.net/
- */
- //--- EDIT THIS PART ------------------------------------------------------------------------------
- define('EVENTRUNTIME', 3600 * 2); //how long into the past on zkill to look for (multiple of 3600)
- define('EVENTREFRESH', 30); //when to refresh list (after 30 seconds)
- define('CHARACTERID', 0000000); //char who owns the ships to be killed (check your own zkill url)
- define('SHIPTYPEID', 606); //shiptype to kill (velator)
- define('NBRSHIPSTOTAL', 45); //amount of ships to kill
- define('NBRSHIPSSYSTEM', 5); //amount of ships to kill per system
- define('LOGFILE', '/tmp/wildvelatorhunt.txt'); //plaintext, use quote on forum
- //--- EDIT THIS PART END ------------------------------------------------------------------------------
- define('ZKILLPASTSECONDS', 'https://zkillboard.com/api/losses/characterID/%d/shipTypeID/%d/pastSeconds/%d/'); //%d = charID, %d = shiptypeid, %d = past seconds 3600 * X
- define('ESIKILLMAIL', 'https://esi.evetech.net/latest/killmails/%d/%s/'); //%d = killmailID, %s = killmailhash
- define('ESICHARNAME', 'https://esi.evetech.net/latest/characters/%d/'); //%d = charID
- define('ESISYSTEMNAME', 'https://esi.evetech.net/latest/universe/systems/%d/'); //%d = systemID
- date_default_timezone_set('UTC'); //evetime = UTC
- $processed = array();
- $char2name = array('Unknown/NPC');
- $system2name = array();
- $ship2name[606] = 'Velator (Gallente)';
- $ship2name[596] = 'Impairor (Amarr)';
- $ship2name[601] = 'Ibis (Caldari)';
- $ship2name[588] = 'Reaper (Minmatar)';
- $countsystem = array();
- $countkill = array();
- $counter = 0;
- $killog = array();
- //---------------------------------------------------------------------------------
- while(true) {
- $zkb = docurlthings(sprintf(ZKILLPASTSECONDS, CHARACTERID, SHIPTYPEID, EVENTRUNTIME));
- if(!empty($zkb)) {
- system('clear');
- foreach($zkb as $killmail) {
- if(in_array($killmail['killmail_id'], $processed)) continue;
- $esikillmail = docurlthings(sprintf(ESIKILLMAIL, $killmail['killmail_id'], $killmail['zkb']['hash']));
- if(empty($esikillmail)) continue;
- if(!array_key_exists($esikillmail['solar_system_id'], $system2name)) {
- $esisystemname = docurlthings(sprintf(ESISYSTEMNAME, $esikillmail['solar_system_id']));
- if(empty($esisystemname)) continue;
- $system2name[$esikillmail['solar_system_id']] = $esisystemname['name'];
- }
- $where = $system2name[$esikillmail['solar_system_id']];
- foreach($esikillmail['attackers'] as $ekm) {
- if(empty($ekm['final_blow'])) continue;
- if(empty($ekm['character_id'])) $ekm['character_id'] = 0;
- if(!array_key_exists($ekm['character_id'], $char2name)) {
- $esicharname = docurlthings(sprintf(ESICHARNAME, $ekm['character_id']));
- if(empty($esicharname)) continue 2;
- $char2name[$ekm['character_id']] = $esicharname['name'];
- }
- $by = $char2name[$ekm['character_id']];
- }
- if(!array_key_exists($esikillmail['victim']['character_id'], $char2name)) {
- $esicharname = docurlthings(sprintf(ESICHARNAME, $esikillmail['victim']['character_id']));
- if(empty($esicharname)) continue;
- $char2name[$esikillmail['victim']['character_id']] = $esicharname['name'];
- }
- $who = $char2name[$esikillmail['victim']['character_id']];
- $when = date('Y-m-d H:i:s', strtotime($esikillmail['killmail_time']));
- $counter++;
- if(!array_key_exists($by, $countkill)) $countkill[$by] = 1;
- else $countkill[$by]++;
- if(!array_key_exists($where, $countsystem)) $countsystem[$where] = 1;
- else $countsystem[$where]++;
- //$killog[$killmail['killmail_id']] = sprintf('%02d/%d - %s - id: %d - where: %s (%d/%d) - who: %s - by: %s'.PHP_EOL, $counter, NBRSHIPSTOTAL, $when, $killmail['killmail_id'], $where, $countsystem[$where], NBRSHIPSSYSTEM, $who, $by);
- $killog[$killmail['killmail_id']] = sprintf('%02d/%d - %s - id: %d - where: %s (%d/%d) - by: %s'.PHP_EOL, $counter, NBRSHIPSTOTAL, $when, $killmail['killmail_id'], $where, $countsystem[$where], NBRSHIPSSYSTEM, $by);
- echo $killog[$killmail['killmail_id']];
- $processed[] = $killmail['killmail_id'];
- }
- }
- if(!empty($countkill)) {
- arsort($countkill);
- $string = sprintf('---------------- Leaderboard (%02d/%02d) ----------------'.PHP_EOL, $counter, NBRSHIPSTOTAL);
- foreach($countkill as $who => $points) $string .= sprintf('%s -> %d Points'.PHP_EOL, $who, $points);
- echo $string;
- file_put_contents(LOGFILE, $string);
- }
- echo sprintf('------------------ Timer (%02d secs) ------------------'.PHP_EOL, EVENTREFRESH);
- if($counter < NBRSHIPSTOTAL) {
- echo sprintf('Now: %s - Next Refresh: %s'.PHP_EOL, date('H:i:s'), date('H:i:s', time() + EVENTREFRESH));
- } else {
- $string = '--------------------- Kill log ----------------------'.PHP_EOL;
- foreach($killog as $kl) $string .= substr($kl, strlen(NBRSHIPSTOTAL) * 2 + 4);
- file_put_contents(LOGFILE, $string, FILE_APPEND);
- echo sprintf('Now: %s - Event ended, Killcount reached !'.PHP_EOL, date('H:i:s'));
- echo sprintf('Logfile: %s'.PHP_EOL, LOGFILE);
- exit;
- }
- sleep(EVENTREFRESH);
- }
- //---------------------------------------------------------------------------------
- function docurlthings($url = false) {
- $result = false;
- if(!empty($url)) {
- $curlconnection = curl_init();
- curl_setopt($curlconnection, CURLOPT_CONNECTTIMEOUT, 10);
- curl_setopt($curlconnection, CURLOPT_TIMEOUT, 10);
- curl_setopt($curlconnection, CURLOPT_URL, $url);
- curl_setopt($curlconnection, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curlconnection, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($curlconnection, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($curlconnection, CURLOPT_ACCEPT_ENCODING, 'gzip');
- curl_setopt($curlconnection, CURLOPT_HTTPHEADER, array('content-type: application/json'));
- $result = curl_exec($curlconnection);
- if(curl_errno($curlconnection)) $result = false;
- curl_close($curlconnection);
- }
- return json_decode($result, true);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment