root/dev/common/sync_server.php @ 31

Revision 31, 2.4 KB (checked in by exi, 15 years ago)

Fixes belonging to importscript

Line 
1<?php
2require_once('db.php');
3
4// modify the header here so the client gets our version
5header('X-KBVersion: '.KB_VERSION);
6
7if (!strstr($_SERVER['HTTP_USER_AGENT'], 'EVE-KB SYNC'))
8{
9    echo 'Current version is '.KB_VERSION.'.<br>';
10    echo 'You should not call this file directly unless you\'re told to<br>';
11    return;
12}
13
14// this is an example for version checking with client ban
15// in case we change the protocol/data format
16preg_match("^\(VER (.*?)\)^", $_SERVER['HTTP_USER_AGENT'], $match);
17$version = explode('.', $match[1]);
18if ($version[0] <= 1 && $version[1] < 1)
19{
20    echo "Your Killboard is too old, please upgrade to 1.2.0 or newer<br>\n";
21    return;
22}
23
24// check if we got a file supplied with the request
25if (!file_exists($_FILES['data']['tmp_name']))
26{
27    echo "malformed request<br>\n";
28    return;
29}
30
31// we get a file, process
32$data = gzinflate(file_get_contents($_FILES['data']['tmp_name']));
33
34// get all names we'll find
35preg_match_all("^!(.*?)\|(.*?)-^", &$data, $matches);
36unset($data);
37$results = count($matches[1]);
38if ($results == 0)
39{
40    // if we got no ids from the client we won't send him ours
41    // bad idea for new installations
42    //echo "malformed request<br>\n";
43    //return;
44}
45
46// construct an array with name as key and id as value
47for ($i = 0; $i<$results; $i++)
48{
49    $s_data[$matches[1][$i]] = $matches[2][$i];
50}
51
52// now get our list from the database
53$qry = new DBQuery();
54$qry->execute("select plt_name, plt_externalid from kb3_pilots where plt_externalid != 0");
55while ($data = $qry->getRow())
56{
57    $data_array[$data['plt_name']] = $data['plt_externalid'];
58}
59$update = new DBQuery();
60
61// compare the entries supplied with our own
62foreach ($s_data as $name => $id)
63{
64    if (!$data_array[$name])
65    {
66        // we dont got that one in our database, update
67        // TODO: we don't care about missing pilots yet
68        $update->execute("update kb3_pilots set plt_externalid='".$id."' where plt_name='".$name."'");
69    }
70    else
71    {
72        // unset to save comparison time, we know the client has it
73        unset($data_array[$name]);
74    }
75}
76
77// $data_array now contains only unknown ids to the client
78$content_file = 'DATA_START';
79foreach ($data_array as $name => $id)
80{
81    $content_file .= '!'.$name.'|'.$id.'-';
82}
83
84// return the compressed data back to the client
85echo gzdeflate($content_file);
86?>
Note: See TracBrowser for help on using the browser.