|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
Function wrapping |
|
5
|
|
|
|
|
6
|
|
|
Due glitch in PHP 5.3.1 SuperNova is incompatible with this version |
|
7
|
|
|
Reference: https://bugs.php.net/bug.php?id=50394 |
|
8
|
|
|
|
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
require_once('general/math.php'); |
|
12
|
|
|
require_once('general/compatibility.php'); |
|
13
|
|
|
require_once('general_pname.php'); |
|
14
|
|
|
|
|
15
|
|
|
function sn_function_call($func_name, $func_arg = array()) |
|
16
|
|
|
{ |
|
17
|
|
|
global $functions; // All data in $functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>') |
|
18
|
|
|
|
|
19
|
|
|
if(is_array($functions[$func_name]) && !is_callable($functions[$func_name])) |
|
20
|
|
|
{ |
|
21
|
|
|
// Chain-callable functions should be made as following: |
|
22
|
|
|
// 1. Never use incomplete calls with parameters "by default" |
|
23
|
|
|
// 2. Reserve last parameter for cumulative result |
|
24
|
|
|
// 3. Use same format for original value and cumulative result (if there is original value) |
|
25
|
|
|
// 4. Honor cumulative result |
|
26
|
|
|
// 5. Return cumulative result |
|
27
|
|
|
foreach($functions[$func_name] as $func_chain_name) |
|
28
|
|
|
{ |
|
29
|
|
|
// По идее - это уже тут не нужно, потому что оно все должно быть callable к этому моменту |
|
30
|
|
|
// Но для старых модулей... |
|
31
|
|
|
if(is_callable($func_chain_name)) |
|
32
|
|
|
{ |
|
33
|
|
|
$result = call_user_func_array($func_chain_name, $func_arg); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
else |
|
38
|
|
|
{ |
|
39
|
|
|
// TODO: This is left for backward compatibility. Appropriate code should be rewrote! |
|
40
|
|
|
$func_name = isset($functions[$func_name]) && is_callable($functions[$func_name]) ? $functions[$func_name] : ('sn_' . $func_name); |
|
41
|
|
|
if(is_callable($func_name)) |
|
42
|
|
|
{ |
|
43
|
|
|
$result = call_user_func_array($func_name, $func_arg); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $result; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $hook_list |
|
52
|
|
|
* @param $template |
|
53
|
|
|
* @param string $hook_type - тип хука 'model' или 'view' |
|
54
|
|
|
* @param string $page_name - имя страницы, для которого должен был быть выполнен хук |
|
55
|
|
|
*/ |
|
56
|
|
|
function execute_hooks(&$hook_list, &$template, $hook_type = null, $page_name = null) { |
|
57
|
|
|
if(!empty($hook_list)) { |
|
58
|
|
|
foreach($hook_list as $hook) { |
|
59
|
|
|
if(is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
60
|
|
|
$template = call_user_func($hook_call, $template, $hook_type, $page_name); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
67
|
|
|
// Fonction de lecture / ecriture / exploitation de templates |
|
68
|
|
|
function sys_file_read($filename) |
|
69
|
|
|
{ |
|
70
|
|
|
return @file_get_contents($filename); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function sys_file_write($filename, $content) |
|
74
|
|
|
{ |
|
75
|
|
|
return @file_put_contents($filename, $content, FILE_APPEND); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
function get_game_speed($plain = false){return sn_function_call('get_game_speed', array($plain, &$result));} |
|
|
|
|
|
|
79
|
|
|
function sn_get_game_speed($plain = false, &$result) { |
|
|
|
|
|
|
80
|
|
|
return $result = classSupernova::$config->game_speed ? classSupernova::$config->game_speed : 1; |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function flt_server_flight_speed_multiplier($plain = false){return sn_function_call('flt_server_flight_speed_multiplier', array($plain, &$result));} |
|
84
|
|
|
function sn_flt_server_flight_speed_multiplier($plain = false, &$result) { |
|
|
|
|
|
|
85
|
|
|
global $config; |
|
86
|
|
|
|
|
87
|
|
|
return $result = classSupernova::$config->fleet_speed; |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function game_resource_multiplier($plain = false){return sn_function_call('game_resource_multiplier', array($plain,&$result));} |
|
|
|
|
|
|
91
|
|
|
function sn_game_resource_multiplier($plain = false, &$result) { |
|
|
|
|
|
|
92
|
|
|
global $config; |
|
93
|
|
|
|
|
94
|
|
|
return $result = classSupernova::$config->resource_multiplier; |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Получение стоимости ММ в валюте сервера |
|
99
|
|
|
* |
|
100
|
|
|
* @param bool|false $plain |
|
101
|
|
|
* |
|
102
|
|
|
* @return mixed |
|
103
|
|
|
*/ |
|
104
|
|
|
function get_mm_cost($plain = false){return sn_function_call('get_mm_cost', array($plain, &$result));} |
|
105
|
|
|
function sn_get_mm_cost($plain = false, &$result) { |
|
|
|
|
|
|
106
|
|
|
global $config; |
|
107
|
|
|
|
|
108
|
|
|
return $result = classSupernova::$config->payment_currency_exchange_mm_ ? classSupernova::$config->payment_currency_exchange_mm_ : 20000; |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Получение курса обмены валюты в серверную валюту |
|
113
|
|
|
* |
|
114
|
|
|
* @param $currency_symbol |
|
115
|
|
|
* |
|
116
|
|
|
* @return float |
|
117
|
|
|
*/ |
|
118
|
|
|
function get_exchange_rate($currency_symbol) { |
|
119
|
|
|
global $config; |
|
120
|
|
|
|
|
121
|
|
|
$currency_symbol = strtolower($currency_symbol); |
|
122
|
|
|
$config_field = 'payment_currency_exchange_' . $currency_symbol; |
|
123
|
|
|
|
|
124
|
|
|
// Заворачиваем получение стоимости ММ через перекрываемую процедуру |
|
125
|
|
|
$exchange_rate = floatval($currency_symbol == 'mm_' ? get_mm_cost() : classSupernova::$config->$config_field); |
|
126
|
|
|
|
|
127
|
|
|
return $exchange_rate; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
pretty_number implementation for SuperNova |
|
132
|
|
|
|
|
133
|
|
|
$n - number to format |
|
134
|
|
|
$floor: (ignored if $limit set) |
|
135
|
|
|
integer - floors to $floor numbers after decimal points |
|
136
|
|
|
true - floors number before format |
|
137
|
|
|
otherwise - floors to 2 numbers after decimal points |
|
138
|
|
|
$color: |
|
139
|
|
|
true - colors number to green if positive or zero; red if negative |
|
140
|
|
|
0 |
|
141
|
|
|
numeric - colors number to green if less then $color; red if greater |
|
142
|
|
|
$limit: |
|
143
|
|
|
0/false - proceed with $floor |
|
144
|
|
|
numeric - divides number to segments by power of $limit and adds 'k' for each segment |
|
145
|
|
|
makes sense for 1000, but works with any number |
|
146
|
|
|
generally converts "15000" to "15k", "2000000" to "2kk" etc |
|
147
|
|
|
$style |
|
148
|
|
|
null - standard result |
|
149
|
|
|
true - return only style class for current params |
|
150
|
|
|
false - return array('text' => $ret, 'class' => $class), where $ret - unstyled |
|
151
|
|
|
*/ |
|
152
|
|
|
|
|
153
|
|
|
function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) |
|
154
|
|
|
{ |
|
155
|
|
|
$n = floatval($n); |
|
156
|
|
|
if(is_int($floor)) |
|
157
|
|
|
{ |
|
158
|
|
|
$n = round($n, $floor); |
|
159
|
|
|
} |
|
160
|
|
|
elseif($floor === true) |
|
161
|
|
|
{ |
|
162
|
|
|
$n = floor($n); |
|
163
|
|
|
$floor = 0; |
|
164
|
|
|
} |
|
165
|
|
|
else |
|
166
|
|
|
{ |
|
167
|
|
|
$floor = 2; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$ret = $n; |
|
171
|
|
|
|
|
172
|
|
|
$suffix = ''; |
|
173
|
|
|
if($limit) |
|
174
|
|
|
{ |
|
175
|
|
|
if($ret > 0) |
|
176
|
|
|
{ |
|
177
|
|
|
while($ret > $limit) |
|
178
|
|
|
{ |
|
179
|
|
|
$suffix .= 'k'; |
|
180
|
|
|
$ret = round($ret / 1000); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
else |
|
184
|
|
|
{ |
|
185
|
|
|
while($ret < -$limit) |
|
186
|
|
|
{ |
|
187
|
|
|
$suffix .= 'k'; |
|
188
|
|
|
$ret = round($ret / 1000); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
$ret = number_format($ret, $floor, ',', '.'); |
|
194
|
|
|
$ret .= $suffix; |
|
195
|
|
|
|
|
196
|
|
|
if($color !== false) |
|
197
|
|
|
{ |
|
198
|
|
|
if($color === true) |
|
199
|
|
|
{ |
|
200
|
|
|
$class = $n == 0 ? 'zero' : ($n > 0 ? 'positive' : 'negative'); |
|
201
|
|
|
} |
|
202
|
|
View Code Duplication |
elseif($color >= 0) |
|
|
|
|
|
|
203
|
|
|
{ |
|
204
|
|
|
$class = $n == $color ? 'zero' : ($n < $color ? 'positive' : 'negative'); |
|
205
|
|
|
} |
|
206
|
|
View Code Duplication |
else |
|
|
|
|
|
|
207
|
|
|
{ |
|
208
|
|
|
$class = ($n == -$color) ? 'zero' : ($n < -$color ? 'negative' : 'positive'); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
if(!isset($style)) |
|
212
|
|
|
{ |
|
213
|
|
|
$ret = "<span class='{$class}'>{$ret}</span>"; |
|
214
|
|
|
} |
|
215
|
|
|
else |
|
216
|
|
|
{ |
|
217
|
|
|
$ret = $style ? $ret = $class : $ret = array('text' => $ret, 'class' => $class); |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
return $ret; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
225
|
|
|
function pretty_time($seconds) { |
|
226
|
|
|
global $lang; |
|
227
|
|
|
|
|
228
|
|
|
$day = floor($seconds / (24 * 3600)); |
|
229
|
|
|
return sprintf("%s%02d:%02d:%02d", $day ? "{$day}{$lang['sys_day_short']} " : '', floor($seconds / 3600 % 24), floor($seconds / 60 % 60), floor($seconds / 1 % 60)); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
233
|
|
|
function eco_planet_fields_max($planet) { |
|
234
|
|
|
return $planet['field_max'] + ($planet['planet_type'] == PT_PLANET ? mrc_get_level($user, $planet, STRUC_TERRAFORMER) * 5 : (mrc_get_level($user, $planet, STRUC_MOON_STATION) * 3)); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
238
|
|
|
function flt_get_missile_range($user) { |
|
239
|
|
|
return max(0, mrc_get_level($user, false, TECH_ENGINE_ION) * 5 - 1); |
|
|
|
|
|
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
243
|
|
|
function GetSpyLevel(&$user) { |
|
244
|
|
|
return mrc_modify_value($user, false, array(MRC_SPY, TECH_SPY), 0); |
|
|
|
|
|
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
248
|
|
|
function GetMaxFleets(&$user) { |
|
249
|
|
|
return mrc_modify_value($user, false, array(MRC_COORDINATOR, TECH_COMPUTER), 1); |
|
|
|
|
|
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
|
|
|
|
|
253
|
|
|
/* |
|
254
|
|
|
function GetMaxExpeditions(&$user) |
|
255
|
|
|
{ |
|
256
|
|
|
return floor(sqrt(mrc_get_level($user, false, TECH_EXPEDITION))); |
|
257
|
|
|
} |
|
258
|
|
|
*/ |
|
259
|
|
|
|
|
260
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
|
261
|
|
|
// Check input string for forbidden words |
|
262
|
|
|
// |
|
263
|
|
|
function CheckInputStrings($String) |
|
264
|
|
|
{ |
|
265
|
|
|
global $ListCensure; |
|
266
|
|
|
|
|
267
|
|
|
return preg_replace($ListCensure, '*', $String); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
function is_email($email) { |
|
271
|
|
|
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
function is_id($value) |
|
275
|
|
|
{ |
|
276
|
|
|
return preg_match('/^\d+$/', $value) && ($value >= 0); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @param $param_name |
|
281
|
|
|
* @param string $default |
|
282
|
|
|
* |
|
283
|
|
|
* @return string|array |
|
284
|
|
|
*/ |
|
285
|
|
|
function sys_get_param($param_name, $default = '') |
|
286
|
|
|
{ |
|
287
|
|
|
return $_POST[$param_name] !== NULL ? $_POST[$param_name] : ($_GET[$param_name] !== NULL ? $_GET[$param_name] : $default); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
function sys_get_param_id($param_name, $default = 0) |
|
291
|
|
|
{ |
|
292
|
|
|
return is_id($value = sys_get_param($param_name, $default)) ? $value : $default; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
function sys_get_param_int($param_name, $default = 0) |
|
296
|
|
|
{ |
|
297
|
|
|
$value = sys_get_param($param_name, $default); |
|
298
|
|
|
return $value === 'on' ? 1 : ($value === 'off' ? $default : intval($value)); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
function sys_get_param_float($param_name, $default = 0) |
|
302
|
|
|
{ |
|
303
|
|
|
return floatval(sys_get_param($param_name, $default)); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
function sys_get_param_escaped($param_name, $default = '') |
|
307
|
|
|
{ |
|
308
|
|
|
return db_escape(sys_get_param($param_name, $default)); |
|
309
|
|
|
} |
|
310
|
|
|
/* |
|
|
|
|
|
|
311
|
|
|
function sys_get_param_safe($param_name, $default = '') |
|
312
|
|
|
{ |
|
313
|
|
|
return db_escape(strip_tags(sys_get_param($param_name, $default))); |
|
314
|
|
|
} |
|
315
|
|
|
*/ |
|
316
|
|
|
function sys_get_param_date_sql($param_name, $default = '2000-01-01') |
|
317
|
|
|
{ |
|
318
|
|
|
$val = sys_get_param($param_name, $default); |
|
319
|
|
|
return preg_match(PREG_DATE_SQL_RELAXED, $val) ? $val : $default; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
function sys_get_param_str_unsafe($param_name, $default = '') |
|
323
|
|
|
{ |
|
324
|
|
|
return str_raw2unsafe(sys_get_param($param_name, $default)); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
function sys_get_param_str($param_name, $default = '') |
|
328
|
|
|
{ |
|
329
|
|
|
return db_escape(sys_get_param_str_unsafe($param_name, $default)); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
function sys_get_param_str_both($param_name, $default = '') |
|
333
|
|
|
{ |
|
334
|
|
|
$param = sys_get_param($param_name, $default); |
|
335
|
|
|
$param_unsafe = str_raw2unsafe($param); |
|
336
|
|
|
return array( |
|
337
|
|
|
'raw' => $param, |
|
338
|
|
|
'unsafe' => $param_unsafe, |
|
339
|
|
|
'safe' => db_escape($param_unsafe), |
|
340
|
|
|
); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
function sys_get_param_phone($param_name, $default = '') |
|
|
|
|
|
|
344
|
|
|
{ |
|
345
|
|
|
$phone_raw = sys_get_param_str_unsafe($param_name, $default = ''); |
|
346
|
|
|
if($phone_raw) |
|
347
|
|
|
{ |
|
348
|
|
|
$phone = $phone_raw[0] == '+' ? '+' : ''; |
|
349
|
|
|
for($i = 0; $i < strlen($phone_raw); $i++) |
|
350
|
|
|
{ |
|
351
|
|
|
$ord = ord($phone_raw[$i]); |
|
352
|
|
|
if($ord >= 48 && $ord <= 57) |
|
353
|
|
|
{ |
|
354
|
|
|
$phone .= $phone_raw[$i]; |
|
355
|
|
|
} |
|
356
|
|
|
} |
|
357
|
|
|
$phone = strlen($phone) < 11 ? '' : $phone; |
|
358
|
|
|
} |
|
359
|
|
|
else |
|
360
|
|
|
{ |
|
361
|
|
|
$phone = ''; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
return array('raw' => $phone_raw, 'phone' => $phone); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
function GetPhalanxRange($phalanx_level) |
|
368
|
|
|
{ |
|
369
|
|
|
return $phalanx_level > 1 ? pow($phalanx_level, 2) - 1 : 0; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
function CheckAbandonPlanetState(&$planet) |
|
373
|
|
|
{ |
|
374
|
|
|
if($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) |
|
375
|
|
|
{ |
|
376
|
|
|
DBStaticPlanet::db_planet_delete_by_id($planet['id']); |
|
377
|
|
|
} |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
function eco_get_total_cost($unit_id, $unit_level) |
|
381
|
|
|
{ |
|
382
|
|
|
global $config; |
|
383
|
|
|
|
|
384
|
|
|
static $rate, $sn_group_resources_all, $sn_group_resources_loot; |
|
385
|
|
|
if(!$rate) |
|
386
|
|
|
{ |
|
387
|
|
|
$sn_group_resources_all = sn_get_groups('resources_all'); |
|
388
|
|
|
$sn_group_resources_loot = sn_get_groups('resources_loot'); |
|
389
|
|
|
|
|
390
|
|
|
$rate[RES_METAL] = classSupernova::$config->rpg_exchange_metal; |
|
|
|
|
|
|
391
|
|
|
$rate[RES_CRYSTAL] = classSupernova::$config->rpg_exchange_crystal / classSupernova::$config->rpg_exchange_metal; |
|
|
|
|
|
|
392
|
|
|
$rate[RES_DEUTERIUM] = classSupernova::$config->rpg_exchange_deuterium / classSupernova::$config->rpg_exchange_metal; |
|
|
|
|
|
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
$unit_cost_data = get_unit_param($unit_id, 'cost'); |
|
396
|
|
|
if(!is_array($unit_cost_data)) |
|
397
|
|
|
{ |
|
398
|
|
|
return array('total' => 0); |
|
399
|
|
|
} |
|
400
|
|
|
$factor = isset($unit_cost_data['factor']) ? $unit_cost_data['factor'] : 1; |
|
401
|
|
|
$cost_array = array(BUILD_CREATE => array(), 'total' => 0); |
|
402
|
|
|
$unit_level = $unit_level > 0 ? $unit_level : 0; |
|
403
|
|
|
foreach($unit_cost_data as $resource_id => $resource_amount) |
|
404
|
|
|
{ |
|
405
|
|
|
if(!in_array($resource_id, $sn_group_resources_all)) |
|
406
|
|
|
{ |
|
407
|
|
|
continue; |
|
408
|
|
|
} |
|
409
|
|
|
// $cost_array[BUILD_CREATE][$resource_id] = $resource_amount * ($factor == 1 ? $unit_level : ((pow($factor, $unit_level) - $factor) / ($factor - 1))); |
|
|
|
|
|
|
410
|
|
|
$cost_array[BUILD_CREATE][$resource_id] = round($resource_amount * ($factor == 1 ? $unit_level : ((1 - pow($factor, $unit_level)) / (1 - $factor)))); |
|
411
|
|
|
if(in_array($resource_id, $sn_group_resources_loot)) |
|
412
|
|
|
{ |
|
413
|
|
|
$cost_array['total'] += $cost_array[BUILD_CREATE][$resource_id] * $rate[$resource_id]; |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
return $cost_array; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
function sn_unit_purchase($unit_id){} |
|
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
function sn_unit_relocate($unit_id, $from, $to){} |
|
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
/* |
|
425
|
|
|
ЭТО ПРОСТОЙ ВРАППЕР ДЛЯ БД! Здесь НЕТ никаких проверок! ВСЕ проверки должны быть сделаны заранее! |
|
426
|
|
|
Враппер возвращает уровень для указанного UNIT_ID и заполняет поле в соответствующей записи |
|
427
|
|
|
TODO: Он может быть перекрыт для возвращения дополнительной информации о юните - например, о Капитане (пока не реализовано) |
|
428
|
|
|
|
|
429
|
|
|
$context |
|
430
|
|
|
'location' - где искать данный тип юнита: LOC_USER |
|
431
|
|
|
'user' - &$user |
|
432
|
|
|
|
|
433
|
|
|
$options |
|
434
|
|
|
'for_update' - блокировать запись до конца транзакции |
|
435
|
|
|
*/ |
|
436
|
|
|
/* |
|
|
|
|
|
|
437
|
|
|
function unit_get_level($unit_id, &$context = null, $options = null){return sn_function_call('unit_get_level', array($unit_id, &$context, $options, &$result));} |
|
438
|
|
|
function sn_unit_get_level($unit_id, &$context = null, $options = null, &$result) |
|
439
|
|
|
{ |
|
440
|
|
|
$unit_db_name = pname_resource_name($unit_id); |
|
441
|
|
|
$for_update = $options['for_update']; |
|
442
|
|
|
|
|
443
|
|
|
$unit_level = 0; |
|
444
|
|
|
if($context['location'] == LOC_USER) |
|
445
|
|
|
{ |
|
446
|
|
|
$user = &$context['user']; |
|
447
|
|
|
if(!$user['id']) |
|
448
|
|
|
{ |
|
449
|
|
|
$user[$unit_id]['unit_level'] = $user[$unit_db_name]; |
|
450
|
|
|
} |
|
451
|
|
|
elseif($for_update || !isset($user[$unit_id])) |
|
452
|
|
|
{ |
|
453
|
|
|
$unit_level = db_unit_by_location($user['id'], $context['location'], $user['id'], $unit_id, $for_update); |
|
454
|
|
|
$unit_level['unit_time_start'] = strtotime($unit_level['unit_time_start']); |
|
455
|
|
|
$unit_level['unit_time_finish'] = strtotime($unit_level['unit_time_finish']); |
|
456
|
|
|
$user[$unit_id] = $unit_level; |
|
457
|
|
|
} |
|
458
|
|
|
$unit_level = intval($user[$unit_id]['unit_level']); |
|
459
|
|
|
} |
|
460
|
|
|
elseif($context['location'] == LOC_PLANET) |
|
461
|
|
|
{ |
|
462
|
|
|
$planet = &$context['planet']; |
|
463
|
|
|
if(!$planet['id']) |
|
464
|
|
|
{ |
|
465
|
|
|
$planet[$unit_id]['unit_level'] = $planet[$unit_db_name]; |
|
466
|
|
|
} |
|
467
|
|
|
elseif($for_update || !isset($planet[$unit_id])) |
|
468
|
|
|
{ |
|
469
|
|
|
$unit_level = db_unit_by_location(0, $context['location'], $planet['id'], $unit_id, $for_update); |
|
470
|
|
|
$unit_level['unit_time_start'] = strtotime($unit_level['unit_time_start']); |
|
471
|
|
|
$unit_level['unit_time_finish'] = strtotime($unit_level['unit_time_finish']); |
|
472
|
|
|
$planet[$unit_id] = $unit_level; |
|
473
|
|
|
} |
|
474
|
|
|
$unit_level = intval($planet[$unit_id]['unit_level']); |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
return $result = $unit_level; |
|
478
|
|
|
} |
|
479
|
|
|
*/ |
|
480
|
|
|
|
|
481
|
|
|
function mrc_get_level(&$user, $planet = array(), $unit_id, $for_update = false, $plain = false){return sn_function_call(__FUNCTION__, array(&$user, $planet, $unit_id, $for_update, $plain, &$result));} |
|
482
|
|
|
function sn_mrc_get_level(&$user, $planet = array(), $unit_id, $for_update = false, $plain = false, &$result) { |
|
|
|
|
|
|
483
|
|
|
$mercenary_level = 0; |
|
484
|
|
|
$unit_db_name = pname_resource_name($unit_id); |
|
485
|
|
|
|
|
486
|
|
|
if(in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
487
|
|
|
$unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id); |
|
488
|
|
|
$mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
|
489
|
|
|
} elseif(in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
490
|
|
|
$unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id); |
|
491
|
|
|
$mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
|
492
|
|
|
} elseif(in_array($unit_id, sn_get_groups('governors'))) { |
|
493
|
|
|
$mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0; |
|
494
|
|
|
} elseif($unit_id == RES_DARK_MATTER) { |
|
495
|
|
|
$mercenary_level = $user[$unit_db_name] + ($plain || $user['user_as_ally'] ? 0 : classSupernova::$auth->account->account_metamatter); |
|
496
|
|
|
} elseif($unit_id == RES_METAMATTER) { |
|
497
|
|
|
$mercenary_level = classSupernova::$auth->account->account_metamatter; //$user[$unit_db_name]; |
|
498
|
|
|
} elseif(in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
499
|
|
|
$mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name]; |
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
|
|
return $result = $mercenary_level; |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
function mrc_modify_value(&$user, $planet = array(), $mercenaries, $value) {return sn_function_call('mrc_modify_value', array(&$user, $planet, $mercenaries, $value));} |
|
506
|
|
|
function sn_mrc_modify_value(&$user, $planet = array(), $mercenaries, $value, $base_value = null) |
|
507
|
|
|
{ |
|
508
|
|
|
if(!is_array($mercenaries)) |
|
509
|
|
|
{ |
|
510
|
|
|
$mercenaries = array($mercenaries); |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
$base_value = isset($base_value) ? $base_value : $value; |
|
514
|
|
|
|
|
515
|
|
|
foreach($mercenaries as $mercenary_id) |
|
516
|
|
|
{ |
|
517
|
|
|
$mercenary_level = mrc_get_level($user, $planet, $mercenary_id); |
|
518
|
|
|
|
|
519
|
|
|
$mercenary = get_unit_param($mercenary_id); |
|
520
|
|
|
$mercenary_bonus = $mercenary['bonus']; |
|
521
|
|
|
|
|
522
|
|
|
switch($mercenary['bonus_type']) |
|
523
|
|
|
{ |
|
524
|
|
|
case BONUS_PERCENT_CUMULATIVE: |
|
525
|
|
|
$value *= 1 + $mercenary_level * $mercenary_bonus / 100; |
|
526
|
|
|
break; |
|
527
|
|
|
|
|
528
|
|
|
case BONUS_PERCENT: |
|
529
|
|
|
$mercenary_level = $mercenary_bonus < 0 && $mercenary_level * $mercenary_bonus < -90 ? -90 / $mercenary_bonus : $mercenary_level; |
|
530
|
|
|
$value += $base_value * $mercenary_level * $mercenary_bonus / 100; |
|
531
|
|
|
break; |
|
532
|
|
|
|
|
533
|
|
|
case BONUS_ADD: |
|
534
|
|
|
$value += $mercenary_level * $mercenary_bonus; |
|
535
|
|
|
break; |
|
536
|
|
|
|
|
537
|
|
|
case BONUS_ABILITY: |
|
538
|
|
|
$value = $mercenary_level ? $mercenary_level : 0; |
|
539
|
|
|
break; |
|
540
|
|
|
|
|
541
|
|
|
default: |
|
542
|
|
|
break; |
|
543
|
|
|
} |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
return $value; |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
// Generates random string of $length symbols from $allowed_chars charset |
|
550
|
|
|
function sys_random_string($length = 16, $allowed_chars = SN_SYS_SEC_CHARS_ALLOWED) { |
|
551
|
|
|
$allowed_length = strlen($allowed_chars); |
|
552
|
|
|
|
|
553
|
|
|
$random_string = ''; |
|
554
|
|
|
for($i = 0; $i < $length; $i++) { |
|
555
|
|
|
$random_string .= $allowed_chars[mt_rand(0, $allowed_length - 1)]; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
return $random_string; |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
function js_safe_string($string) |
|
562
|
|
|
{ |
|
563
|
|
|
return str_replace(array("\r", "\n"), array('\r', '\n'), addslashes($string)); |
|
564
|
|
|
} |
|
565
|
|
|
|
|
566
|
|
|
function sys_safe_output($string) |
|
567
|
|
|
{ |
|
568
|
|
|
return str_replace(array("&", "\"", "<", ">", "'"), array("&", """, "<", ">", "'"), $string); |
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
function sys_user_options_pack(&$user) |
|
572
|
|
|
{ |
|
573
|
|
|
global $user_option_list; |
|
574
|
|
|
|
|
575
|
|
|
$options = ''; |
|
576
|
|
|
$option_list = array(); |
|
577
|
|
|
foreach($user_option_list as $option_group_id => $option_group) |
|
578
|
|
|
{ |
|
579
|
|
|
$option_list[$option_group_id] = array(); |
|
580
|
|
|
foreach($option_group as $option_name => $option_value) |
|
581
|
|
|
{ |
|
582
|
|
|
if (!isset($user[$option_name])) |
|
583
|
|
|
{ |
|
584
|
|
|
$user[$option_name] = $option_value; |
|
585
|
|
|
} elseif ($user[$option_name] == '') { |
|
586
|
|
|
$user[$option_name] = 0; |
|
587
|
|
|
} |
|
588
|
|
|
$options .= "{$option_name}^{$user[$option_name]}|"; |
|
589
|
|
|
$option_list[$option_group_id][$option_name] = $user[$option_name]; |
|
590
|
|
|
} |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
$user['options'] = $options; |
|
594
|
|
|
$user['option_list'] = $option_list; |
|
595
|
|
|
|
|
596
|
|
|
return $options; |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
function sys_user_options_unpack(&$user) |
|
600
|
|
|
{ |
|
601
|
|
|
global $user_option_list; |
|
602
|
|
|
|
|
603
|
|
|
$option_list = array(); |
|
604
|
|
|
$option_string_list = explode('|', $user['options']); |
|
605
|
|
|
|
|
606
|
|
|
foreach($option_string_list as $option_string) |
|
607
|
|
|
{ |
|
608
|
|
|
list($option_name, $option_value) = explode('^', $option_string); |
|
609
|
|
|
$option_list[$option_name] = $option_value; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
$final_list = array(); |
|
613
|
|
|
foreach($user_option_list as $option_group_id => $option_group) |
|
614
|
|
|
{ |
|
615
|
|
|
$final_list[$option_group_id] = array(); |
|
616
|
|
|
foreach($option_group as $option_name => $option_value) |
|
617
|
|
|
{ |
|
618
|
|
|
if(!isset($option_list[$option_name])) |
|
619
|
|
|
{ |
|
620
|
|
|
$option_list[$option_name] = $option_value; |
|
621
|
|
|
} |
|
622
|
|
|
$user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name]; |
|
623
|
|
|
} |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
$user['option_list'] = $final_list; |
|
627
|
|
|
|
|
628
|
|
|
return $final_list; |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
function sys_unit_str2arr($fleet_string) |
|
632
|
|
|
{ |
|
633
|
|
|
$fleet_array = array(); |
|
634
|
|
|
if(!empty($fleet_string)) |
|
635
|
|
|
{ |
|
636
|
|
|
$arrTemp = explode(';', $fleet_string); |
|
637
|
|
|
foreach($arrTemp as $temp) |
|
638
|
|
|
{ |
|
639
|
|
|
if($temp) |
|
640
|
|
|
{ |
|
641
|
|
|
$temp = explode(',', $temp); |
|
642
|
|
|
if(!empty($temp[0]) && !empty($temp[1])) |
|
643
|
|
|
{ |
|
644
|
|
|
$fleet_array[$temp[0]] += $temp[1]; |
|
645
|
|
|
} |
|
646
|
|
|
} |
|
647
|
|
|
} |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
return $fleet_array; |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
function sys_unit_arr2str($unit_list) |
|
654
|
|
|
{ |
|
655
|
|
|
$fleet_string = array(); |
|
656
|
|
|
if(isset($unit_list)) |
|
657
|
|
|
{ |
|
658
|
|
|
if(!is_array($unit_list)) |
|
659
|
|
|
{ |
|
660
|
|
|
$unit_list = array($unit_list => 1); |
|
661
|
|
|
} |
|
662
|
|
|
|
|
663
|
|
|
foreach($unit_list as $unit_id => $unit_count) |
|
664
|
|
|
{ |
|
665
|
|
|
if($unit_id && $unit_count) |
|
666
|
|
|
{ |
|
667
|
|
|
$fleet_string[] = "{$unit_id},{$unit_count}"; |
|
668
|
|
|
} |
|
669
|
|
|
} |
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
|
|
return implode(';', $fleet_string); |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
function mymail($email_unsafe, $title, $body, $from = '', $html = false) { |
|
676
|
|
|
global $config, $lang; |
|
677
|
|
|
|
|
678
|
|
|
$from = trim($from ? $from : classSupernova::$config->game_adminEmail); |
|
|
|
|
|
|
679
|
|
|
|
|
680
|
|
|
$head = ''; |
|
681
|
|
|
$head .= "Content-Type: text/" . ($html ? 'html' : 'plain'). "; charset=utf-8 \r\n"; |
|
682
|
|
|
$head .= "Date: " . date('r') . " \r\n"; |
|
683
|
|
|
$head .= "Return-Path: {classSupernova::$config->game_adminEmail} \r\n"; |
|
684
|
|
|
$head .= "From: {$from} \r\n"; |
|
685
|
|
|
$head .= "Sender: {$from} \r\n"; |
|
686
|
|
|
$head .= "Reply-To: {$from} \r\n"; |
|
687
|
|
|
$head .= "Organization: {$org} \r\n"; |
|
|
|
|
|
|
688
|
|
|
$head .= "X-Sender: {$from} \r\n"; |
|
689
|
|
|
$head .= "X-Priority: 3 \r\n"; |
|
690
|
|
|
$body = str_replace("\r\n", "\n", $body); |
|
691
|
|
|
$body = str_replace("\n", "\r\n", $body); |
|
692
|
|
|
|
|
693
|
|
|
if($html) { |
|
694
|
|
|
$body = '<html><head><base href="' . SN_ROOT_VIRTUAL . '"></head><body>' . nl2br($body) . '</body></html>'; |
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
|
|
$title = '=?UTF-8?B?' . base64_encode($title) . '?='; |
|
698
|
|
|
|
|
699
|
|
|
return @mail($email_unsafe, $title, $body, $head); |
|
|
|
|
|
|
700
|
|
|
} |
|
701
|
|
|
|
|
702
|
|
|
function sys_time_human($time, $full = false) |
|
703
|
|
|
{ |
|
704
|
|
|
global $lang; |
|
705
|
|
|
|
|
706
|
|
|
$seconds = $time % 60; |
|
707
|
|
|
$time = floor($time/60); |
|
708
|
|
|
$minutes = $time % 60; |
|
709
|
|
|
$time = floor($time/60); |
|
710
|
|
|
$hours = $time % 24; |
|
711
|
|
|
$time = floor($time/24); |
|
712
|
|
|
|
|
713
|
|
|
return |
|
714
|
|
|
($full || $time ? "{$time} {$lang['sys_day']} " : '') . |
|
715
|
|
|
($full || $hours ? "{$hours} {$lang['sys_hrs']} " : '') . |
|
716
|
|
|
($full || $minutes ? "{$minutes} {$lang['sys_min']} " : '') . |
|
717
|
|
|
($full || !$time || $seconds ? "{$seconds} {$lang['sys_sec']}" : ''); |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
function sys_time_human_system($time) { |
|
721
|
|
|
return $time ? date(FMT_DATE_TIME_SQL, $time) . " ({$time}), " . sys_time_human(SN_TIME_NOW - $time) : '{NEVER}'; |
|
722
|
|
|
} |
|
723
|
|
|
|
|
724
|
|
|
function sys_redirect($url) |
|
725
|
|
|
{ |
|
726
|
|
|
header("Location: {$url}"); |
|
727
|
|
|
ob_end_flush(); |
|
728
|
|
|
die(); |
|
729
|
|
|
} |
|
730
|
|
|
|
|
731
|
|
|
/** |
|
732
|
|
|
* Redirects via JS-script |
|
733
|
|
|
* |
|
734
|
|
|
* @param string $url |
|
735
|
|
|
*/ |
|
736
|
|
|
function sys_redirect_js($url) |
|
737
|
|
|
{ |
|
738
|
|
|
ob_end_flush(); |
|
739
|
|
|
|
|
740
|
|
|
$redirectTemplate = gettemplate('_redirect'); |
|
741
|
|
|
$redirectTemplate->assign_vars(array( |
|
742
|
|
|
'URL' => js_safe_string($url), |
|
743
|
|
|
)); |
|
744
|
|
|
|
|
745
|
|
|
display($redirectTemplate); |
|
746
|
|
|
die(); |
|
747
|
|
|
} |
|
748
|
|
|
|
|
749
|
|
|
/** |
|
750
|
|
|
* Wrapper for header() function |
|
751
|
|
|
* |
|
752
|
|
|
* @param string $header |
|
753
|
|
|
*/ |
|
754
|
|
|
function setHeader($header) { |
|
755
|
|
|
header($header); |
|
756
|
|
|
} |
|
757
|
|
|
|
|
758
|
|
|
// TODO Для полноценного функионирования апдейтера пакет функций, включая эту должен быть вынесен раньше - или грузить general.php до апдейтера |
|
759
|
|
|
function sys_get_unit_location($user, $planet, $unit_id){return sn_function_call('sys_get_unit_location', array($user, $planet, $unit_id));} |
|
760
|
|
|
function sn_sys_get_unit_location($user, $planet, $unit_id) |
|
|
|
|
|
|
761
|
|
|
{ |
|
762
|
|
|
return get_unit_param($unit_id, 'location'); |
|
763
|
|
|
} |
|
764
|
|
|
|
|
765
|
|
|
function sn_ali_fill_user_ally(&$user) { |
|
766
|
|
|
if(!$user['ally_id']) { |
|
767
|
|
|
return; |
|
768
|
|
|
} |
|
769
|
|
|
|
|
770
|
|
|
if(!isset($user['ally'])) { |
|
771
|
|
|
$user['ally'] = doquery("SELECT * FROM {{alliance}} WHERE `id` = {$user['ally_id']} LIMIT 1;", true); |
|
|
|
|
|
|
772
|
|
|
} |
|
773
|
|
|
|
|
774
|
|
|
if(!isset($user['ally']['player'])) { |
|
775
|
|
|
$user['ally']['player'] = db_user_by_id($user['ally']['ally_user_id'], true, '*', false); |
|
|
|
|
|
|
776
|
|
|
} |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
function sn_get_url_contents($url) |
|
780
|
|
|
{ |
|
781
|
|
|
if(function_exists('curl_init')) |
|
782
|
|
|
{ |
|
783
|
|
|
$crl = curl_init(); |
|
784
|
|
|
$timeout = 5; |
|
785
|
|
|
curl_setopt ($crl, CURLOPT_URL,$url); |
|
786
|
|
|
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); |
|
787
|
|
|
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); |
|
788
|
|
|
$return = curl_exec($crl); |
|
789
|
|
|
curl_close($crl); |
|
790
|
|
|
} |
|
791
|
|
|
else |
|
792
|
|
|
{ |
|
793
|
|
|
$return = @file_get_contents($url); |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
|
|
return $return; |
|
797
|
|
|
} |
|
798
|
|
|
|
|
799
|
|
|
function get_engine_data($user, $engine_info) |
|
800
|
|
|
{ |
|
801
|
|
|
$sn_data_tech_bonus = get_unit_param($engine_info['tech'], 'bonus'); |
|
802
|
|
|
|
|
803
|
|
|
$user_tech_level = intval(mrc_get_level($user, false, $engine_info['tech'])); |
|
|
|
|
|
|
804
|
|
|
|
|
805
|
|
|
$engine_info['speed_base'] = $engine_info['speed']; |
|
806
|
|
|
$tech_bonus = ($user_tech_level - $engine_info['min_level']) * $sn_data_tech_bonus / 100; |
|
807
|
|
|
$tech_bonus = $tech_bonus < -0.9 ? -0.95 : $tech_bonus; |
|
808
|
|
|
$engine_info['speed'] = floor(mrc_modify_value($user, false, array(MRC_NAVIGATOR), $engine_info['speed']) * (1 + $tech_bonus)); |
|
|
|
|
|
|
809
|
|
|
|
|
810
|
|
|
$engine_info['consumption_base'] = $engine_info['consumption']; |
|
811
|
|
|
$tech_bonus = ($user_tech_level - $engine_info['min_level']) * $sn_data_tech_bonus / 1000; |
|
812
|
|
|
$tech_bonus = $tech_bonus > 0.5 ? 0.5 : ($tech_bonus < 0 ? $tech_bonus * 2 : $tech_bonus); |
|
813
|
|
|
$engine_info['consumption'] = ceil($engine_info['consumption'] * (1 - $tech_bonus)); |
|
814
|
|
|
|
|
815
|
|
|
return $engine_info; |
|
816
|
|
|
} |
|
817
|
|
|
|
|
818
|
|
|
function get_ship_data($ship_id, $user) |
|
819
|
|
|
{ |
|
820
|
|
|
$ship_data = array(); |
|
821
|
|
|
if(in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) |
|
822
|
|
|
{ |
|
823
|
|
|
foreach(get_unit_param($ship_id, 'engine') as $engine_info) |
|
824
|
|
|
{ |
|
825
|
|
|
$tech_level = intval(mrc_get_level($user, false, $engine_info['tech'])); |
|
|
|
|
|
|
826
|
|
|
if(empty($ship_data) || $tech_level >= $engine_info['min_level']) |
|
827
|
|
|
{ |
|
828
|
|
|
$ship_data = $engine_info; |
|
829
|
|
|
$ship_data['tech_level'] = $tech_level; |
|
830
|
|
|
} |
|
831
|
|
|
} |
|
832
|
|
|
$ship_data = get_engine_data($user, $ship_data); |
|
833
|
|
|
$ship_data['capacity'] = get_unit_param($ship_id, 'capacity'); |
|
834
|
|
|
} |
|
835
|
|
|
|
|
836
|
|
|
return $ship_data; |
|
837
|
|
|
} |
|
838
|
|
|
|
|
839
|
|
|
if(!function_exists('strptime')) |
|
840
|
|
|
{ |
|
841
|
|
|
function strptime($date, $format) |
|
842
|
|
|
{ |
|
843
|
|
|
$masks = array( |
|
844
|
|
|
'%d' => '(?P<d>[0-9]{2})', |
|
845
|
|
|
'%m' => '(?P<m>[0-9]{2})', |
|
846
|
|
|
'%Y' => '(?P<Y>[0-9]{4})', |
|
847
|
|
|
'%H' => '(?P<H>[0-9]{2})', |
|
848
|
|
|
'%M' => '(?P<M>[0-9]{2})', |
|
849
|
|
|
'%S' => '(?P<S>[0-9]{2})', |
|
850
|
|
|
// usw.. |
|
851
|
|
|
); |
|
852
|
|
|
|
|
853
|
|
|
$rexep = "#".strtr(preg_quote($format), $masks)."#"; |
|
854
|
|
|
if(preg_match($rexep, $date, $out)) |
|
855
|
|
|
{ |
|
856
|
|
|
$ret = array( |
|
857
|
|
|
"tm_sec" => (int) $out['S'], |
|
858
|
|
|
"tm_min" => (int) $out['M'], |
|
859
|
|
|
"tm_hour" => (int) $out['H'], |
|
860
|
|
|
"tm_mday" => (int) $out['d'], |
|
861
|
|
|
"tm_mon" => $out['m'] ? $out['m'] - 1 : 0, |
|
862
|
|
|
"tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0, |
|
863
|
|
|
); |
|
864
|
|
|
} |
|
865
|
|
|
else |
|
866
|
|
|
{ |
|
867
|
|
|
$ret = false; |
|
868
|
|
|
} |
|
869
|
|
|
return $ret; |
|
870
|
|
|
} |
|
871
|
|
|
} |
|
872
|
|
|
|
|
873
|
|
|
function sn_sys_sector_buy($redirect = 'overview.php') { |
|
874
|
|
|
global $lang, $user, $planetrow; |
|
875
|
|
|
|
|
876
|
|
|
if(!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
877
|
|
|
return; |
|
878
|
|
|
} |
|
879
|
|
|
|
|
880
|
|
|
sn_db_transaction_start(); |
|
881
|
|
|
$user = db_user_by_id($user['id'], true, '*'); |
|
|
|
|
|
|
882
|
|
|
$planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*'); |
|
883
|
|
|
// Тут не надо делать обсчет - ресурсы мы уже посчитали, очередь (и количество зданий) - тоже |
|
884
|
|
|
// $planetrow = sys_o_get_updated($user, $planetrow, SN_TIME_NOW); |
|
885
|
|
|
// $user = $planetrow['user']; |
|
886
|
|
|
// $planetrow = $planetrow['planet']; |
|
887
|
|
|
$sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); |
|
|
|
|
|
|
888
|
|
|
$sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; |
|
889
|
|
|
if($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
|
|
|
|
|
890
|
|
|
$planet_name_text = uni_render_planet($planetrow); |
|
891
|
|
|
if(rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf($lang['sys_sector_purchase_log'], |
|
|
|
|
|
|
892
|
|
|
$user['username'], $user['id'], $planet_name_text, $lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost) |
|
893
|
|
|
)) { |
|
894
|
|
|
$sector_db_name = pname_resource_name(UNIT_SECTOR); |
|
895
|
|
|
DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "{$sector_db_name} = {$sector_db_name} + 1"); |
|
896
|
|
|
} else { |
|
897
|
|
|
sn_db_transaction_rollback(); |
|
898
|
|
|
} |
|
899
|
|
|
} |
|
900
|
|
|
sn_db_transaction_commit(); |
|
901
|
|
|
|
|
902
|
|
|
sys_redirect($redirect); |
|
903
|
|
|
} |
|
904
|
|
|
|
|
905
|
|
|
function sn_sys_handler_add(&$functions, $handler_list, $class_module_name = '', $sub_type = '') |
|
906
|
|
|
{ |
|
907
|
|
|
if(isset($handler_list) && is_array($handler_list) && !empty($handler_list)) |
|
908
|
|
|
{ |
|
909
|
|
|
foreach($handler_list as $function_name => $function_data) |
|
910
|
|
|
{ |
|
911
|
|
|
if(is_string($function_data)) |
|
912
|
|
|
{ |
|
913
|
|
|
$override_with = &$function_data; |
|
914
|
|
|
} |
|
915
|
|
|
elseif(isset($function_data['callable'])) |
|
916
|
|
|
{ |
|
917
|
|
|
$override_with = &$function_data['callable']; |
|
918
|
|
|
} |
|
919
|
|
|
|
|
920
|
|
|
$overwrite = $override_with[0] == '*'; |
|
|
|
|
|
|
921
|
|
|
if($overwrite) |
|
922
|
|
|
{ |
|
923
|
|
|
$override_with = substr($override_with, 1); |
|
924
|
|
|
} |
|
925
|
|
|
|
|
926
|
|
|
if(($point_position = strpos($override_with, '.')) === false && $class_module_name) |
|
927
|
|
|
{ |
|
928
|
|
|
$override_with = array($class_module_name, $override_with); |
|
929
|
|
|
} |
|
930
|
|
|
elseif($point_position == 0) |
|
931
|
|
|
{ |
|
932
|
|
|
$override_with = substr($override_with, 1); |
|
933
|
|
|
} |
|
934
|
|
|
elseif($point_position > 0) |
|
935
|
|
|
{ |
|
936
|
|
|
$override_with = array(substr($override_with, 0, $point_position), substr($override_with, $point_position + 1)); |
|
937
|
|
|
} |
|
938
|
|
|
|
|
939
|
|
|
if($overwrite) |
|
940
|
|
|
{ |
|
941
|
|
|
$functions[$function_name] = array(); |
|
942
|
|
|
} |
|
943
|
|
|
elseif(!isset($functions[$function_name])) |
|
944
|
|
|
{ |
|
945
|
|
|
$functions[$function_name] = array(); |
|
946
|
|
|
$sn_function_name = 'sn_' . $function_name . ($sub_type ? '_' . $sub_type : ''); |
|
947
|
|
|
//if(is_callable($sn_function_name)) |
|
|
|
|
|
|
948
|
|
|
{ |
|
949
|
|
|
$functions[$function_name][] = $sn_function_name; |
|
950
|
|
|
} |
|
951
|
|
|
} |
|
952
|
|
|
|
|
953
|
|
|
$functions[$function_name][] = $function_data; |
|
954
|
|
|
} |
|
955
|
|
|
} |
|
956
|
|
|
} |
|
957
|
|
|
|
|
958
|
|
|
// TODO - поменять название |
|
959
|
|
|
// Может принимать: (array)$user, $nick_render_array, $nick_render_array_html, $nick_render_string_compact |
|
960
|
|
|
function player_nick_render_to_html($result, $options = false){ |
|
961
|
|
|
// TODO - обрабатывать разные случаи: $user, $render_nick_array, $string |
|
962
|
|
|
|
|
963
|
|
|
if(is_string($result) && strpos($result, ':{i:')) { |
|
964
|
|
|
$result = player_nick_uncompact($result); |
|
965
|
|
|
} |
|
966
|
|
|
|
|
967
|
|
|
if(is_array($result)) { |
|
968
|
|
|
if(isset($result['id'])) { |
|
969
|
|
|
$result = player_nick_render_current_to_array($result, $options); |
|
970
|
|
|
} |
|
971
|
|
|
if(!isset($result[NICK_HTML])) { |
|
972
|
|
|
$result = player_nick_render_array_to_html($result); |
|
973
|
|
|
} |
|
974
|
|
|
unset($result[NICK_HTML]); |
|
975
|
|
|
// unset($result[NICK_ID]); |
|
|
|
|
|
|
976
|
|
|
ksort($result); |
|
977
|
|
|
$result = implode('', $result); |
|
978
|
|
|
} |
|
979
|
|
|
|
|
980
|
|
|
return $result; |
|
981
|
|
|
} |
|
982
|
|
|
|
|
983
|
|
|
|
|
984
|
|
|
function player_nick_compact($nick_array) { |
|
985
|
|
|
ksort($nick_array); |
|
986
|
|
|
return serialize($nick_array); |
|
987
|
|
|
} |
|
988
|
|
|
|
|
989
|
|
|
function player_nick_uncompact($nick_string) { |
|
990
|
|
|
try { |
|
991
|
|
|
$result = unserialize($nick_string); |
|
992
|
|
|
// ksort($result); // Всегда ksort-ый в player_nick_compact() |
|
|
|
|
|
|
993
|
|
|
} catch(exception $e) { |
|
994
|
|
|
$result = strpos($nick_string, ':{i:') ? null : $nick_string; // fallback if it is already string - for old chat strings, for example |
|
995
|
|
|
} |
|
996
|
|
|
return $result; |
|
997
|
|
|
} |
|
998
|
|
|
|
|
999
|
|
|
function player_nick_render_array_to_html($nick_array){return sn_function_call('player_nick_render_array_to_html', array($nick_array, &$result));} |
|
1000
|
|
|
function sn_player_nick_render_array_to_html($nick_array, &$result) { |
|
1001
|
|
|
global $config, $user; |
|
1002
|
|
|
|
|
1003
|
|
|
static $iconCache = array(); |
|
1004
|
|
|
|
|
1005
|
|
|
if(empty($iconCache['gender_' . $nick_array[NICK_GENDER]])) { |
|
1006
|
|
|
$iconCache['gender_' . $nick_array[NICK_GENDER]] = classSupernova::$gc->skinModel->getImageCurrent("gender_{$nick_array[NICK_GENDER]}|html"); |
|
|
|
|
|
|
1007
|
|
|
$iconCache['icon_vacation'] = classSupernova::$gc->skinModel->getImageCurrent('icon_vacation|html'); |
|
|
|
|
|
|
1008
|
|
|
$iconCache['icon_birthday'] = classSupernova::$gc->skinModel->getImageCurrent('icon_birthday|html'); |
|
|
|
|
|
|
1009
|
|
|
} |
|
1010
|
|
|
$iconGender = $iconCache['gender_' . $nick_array[NICK_GENDER]]; |
|
1011
|
|
|
|
|
1012
|
|
|
// ALL STRING ARE UNSAFE!!! |
|
1013
|
|
|
if(isset($nick_array[NICK_BIRTHSDAY])) { |
|
1014
|
|
|
// $result[NICK_BIRTHSDAY] = '<img src="design/images/birthday.png" />'; |
|
|
|
|
|
|
1015
|
|
|
$result[NICK_BIRTHSDAY] = $iconCache['icon_birthday']; |
|
1016
|
|
|
} |
|
1017
|
|
|
|
|
1018
|
|
|
if(isset($nick_array[NICK_VACATION])) { |
|
1019
|
|
|
// $result[NICK_VACATION] = '<img src="design/images/icon_vacation.png" />'; |
|
|
|
|
|
|
1020
|
|
|
// $result[NICK_VACATION] = classSupernova::$gc->skinModel->getImageCurrent('icon_vacation|html'); |
|
1021
|
|
|
$result[NICK_VACATION] = $iconCache['icon_vacation']; |
|
1022
|
|
|
} |
|
1023
|
|
|
|
|
1024
|
|
|
if(isset($nick_array[NICK_GENDER])) { |
|
1025
|
|
|
// $result[NICK_GENDER] = '<img src="' . classSupernova::$gc->theUser->getSkinPath() . 'images/gender_' . $nick_array[NICK_GENDER] . '.png" />'; |
|
|
|
|
|
|
1026
|
|
|
// $result[NICK_GENDER] = classSupernova::$gc->skinModel->getImageCurrent("gender_{$nick_array[NICK_GENDER]}|html"); |
|
1027
|
|
|
$result[NICK_GENDER] = $iconGender; |
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
|
if(isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
1031
|
|
|
switch($nick_array[NICK_AUTH_LEVEL]) { |
|
1032
|
|
|
case 4: |
|
1033
|
|
|
$highlight = classSupernova::$config->chat_highlight_developer; |
|
|
|
|
|
|
1034
|
|
|
break; |
|
1035
|
|
|
|
|
1036
|
|
|
case 3: |
|
1037
|
|
|
$highlight = classSupernova::$config->chat_highlight_admin; |
|
|
|
|
|
|
1038
|
|
|
break; |
|
1039
|
|
|
|
|
1040
|
|
|
case 2: |
|
1041
|
|
|
$highlight = classSupernova::$config->chat_highlight_operator; |
|
|
|
|
|
|
1042
|
|
|
break; |
|
1043
|
|
|
|
|
1044
|
|
|
case 1: |
|
1045
|
|
|
$highlight = classSupernova::$config->chat_highlight_moderator; |
|
|
|
|
|
|
1046
|
|
|
break; |
|
1047
|
|
|
|
|
1048
|
|
|
default: |
|
1049
|
|
|
$highlight = isset($nick_array[NICK_PREMIUM]) ? classSupernova::$config->chat_highlight_premium : ''; |
|
|
|
|
|
|
1050
|
|
|
} |
|
1051
|
|
|
|
|
1052
|
|
|
if($highlight) { |
|
1053
|
|
|
list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight); |
|
1054
|
|
|
} |
|
1055
|
|
|
// $result = preg_replace("#(.+)#", $highlight, $result); |
|
|
|
|
|
|
1056
|
|
|
} |
|
1057
|
|
|
|
|
1058
|
|
View Code Duplication |
if(isset($nick_array[NICK_CLASS])) { |
|
|
|
|
|
|
1059
|
|
|
$result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] .'>'; |
|
1060
|
|
|
$result[NICK_CLASS_END] = '</span>'; |
|
1061
|
|
|
} |
|
1062
|
|
|
|
|
1063
|
|
|
$result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]); |
|
1064
|
|
|
|
|
1065
|
|
View Code Duplication |
if(isset($nick_array[NICK_ALLY])) { |
|
|
|
|
|
|
1066
|
|
|
$result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']'; |
|
1067
|
|
|
} |
|
1068
|
|
|
|
|
1069
|
|
|
$result[NICK_HTML] = true; |
|
1070
|
|
|
|
|
1071
|
|
|
return $result; |
|
1072
|
|
|
} |
|
1073
|
|
|
|
|
1074
|
|
|
function player_nick_render_current_to_array($render_user, $options = false){return sn_function_call('player_nick_render_current_to_array', array($render_user, $options, &$result));} |
|
|
|
|
|
|
1075
|
|
|
function sn_player_nick_render_current_to_array($render_user, $options = false, &$result) { |
|
1076
|
|
|
/* |
|
|
|
|
|
|
1077
|
|
|
$options = $options !== true ? $options : |
|
1078
|
|
|
array( |
|
1079
|
|
|
'color' => true, |
|
1080
|
|
|
'icons' => true, |
|
1081
|
|
|
'gender' => true, |
|
1082
|
|
|
'birthday' => true, |
|
1083
|
|
|
'ally' => true, |
|
1084
|
|
|
); |
|
1085
|
|
|
*/ |
|
1086
|
|
|
|
|
1087
|
|
|
|
|
1088
|
|
|
if($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
1089
|
|
|
$result[NICK_BIRTHSDAY] = ''; |
|
1090
|
|
|
} |
|
1091
|
|
|
|
|
1092
|
|
|
if($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
1093
|
|
|
$result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male'); |
|
1094
|
|
|
} |
|
1095
|
|
|
|
|
1096
|
|
|
if(($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
1097
|
|
|
$result[NICK_VACATION] = $render_user['vacation']; |
|
1098
|
|
|
} |
|
1099
|
|
|
|
|
1100
|
|
|
if($options === true || (isset($options['color']) && $options['color'])) { |
|
1101
|
|
|
if($user_auth_level = $render_user['authlevel']) { |
|
1102
|
|
|
$result[NICK_AUTH_LEVEL] = $user_auth_level; |
|
1103
|
|
|
} |
|
1104
|
|
|
if($user_premium = mrc_get_level($render_user, false, UNIT_PREMIUM)) { |
|
|
|
|
|
|
1105
|
|
|
$result[NICK_PREMIUM] = $user_premium; |
|
1106
|
|
|
} |
|
1107
|
|
|
} |
|
1108
|
|
|
|
|
1109
|
|
|
if((isset($options['class']) && $options['class'])) { |
|
1110
|
|
|
$result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class']; |
|
|
|
|
|
|
1111
|
|
|
} |
|
1112
|
|
|
|
|
1113
|
|
|
if($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
1114
|
|
|
$result[NICK_ALLY] = $render_user['ally_tag']; |
|
1115
|
|
|
} |
|
1116
|
|
|
|
|
1117
|
|
|
$result[NICK_NICK] = $render_user['username']; |
|
1118
|
|
|
|
|
1119
|
|
|
return $result; |
|
1120
|
|
|
} |
|
1121
|
|
|
|
|
1122
|
|
|
|
|
1123
|
|
|
|
|
1124
|
|
|
|
|
1125
|
|
|
|
|
1126
|
|
|
|
|
1127
|
|
|
|
|
1128
|
|
|
|
|
1129
|
|
|
|
|
1130
|
|
|
|
|
1131
|
|
|
|
|
1132
|
|
|
|
|
1133
|
|
|
|
|
1134
|
|
|
|
|
1135
|
|
|
|
|
1136
|
|
|
|
|
1137
|
|
|
|
|
1138
|
|
|
|
|
1139
|
|
|
|
|
1140
|
|
|
|
|
1141
|
|
|
|
|
1142
|
|
|
|
|
1143
|
|
|
|
|
1144
|
|
|
|
|
1145
|
|
|
|
|
1146
|
|
|
|
|
1147
|
|
|
|
|
1148
|
|
|
|
|
1149
|
|
|
|
|
1150
|
|
|
|
|
1151
|
|
|
|
|
1152
|
|
|
|
|
1153
|
|
|
|
|
1154
|
|
|
|
|
1155
|
|
|
|
|
1156
|
|
|
// TODO sys_stat_get_user_skip_list() ПЕРЕДЕЛАТЬ! |
|
1157
|
|
|
function sys_stat_get_user_skip_list() { |
|
1158
|
|
|
global $config; |
|
1159
|
|
|
|
|
1160
|
|
|
$result = array(); |
|
1161
|
|
|
|
|
1162
|
|
|
$user_skip_list = array(); |
|
1163
|
|
|
|
|
1164
|
|
|
if(classSupernova::$config->stats_hide_admins) { |
|
|
|
|
|
|
1165
|
|
|
$user_skip_list[] = '`authlevel` > 0'; |
|
1166
|
|
|
} |
|
1167
|
|
|
|
|
1168
|
|
|
if(classSupernova::$config->stats_hide_player_list) { |
|
|
|
|
|
|
1169
|
|
|
$temp = explode(',', classSupernova::$config->stats_hide_player_list); |
|
|
|
|
|
|
1170
|
|
|
foreach($temp as $user_id) { |
|
1171
|
|
|
$user_id = floatval($user_id); |
|
1172
|
|
|
if($user_id) { |
|
1173
|
|
|
$user_skip_list[] = '`id` = ' . $user_id; |
|
1174
|
|
|
} |
|
1175
|
|
|
} |
|
1176
|
|
|
} |
|
1177
|
|
|
|
|
1178
|
|
|
if(!empty($user_skip_list)) { |
|
1179
|
|
|
$user_skip_list = implode(' OR ', $user_skip_list); |
|
1180
|
|
|
$user_skip_query = db_user_list($user_skip_list); |
|
|
|
|
|
|
1181
|
|
|
if(!empty($user_skip_query)) { |
|
1182
|
|
|
foreach($user_skip_query as $user_skip_row) { |
|
1183
|
|
|
$result[$user_skip_row['id']] = $user_skip_row['id']; |
|
1184
|
|
|
} |
|
1185
|
|
|
} |
|
1186
|
|
|
} |
|
1187
|
|
|
|
|
1188
|
|
|
return $result; |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
// function player_nick_render_to_html($render_user, $options = false){return sn_function_call('player_nick_render_to_html', array($render_user, $options, &$result));} |
|
|
|
|
|
|
1192
|
|
|
// function sn_render_player_nick($render_user, $options = false, &$result) |
|
1193
|
|
|
|
|
1194
|
|
|
function get_unit_param($unit_id, $param_name = null, $user = null, $planet = null){return sn_function_call('get_unit_param', array($unit_id, $param_name, $user, $planet, &$result));} |
|
|
|
|
|
|
1195
|
|
|
function sn_get_unit_param($unit_id, $param_name = null, $user = null, $planet = null, &$result) |
|
|
|
|
|
|
1196
|
|
|
{ |
|
1197
|
|
|
global $sn_data; |
|
1198
|
|
|
|
|
1199
|
|
|
$result = isset($sn_data[$unit_id]) |
|
1200
|
|
|
? ($param_name === null |
|
1201
|
|
|
? $sn_data[$unit_id] |
|
1202
|
|
|
: (isset($sn_data[$unit_id][$param_name]) ? $sn_data[$unit_id][$param_name] : $result) |
|
1203
|
|
|
) |
|
1204
|
|
|
: $result; |
|
1205
|
|
|
|
|
1206
|
|
|
return $result; |
|
1207
|
|
|
} |
|
1208
|
|
|
|
|
1209
|
|
|
function sn_get_groups($groups){return sn_function_call('sn_get_groups', array($groups, &$result));} |
|
|
|
|
|
|
1210
|
|
|
function sn_sn_get_groups($groups, &$result) |
|
1211
|
|
|
{ |
|
1212
|
|
|
$result = is_array($result) ? $result : array(); |
|
1213
|
|
|
foreach($groups = is_array($groups) ? $groups : array($groups) as $group_name) |
|
1214
|
|
|
{ |
|
1215
|
|
|
$result += is_array($a_group = get_unit_param(UNIT_GROUP, $group_name)) ? $a_group : array(); |
|
1216
|
|
|
} |
|
1217
|
|
|
|
|
1218
|
|
|
return $result; |
|
1219
|
|
|
} |
|
1220
|
|
|
|
|
1221
|
|
|
// Format $value to ID |
|
1222
|
|
|
/** |
|
1223
|
|
|
* @param $value |
|
1224
|
|
|
* @param int $default |
|
1225
|
|
|
* |
|
1226
|
|
|
* @return float|int |
|
1227
|
|
|
*/ |
|
1228
|
|
|
function idval($value, $default = 0) |
|
1229
|
|
|
{ |
|
1230
|
|
|
$value = floatval($value); |
|
1231
|
|
|
return preg_match('#^(\d*)#', $value, $matches) && $matches[1] ? floatval($matches[1]) : $default; |
|
1232
|
|
|
} |
|
1233
|
|
|
|
|
1234
|
|
|
function unit_requirements_render($user, $planetrow, $unit_id, $field = 'require'){return sn_function_call('unit_requirements_render', array($user, $planetrow, $unit_id, $field, &$result));} |
|
|
|
|
|
|
1235
|
|
|
function sn_unit_requirements_render($user, $planetrow, $unit_id, $field = 'require', &$result) |
|
1236
|
|
|
{ |
|
1237
|
|
|
global $lang, $config; |
|
1238
|
|
|
|
|
1239
|
|
|
$sn_data_unit = get_unit_param($unit_id); |
|
1240
|
|
|
|
|
1241
|
|
|
$result = is_array($result) ? $result : array(); |
|
1242
|
|
|
if($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && classSupernova::$config->empire_mercenary_temporary)) |
|
|
|
|
|
|
1243
|
|
|
{ |
|
1244
|
|
|
foreach($sn_data_unit[$field] as $require_id => $require_level) |
|
1245
|
|
|
{ |
|
1246
|
|
|
$level_got = mrc_get_level($user, $planetrow, $require_id); |
|
1247
|
|
|
$level_basic = mrc_get_level($user, $planetrow, $require_id, false, true); |
|
1248
|
|
|
$result[] = array( |
|
1249
|
|
|
'NAME' => $lang['tech'][$require_id], |
|
1250
|
|
|
//'CLASS' => $require_level > $level_got ? 'negative' : ($require_level == $level_got ? 'zero' : 'positive'), |
|
|
|
|
|
|
1251
|
|
|
'REQUEREMENTS_MET' => intval($require_level <= $level_got ? REQUIRE_MET : REQUIRE_MET_NOT), |
|
1252
|
|
|
'LEVEL_REQUIRE' => $require_level, |
|
1253
|
|
|
'LEVEL' => $level_got, |
|
1254
|
|
|
'LEVEL_BASIC' => $level_basic, |
|
1255
|
|
|
'LEVEL_BONUS' => max(0, $level_got - $level_basic), |
|
1256
|
|
|
'ID' => $require_id, |
|
1257
|
|
|
); |
|
1258
|
|
|
} |
|
1259
|
|
|
} |
|
1260
|
|
|
|
|
1261
|
|
|
return $result; |
|
1262
|
|
|
} |
|
1263
|
|
|
|
|
1264
|
|
|
function ally_get_ranks(&$ally) |
|
1265
|
|
|
{ |
|
1266
|
|
|
global $ally_rights; |
|
1267
|
|
|
|
|
1268
|
|
|
$ranks = array(); |
|
1269
|
|
|
|
|
1270
|
|
|
if($ally['ranklist']) |
|
1271
|
|
|
{ |
|
1272
|
|
|
$str_ranks = explode(';', $ally['ranklist']); |
|
1273
|
|
|
foreach($str_ranks as $str_rank) |
|
1274
|
|
|
{ |
|
1275
|
|
|
if(!$str_rank) |
|
1276
|
|
|
{ |
|
1277
|
|
|
continue; |
|
1278
|
|
|
} |
|
1279
|
|
|
|
|
1280
|
|
|
$tmp = explode(',', $str_rank); |
|
1281
|
|
|
$rank_id = count($ranks); |
|
1282
|
|
|
foreach($ally_rights as $key => $value) |
|
1283
|
|
|
{ |
|
1284
|
|
|
$ranks[$rank_id][$value] = $tmp[$key]; |
|
1285
|
|
|
} |
|
1286
|
|
|
} |
|
1287
|
|
|
} |
|
1288
|
|
|
|
|
1289
|
|
|
return $ranks; |
|
1290
|
|
|
} |
|
1291
|
|
|
|
|
1292
|
|
|
function sys_player_new_adjust($user_id, $planet_id){return sn_function_call('sys_player_new_adjust', array($user_id, $planet_id, &$result));} |
|
|
|
|
|
|
1293
|
|
|
function sn_sys_player_new_adjust($user_id, $planet_id, &$result) { |
|
|
|
|
|
|
1294
|
|
|
return $result; |
|
1295
|
|
|
} |
|
1296
|
|
|
|
|
1297
|
|
|
function array_merge_recursive_numeric($array1, $array2) { |
|
1298
|
|
|
if(!empty($array2) && is_array($array2)) { |
|
1299
|
|
|
foreach($array2 as $key => $value) { |
|
1300
|
|
|
// if(!isset($array1[$key]) || !is_array($array1[$key])) { |
|
|
|
|
|
|
1301
|
|
|
// $array1[$key] = $value; |
|
1302
|
|
|
// } else { |
|
1303
|
|
|
// $array1[$key] = array_merge_recursive_numeric($array1[$key], $value); |
|
1304
|
|
|
// } |
|
1305
|
|
|
$array1[$key] = !isset($array1[$key]) || !is_array($array1[$key]) ? $value : array_merge_recursive_numeric($array1[$key], $value); |
|
1306
|
|
|
} |
|
1307
|
|
|
} |
|
1308
|
|
|
|
|
1309
|
|
|
return $array1; |
|
1310
|
|
|
} |
|
1311
|
|
|
|
|
1312
|
|
|
function sn_sys_array_cumulative_sum(&$array) |
|
1313
|
|
|
{ |
|
1314
|
|
|
$accum = 0; |
|
1315
|
|
|
foreach($array as &$value) |
|
1316
|
|
|
{ |
|
1317
|
|
|
$accum += $value; |
|
1318
|
|
|
$value = $accum; |
|
1319
|
|
|
} |
|
1320
|
|
|
} |
|
1321
|
|
|
|
|
1322
|
|
|
function planet_density_price_chart($planet_row) { |
|
1323
|
|
|
$sn_data_density = sn_get_groups('planet_density'); |
|
1324
|
|
|
$density_price_chart = array(); |
|
1325
|
|
|
|
|
1326
|
|
|
foreach($sn_data_density as $density_id => $density_data) { |
|
1327
|
|
|
// Отсекаем записи с RARITY = 0 - служебные записи и супер-ядра |
|
1328
|
|
|
$density_data[UNIT_PLANET_DENSITY_RARITY] ? $density_price_chart[$density_id] = $density_data[UNIT_PLANET_DENSITY_RARITY] : false; |
|
1329
|
|
|
} |
|
1330
|
|
|
unset($density_price_chart[PLANET_DENSITY_NONE]); |
|
1331
|
|
|
|
|
1332
|
|
|
$total_rarity = array_sum($density_price_chart); |
|
1333
|
|
|
|
|
1334
|
|
|
foreach($density_price_chart as &$density_data) { |
|
1335
|
|
|
$density_data = ceil($total_rarity / $density_data * $planet_row['field_max'] * PLANET_DENSITY_TO_DARK_MATTER_RATE); |
|
1336
|
|
|
} |
|
1337
|
|
|
|
|
1338
|
|
|
return $density_price_chart; |
|
1339
|
|
|
} |
|
1340
|
|
|
|
|
1341
|
|
|
function sn_sys_planet_core_transmute(&$user, &$planetrow) { |
|
1342
|
|
|
if(!sys_get_param_str('transmute')) { |
|
1343
|
|
|
return array(); |
|
1344
|
|
|
} |
|
1345
|
|
|
|
|
1346
|
|
|
global $lang; |
|
1347
|
|
|
|
|
1348
|
|
|
try { |
|
1349
|
|
|
if($planetrow['planet_type'] != PT_PLANET) { |
|
1350
|
|
|
throw new exception($lang['ov_core_err_not_a_planet'], ERR_ERROR); |
|
1351
|
|
|
} |
|
1352
|
|
|
|
|
1353
|
|
|
if($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
1354
|
|
|
throw new exception($lang['ov_core_err_same_density'], ERR_WARNING); |
|
1355
|
|
|
} |
|
1356
|
|
|
|
|
1357
|
|
|
sn_db_transaction_start(); |
|
1358
|
|
|
$user = db_user_by_id($user['id'], true, '*'); |
|
|
|
|
|
|
1359
|
|
|
$planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*'); |
|
1360
|
|
|
// $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW); |
|
|
|
|
|
|
1361
|
|
|
// $user = $global_data['user']; |
|
1362
|
|
|
// $planetrow = $global_data['planet']; |
|
1363
|
|
|
|
|
1364
|
|
|
$planet_density_index = $planetrow['density_index']; |
|
1365
|
|
|
|
|
1366
|
|
|
$density_price_chart = planet_density_price_chart($planetrow); |
|
1367
|
|
|
if(!isset($density_price_chart[$new_density_index])) { |
|
1368
|
|
|
// Hack attempt |
|
1369
|
|
|
throw new exception($lang['ov_core_err_denisty_type_wrong'], ERR_ERROR); |
|
1370
|
|
|
} |
|
1371
|
|
|
|
|
1372
|
|
|
$user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER); |
|
|
|
|
|
|
1373
|
|
|
// $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost'); |
|
|
|
|
|
|
1374
|
|
|
// $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index]; |
|
|
|
|
|
|
1375
|
|
|
$transmute_cost = $density_price_chart[$new_density_index]; |
|
1376
|
|
|
if($user_dark_matter < $transmute_cost) { |
|
1377
|
|
|
throw new exception($lang['ov_core_err_no_dark_matter'], ERR_ERROR); |
|
1378
|
|
|
} |
|
1379
|
|
|
|
|
1380
|
|
|
$sn_data_planet_density = sn_get_groups('planet_density'); |
|
1381
|
|
|
foreach($sn_data_planet_density as $key => $value) { |
|
1382
|
|
|
if($key == $new_density_index) { |
|
1383
|
|
|
break; |
|
1384
|
|
|
} |
|
1385
|
|
|
$prev_density_index = $key; |
|
1386
|
|
|
} |
|
1387
|
|
|
|
|
1388
|
|
|
$new_density = round(($sn_data_planet_density[$new_density_index][UNIT_PLANET_DENSITY] + $sn_data_planet_density[$prev_density_index][UNIT_PLANET_DENSITY]) / 2); |
|
|
|
|
|
|
1389
|
|
|
|
|
1390
|
|
|
rpg_points_change($user['id'], RPG_PLANET_DENSITY_CHANGE, -$transmute_cost, |
|
1391
|
|
|
array( |
|
|
|
|
|
|
1392
|
|
|
'Planet %1$s ID %2$d at coordinates %3$s changed density type from %4$d "%5$s" to %6$d "%7$s". New density is %8$d kg/m3', |
|
1393
|
|
|
$planetrow['name'], |
|
1394
|
|
|
$planetrow['id'], |
|
1395
|
|
|
uni_render_coordinates($planetrow), |
|
1396
|
|
|
$planet_density_index, |
|
1397
|
|
|
$lang['uni_planet_density_types'][$planet_density_index], |
|
1398
|
|
|
$new_density_index, |
|
1399
|
|
|
$lang['uni_planet_density_types'][$new_density_index], |
|
1400
|
|
|
$new_density |
|
1401
|
|
|
) |
|
1402
|
|
|
); |
|
1403
|
|
|
|
|
1404
|
|
|
DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`density` = {$new_density}, `density_index` = {$new_density_index}"); |
|
1405
|
|
|
sn_db_transaction_commit(); |
|
1406
|
|
|
|
|
1407
|
|
|
$planetrow['density'] = $new_density; |
|
1408
|
|
|
$planetrow['density_index'] = $new_density_index; |
|
1409
|
|
|
$result = array( |
|
1410
|
|
|
'STATUS' => ERR_NONE, |
|
1411
|
|
|
'MESSAGE' => sprintf($lang['ov_core_err_none'], $lang['uni_planet_density_types'][$planet_density_index], $lang['uni_planet_density_types'][$new_density_index], $new_density), |
|
1412
|
|
|
); |
|
1413
|
|
|
} catch(exception $e) { |
|
1414
|
|
|
sn_db_transaction_rollback(); |
|
1415
|
|
|
$result = array( |
|
1416
|
|
|
'STATUS' => $e->getCode(), |
|
1417
|
|
|
'MESSAGE' => $e->getMessage(), |
|
1418
|
|
|
); |
|
1419
|
|
|
} |
|
1420
|
|
|
|
|
1421
|
|
|
return $result; |
|
1422
|
|
|
} |
|
1423
|
|
|
|
|
1424
|
|
|
function sn_module_get_active_count($group = '*') |
|
1425
|
|
|
{ |
|
1426
|
|
|
global $sn_module_list; |
|
1427
|
|
|
|
|
1428
|
|
|
$active_modules = 0; |
|
1429
|
|
|
if(isset($sn_module_list[$group]) && is_array($sn_module_list[$group])) |
|
1430
|
|
|
{ |
|
1431
|
|
|
foreach($sn_module_list[$group] as $payment_module) |
|
1432
|
|
|
{ |
|
1433
|
|
|
$active_modules += $payment_module->manifest['active']; |
|
1434
|
|
|
} |
|
1435
|
|
|
} |
|
1436
|
|
|
|
|
1437
|
|
|
return $active_modules; |
|
1438
|
|
|
} |
|
1439
|
|
|
|
|
1440
|
|
|
function get_resource_exchange() |
|
1441
|
|
|
{ |
|
1442
|
|
|
static $rates; |
|
1443
|
|
|
|
|
1444
|
|
|
if(!$rates) |
|
1445
|
|
|
{ |
|
1446
|
|
|
global $config; |
|
1447
|
|
|
|
|
1448
|
|
|
$rates = array( |
|
1449
|
|
|
RES_METAL => 'rpg_exchange_metal', |
|
1450
|
|
|
RES_CRYSTAL => 'rpg_exchange_crystal', |
|
1451
|
|
|
RES_DEUTERIUM => 'rpg_exchange_deuterium', |
|
1452
|
|
|
RES_DARK_MATTER => 'rpg_exchange_darkMatter', |
|
1453
|
|
|
); |
|
1454
|
|
|
|
|
1455
|
|
|
foreach($rates as &$rate) |
|
1456
|
|
|
{ |
|
1457
|
|
|
$rate = classSupernova::$config->$rate; |
|
1458
|
|
|
} |
|
1459
|
|
|
} |
|
1460
|
|
|
|
|
1461
|
|
|
return $rates; |
|
1462
|
|
|
} |
|
1463
|
|
|
|
|
1464
|
|
|
function get_unit_cost_in(&$cost, $in_resource = RES_METAL) |
|
|
|
|
|
|
1465
|
|
|
{ |
|
1466
|
|
|
static $rates; |
|
1467
|
|
|
|
|
1468
|
|
|
if(!$rates) |
|
1469
|
|
|
{ |
|
1470
|
|
|
$rates = get_resource_exchange(); |
|
1471
|
|
|
} |
|
1472
|
|
|
|
|
1473
|
|
|
$metal_cost = 0; |
|
1474
|
|
|
foreach($cost as $resource_id => $resource_value) |
|
1475
|
|
|
{ |
|
1476
|
|
|
$metal_cost += $rates[$resource_id] * $resource_value; |
|
1477
|
|
|
} |
|
1478
|
|
|
|
|
1479
|
|
|
return $metal_cost; |
|
1480
|
|
|
} |
|
1481
|
|
|
|
|
1482
|
|
|
function get_player_max_expeditons(&$user, $astrotech = -1){return sn_function_call('get_player_max_expeditons', array(&$user, $astrotech, &$result));} |
|
|
|
|
|
|
1483
|
|
|
function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) |
|
1484
|
|
|
{ |
|
1485
|
|
|
if($astrotech == -1) { |
|
1486
|
|
|
if(!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) |
|
1487
|
|
|
{ |
|
1488
|
|
|
$astrotech = mrc_get_level($user, false, TECH_ASTROTECH); |
|
|
|
|
|
|
1489
|
|
|
$user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0; |
|
1490
|
|
|
} |
|
1491
|
|
|
|
|
1492
|
|
|
return $result += $user[UNIT_PLAYER_EXPEDITIONS_MAX]; |
|
1493
|
|
|
} else { |
|
1494
|
|
|
return $result += $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0; |
|
1495
|
|
|
} |
|
1496
|
|
|
} |
|
1497
|
|
|
|
|
1498
|
|
|
function get_player_max_expedition_duration(&$user, $astrotech = -1) |
|
1499
|
|
|
{ |
|
1500
|
|
|
return $astrotech == -1 ? mrc_get_level($user, false, TECH_ASTROTECH) : $astrotech; |
|
|
|
|
|
|
1501
|
|
|
} |
|
1502
|
|
|
|
|
1503
|
|
|
function get_player_max_colonies(&$user, $astrotech = -1) { |
|
1504
|
|
|
global $config; |
|
1505
|
|
|
|
|
1506
|
|
|
if($astrotech == -1) { |
|
1507
|
|
|
if(!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
1508
|
|
|
|
|
1509
|
|
|
$expeditions = get_player_max_expeditons($user); |
|
1510
|
|
|
$astrotech = mrc_get_level($user, false, TECH_ASTROTECH); |
|
|
|
|
|
|
1511
|
|
|
$colonies = $astrotech - $expeditions; |
|
1512
|
|
|
|
|
1513
|
|
|
$user[UNIT_PLAYER_COLONIES_MAX] = classSupernova::$config->player_max_colonies < 0 ? $colonies : min(classSupernova::$config->player_max_colonies, $colonies); |
|
|
|
|
|
|
1514
|
|
|
} |
|
1515
|
|
|
|
|
1516
|
|
|
return $user[UNIT_PLAYER_COLONIES_MAX]; |
|
1517
|
|
|
} else { |
|
1518
|
|
|
$expeditions = get_player_max_expeditons($user, $astrotech); |
|
1519
|
|
|
// $astrotech = mrc_get_level($user, false, TECH_ASTROTECH); |
|
|
|
|
|
|
1520
|
|
|
$colonies = $astrotech - $expeditions; |
|
1521
|
|
|
|
|
1522
|
|
|
return classSupernova::$config->player_max_colonies < 0 ? $colonies : min(classSupernova::$config->player_max_colonies, $colonies); |
|
|
|
|
|
|
1523
|
|
|
} |
|
1524
|
|
|
} |
|
1525
|
|
|
|
|
1526
|
|
|
function get_player_current_colonies(&$user) |
|
1527
|
|
|
{ |
|
1528
|
|
|
return $user[UNIT_PLAYER_COLONIES_CURRENT] = isset($user[UNIT_PLAYER_COLONIES_CURRENT]) ? $user[UNIT_PLAYER_COLONIES_CURRENT] : max(0, DBStaticPlanet::db_planet_count_by_type($user['id']) - 1); |
|
1529
|
|
|
} |
|
1530
|
|
|
|
|
1531
|
|
|
function str_raw2unsafe($raw) { |
|
1532
|
|
|
return trim(strip_tags($raw)); |
|
1533
|
|
|
} |
|
1534
|
|
|
|
|
1535
|
|
|
function ip2longu($ip) { |
|
1536
|
|
|
return sprintf('%u', floatval(ip2long($ip))); |
|
1537
|
|
|
} |
|
1538
|
|
|
|
|
1539
|
|
|
|
|
1540
|
|
|
function sn_powerup_get_price_matrix($powerup_id, $powerup_unit = false, $level_max = null, $plain = false){return sn_function_call('sn_powerup_get_price_matrix', array($powerup_id, $powerup_unit, $level_max, $plain, &$result));} |
|
|
|
|
|
|
1541
|
|
|
function sn_sn_powerup_get_price_matrix($powerup_id, $powerup_unit = false, $level_max = null, $plain = false, &$result) { |
|
|
|
|
|
|
1542
|
|
|
global $sn_powerup_buy_discounts; |
|
1543
|
|
|
|
|
1544
|
|
|
$result = array(); |
|
1545
|
|
|
|
|
1546
|
|
|
$powerup_data = get_unit_param($powerup_id); |
|
1547
|
|
|
$is_upgrade = !empty($powerup_unit) && $powerup_unit; |
|
1548
|
|
|
|
|
1549
|
|
|
$level_current = $term_original = $time_left = 0; |
|
1550
|
|
|
if($is_upgrade) { |
|
1551
|
|
|
$time_finish = strtotime($powerup_unit['unit_time_finish']); |
|
1552
|
|
|
$time_left = max(0, $time_finish - SN_TIME_NOW); |
|
1553
|
|
|
if($time_left > 0) { |
|
1554
|
|
|
$term_original = $time_finish - strtotime($powerup_unit['unit_time_start']); |
|
1555
|
|
|
$level_current = $powerup_unit['unit_level']; |
|
1556
|
|
|
} |
|
1557
|
|
|
} |
|
1558
|
|
|
|
|
1559
|
|
|
$level_max = $level_max > $powerup_data[P_MAX_STACK] ? $level_max : $powerup_data[P_MAX_STACK]; |
|
1560
|
|
|
$original_cost = 0; |
|
1561
|
|
|
for($i = 1; $i <= $level_max; $i++) { |
|
1562
|
|
|
$base_cost = eco_get_total_cost($powerup_id, $i); |
|
1563
|
|
|
$base_cost = $base_cost[BUILD_CREATE][RES_DARK_MATTER]; |
|
1564
|
|
|
foreach($sn_powerup_buy_discounts as $period => $discount) { |
|
1565
|
|
|
$upgrade_price = floor($base_cost * $discount * $period / PERIOD_MONTH); |
|
1566
|
|
|
$result[$i][$period] = $upgrade_price; |
|
1567
|
|
|
$original_cost = $is_upgrade && $i == $level_current && $period <= $term_original ? $upgrade_price : $original_cost; |
|
1568
|
|
|
} |
|
1569
|
|
|
} |
|
1570
|
|
|
|
|
1571
|
|
|
if($is_upgrade && $time_left) { |
|
1572
|
|
|
$term_original = round($term_original / PERIOD_DAY); |
|
1573
|
|
|
$time_left = min(floor($time_left / PERIOD_DAY), $term_original); |
|
1574
|
|
|
$cost_left = $term_original > 0 ? ceil($time_left / $term_original * $original_cost) : 0; |
|
1575
|
|
|
|
|
1576
|
|
|
array_walk_recursive($result, function(&$value) use ($cost_left) { |
|
1577
|
|
|
$value -= $cost_left; |
|
1578
|
|
|
}); |
|
1579
|
|
|
} |
|
1580
|
|
|
|
|
1581
|
|
|
return $result; |
|
1582
|
|
|
} |
|
1583
|
|
|
|
|
1584
|
|
|
function note_assign(&$template, $note_row) { |
|
1585
|
|
|
global $note_priority_classes, $lang; |
|
1586
|
|
|
|
|
1587
|
|
|
$template->assign_block_vars('note', array( |
|
1588
|
|
|
'ID' => $note_row['id'], |
|
1589
|
|
|
'TIME' => $note_row['time'], |
|
1590
|
|
|
'TIME_TEXT' => date(FMT_DATE_TIME, $note_row['time']), |
|
1591
|
|
|
'PRIORITY' => $note_row['priority'], |
|
1592
|
|
|
'PRIORITY_CLASS' => $note_priority_classes[$note_row['priority']], |
|
1593
|
|
|
'PRIORITY_TEXT' => $lang['sys_notes_priorities'][$note_row['priority']], |
|
1594
|
|
|
'TITLE' => htmlentities($note_row['title'], ENT_COMPAT, 'UTF-8'), |
|
1595
|
|
|
'GALAXY' => intval($note_row['galaxy']), |
|
1596
|
|
|
'SYSTEM' => intval($note_row['system']), |
|
1597
|
|
|
'PLANET' => intval($note_row['planet']), |
|
1598
|
|
|
'PLANET_TYPE' => intval($note_row['planet_type']), |
|
1599
|
|
|
'PLANET_TYPE_TEXT' => $lang['sys_planet_type'][$note_row['planet_type']], |
|
1600
|
|
|
'PLANET_TYPE_TEXT_SHORT' => $lang['sys_planet_type_sh'][$note_row['planet_type']], |
|
1601
|
|
|
'TEXT' => HelperString::htmlEncode($note_row['text'], HTML_ENCODE_MULTILINE), |
|
1602
|
|
|
'TEXT_EDIT' => htmlentities($note_row['text'], ENT_COMPAT, 'UTF-8'), |
|
1603
|
|
|
'STICKY' => intval($note_row['sticky']), |
|
1604
|
|
|
)); |
|
1605
|
|
|
} |
|
1606
|
|
|
|
|
1607
|
|
|
function sn_version_compare_extra($version) { |
|
1608
|
|
|
static $version_regexp = '#(\d+)([a-f])(\d+)(?:\.(\d+))*#'; |
|
1609
|
|
|
preg_match($version_regexp, $version, $version); |
|
1610
|
|
|
unset($version[0]); |
|
1611
|
|
|
$version[2] = ord($version[2]) - ord('a'); |
|
1612
|
|
|
return implode('.', $version); |
|
1613
|
|
|
} |
|
1614
|
|
|
|
|
1615
|
|
|
function sn_version_compare($ver1, $ver2) { |
|
1616
|
|
|
return version_compare(sn_version_compare_extra($ver1), sn_version_compare_extra($ver2)); |
|
1617
|
|
|
} |
|
1618
|
|
|
|
|
1619
|
|
|
function sn_setcookie($name, $value = null, $expire = null, $path = SN_ROOT_RELATIVE, $domain = null, $secure = null, $httponly = null) { |
|
1620
|
|
|
$_COOKIE[$name] = $value; |
|
1621
|
|
|
return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); |
|
1622
|
|
|
} |
|
1623
|
|
|
|
|
1624
|
|
|
function market_get_autoconvert_cost() { |
|
1625
|
|
|
global $config; |
|
1626
|
|
|
|
|
1627
|
|
|
return classSupernova::$config->rpg_cost_exchange ? classSupernova::$config->rpg_cost_exchange * 3 : 3000; |
|
|
|
|
|
|
1628
|
|
|
} |
|
1629
|
|
|
|
|
1630
|
|
|
function print_rr($var, $capture = false) { |
|
1631
|
|
|
$print = '<pre>' . htmlspecialchars(print_r($var, true)) . '</pre>'; |
|
1632
|
|
|
if($capture) { |
|
1633
|
|
|
return $print; |
|
1634
|
|
|
} else { |
|
1635
|
|
|
print($print); |
|
1636
|
|
|
} |
|
1637
|
|
|
} |
|
1638
|
|
|
|
|
1639
|
|
|
function can_capture_planet(){return sn_function_call('can_capture_planet', array(&$result));} |
|
|
|
|
|
|
1640
|
|
|
function sn_can_capture_planet(&$result) { |
|
1641
|
|
|
return $result = false; |
|
1642
|
|
|
} |
|
1643
|
|
|
|
|
1644
|
|
|
/** |
|
1645
|
|
|
* Возвращает информацию об IPv4 адресах пользователя |
|
1646
|
|
|
* |
|
1647
|
|
|
* НЕ ПОДДЕРЖИВАЕТ IPv6! |
|
1648
|
|
|
* |
|
1649
|
|
|
* @return array |
|
1650
|
|
|
*/ |
|
1651
|
|
|
// OK v4 |
|
1652
|
|
|
function sec_player_ip() { |
|
1653
|
|
|
// TODO - IPv6 support |
|
1654
|
|
|
$ip = array( |
|
1655
|
|
|
'ip' => $_SERVER["REMOTE_ADDR"], |
|
1656
|
|
|
'proxy_chain' => $_SERVER["HTTP_X_FORWARDED_FOR"] |
|
1657
|
|
|
? $_SERVER["HTTP_X_FORWARDED_FOR"] |
|
1658
|
|
|
: ($_SERVER["HTTP_CLIENT_IP"] |
|
1659
|
|
|
? $_SERVER["HTTP_CLIENT_IP"] |
|
1660
|
|
|
: '' // $_SERVER["REMOTE_ADDR"] |
|
1661
|
|
|
), |
|
1662
|
|
|
); |
|
1663
|
|
|
|
|
1664
|
|
|
return array_map('db_escape', $ip); |
|
1665
|
|
|
} |
|
1666
|
|
|
|
|
1667
|
|
|
|
|
1668
|
|
|
function price_matrix_templatize(&$price_matrix_plain, &$price_matrix_original, &$price_matrix_upgrade, $user_dark_matter) { |
|
1669
|
|
|
$prices = array(); |
|
1670
|
|
|
foreach($price_matrix_original as $level_num => $level_data) { |
|
1671
|
|
|
$price_per_period = array(); |
|
1672
|
|
|
foreach($level_data as $period => $price) { |
|
1673
|
|
|
$price_text = pretty_number($price, true, $user_dark_matter, false, false); |
|
1674
|
|
|
$price_per_period[$period] = array( |
|
1675
|
|
|
'PERIOD' => $period, |
|
1676
|
|
|
'PRICE_ORIGIN' => $price, |
|
1677
|
|
|
'PRICE_ORIGIN_TEXT' => $price_text['text'], |
|
1678
|
|
|
'PRICE_ORIGIN_CLASS' => $price_text['class'], |
|
1679
|
|
|
'PRICE_UPGRADE' => $price_matrix_upgrade[$level_num][$period], |
|
1680
|
|
|
'PRICE_UPGRADE_TEXT' => pretty_number($price_matrix_upgrade[$level_num][$period], true), |
|
1681
|
|
|
); |
|
1682
|
|
|
if(isset($price_matrix_plain[$level_num][$period])) { |
|
1683
|
|
|
$price_per_period[$period] += array( |
|
1684
|
|
|
'PRICE_PLAIN_PERCENT' => ceil(100 - ($price / $price_matrix_plain[$level_num][$period]) * 100), |
|
1685
|
|
|
'PRICE_PLAIN' => $price_matrix_plain[$level_num][$period], |
|
1686
|
|
|
'PRICE_PLAIN_TEXT' => pretty_number($price_matrix_plain[$level_num][$period], true), |
|
1687
|
|
|
); |
|
1688
|
|
|
} |
|
1689
|
|
|
} |
|
1690
|
|
|
|
|
1691
|
|
|
$prices[$level_num] = array( |
|
1692
|
|
|
'.' => array('period' => $price_per_period), |
|
1693
|
|
|
'LEVEL' => $level_num, |
|
1694
|
|
|
); |
|
1695
|
|
|
} |
|
1696
|
|
|
|
|
1697
|
|
|
return $prices; |
|
1698
|
|
|
} |
|
1699
|
|
|
|
|
1700
|
|
|
// ------------------------------------------------------------------------------------------------------------------------------ |
|
1701
|
|
|
function sn_sys_load_php_files($dir_name, $load_extension = 'php', $modules = false) { |
|
1702
|
|
|
if(file_exists($dir_name)) { |
|
1703
|
|
|
$dir = opendir($dir_name); |
|
1704
|
|
|
while(($file = readdir($dir)) !== false) { |
|
1705
|
|
|
if($file == '..' || $file == '.') { |
|
1706
|
|
|
continue; |
|
1707
|
|
|
} |
|
1708
|
|
|
|
|
1709
|
|
|
$full_filename = $dir_name . $file; |
|
1710
|
|
|
if($modules && is_dir($full_filename)) { |
|
1711
|
|
|
if(file_exists($full_filename = "{$full_filename}/{$file}.{$load_extension}")) { |
|
1712
|
|
|
require_once($full_filename); |
|
1713
|
|
|
// Registering module |
|
1714
|
|
|
if(class_exists($file)) { |
|
1715
|
|
|
new $file($full_filename); |
|
1716
|
|
|
} |
|
1717
|
|
|
} |
|
1718
|
|
|
} else { |
|
1719
|
|
|
$extension = substr($full_filename, -strlen($load_extension)); |
|
1720
|
|
|
if($extension == $load_extension) { |
|
1721
|
|
|
require_once($full_filename); |
|
1722
|
|
|
} |
|
1723
|
|
|
} |
|
1724
|
|
|
} |
|
1725
|
|
|
} |
|
1726
|
|
|
} |
|
1727
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: