-
Notifications
You must be signed in to change notification settings - Fork 0
/
map2.update.ajax.php
163 lines (143 loc) · 4.66 KB
/
map2.update.ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
include_once 'system.php';
$db = new Database();
// get key (ajax)
$u = (int) $_POST['u'];
$t = (int) $_POST['t'];
$d = (int) $_POST['d'];
$x = (int) $_POST['x'];
$y = (int) $_POST['y'];
$a = (string) $_POST['a'];
#$session = $db->query(' SELECT xml FROM dvoo_rawdata WHERE id = '.$u.' ORDER BY time DESC LIMIT 1 ');
#$data = unserialize($session[0][0]);
$r = $db->query('SELECT name FROM dvoo_citizens WHERE id = '.$u);
$uname = $r[0][0];
switch ( $a ) {
// load current status
case 'load':
{
$q = ' SELECT items FROM dvoo_zones_visit WHERE tid = '.$t.' AND x = '.$x.' AND y = '.$y.' ORDER BY `on` DESC LIMIT 1';
$r = $db->query($q);
if ( isset($r[0]) && count($r[0]) > 0 ) {
$items = unserialize($r[0][0]);
}
else {
$items = array();
}
print styleItems($items);
break;
}
// add an item
case 'additem':
{
$n = (string) $_POST['item-name'];
$z = (int) $_POST['czu_z'];
$q = ' SELECT items FROM dvoo_zones_visit WHERE tid = '.$t.' AND day = '.$d.' AND x = '.$x.' AND y = '.$y.' ORDER BY `on` DESC LIMIT 1 ';
$r = $db->query($q);
if ( isset($r[0][0]) ) {
$items2 = unserialize($r[0][0]);
}
else {
$items2 = array();
}
$q = ' SELECT iid FROM dvoo_items WHERE iname = "'.$n.'" ';
$r = $db->query($q);
if ( isset($r[0][0]) ) {
$pro = 0;
if ( count($items2) > 0 ) {
foreach ( $items2 AS $i => $item ) {
if ( $item['id'] == (int) $r[0][0] ) {
$items2[$i]['count']++;
$pro = 1;
}
}
}
if ( $pro == 0 ) {
$items2[] = array(
'id' => (int) $r[0][0],
'count' => 1,
'broken' => 0,
);
}
}
$q = 'INSERT INTO dvoo_zones_visit VALUES ('.$t.', '.$d.', '.$x.', '.$y.', 0, 0, '.$z.', "'.mysql_escape_string(serialize($items2)).'", '.time().', "'.mysql_real_escape_string($uname).'") ON DUPLICATE KEY UPDATE z = '.$z.', items = "'.mysql_escape_string(serialize($items2)).'", `on` = '.time().', `by` = "'.mysql_real_escape_string($uname.' (via OO)').'" ';
$db->iquery($q);
print styleItems($items2);
break;
}
case 'changeitem':
{
$i = (int) $_POST['i'];
$c = (int) $_POST['c'];
$q = ' SELECT name FROM dvoo_citizens WHERE id = ' . $u;
$r = $db->query($q);
$uname = $r[0][0];
$q = ' SELECT items FROM dvoo_zones_visit WHERE tid = '.$t.' AND day = '.$d.' AND x = '.$x.' AND y = '.$y.' ORDER BY `on` DESC LIMIT 1 ';
$r = $db->query($q);
if ( isset($r[0][0]) ) {
$items = unserialize($r[0][0]);
}
else {
$items = array();
}
if ( count($items) > 0 ) {
foreach ( $items AS $n => $item ) {
if ( $item['id'] == $i ) {
if ( $c > 0 ) {
$items[$n]['count'] = $c;
}
elseif ( $c == 0 ) {
unset($items[$n]);
}
elseif ( $c == -1 ) {
$items[$n]['broken'] = 1 - $items[$n]['broken'];
}
}
}
}
$q = 'UPDATE dvoo_zones_visit SET items = "'.mysql_escape_string(serialize($items)).'" WHERE tid = '.$t.' AND day = '.$d.' AND x = '.$x.' AND y = '.$y.' ';
$db->iquery($q);
print styleItems($items);
break;
}
// load current status
case 'storm':
{
#if ($u == 3137) { print var_export($_POST,true); }
$s = (int) $_POST['musd'];
$q = ' SELECT * FROM dvoo_storm WHERE tid = '.$t.' AND day = '.$d.' AND uid = '.$u.' LIMIT 1 ';
$r = $db->query($q);
if ( isset($r[0]) && count($r[0]) > 0 ) {
$m = $r[0]['dir'];
switch ( $m ) {
case 1: $mt = t('Nx'); break;
case 2: $mt = t('NEx'); break;
case 3: $mt = t('Ex'); break;
case 4: $mt = t('SEx'); break;
case 5: $mt = t('Sx'); break;
case 6: $mt = t('SWx'); break;
case 7: $mt = t('Wx'); break;
case 8: $mt = t('NWx'); break;
}
print 'Today, you already have registered a storm ('.$mt.').';
}
else {
$q = ' INSERT INTO dvoo_storm VALUES ('.$t.','.$d.','.$s.','.$u.') ';
$db->iquery($q);
print 'Your storm observation has been recorded.';
}
break;
}
}
function styleItems($items) {
global $db;
$out = '';
if ( is_array($items) && count($items) > 0 ) {
foreach ( $items AS $item ) {
$bis = $db->query(' SELECT i.iid AS id, i.iimg AS img, i.iname AS name, i.icat AS cat FROM dvoo_items i WHERE i.iid = '.$item['id'].' ');
$bh = $bis[0];
$out .= '<div class="item '.($item['broken'] ? ' broken' : '').'"><span class="break" onclick="javascript:changeItem(-1, '.$item['id'].');"></span> <img src="'.t('GAME_ICON_SERVER').$bh['img'].'.gif" title="'.$bh['name'].'" /> <span class="minus" onclick="javascript:changeItem('.($item['count'] - 1).', '.$item['id'].');"></span><span class="count">'.$item['count'].'</span><span class="plus" onclick="javascript:changeItem('.($item['count'] + 1).', '.$item['id'].');"></span></div>';
}
}
return $out.'<br style="clear:left;" />';
}