Changeset 162

Show
Ignore:
Timestamp:
12/23/06 02:31:43 (14 years ago)
Author:
exi
Message:

Added externalids to autoupgrade code.
Added custom headers to the http_class.
Added an option to set the socket timeout when using the http_class.
Pushed version to 1.2.2 in globals.php.
Fixed a bug in the battle parser which prevented it from parsing kills of the last day.
Added code to the synchronization module so it can handle item value updates as well.
Changed killists so they don't list kills as a kill anymore where an corp/alliance member has been killed, right, those are now pure losses. This should also resolve an issue with the battle parser going mad.

Location:
dev/common
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • dev/common/admin.php

    r158 r162  
    2323check_tblstrct5(); 
    2424chk_kb3_items(); 
     25chk_kb3_items2(); 
    2526check_tblstrct6(); 
    2627 
  • dev/common/admin_sync.php

    r154 r162  
    11<?php 
    2 require_once("db.php"); 
    32require_once("class.page.php"); 
    43require_once("class.contract.php"); 
     
    109$page->setTitle("Administration - Synchronization"); 
    1110 
    12 if ($_REQUEST['do'] == "sync") 
     11if ($_REQUEST['do'] == 'sync') 
    1312{ 
    14     $do_sync = true; 
    15 } 
     13    $http = new http_request(KB_SYNCURL); 
     14    $fp = $http->connect(); 
     15    if (!$fp) 
     16    { 
     17        $html .= "Could not connect to Server:<br/>\n"; 
     18        $html .= $http-getError(); 
    1619 
    17 if ($do_sync) 
    18 { 
     20        $page->addContext($menubox->generate()); 
     21        $page->setContent($html); 
     22        $page->generate(); 
     23        return; 
     24    } 
     25 
     26    $content_file = 'DATA_START'; 
    1927    $qry = new DBQuery(); 
    2028    $qry->execute("select plt_name, plt_externalid from kb3_pilots where plt_externalid != 0"); 
     
    2432    } 
    2533 
    26     $http = new http_request(KB_SYNCURL); 
    27     $fp = $http->connect(); 
    28     if (!$fp) 
     34    $content_file .= 'ITEMS_START'; 
     35    $qry->execute("select itm_name, itm_externalid, itm_value from kb3_items where itm_value != 0"); 
     36    while ($data = $qry->getRow()) 
    2937    { 
    30         $html .= "Could not connect to Server<br>\n"; 
     38        $content_file .= '§'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$data['itm_value'].'-'; 
    3139    } 
    32 } 
    33 if ($do_sync && $fp) 
    34 { 
     40 
    3541    $content_file = gzdeflate($content_file); 
    3642 
    3743    $http->set_postdata('data', $content_file); 
    3844    $http->set_useragent("EVE-KB SYNC (VER ".KB_VERSION.")"); 
     45    $http->set_header('X-KBHost: '.base64_encode(KB_HOST)); 
     46    $http->setSockettimeout(30); 
    3947    $file = $http->get_content(); 
    4048    $header = $http->get_header(); 
     
    5866        // get all names we'll find 
    5967        preg_match_all("^!(.*?)\|(.*?)-^", $data, $matches); 
    60         unset($data); 
    6168        $results = count($matches[1]); 
    6269        $update = new DBQuery(); 
     
    6572            $update->execute("update kb3_pilots set plt_externalid='".addslashes($matches[2][$i])."' where plt_name='".addslashes($matches[1][$i])."' limit 1"); 
    6673        } 
    67         $html .= "Synchronization complete, got $results new ids from server running version ".$version[0].'.'.$version[1].'.'.$version[2].'.<br>'; 
     74        $html .= "Synchronization complete, got $results new ids from server running version ".$version[0].'.'.$version[1].'.'.$version[2].'.<br/>'; 
     75 
     76        if (isset($_REQUEST['itm_update'])) 
     77        { 
     78            preg_match_all('^§(.*?)\|(.*?)\|(.*?)-^', $data, $matches); 
     79            unset($data); 
     80            $results = count($matches[1]); 
     81            for ($i = 0; $i<$results; $i++) 
     82            { 
     83                $update->execute("update kb3_items set itm_externalid='".addslashes($matches[2][$i])."', itm_value='".addslashes($matches[3][$i])."' where itm_name='".addslashes($matches[1][$i])."' limit 1"); 
     84            } 
     85            if ($results == 0) 
     86            { 
     87                $html .= 'No items fetched, itm_sync_module may be offline.<br/>'; 
     88            } 
     89            else 
     90            { 
     91                $html .= $results.' item prices have been fetched.<br/>'; 
     92            } 
     93        } 
     94 
    6895        $html .= "Sent ".round($sended/1024, 2)." kB and received ".round($recv/1024, 2)." kB of data.<br>\n"; 
    6996        $html .= '<a href="?a=admin_sync">Back</a>'; 
     
    74101        if ($version[1] > $ownversion[1] && $version[1] % 2 == 1) 
    75102        { 
    76             // test vor new minor updates below the dev-version 
     103            // test for new minor updates below the dev-version 
    77104            if ($version[1]-1 > $ownversion[1]) 
    78105            { 
     
    87114        if ($version[0] > $ownversion[0] || $upgrade) 
    88115        { 
    89             $html .= "Looks like your Killboard version is pretty old, perhaps you want to upgrade it ?<br>\n"; 
     116            $html .= "Looks like your Killboard version is pretty old, perhaps you want to upgrade it ?<br/>\n"; 
    90117            $html .= "Check the <a href='http://www.eve-dev.net/forums/viewforum.php?f=2'>EVE-Dev Forums</a> for new releases and additional information<br>\n"; 
    91118        } 
     
    98125    $html .= 'One synchronization every one or two weeks should be enough.<br>'; 
    99126    $html .= 'Please don\'t abuse this free service!<br>'; 
    100     $html .= '<a href="?a=admin_sync&do=sync">Synchronize now</a>'; 
     127    $html .= '<form id="options" name="options" method="post" action="?a=admin_sync">'; 
     128    $html .= "<table class=kb-subtable>"; 
     129    $html .= "<tr><td width=120><b>Update item values</b></td><td><input type=checkbox name=itm_update id=itm_update"; 
     130    $html .= " checked=\"checked\"></td></tr>"; 
     131    $html .= '<input type="hidden" name="do" value="sync">'; 
     132    $html .= '<tr><td width=120></td><td><input type=submit name=submit value="Synchronize now"></td></tr></table></form>'; 
    101133} 
    102134$page->addContext($menubox->generate()); 
  • dev/common/autoupgrade.php

    r158 r162  
    269269    } 
    270270} 
     271function chk_kb3_items2() 
     272{ 
     273    $qry = new DBQuery(); 
     274    $query = 'select itm_externalid from kb3_items where itm_name = \'Repair Drone\''; 
     275    $result = mysql_query($query); 
     276    $result = mysql_fetch_array($result); 
     277    if ($result['itm_externalid'] == '9871') 
     278    { 
     279        return; 
     280    } 
     281    $queries = " 
     282            update kb3_items set itm_externalid='10246' where itm_name='Mining Drone I'; 
     283            update kb3_items set itm_externalid='10248' where itm_name='Mining Drone - Improved UNUSED'; 
     284            update kb3_items set itm_externalid='10250' where itm_name='Mining Drone II'; 
     285            update kb3_items set itm_externalid='1187' where itm_name='Mining Drone - Elite'; 
     286            update kb3_items set itm_externalid='1201' where itm_name='Proximity Drone'; 
     287            update kb3_items set itm_externalid='1202' where itm_name='Wasp I'; 
     288            update kb3_items set itm_externalid='15508' where itm_name='Civilian Mining Drone'; 
     289            update kb3_items set itm_externalid='15510' where itm_name='Vespa I'; 
     290            update kb3_items set itm_externalid='16206' where itm_name='Valkyrie I'; 
     291            update kb3_items set itm_externalid='17565' where itm_name='Hellhound I'; 
     292            update kb3_items set itm_externalid='21050' where itm_name='Unanchoring Drone'; 
     293            update kb3_items set itm_externalid='21638' where itm_name='Survey Drone'; 
     294            update kb3_items set itm_externalid='21640' where itm_name='Vespa II'; 
     295            update kb3_items set itm_externalid='2173' where itm_name='Valkyrie II'; 
     296            update kb3_items set itm_externalid='2175' where itm_name='Infiltrator I'; 
     297            update kb3_items set itm_externalid='2183' where itm_name='Infiltrator II'; 
     298            update kb3_items set itm_externalid='2185' where itm_name='Hammerhead I'; 
     299            update kb3_items set itm_externalid='2193' where itm_name='Hammerhead II'; 
     300            update kb3_items set itm_externalid='2195' where itm_name='Praetor I'; 
     301            update kb3_items set itm_externalid='2203' where itm_name='Praetor II'; 
     302            update kb3_items set itm_externalid='2205' where itm_name='Acolyte I'; 
     303            update kb3_items set itm_externalid='2205' where itm_name='Acolyte II'; 
     304            update kb3_items set itm_externalid='22572' where itm_name='Praetor EV-900'; 
     305            update kb3_items set itm_externalid='22574' where itm_name='Warp Scrambling Drone'; 
     306            update kb3_items set itm_externalid='22713' where itm_name='10mn webscramblifying Drone'; 
     307            update kb3_items set itm_externalid='22765' where itm_name='Heavy Shield Maintenance Bot I'; 
     308            update kb3_items set itm_externalid='22780' where itm_name='Fighter Uno'; 
     309            update kb3_items set itm_externalid='23055' where itm_name='Templar'; 
     310            update kb3_items set itm_externalid='23057' where itm_name='Dragonfly'; 
     311            update kb3_items set itm_externalid='23059' where itm_name='Firbolg'; 
     312            update kb3_items set itm_externalid='23061' where itm_name='Einherji'; 
     313            update kb3_items set itm_externalid='23473' where itm_name='Wasp EC-900'; 
     314            update kb3_items set itm_externalid='23506' where itm_name='Ogre SD-900'; 
     315            update kb3_items set itm_externalid='23510' where itm_name='Praetor TD-900'; 
     316            update kb3_items set itm_externalid='23512' where itm_name='Berserker TP-900'; 
     317            update kb3_items set itm_externalid='23523' where itm_name='Heavy Armor Maintenance Bot I'; 
     318            update kb3_items set itm_externalid='23525' where itm_name='Curator I'; 
     319            update kb3_items set itm_externalid='23559' where itm_name='Berserker SW-900'; 
     320            update kb3_items set itm_externalid='23559' where itm_name='Warden I'; 
     321            update kb3_items set itm_externalid='23561' where itm_name='Garde I'; 
     322            update kb3_items set itm_externalid='23563' where itm_name='Bouncer I'; 
     323            update kb3_items set itm_externalid='23659' where itm_name='Acolyte EV-300'; 
     324            update kb3_items set itm_externalid='23702' where itm_name='Infiltrator EV-600'; 
     325            update kb3_items set itm_externalid='23705' where itm_name='Vespa EC-600'; 
     326            update kb3_items set itm_externalid='23707' where itm_name='Hornet EC-300'; 
     327            update kb3_items set itm_externalid='23709' where itm_name='Medium Armor Maintenance Bot I'; 
     328            update kb3_items set itm_externalid='23711' where itm_name='Light Armor Maintenance Bot I'; 
     329            update kb3_items set itm_externalid='23713' where itm_name='Hammerhead SD-600'; 
     330            update kb3_items set itm_externalid='23715' where itm_name='Hobgoblin SD-300'; 
     331            update kb3_items set itm_externalid='23717' where itm_name='Medium Shield Maintenance Bot I'; 
     332            update kb3_items set itm_externalid='23719' where itm_name='Light Shield Maintenance Bot I'; 
     333            update kb3_items set itm_externalid='23721' where itm_name='Valkyrie TP-600'; 
     334            update kb3_items set itm_externalid='23723' where itm_name='Warrior TP-300'; 
     335            update kb3_items set itm_externalid='23725' where itm_name='Infiltrator TD-600'; 
     336            update kb3_items set itm_externalid='23727' where itm_name='Acolyte TD-300'; 
     337            update kb3_items set itm_externalid='23729' where itm_name='Valkyrie SW-600'; 
     338            update kb3_items set itm_externalid='23731' where itm_name='Warrior SW-300'; 
     339            update kb3_items set itm_externalid='23759' where itm_name='FA-14 Templar'; 
     340            update kb3_items set itm_externalid='2436' where itm_name='Wasp II'; 
     341            update kb3_items set itm_externalid='2444' where itm_name='Ogre I'; 
     342            update kb3_items set itm_externalid='2446' where itm_name='Ogre II'; 
     343            update kb3_items set itm_externalid='2454' where itm_name='Hobgoblin I'; 
     344            update kb3_items set itm_externalid='2456' where itm_name='Hobgoblin II'; 
     345            update kb3_items set itm_externalid='24618' where itm_name='horrible tracking drone'; 
     346            update kb3_items set itm_externalid='2464' where itm_name='Hornet I'; 
     347            update kb3_items set itm_externalid='2466' where itm_name='Hornet II'; 
     348            update kb3_items set itm_externalid='2476' where itm_name='Berserker I'; 
     349            update kb3_items set itm_externalid='2478' where itm_name='Berserker II'; 
     350            update kb3_items set itm_externalid='2486' where itm_name='Warrior I'; 
     351            update kb3_items set itm_externalid='2488' where itm_name='Warrior II'; 
     352            update kb3_items set itm_externalid='3218' where itm_name='Harvester Mining Drone'; 
     353            update kb3_items set itm_externalid='3549' where itm_name='Tutorial Attack Drone'; 
     354            update kb3_items set itm_externalid='9871' where itm_name='Repair Drone'; 
     355        "; 
     356    $query = explode("\n", $queries); 
     357    foreach ($query as $querystring) 
     358    { 
     359        if ($string = trim(str_replace(');', ')', $querystring))) 
     360        { 
     361            $qry->execute($string); 
     362        } 
     363    } 
     364} 
    271365function check_tblstrct6() 
    272366{ 
  • dev/common/class.http.php

    r159 r162  
    2020        $this->postform = array(); 
    2121        $this->postdata = array(); 
     22        $this->headers = array(); 
     23        $this->socket_timeout = 5; 
     24    } 
     25 
     26    // socket timeout is the amount of time in second which is waited 
     27    // for incoming data, set higher if you request stuff from heavy-loaded 
     28    // scripts or compressed data streams 
     29    function setSockettimeout($int) 
     30    { 
     31        $this->socket_timeout = $int; 
    2232    } 
    2333 
     
    5464        if (!$this->fp) 
    5565        { 
    56             //echo "Error occured with fsockopen: $errstr ($errno)<br>\n"; 
     66            $this->_errno = $errno; 
     67            $this->_errstr = $errstr; 
    5768            return false; 
    5869        } 
    5970        return true; 
     71    } 
     72 
     73    function getError() 
     74    { 
     75        return 'Error occured with fsockopen: '.$this->_errstr.' ('.$this->_errno.')<br/>'."\n"; 
    6076    } 
    6177 
     
    8298                          .'Host: '.$this->url['host'].$lf 
    8399                          .'Connection: close'.$lf; 
     100        if (count($this->headers)) 
     101        { 
     102            $request_string .= join($lf, $this->headers).$lf; 
     103        } 
    84104        if ($this->method == 'POST') 
    85105        { 
     
    115135 
    116136        $header = 1; 
    117         socket_set_timeout($fp, 5); 
     137        socket_set_timeout($fp, $this->socket_timeout); 
    118138        while ($line = fgets($fp, 4096)) 
    119139        { 
     
    161181        $this->useragent = $string; 
    162182    } 
     183 
     184    function set_header($headerstring) 
     185    { 
     186        if (!strpos($headerstring, ':')) 
     187        { 
     188            return; 
     189        } 
     190        $this->headers[$headerstring] = $headerstring; 
     191    } 
    163192} 
    164193?> 
  • dev/common/class.killlist.php

    r158 r162  
    5959            if ($config->getConfig('ship_values')) 
    6060            { 
    61                 $this->sql_ .= ' left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id)'; 
     61                $this->sql_ .= ' left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id) '; 
    6262            } 
    6363 
     
    8383                if ($this->inv_crp_) 
    8484                    $this->sql_ .= " inner join kb3_inv_crp inc 
    85                               on ( inc.inc_crp_id in ( ".substr($this->inv_crp_, 0, strlen($this->inv_crp_) - 2)." ) and kll.kll_id = inc.inc_kll_id ) "; 
     85                              on ( inc.inc_crp_id in ( ".substr($this->inv_crp_, 0, strlen($this->inv_crp_) - 2)." ) and kll.kll_id = inc.inc_kll_id 
     86                               and inc.inc_crp_id != kll.kll_crp_id ) "; 
    8687                if ($this->inv_all_) 
    8788                    $this->sql_ .= " inner join kb3_inv_all ina 
    88                               on ( ina.ina_all_id in ( ".substr($this->inv_all_, 0, strlen($this->inv_all_) - 2)." ) and kll.kll_id = ina.ina_kll_id ) "; 
     89                              on ( ina.ina_all_id in ( ".substr($this->inv_all_, 0, strlen($this->inv_all_) - 2)." ) and kll.kll_id = ina.ina_kll_id 
     90                               and ina.ina_all_id != kll.kll_all_id ) "; 
    8991            } 
    9092            else 
  • dev/common/globals.php

    r139 r162  
    66// current version: major.minor.sub 
    77// unpair numbers for minor = development version 
    8 define('KB_VERSION', '1.2.1'); 
     8define('KB_VERSION', '1.2.2'); 
    99 
    1010// set the running-server for id-syncs here 
  • dev/common/kill_related.php

    r157 r162  
    5656{ 
    5757    $h = ($baseh-$i) % 24; 
     58    if ($h < 0) 
     59    { 
     60        $h += 24; 
     61    } 
    5862    if (!isset($ts[$h])) 
    5963    { 
  • dev/common/sync_server.php

    r57 r162  
    1818if ($version[0] <= 1 && $version[1] < 1) 
    1919{ 
    20     echo "Your Killboard is too old, please upgrade to 1.2.0 or newer<br>\n"; 
     20    echo "Your Killboard is too old, please upgrade to 1.2.2 or newer<br>\n"; 
    2121    return; 
     22} 
     23 
     24if (!function_exists('apache_request_headers')) 
     25{ 
     26    function apache_request_headers() 
     27    { 
     28        return getallheaders(); 
     29    } 
     30} 
     31$header = apache_request_headers(); 
     32foreach ($header as $key => $value) 
     33{ 
     34    if ($key == 'X-KBHost') 
     35    { 
     36        $host = base64_decode($value); 
     37    } 
    2238} 
    2339 
     
    3652// get all names we'll find 
    3753preg_match_all("^!(.*?)\|(.*?)-^", &$data, $matches); 
    38 unset($data); 
     54$data = strstr($data, 'ITEMS_START'); 
    3955$results = count($matches[1]); 
    4056if ($results == 0) 
     
    4662} 
    4763 
     64$s_data = array(); 
    4865// construct an array with name as key and id as value 
    4966for ($i = 0; $i<$results; $i++) 
     
    5168    $s_data[$matches[1][$i]] = $matches[2][$i]; 
    5269} 
     70unset($matches); 
     71 
     72if ($host) 
     73{ 
     74    $qry = new DBQuery(); 
     75    $qry->execute("show tables like '%item_%'"); 
     76    while ($row = $qry->getRow()) 
     77    { 
     78        $tables .= array_pop($row); 
     79    } 
     80    if (!strstr($tables, 'kb3_item_stats')) 
     81    { 
     82        $qry->execute("CREATE TABLE `kb3_item_stats` (\n `itm_name` varchar(128) NOT NULL,\n `kb_host` int(11) NOT NULL,\n `itm_externalid` int(11) NOT NULL,\n `itm_value` bigint(4) NOT NULL,\n PRIMARY KEY (`itm_name`,`kb_host`)\n) TYPE=MyISAM"); 
     83        $qry->execute("CREATE TABLE `kb3_item_hosts` (\n `kb_host` int(11) NOT NULL,\n `kb_name` varchar(255) NOT NULL,\n `itm_update` timestamp NOT NULL default '0000-00-00 00:00:00',\n RPIMARY KEY (`kb_host`)\n) TYPE=MyISAM"); 
     84    } 
     85    preg_match_all('^§(.*?)\|(.*?)\|(.*?)-^', &$data, $matches); 
     86 
     87    $hostid = abs(crc32($host)); 
     88    $qry->execute('replace into kb3_item_hosts (kb_host, kb_name, itm_update) VALUES (\''.$hostid.'\',\''.addslashes($host).'\',\''.date('Y-m-d H:i:s').'\')'); 
     89 
     90    $results = count($matches[1]); 
     91    for ($i = 0; $i<$results; $i++) 
     92    { 
     93        $qry->execute("replace into kb3_item_stats (itm_name,kb_host,itm_externalid,itm_value) VALUES ('".addslashes($matches[1][$i])."','".$hostid."','".addslashes($matches[2][$i])."','".addslashes($matches[3][$i])."')"); 
     94    } 
     95} 
     96unset($data); 
    5397 
    5498// now get our list from the database 
     
    84128} 
    85129 
     130$data_array = $data_values = array(); 
     131$qry->execute('select itm_name, itm_externalid, itm_value from kb3_item_stats order by itm_name asc, itm_value asc'); 
     132while ($data = $qry->getRow()) 
     133{ 
     134    $data_array[$data['itm_name']] = $data; 
     135    $data_values[$data['itm_name']][] = $data['itm_value']; 
     136} 
     137 
     138$content_file .= 'ITEMS_START'; 
     139foreach ($data_array as $data) 
     140{ 
     141    // get the median value for every item 
     142    $val_cnt = count($data_values[$data['itm_name']]); 
     143    $val_cnt = min(ceil($val_cnt/2), $val_cnt)-1; 
     144    $value = $data_values[$data['itm_name']][$val_cnt]; 
     145 
     146    $content_file .= '§'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$value.'-'; 
     147} 
     148 
    86149// return the compressed data back to the client 
    87150echo gzdeflate($content_file);