|
1
|
|
|
<?php /** @noinspection PhpUnnecessaryCurlyVarSyntaxInspection */ |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @version 2015-04-11 11:47:49 39b14.2 |
|
5
|
|
|
* @copyright 2008-2015 Gorlum for Project "SuperNova.WS" |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
if (!defined('INSIDE')) { |
|
9
|
|
|
die(); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
require_once('db/db_queries.php'); |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param $query |
|
16
|
|
|
* @param $tableName |
|
17
|
|
|
* @param $object_id |
|
18
|
|
|
* |
|
19
|
|
|
* @return array|bool|mysqli_result|null |
|
20
|
|
|
*/ |
|
21
|
|
|
function db_change_units_perform($query, $tableName, $object_id) { |
|
22
|
|
|
$query = implode(',', $query); |
|
23
|
|
|
if ($query && $object_id) { |
|
24
|
|
|
return SN::db_upd_record_by_id($tableName == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return null; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param $user |
|
32
|
|
|
* @param $planet |
|
33
|
|
|
* @param $unit_list |
|
34
|
|
|
* @param $query |
|
35
|
|
|
* |
|
36
|
|
|
// TODO: THIS FUNCTION IS OBSOLETE AND SHOULD BE REPLACED! |
|
37
|
|
|
// TODO - ТОЛЬКО ДЛЯ РЕСУРСОВ |
|
38
|
|
|
// $unit_list should have unique entrances! Recompress non-uniq entrances before pass param! |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
function db_change_units(&$user, &$planet, $unit_list = [], $query = null) { |
|
43
|
|
|
$query = is_array($query) ? $query : [ |
|
44
|
|
|
LOC_USER => [], |
|
45
|
|
|
LOC_PLANET => [], |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$group = sn_get_groups('resources_loot'); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($unit_list as $unit_id => $unit_amount) { |
|
51
|
|
|
if (!in_array($unit_id, $group)) { |
|
52
|
|
|
// TODO - remove later |
|
53
|
|
|
print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>'); |
|
54
|
|
|
pdump(debug_backtrace()); |
|
55
|
|
|
die('db_change_units() вызван для не-ресурсов!'); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (!$unit_amount) { |
|
59
|
|
|
continue; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$unit_db_name = pname_resource_name($unit_id); |
|
63
|
|
|
|
|
64
|
|
|
$unit_location = sys_get_unit_location($user, $planet, $unit_id); |
|
65
|
|
|
|
|
66
|
|
|
// Changing value in object |
|
67
|
|
|
switch ($unit_location) { |
|
68
|
|
|
case LOC_USER: |
|
69
|
|
|
$user[$unit_db_name] += $unit_amount; |
|
70
|
|
|
break; |
|
71
|
|
|
case LOC_PLANET: |
|
72
|
|
|
$planet[$unit_db_name] += $unit_amount; |
|
73
|
|
|
break; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$unit_amount = $unit_amount < 0 ? $unit_amount : "+{$unit_amount}"; // Converting positive unit_amount to string '+unit_amount' |
|
77
|
|
|
$query[$unit_location][$unit_id] = "`{$unit_db_name}`=`{$unit_db_name}`{$unit_amount}"; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
db_change_units_perform($query[LOC_USER], 'users', $user['id']); |
|
81
|
|
|
db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/* Pass-through functions ******************************************************************************************* */ |
|
85
|
|
|
/** |
|
86
|
|
|
* @param $query |
|
87
|
|
|
* @param string $table |
|
88
|
|
|
* @param bool $fetch |
|
89
|
|
|
* @param bool $skip_query_check |
|
90
|
|
|
* |
|
91
|
|
|
* @return array|bool|mysqli_result|null |
|
92
|
|
|
* |
|
93
|
|
|
* @deprecated |
|
94
|
|
|
*/ |
|
95
|
|
|
function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
|
96
|
|
|
if (!is_string($table)) { |
|
|
|
|
|
|
97
|
|
|
$fetch = $table; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return SN::$db->doquery($query, $fetch, $skip_query_check); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param $query |
|
105
|
|
|
* |
|
106
|
|
|
* @return array|null |
|
107
|
|
|
* |
|
108
|
|
|
* @deprecated |
|
109
|
|
|
*/ |
|
110
|
|
|
function db_fetch(&$query) { |
|
111
|
|
|
return SN::$db->db_fetch($query); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param $unescaped_string |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
* |
|
119
|
|
|
* @deprecated |
|
120
|
|
|
*/ |
|
121
|
|
|
function db_escape($unescaped_string) { |
|
122
|
|
|
return SN::$db->db_escape($unescaped_string); |
|
123
|
|
|
} |
|
124
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.