-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_update.php
More file actions
198 lines (176 loc) · 3.78 KB
/
Copy path_update.php
File metadata and controls
198 lines (176 loc) · 3.78 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php set_time_limit(180);
require_once '_apk/config.php';
/*
API links
*/
$url_sectors = _DB['sectors'];
$url_systems = _DB['systems'];
/*
DATA files
*/
$fil_sectors = _PATH['sectors'];
$fil_systems = _PATH['systems'];
$fil_factions = _PATH['factions'];
/*
UPDATE stage selection
(DISABLED)
*/
$update = [
'basic' => true,
'extra' => false,
];
if ( $forceupdate = htmlspecialchars($_GET["forceupdate"]) ){
if ( isset($update[$forceupdate]) ){
foreach($update as $k => $v){
if ( $k == $forceupdate ) {
$switch = true;
}else{
$switch = false;
}
$update[$k] = $switch;
}
}
}
/*
Read and write all sectors and factions inside
*/
$start_index = 1;
$item_count = 50;
$total = 0;
$sectors = [];
$factions = [];
$i = -1;
while($i<$total){
$file = get_xml_from_url($url_sectors."?start_index=".$start_index."&item_count=".$item_count);
$xml = simplexml_load_string($file);
if ($total==0){
$total = $xml->sectors['total'];
$i = 0;
}
foreach($xml->sectors->sector as $v){
$name = (string)$v['name'];
$uid = swcGetUid($v['uid']);
if ($name) {
// SECTOR : name
$sectors['name'][$uid] = $name;
// SECTOR : population
$sectors['population'][$uid] = intval($v->population);
// SECTOR : knownsystems
$sectors['knownsystems'][$uid] = intval($v->knownsystems);
// SECTOR : controlledby
$fid = swcGetUid($v->controlledby['uid']);
if ($fid) {
// FACTION : check and save
$sectors['faction'][$uid] = $fid;
if (!isset($factions['name'][$fid])){
$factions['name'][$fid] = (string)$v->controlledby;
}
}
}
$i++;
}
$start_index += $item_count;
}
fileSave($fil_sectors,$sectors);
/*
Read and write all systems
*/
$start_index = 1;
$item_count = 50;
$total = 0;
$systems = [];
$i = -1;
while($i<$total){
$file = get_xml_from_url($url_systems."?start_index=".$start_index."&item_count=".$item_count);
$xml = simplexml_load_string($file);
if ($total==0){
$total = $xml->systems['total'];
$i = 0;
}
foreach($xml->systems->system as $v){
$name = (string)$v['name'];
$uid = swcGetUid($v['uid']);
if ($name) {
// SYSTEM : name
$systems['name'][$uid] = $name;
// SYSTEM : population
$systems['population'][$uid] = intval($v->population);
// SYSTEM : sector ID
$sid = swcGetUid($v->location->sector['uid']);
$systems['sector'][$uid] = $sid;
// SYSTEM : controlledby
$fid = swcGetUid($v->controlledby['uid']);
if ($fid){
// FACTION : check and save
$systems['faction'][$uid] = $fid;
if (!isset($factions['name'][$fid])){
$factions['name'][$fid] = (string)$v->controlledby;
}
}
// SYSTEM : location inside sector
$c = $v->location->coordinates->galaxy;
$systems['x'][$uid] = intval($c['x']);
$systems['y'][$uid] = intval($c['y']);
}
$i++;
}
$start_index += $item_count;
}
fileSave($fil_systems,$systems);
fileSave($fil_factions,$factions);
/*
Extend read
*/
/*
First read TYPES
planets
stations
*/
/*
Read each system in loop
XML access number in loop
-> systems
-> planets
-> cities
-> stations
foreach($systems['name'] as $sid => $name){
> PASS 1 >
~60s
$file = get_xml_from_url($url_systems . swcMakeUid($sid, _CODE['systems']) );
$xml = simplexml_load_string($file);
[
system UID
planets[sid]
uid -> pid
name
stations[sid]
uid
name
]
(!) - no need to read and check if exists then skip
PLANET name having {
Sun -> (!) Sun
Moon -> Moon
Companion -> Moon
Hole -> (!) BlackHole
Comet -> usaly have 1 city
Belt -> asteroid field
}
>> PASS 2 >>
~180s
/galaxy/planets/ID (with exeption of SUN and HOLE)
From PLANETS read Cities and planet type
planets
type
cities[pid]
uid
name
x
y
/galaxy/stations/ID
From STATIONS read type of station
stations
type
}
*/
?>