Completed
Push — work-fleets ( fdc1c4...451000 )
by SuperNova.WS
04:55
created
includes/debug.class.php 1 patch
Spacing   +38 added lines, -39 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 defined('INSIDE') || die();
32 32
 
33
-if(php_sapi_name() == "cli") {
33
+if (php_sapi_name() == "cli") {
34 34
   // In cli-mode
35 35
   define('__DEBUG_CRLF', "\r\n");
36 36
   define('__DEBUG_LINE', '-------------------------------------------------' . __DEBUG_CRLF);
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
   function log_file($message, $ident_change = 0) {
51 51
     static $ident = 0;
52 52
 
53
-    if(!defined('SN_DEBUG_LOG')) {
53
+    if (!defined('SN_DEBUG_LOG')) {
54 54
       return;
55 55
     }
56 56
 
57
-    if($this->log_file_handler === null) {
57
+    if ($this->log_file_handler === null) {
58 58
       $this->log_file_handler = @fopen(SN_ROOT_PHYSICAL . '/.logs/supernova.log', 'a+');
59 59
       @fwrite($this->log_file_handler, "\r\n\r\n");
60 60
     }
61 61
     $ident_change < 0 ? $ident += $ident_change * 2 : false;
62
-    if($this->log_file_handler) {
62
+    if ($this->log_file_handler) {
63 63
       @fwrite($this->log_file_handler, date(FMT_DATE_TIME_SQL, time()) . str_repeat(' ', $ident + 1) . $message . "\r\n");
64 64
     }
65 65
     $ident_change > 0 ? $ident += $ident_change * 2 : false;
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
     $result = array();
91 91
     $transaction_id = classSupernova::db_transaction_check(false) ? classSupernova::$transaction_id : classSupernova::$transaction_id++;
92 92
     $result[] = "tID {$transaction_id}";
93
-    foreach($backtrace as $a_trace) {
94
-      if(in_array($a_trace['function'], $exclude_functions)) {
93
+    foreach ($backtrace as $a_trace) {
94
+      if (in_array($a_trace['function'], $exclude_functions)) {
95 95
         continue;
96 96
       }
97 97
       $function =
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
       // $result[] = "{$function} ({$a_trace['line']})'{$file}'";
109 109
       $result[] = "{$function} - '{$file}' Line {$a_trace['line']}";
110 110
 
111
-      if(!$long_comment) {
111
+      if (!$long_comment) {
112 112
         break;
113 113
       }
114 114
     }
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
   function dump($dump = false, $force_base = false, $deadlock = false) {
123 123
     global $user, $planetrow;
124 124
 
125
-    if($dump === false) {
125
+    if ($dump === false) {
126 126
       return;
127 127
     }
128 128
 
129 129
     $error_backtrace = array();
130 130
     $base_dump = false;
131 131
 
132
-    if($force_base === true) {
132
+    if ($force_base === true) {
133 133
       $base_dump = true;
134 134
     }
135 135
 
136
-    if($dump === true) {
136
+    if ($dump === true) {
137 137
       $base_dump = true;
138 138
     } else {
139
-      if(!is_array($dump)) {
139
+      if (!is_array($dump)) {
140 140
         $dump = array('var' => $dump);
141 141
       }
142 142
 
143
-      foreach($dump as $dump_var_name => $dump_var) {
144
-        if($dump_var_name == 'base_dump') {
143
+      foreach ($dump as $dump_var_name => $dump_var) {
144
+        if ($dump_var_name == 'base_dump') {
145 145
           $base_dump = $dump_var;
146 146
         } else {
147 147
           $error_backtrace[$dump_var_name] = $dump_var;
@@ -149,22 +149,21 @@  discard block
 block discarded – undo
149 149
       }
150 150
     }
151 151
 
152
-    if($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) {
152
+    if ($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) {
153 153
       $error_backtrace['deadlock'] = explode("\n", $q['Status']);
154 154
       $error_backtrace['locks'] = classSupernova::$locks;
155 155
       $error_backtrace['cSN_data'] = classSupernova::$data;
156
-      foreach($error_backtrace['cSN_data'] as &$location) {
157
-        foreach($location as $location_id => &$location_data) {
158
-          $location_data = isset($location_data['username']) ? $location_data['username'] :
159
-            (isset($location_data['name']) ? $location_data['name'] : $location_id);
156
+      foreach ($error_backtrace['cSN_data'] as &$location) {
157
+        foreach ($location as $location_id => &$location_data) {
158
+          $location_data = isset($location_data['username']) ? $location_data['username'] : (isset($location_data['name']) ? $location_data['name'] : $location_id);
160 159
         }
161 160
       }
162 161
       $error_backtrace['cSN_queries'] = classSupernova::$queries;
163 162
     }
164 163
 
165
-    if($base_dump) {
166
-      if(is_array($this->log_array) && count($this->log_array) > 0) {
167
-        foreach($this->log_array as $log) {
164
+    if ($base_dump) {
165
+      if (is_array($this->log_array) && count($this->log_array) > 0) {
166
+        foreach ($this->log_array as $log) {
168 167
           $error_backtrace['queries'][] = $log;
169 168
         }
170 169
       }
@@ -193,14 +192,14 @@  discard block
 block discarded – undo
193 192
   function error($message = 'There is a error on page', $title = 'Internal Error', $error_code = 500, $dump = true) {
194 193
     global $sys_stop_log_hit, $sys_log_disabled, $user;
195 194
 
196
-    if(empty(classSupernova::$db->connected)) {
195
+    if (empty(classSupernova::$db->connected)) {
197 196
       // TODO - писать ошибку в файл
198 197
       die('SQL server currently unavailable. Please contact Administration...');
199 198
     }
200 199
 
201 200
     sn_db_transaction_rollback();
202 201
 
203
-    if(classSupernova::$config->debug == 1) {
202
+    if (classSupernova::$config->debug == 1) {
204 203
       echo "<h2>{$title}</h2><br><font color=red>{$message}</font><br><hr>";
205 204
       echo "<table>{$this->log}</table>";
206 205
     }
@@ -210,7 +209,7 @@  discard block
 block discarded – undo
210 209
     $error_text = db_escape($message);
211 210
     $error_backtrace = $this->dump($dump, true, strpos($message, 'Deadlock') !== false);
212 211
 
213
-    if(!$sys_log_disabled) {
212
+    if (!$sys_log_disabled) {
214 213
       $query = "INSERT INTO `{{logs}}` SET
215 214
         `log_time` = '" . time() . "', `log_code` = '" . db_escape($error_code) . "', `log_sender` = '" . db_escape($user['id']) . "',
216 215
         `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "',  `log_text` = '" . db_escape($message) . "',
@@ -228,7 +227,7 @@  discard block
 block discarded – undo
228 227
       ob_start();
229 228
       print("<hr>User ID {$user['id']} raised error code {$error_code} titled '{$title}' with text '{$error_text}' on page {$_SERVER['SCRIPT_NAME']}");
230 229
 
231
-      foreach($error_backtrace as $name => $value) {
230
+      foreach ($error_backtrace as $name => $value) {
232 231
         print(__DEBUG_LINE);
233 232
         pdump($value, $name);
234 233
       }
@@ -240,14 +239,14 @@  discard block
 block discarded – undo
240 239
   function warning($message, $title = 'System Message', $log_code = 300, $dump = false) {
241 240
     global $user, $sys_log_disabled;
242 241
 
243
-    if(empty(classSupernova::$db->connected)) {
242
+    if (empty(classSupernova::$db->connected)) {
244 243
       // TODO - писать ошибку в файл
245 244
       die('SQL server currently unavailable. Please contact Administration...');
246 245
     }
247 246
 
248 247
     $error_backtrace = $this->dump($dump, false);
249 248
 
250
-    if(!$sys_log_disabled) {
249
+    if (!$sys_log_disabled) {
251 250
       $query = "INSERT INTO `{{logs}}` SET
252 251
         `log_time` = '" . time() . "', `log_code` = '" . db_escape($log_code) . "', `log_sender` = '" . db_escape($user['id']) . "',
253 252
         `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "',  `log_text` = '" . db_escape($message) . "',
@@ -265,11 +264,11 @@  discard block
 block discarded – undo
265 264
 // Dump variables nicer then var_dump()
266 265
 
267 266
 function dump($value, $varname = null, $level = 0, $dumper = '') {
268
-  if(isset($varname)) {
267
+  if (isset($varname)) {
269 268
     $varname .= " = ";
270 269
   }
271 270
 
272
-  if($level == -1) {
271
+  if ($level == -1) {
273 272
     $trans[' '] = '&there4;';
274 273
     $trans["\t"] = '&rArr;';
275 274
     $trans["\n"] = '&para;;';
@@ -278,7 +277,7 @@  discard block
 block discarded – undo
278 277
 
279 278
     return strtr(htmlspecialchars($value), $trans);
280 279
   }
281
-  if($level == 0) {
280
+  if ($level == 0) {
282 281
 //    $dumper = '<pre>' . mt_rand(10, 99) . '|' . $varname;
283 282
     $dumper = mt_rand(10, 99) . '|' . $varname;
284 283
   }
@@ -286,22 +285,22 @@  discard block
 block discarded – undo
286 285
   $type = gettype($value);
287 286
   $dumper .= $type;
288 287
 
289
-  if($type == 'string') {
288
+  if ($type == 'string') {
290 289
     $dumper .= '(' . strlen($value) . ')';
291 290
     $value = dump($value, '', -1);
292
-  } elseif($type == 'boolean') {
291
+  } elseif ($type == 'boolean') {
293 292
     $value = ($value ? 'true' : 'false');
294
-  } elseif($type == 'object') {
293
+  } elseif ($type == 'object') {
295 294
     $props = get_class_vars(get_class($value));
296 295
     $dumper .= '(' . count($props) . ') <u>' . get_class($value) . '</u>';
297
-    foreach($props as $key => $val) {
296
+    foreach ($props as $key => $val) {
298 297
       $dumper .= "\n" . str_repeat("\t", $level + 1) . $key . ' => ';
299 298
       $dumper .= dump($value->$key, '', $level + 1);
300 299
     }
301 300
     $value = '';
302
-  } elseif($type == 'array') {
301
+  } elseif ($type == 'array') {
303 302
     $dumper .= '(' . count($value) . ')';
304
-    foreach($value as $key => $val) {
303
+    foreach ($value as $key => $val) {
305 304
       $dumper .= "\n" . str_repeat("\t", $level + 1) . dump($key, '', -1) . ' => ';
306 305
       $dumper .= dump($val, '', $level + 1);
307 306
     }
@@ -321,7 +320,7 @@  discard block
 block discarded – undo
321 320
 //  $backtrace = $backtrace[1];
322 321
 
323 322
   $caller = '';
324
-  if(defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) {
323
+  if (defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) {
325 324
     $caller = (!empty($backtrace[1]['class']) ? $backtrace[1]['class'] : '') .
326 325
       (!empty($backtrace[1]['type']) ? $backtrace[1]['type'] : '') .
327 326
       $backtrace[1]['function'] .
@@ -348,7 +347,7 @@  discard block
 block discarded – undo
348 347
 }
349 348
 
350 349
 function pr($prePrint = false) {
351
-  if($prePrint) {
350
+  if ($prePrint) {
352 351
     print(__DEBUG_CRLF);
353 352
   }
354 353
   print(mt_rand() . __DEBUG_CRLF);
@@ -358,7 +357,7 @@  discard block
 block discarded – undo
358 357
   global $_PRINT_COUNT_VALUE;
359 358
   $_PRINT_COUNT_VALUE++;
360 359
 
361
-  if($prePrint) {
360
+  if ($prePrint) {
362 361
     print(__DEBUG_CRLF);
363 362
   }
364 363
   print($_PRINT_COUNT_VALUE . __DEBUG_CRLF);
Please login to merge, or discard this patch.
includes/classes/db_mysql.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
   public function sn_db_connect($external_db_settings = null) {
74 74
     $this->db_disconnect();
75 75
 
76
-    if(!empty($external_db_settings) && is_array($external_db_settings)) {
76
+    if (!empty($external_db_settings) && is_array($external_db_settings)) {
77 77
       $this->dbsettings = $external_db_settings;
78 78
     }
79 79
 
80
-    if(empty($this->dbsettings)) {
80
+    if (empty($this->dbsettings)) {
81 81
       $this->load_db_settings();
82 82
     }
83 83
 
84 84
     // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны
85
-    if(!empty($this->dbsettings)) {
85
+    if (!empty($this->dbsettings)) {
86 86
       $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver'];
87 87
       $this->driver = new $driver_name();
88 88
       $this->db_prefix = $this->dbsettings['prefix'];
89 89
 
90 90
       $this->connected = $this->connected || $this->driver_connect();
91 91
 
92
-      if($this->connected) {
92
+      if ($this->connected) {
93 93
         $this->table_list = $this->db_get_table_list();
94 94
         // TODO Проверка на пустоту
95 95
       }
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
   protected function driver_connect() {
104 104
     global $debug;
105 105
 
106
-    if(!is_object($this->driver)) {
106
+    if (!is_object($this->driver)) {
107 107
       $debug->error_fatal('DB Error - No driver for MySQL found!');
108 108
     }
109 109
 
110
-    if(!method_exists($this->driver, 'mysql_connect')) {
110
+    if (!method_exists($this->driver, 'mysql_connect')) {
111 111
       $debug->error_fatal('DB Error - WRONG MySQL driver!');
112 112
     }
113 113
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
   }
116 116
 
117 117
   public function db_disconnect() {
118
-    if($this->connected) {
118
+    if ($this->connected) {
119 119
       $this->connected = !$this->driver_disconnect();
120 120
       $this->connected = false;
121 121
     }
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
    */
131 131
   public function replaceTablePlaceholders($query) {
132 132
     $sql = $query;
133
-    if(strpos($sql, '{{') !== false) {
134
-      foreach($this->table_list as $tableName) {
133
+    if (strpos($sql, '{{') !== false) {
134
+      foreach ($this->table_list as $tableName) {
135 135
         $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql);
136 136
       }
137 137
     }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
    * @param       $fetch
145 145
    */
146 146
   protected function logQuery($query, $fetch) {
147
-    if(!classSupernova::$config->debug) {
147
+    if (!classSupernova::$config->debug) {
148 148
       return;
149 149
     }
150 150
 
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
    * @return void
163 163
    */
164 164
   protected function commentQuery(&$sql) {
165
-    if(!defined('DEBUG_SQL_COMMENT')) {
165
+    if (!defined('DEBUG_SQL_COMMENT')) {
166 166
       return;
167 167
     }
168 168
     $backtrace = debug_backtrace();
169 169
     $sql_comment = classSupernova::$debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG'));
170 170
 
171 171
     $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql);
172
-    if(defined('DEBUG_SQL_ONLINE')) {
172
+    if (defined('DEBUG_SQL_ONLINE')) {
173 173
       classSupernova::$debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL);
174 174
     }
175 175
 
176
-    if(defined('DEBUG_SQL_ERROR')) {
176
+    if (defined('DEBUG_SQL_ERROR')) {
177 177
       array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql));
178 178
       classSupernova::$debug->add_to_array($sql_comment);
179 179
     }
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
   }
183 183
 
184 184
   public function doquery($query, $table = '', $fetch = false, $skip_query_check = false) {
185
-    if(!is_string($table)) {
185
+    if (!is_string($table)) {
186 186
       $fetch = $table;
187 187
     }
188 188
 
189
-    if(!$this->connected) {
189
+    if (!$this->connected) {
190 190
       $this->sn_db_connect();
191 191
     }
192 192
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
   protected function security_watch_user_queries($query) {
208 208
     global $user;
209 209
 
210
-    if(
210
+    if (
211 211
       !$this->isWatching // Not already watching
212 212
       && !empty(classSupernova::$config->game_watchlist_array) // There is some players in watchlist
213 213
       && in_array($user['id'], classSupernova::$config->game_watchlist_array) // Current player is in watchlist
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
     ) {
216 216
       $this->isWatching = true;
217 217
       $msg = "\$query = \"{$query}\"\n\r";
218
-      if(!empty($_POST)) {
218
+      if (!empty($_POST)) {
219 219
         $msg .= "\n\r" . dump($_POST, '$_POST');
220 220
       }
221
-      if(!empty($_GET)) {
221
+      if (!empty($_GET)) {
222 222
         $msg .= "\n\r" . dump($_GET, '$_GET');
223 223
       }
224 224
       classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true));
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
   public function security_query_check_bad_words($query) {
231 231
     global $user, $dm_change_legit, $mm_change_legit;
232 232
 
233
-    switch(true) {
233
+    switch (true) {
234 234
       case stripos($query, 'RUNCATE TABL') != false:
235 235
       case stripos($query, 'ROP TABL') != false:
236 236
       case stripos($query, 'ENAME TABL') != false:
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
     $prefix_length = strlen($this->db_prefix);
293 293
 
294 294
     $tl = array();
295
-    while($row = $this->db_fetch($query)) {
296
-      foreach($row as $table_name) {
297
-        if(strpos($table_name, $this->db_prefix) === 0) {
295
+    while ($row = $this->db_fetch($query)) {
296
+      foreach ($row as $table_name) {
297
+        if (strpos($table_name, $this->db_prefix) === 0) {
298 298
           $table_name = substr($table_name, $prefix_length);
299
-        } elseif($prefixed_only) {
299
+        } elseif ($prefixed_only) {
300 300
           continue;
301 301
         }
302 302
         // $table_name = str_replace($db_prefix, '', $table_name);
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
     $result = array();
392 392
 
393 393
     $status = explode('  ', $this->driver->mysql_stat());
394
-    foreach($status as $value) {
394
+    foreach ($status as $value) {
395 395
       $row = explode(': ', $value);
396 396
       $result[$row[0]] = $row[1];
397 397
     }
@@ -407,10 +407,10 @@  discard block
 block discarded – undo
407 407
     $result = array();
408 408
 
409 409
     $query = $this->db_sql_query('SHOW STATUS;');
410
-    if(is_bool($query)) {
410
+    if (is_bool($query)) {
411 411
       throw new Exception('Result of SHOW STATUS command is boolean - which should never happen. Connection to DB is lost?');
412 412
     }
413
-    while($row = db_fetch($query)) {
413
+    while ($row = db_fetch($query)) {
414 414
       $result[$row['Variable_name']] = $row['Value'];
415 415
     }
416 416
 
Please login to merge, or discard this patch.