Guest User

Untitled

a guest
Mar 8th, 2025
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.99 KB | Gaming | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. /*  2018-02
  4.  
  5.     apt install php-cli php-curl
  6.  
  7.     https://github.com/zKillboard/zKillboard/wiki/API-(Killmails)
  8.     https://esi.evetech.net/
  9. */
  10.  
  11. //--- EDIT THIS PART ------------------------------------------------------------------------------
  12.  
  13. define('EVENTRUNTIME', 3600 * 2);   //how long into the past on zkill to look for (multiple of 3600)
  14. define('EVENTREFRESH', 30); //when to refresh list (after 30 seconds)
  15. define('CHARACTERID', 0000000); //char who owns the ships to be killed (check your own zkill url)
  16. define('SHIPTYPEID', 606);  //shiptype to kill (velator)
  17. define('NBRSHIPSTOTAL', 45);    //amount of ships to kill
  18. define('NBRSHIPSSYSTEM', 5);    //amount of ships to kill per system
  19. define('LOGFILE', '/tmp/wildvelatorhunt.txt');  //plaintext, use quote on forum
  20.  
  21. //--- EDIT THIS PART END ------------------------------------------------------------------------------
  22.  
  23. define('ZKILLPASTSECONDS', 'https://zkillboard.com/api/losses/characterID/%d/shipTypeID/%d/pastSeconds/%d/');   //%d = charID, %d = shiptypeid, %d = past seconds 3600 * X
  24. define('ESIKILLMAIL', 'https://esi.evetech.net/latest/killmails/%d/%s/');   //%d = killmailID, %s = killmailhash
  25. define('ESICHARNAME', 'https://esi.evetech.net/latest/characters/%d/'); //%d = charID
  26. define('ESISYSTEMNAME', 'https://esi.evetech.net/latest/universe/systems/%d/'); //%d = systemID
  27.  
  28. date_default_timezone_set('UTC');   //evetime = UTC
  29.  
  30. $processed = array();
  31. $char2name = array('Unknown/NPC');
  32. $system2name = array();
  33.  
  34. $ship2name[606] = 'Velator (Gallente)';
  35. $ship2name[596] = 'Impairor (Amarr)';
  36. $ship2name[601] = 'Ibis (Caldari)';
  37. $ship2name[588] = 'Reaper (Minmatar)';
  38.  
  39. $countsystem = array();
  40. $countkill = array();
  41. $counter = 0;
  42. $killog = array();
  43.  
  44. //---------------------------------------------------------------------------------
  45. while(true) {
  46.     $zkb = docurlthings(sprintf(ZKILLPASTSECONDS, CHARACTERID, SHIPTYPEID, EVENTRUNTIME));
  47.     if(!empty($zkb)) {
  48.         system('clear');
  49.  
  50.         foreach($zkb as $killmail) {
  51.             if(in_array($killmail['killmail_id'], $processed)) continue;
  52.  
  53.             $esikillmail = docurlthings(sprintf(ESIKILLMAIL, $killmail['killmail_id'], $killmail['zkb']['hash']));
  54.             if(empty($esikillmail)) continue;
  55.  
  56.             if(!array_key_exists($esikillmail['solar_system_id'], $system2name)) {
  57.                 $esisystemname = docurlthings(sprintf(ESISYSTEMNAME, $esikillmail['solar_system_id']));
  58.                 if(empty($esisystemname)) continue;
  59.                 $system2name[$esikillmail['solar_system_id']] = $esisystemname['name'];
  60.             }
  61.             $where = $system2name[$esikillmail['solar_system_id']];
  62.  
  63.             foreach($esikillmail['attackers'] as $ekm) {
  64.                 if(empty($ekm['final_blow'])) continue;
  65.                 if(empty($ekm['character_id'])) $ekm['character_id'] = 0;
  66.                 if(!array_key_exists($ekm['character_id'], $char2name)) {
  67.                     $esicharname = docurlthings(sprintf(ESICHARNAME, $ekm['character_id']));
  68.                     if(empty($esicharname)) continue 2;
  69.                     $char2name[$ekm['character_id']] = $esicharname['name'];
  70.                 }
  71.                 $by = $char2name[$ekm['character_id']];
  72.             }
  73.  
  74.             if(!array_key_exists($esikillmail['victim']['character_id'], $char2name)) {
  75.                 $esicharname = docurlthings(sprintf(ESICHARNAME, $esikillmail['victim']['character_id']));
  76.                 if(empty($esicharname)) continue;
  77.                 $char2name[$esikillmail['victim']['character_id']] = $esicharname['name'];
  78.             }
  79.             $who = $char2name[$esikillmail['victim']['character_id']];
  80.  
  81.             $when = date('Y-m-d H:i:s', strtotime($esikillmail['killmail_time']));
  82.  
  83.             $counter++;
  84.  
  85.             if(!array_key_exists($by, $countkill)) $countkill[$by] = 1;
  86.             else $countkill[$by]++;
  87.  
  88.             if(!array_key_exists($where, $countsystem)) $countsystem[$where] = 1;
  89.             else $countsystem[$where]++;
  90.  
  91.             //$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);
  92.             $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);
  93.             echo $killog[$killmail['killmail_id']];
  94.  
  95.             $processed[] = $killmail['killmail_id'];
  96.         }
  97.     }
  98.  
  99.     if(!empty($countkill)) {
  100.         arsort($countkill);
  101.         $string = sprintf('---------------- Leaderboard (%02d/%02d) ----------------'.PHP_EOL, $counter, NBRSHIPSTOTAL);
  102.         foreach($countkill as $who => $points) $string .= sprintf('%s -> %d Points'.PHP_EOL, $who, $points);
  103.         echo $string;
  104.         file_put_contents(LOGFILE, $string);
  105.     }
  106.  
  107.     echo sprintf('------------------ Timer (%02d secs) ------------------'.PHP_EOL, EVENTREFRESH);
  108.     if($counter < NBRSHIPSTOTAL) {
  109.         echo sprintf('Now: %s - Next Refresh: %s'.PHP_EOL, date('H:i:s'), date('H:i:s', time() + EVENTREFRESH));
  110.     } else {
  111.         $string = '--------------------- Kill log ----------------------'.PHP_EOL;
  112.         foreach($killog as $kl) $string .= substr($kl, strlen(NBRSHIPSTOTAL) * 2 + 4);
  113.         file_put_contents(LOGFILE, $string, FILE_APPEND);
  114.         echo sprintf('Now: %s - Event ended, Killcount reached !'.PHP_EOL, date('H:i:s'));
  115.         echo sprintf('Logfile: %s'.PHP_EOL, LOGFILE);
  116.         exit;
  117.     }
  118.  
  119.     sleep(EVENTREFRESH);
  120. }
  121.  
  122. //---------------------------------------------------------------------------------
  123. function docurlthings($url = false) {
  124.     $result = false;
  125.     if(!empty($url)) {
  126.         $curlconnection = curl_init();
  127.         curl_setopt($curlconnection, CURLOPT_CONNECTTIMEOUT, 10);
  128.         curl_setopt($curlconnection, CURLOPT_TIMEOUT, 10);
  129.         curl_setopt($curlconnection, CURLOPT_URL, $url);
  130.         curl_setopt($curlconnection, CURLOPT_RETURNTRANSFER, 1);
  131.         curl_setopt($curlconnection, CURLOPT_SSL_VERIFYHOST, 0);
  132.         curl_setopt($curlconnection, CURLOPT_SSL_VERIFYPEER, 0);
  133.         curl_setopt($curlconnection, CURLOPT_ACCEPT_ENCODING, 'gzip');
  134.         curl_setopt($curlconnection, CURLOPT_HTTPHEADER, array('content-type: application/json'));
  135.  
  136.         $result = curl_exec($curlconnection);
  137.         if(curl_errno($curlconnection)) $result = false;
  138.         curl_close($curlconnection);
  139.     }
  140.     return json_decode($result, true);
  141. }
  142. ?>
  143.  
Advertisement
Add Comment
Please, Sign In to add comment