- Timestamp:
- 12/23/06 02:17:16 (16 years ago)
- Location:
- mods/Sync_Server
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
mods/Sync_Server/globals.php
r46 r161 2 2 // current version: major.minor.sub 3 3 // unpair numbers for minor = development version 4 define('KB_VERSION', '1. 1.44');4 define('KB_VERSION', '1.2.2'); 5 5 6 6 // set the running-server for id-syncs here 7 define('KB_SYNCURL', 'http:// www.eve-dev.net/killboard_testing/?a=sync_server');7 define('KB_SYNCURL', 'http://sync.eve-dev.net/?a=sync_server'); 8 8 9 9 // add new corporations here once you've added the logo to img/corps/ -
mods/Sync_Server/sync_server.php
r46 r161 18 18 if ($version[0] <= 1 && $version[1] < 1) 19 19 { 20 echo "Your Killboard is too old, please upgrade to 1.2. 0or newer<br>\n";20 echo "Your Killboard is too old, please upgrade to 1.2.2 or newer<br>\n"; 21 21 return; 22 } 23 24 if (!function_exists('apache_request_headers')) 25 { 26 function apache_request_headers() 27 { 28 return getallheaders(); 29 } 30 } 31 $header = apache_request_headers(); 32 foreach ($header as $key => $value) 33 { 34 if ($key == 'X-KBHost') 35 { 36 $host = base64_decode($value); 37 } 22 38 } 23 39 … … 25 41 if (!file_exists($_FILES['data']['tmp_name'])) 26 42 { 43 var_dump($_REQUEST); 27 44 var_dump($_FILES); 28 45 echo "malformed request, expecting data-file<br>\n"; … … 35 52 // get all names we'll find 36 53 preg_match_all("^!(.*?)\|(.*?)-^", &$data, $matches); 37 unset($data);54 $data = strstr($data, 'ITEMS_START'); 38 55 $results = count($matches[1]); 39 56 if ($results == 0) … … 45 62 } 46 63 64 $s_data = array(); 47 65 // construct an array with name as key and id as value 48 66 for ($i = 0; $i<$results; $i++) … … 50 68 $s_data[$matches[1][$i]] = $matches[2][$i]; 51 69 } 70 unset($matches); 71 72 if ($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 } 96 unset($data); 52 97 53 98 // now get our list from the database … … 83 128 } 84 129 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'); 132 while ($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'; 139 foreach ($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 85 149 // return the compressed data back to the client 86 150 echo gzdeflate($content_file);