Changeset 161

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

Modified the sync server to be able to handle item values.

Location:
mods/Sync_Server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • mods/Sync_Server/globals.php

    r46 r161  
    22// current version: major.minor.sub 
    33// unpair numbers for minor = development version 
    4 define('KB_VERSION', '1.1.44'); 
     4define('KB_VERSION', '1.2.2'); 
    55 
    66// set the running-server for id-syncs here 
    7 define('KB_SYNCURL', 'http://www.eve-dev.net/killboard_testing/?a=sync_server'); 
     7define('KB_SYNCURL', 'http://sync.eve-dev.net/?a=sync_server'); 
    88 
    99// add new corporations here once you've added the logo to img/corps/ 
  • mods/Sync_Server/sync_server.php

    r46 r161  
    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 
     
    2541if (!file_exists($_FILES['data']['tmp_name'])) 
    2642{ 
     43    var_dump($_REQUEST); 
    2744    var_dump($_FILES); 
    2845    echo "malformed request, expecting data-file<br>\n"; 
     
    3552// get all names we'll find 
    3653preg_match_all("^!(.*?)\|(.*?)-^", &$data, $matches); 
    37 unset($data); 
     54$data = strstr($data, 'ITEMS_START'); 
    3855$results = count($matches[1]); 
    3956if ($results == 0) 
     
    4562} 
    4663 
     64$s_data = array(); 
    4765// construct an array with name as key and id as value 
    4866for ($i = 0; $i<$results; $i++) 
     
    5068    $s_data[$matches[1][$i]] = $matches[2][$i]; 
    5169} 
     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); 
    5297 
    5398// now get our list from the database 
     
    83128} 
    84129 
     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 
    85149// return the compressed data back to the client 
    86150echo gzdeflate($content_file);