These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * resources.php |
||
5 | * |
||
6 | * Planet resource interface page |
||
7 | * |
||
8 | * 2.2 - copyright (ñ) 2010 by Gorlum for http://supernova.ws |
||
9 | * [~] - more optimization to utilize PTE |
||
10 | * [~] - code formatting according to PCG |
||
11 | * [~] - content of BuildRessourcePage.php moved to resource.php |
||
12 | * 2.1 - copyright 2010 by Gorlum for http://supernova.ws |
||
13 | * [~] - Security checked for SQL-injection |
||
14 | * 2.0 - copyright 2010 by Gorlum for http://supernova.ws |
||
15 | * [+] - almost fully rewrote and optimized |
||
16 | * 1.0 [BuildRessourcePage.php] copyright 2008 by ShadoV for XNova |
||
17 | * [+] - Mise en module initiale (creation) |
||
18 | * 1.1 - copyright 2010 by Gorlum for http://supernova.ws |
||
19 | * [%] - Security checks & tests by Gorlum for http://supernova.ws |
||
20 | * 1.0 copyright (ñ) 2008 by Chlorel for XNova |
||
21 | * [!] - Passage en fonction pour utilisation XNova |
||
22 | * |
||
23 | **/ |
||
24 | |||
25 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||
26 | |||
27 | /** |
||
28 | * @param $resource_id |
||
29 | * @param template $template |
||
30 | * @param $caps_real |
||
31 | * @param $planetrow |
||
32 | * @param $user |
||
33 | */ |
||
34 | function int_calc_storage_bar($resource_id, $template, $caps_real, $planetrow, $user) { |
||
35 | $totalProduction = $caps_real['total'][$resource_id]; |
||
36 | $storage_fill = $caps_real['total_storage'][$resource_id] ? floor(mrc_get_level($user, $planetrow, $resource_id) / $caps_real['total_storage'][$resource_id] * 100) : 0; |
||
37 | |||
38 | $template->assign_block_vars('resources', array( |
||
39 | 'NAME' => classLocale::$lang["sys_" . pname_resource_name($resource_id)], |
||
40 | |||
41 | 'HOURLY' => pretty_number($totalProduction, true, true), |
||
42 | 'WEEKLY' => pretty_number($totalProduction * 24 * 7, true, true), |
||
43 | 'DAILY' => pretty_number($totalProduction * 24, true, true), |
||
44 | 'MONTHLY' => pretty_number($totalProduction * 24 * 30, true, true), |
||
45 | |||
46 | 'STORAGE' => intval($storage_fill), |
||
47 | 'BAR' => min($storage_fill, 100), |
||
48 | )); |
||
49 | } |
||
50 | |||
51 | ; |
||
52 | |||
53 | $ValidList['percent'] = array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); |
||
54 | $template = gettemplate('resources', true); |
||
55 | |||
56 | $transmutation_result = sn_sys_planet_core_transmute($user, $planetrow); |
||
57 | if (!empty($transmutation_result)) { |
||
58 | $template->assign_block_vars('result', $transmutation_result); // array('STATUS' => $transmutation_result['STATUS'], 'MESSAGE' => $transmutation_result['MESSAGE'])); |
||
59 | } |
||
60 | |||
61 | $sn_group_factories = sn_get_groups('factories'); |
||
62 | $production = $_POST['production']; |
||
63 | //$SubQry = ''; |
||
64 | $SubQry = array(); |
||
65 | if (is_array($production)) { |
||
66 | foreach ($production as $prod_id => $percent) { |
||
67 | if ($percent > 100 || $percent < 0) { |
||
68 | classSupernova::$debug->warning('Supplying wrong production percent (less then 0 or greater then 100)', 'Hack attempt', 302, array('base_dump' => true)); |
||
69 | die(); |
||
70 | } |
||
71 | |||
72 | $prod_id = intval($prod_id); |
||
73 | if (in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) { |
||
74 | $field_name = pname_factory_production_field_name($prod_id); |
||
75 | $percent = floor($percent / 10); |
||
76 | $planetrow[$field_name] = $percent; |
||
77 | //$SubQry .= "`{$field_name}` = '{$percent}',"; |
||
0 ignored issues
–
show
|
|||
78 | $SubQry[] = "`{$field_name}` = '{$percent}'"; |
||
79 | } else { |
||
80 | classSupernova::$debug->warning('Supplying wrong ID in production array - attempt to change some field - ID' . $prod_id, 'Resource Page', 301); |
||
81 | continue; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | // $SubQry = substr($SubQry, 0, -1); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
86 | // if($SubQry) { |
||
87 | // db_planet_set_by_id($planetrow['id'], $SubQry); |
||
88 | // } |
||
89 | !empty($SubQry) ? DBStaticPlanet::db_planet_update_set_by_id_DEPRECATED($planetrow['id'], implode(',', $SubQry)) : false; |
||
0 ignored issues
–
show
|
|||
90 | } |
||
91 | |||
92 | // ------------------------------------------------------------------------------------------------------- |
||
93 | // $BuildTemp = $planetrow[ 'temp_max' ]; |
||
94 | // $BuildEnergyTech = $user['energy_tech']; |
||
95 | |||
96 | for ($Option = 10; $Option >= 0; $Option--) { |
||
97 | $template->assign_block_vars('option', array( |
||
98 | 'VALUE' => $Option * 10, |
||
99 | )); |
||
100 | } |
||
101 | |||
102 | $caps_real = eco_get_planet_caps($user, $planetrow, 3600); |
||
103 | |||
104 | $template->assign_block_vars('production', array( |
||
105 | 'TYPE' => classLocale::$lang['res_basic_income'], |
||
106 | |||
107 | 'METAL_TYPE' => pretty_number($caps_real['production'][RES_METAL][0], true, true), |
||
108 | 'CRYSTAL_TYPE' => pretty_number($caps_real['production'][RES_CRYSTAL][0], true, true), |
||
109 | 'DEUTERIUM_TYPE' => pretty_number($caps_real['production'][RES_DEUTERIUM][0], true, true), |
||
110 | 'ENERGY_TYPE' => pretty_number($caps_real['production'][RES_ENERGY][0], true, true), |
||
111 | )); |
||
112 | |||
113 | foreach ($sn_group_factories as $unit_id) { |
||
114 | if (mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id)) { |
||
115 | $level_plain = mrc_get_level($user, $planetrow, $unit_id, false, true); |
||
116 | $template->assign_block_vars('production', array( |
||
117 | 'ID' => $unit_id, |
||
118 | // 'NAME' => $resource_db_name, |
||
119 | 'PERCENT' => $planetrow[pname_factory_production_field_name($unit_id)] * 10, |
||
120 | 'TYPE' => classLocale::$lang['tech'][$unit_id], |
||
121 | 'LEVEL' => $level_plain, |
||
122 | 'LEVEL_BONUS' => mrc_get_level($user, $planetrow, $unit_id) - $level_plain, |
||
123 | 'LEVEL_TYPE' => ($unit_id > 200) ? classLocale::$lang['quantity'] : classLocale::$lang['level'], |
||
124 | |||
125 | 'METAL_TYPE' => pretty_number($caps_real['production'][RES_METAL][$unit_id], true, true), |
||
126 | 'CRYSTAL_TYPE' => pretty_number($caps_real['production'][RES_CRYSTAL][$unit_id], true, true), |
||
127 | 'DEUTERIUM_TYPE' => pretty_number($caps_real['production'][RES_DEUTERIUM][$unit_id], true, true), |
||
128 | 'ENERGY_TYPE' => pretty_number($caps_real['production'][RES_ENERGY][$unit_id], true, true), |
||
129 | |||
130 | 'METAL_FULL' => pretty_number($caps_real['production_full'][RES_METAL][$unit_id], true, true), |
||
131 | 'CRYSTAL_FULL' => pretty_number($caps_real['production_full'][RES_CRYSTAL][$unit_id], true, true), |
||
132 | 'DEUTERIUM_FULL' => pretty_number($caps_real['production_full'][RES_DEUTERIUM][$unit_id], true, true), |
||
133 | 'ENERGY_FULL' => pretty_number($caps_real['production_full'][RES_ENERGY][$unit_id], true, true), |
||
134 | |||
135 | 'SELECT' => $row_select, |
||
136 | 'P_MINING_IS_MANAGED' => get_unit_param($unit_id, P_MINING_IS_MANAGED), |
||
137 | |||
138 | )); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
||
143 | $planet_density_index = $planetrow['density_index']; |
||
144 | $density_price_chart = planet_density_price_chart($planetrow); |
||
145 | tpl_planet_density_info($template, $density_price_chart, $user_dark_matter); |
||
146 | |||
147 | $template->assign_block_vars('production', array( |
||
148 | 'TYPE' => classLocale::$lang['res_total'], |
||
149 | |||
150 | 'METAL_TYPE' => pretty_number($caps_real['total'][RES_METAL], true, true), |
||
151 | 'CRYSTAL_TYPE' => pretty_number($caps_real['total'][RES_CRYSTAL], true, true), |
||
152 | 'DEUTERIUM_TYPE' => pretty_number($caps_real['total'][RES_DEUTERIUM], true, true), |
||
153 | 'ENERGY_TYPE' => pretty_number($caps_real['total'][RES_ENERGY], true, true), |
||
154 | |||
155 | 'METAL_FULL' => pretty_number($caps_real['total_production_full'][RES_METAL], true, true), |
||
156 | 'CRYSTAL_FULL' => pretty_number($caps_real['total_production_full'][RES_CRYSTAL], true, true), |
||
157 | 'DEUTERIUM_FULL' => pretty_number($caps_real['total_production_full'][RES_DEUTERIUM], true, true), |
||
158 | 'ENERGY_FULL' => pretty_number($caps_real['total_production_full'][RES_ENERGY], true, true), |
||
159 | )); |
||
160 | |||
161 | int_calc_storage_bar(RES_METAL, $template, $caps_real, $planetrow, $user); |
||
162 | int_calc_storage_bar(RES_CRYSTAL, $template, $caps_real, $planetrow, $user); |
||
163 | int_calc_storage_bar(RES_DEUTERIUM, $template, $caps_real, $planetrow, $user); |
||
164 | |||
165 | $template->assign_vars(array( |
||
166 | 'PLANET_NAME' => $planetrow['name'], |
||
167 | 'PLANET_TYPE' => $planetrow['planet_type'], |
||
168 | 'PLANET_DENSITY_INDEX' => $planet_density_index, |
||
169 | 'PLANET_CORE_TEXT' => classLocale::$lang['uni_planet_density_types'][$planet_density_index], |
||
170 | |||
171 | 'PRODUCTION_LEVEL' => floor($caps_real['efficiency'] * 100), |
||
172 | |||
173 | 'PAGE_HINT' => classLocale::$lang['res_hint'], |
||
174 | )); |
||
175 | |||
176 | display($template, classLocale::$lang['res_planet_production']); |
||
177 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.