Skip to content

Commit 83a9f6e

Browse files
authored
Merge pull request #373 from XGProyect/development
v3.1
2 parents e04249b + 0f5a366 commit 83a9f6e

File tree

14 files changed

+131
-74
lines changed

14 files changed

+131
-74
lines changed

src/upload/.htaccess

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<IfModule mod_rewrite.c>
22
RewriteEngine on
3-
RewriteRule ^$ public/ [L]
4-
RewriteRule (.*) public/$1 [L]
3+
4+
# define RewriteBase and store it
5+
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
6+
RewriteRule ^(.*)$ - [E=BASE:%1]
7+
8+
# redirect requests to public folder
9+
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
10+
RewriteRule ^ %1 [L,NE,R=302]
11+
12+
RewriteRule ^((?!public/).*)$ %{ENV:BASE}/public/$1 [L,NC]
513
</IfModule>

src/upload/application/config/constants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
);
6060

6161
// SYSTEM ROOT, IGNORING PUBLIC
62-
define('SYSTEM_ROOT', PROTOCOL . strtr(BASE_PATH, ['public' => '']));
62+
define('SYSTEM_ROOT', PROTOCOL . strtr(BASE_PATH, ['public' => '', 'public/' => '']));
6363

6464
// GAME URL
6565
define('GAMEURL', PROTOCOL . $_SERVER['HTTP_HOST'] . '/');
6666

6767
// ADMIN PATHS
68-
define('ADM_URL', PROTOCOL . strtr(BASE_PATH, ['public' => '']));
68+
define('ADM_URL', PROTOCOL . strtr(BASE_PATH, ['public' => '', 'public/' => '']));
6969

7070
/**
7171
*

src/upload/application/controllers/adm/errors.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ private function processErrorsLogs(): array
122122
'error_code' => $error_columns[3],
123123
'error_message' => $error_columns[4],
124124
'error_trace' => $error_columns[5],
125-
'error_datetime' => $error_columns[6],
126-
'alert_type' => ($error_columns[3] == 1 ? 'danger' : 'warning'),
125+
'error_datetime' => $error_columns[7],
126+
'alert_type' => ($error_columns[3] == 'E_ERROR' ? 'danger' : 'warning'),
127127
];
128128
}
129129
}

src/upload/application/controllers/game/fleet3.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,17 @@ private function setInputsData()
543543
}
544544

545545
/**
546-
* Get session set ships
546+
* Get the ships that were set in the session
547547
*
548548
* @return array
549549
*/
550-
private function getSessionShips()
550+
private function getSessionShips(): array
551551
{
552-
return unserialize(base64_decode(str_rot13($_SESSION['fleet_data']['fleetarray'])));
552+
if (isset($_SESSION['fleet_data']['fleetarray'])) {
553+
return unserialize(base64_decode(str_rot13($_SESSION['fleet_data']['fleetarray'])));
554+
}
555+
556+
FunctionsLib::redirect(self::REDIRECT_TARGET);
553557
}
554558

555559
/**

src/upload/application/core/ErrorHandler.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ private function createNewDebugObject(): void
6262
* @param string $line
6363
* @return boolean
6464
*/
65-
final public function errorHandler(int $code, string $description, string $file, string $line): bool
65+
final public function errorHandler(int $code, string $description, string $file, int $line): bool
6666
{
6767
$displayErrors = strtolower(ini_get("display_errors"));
6868

6969
if (error_reporting() === 0 || $displayErrors === "on") {
7070
return false;
7171
}
7272

73-
$this->debug->error($code, $description, $file, $line, 'php');
73+
if ($code === E_ERROR) {
74+
$this->debug->error($code, $description, $file, $line, 'php');
75+
} else {
76+
$this->debug->log($code, $description, $file, $line, 'php');
77+
$this->debug->error();
78+
}
7479

7580
return true;
7681
}

src/upload/application/core/common.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ class Common
6161
*/
6262
private $hooks = null;
6363

64-
/**
65-
* Constructor
66-
*/
67-
public function __construct()
68-
{
69-
}
70-
7164
/**
7265
* Start the system
7366
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Error types enumerator
4+
*
5+
* @category Library
6+
* @package Application
7+
* @author XG Proyect Team
8+
* @license http://www.xgproyect.org XG Proyect
9+
* @link http://www.xgproyect.org
10+
* @version 3.1.0
11+
*/
12+
namespace application\core\enumerators;
13+
14+
/**
15+
* ErrorTypesEnumerator class
16+
*/
17+
abstract class ErrorTypesEnumerator
18+
{
19+
const PHP_ERRORS = [
20+
E_ERROR => 'E_ERROR',
21+
E_WARNING => 'E_WARNING',
22+
E_PARSE => 'E_PARSE',
23+
E_NOTICE => 'E_NOTICE',
24+
E_CORE_ERROR => 'E_CORE_ERROR',
25+
E_CORE_WARNING => 'E_CORE_WARNING',
26+
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
27+
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
28+
E_USER_ERROR => 'E_USER_ERROR',
29+
E_USER_WARNING => 'E_USER_WARNING',
30+
E_USER_NOTICE => 'E_USER_NOTICE',
31+
E_STRICT => 'E_STRICT',
32+
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
33+
E_DEPRECATED => 'E_DEPRECATED',
34+
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
35+
];
36+
}

src/upload/application/language/english/game/colonize_lang.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$lang = [
33
'col_max_colonies' => 'The fleet has arrived at assigned coordinates %s, but, unfortunately, can not colonize, can have no more than %s planets.',
44
'col_successful' => 'The fleet has arrived at assigned coordinates %s, found a new planet there and are beginning to develop upon it immediately.', // ok
5-
'col_occupied' => 'The fleet has arrived at assigned coordinates %s, settlers would not have found a planet with these details. They are forced to turn back completely demoralized ...',
5+
'col_occupied' => 'The fleet has arrived at the assigned coordinates %s. Unfortunately, they found that the location has already been colonised. The disappointed settlers have to return home.', // ok
66
'col_astro_level' => 'The fleet has arrived at assigned coordinates %s and ascertains that the planet is viable for colonisation. Shortly after starting to develop the planet, the colonists realise that their knowledge of astrophysics is not sufficient to complete the colonisation of a new planet.', // ok
77
'col_report_from' => 'Settlers', // ok
88
'col_report_title' => 'Settlement Report', // ok

src/upload/application/language/english/game/expedition_lang.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'exp_new_ships_3' => '',
99
'exp_new_ships_4' => 'We found a deserted pirate station. There are some old ships lying in the hangar. Our technicians are figuring out whether some of them are still useful or not.<br><br>The following ships are now part of the fleet:<br>%s', // ok
1010
'exp_new_ships_5' => 'Your expedition ran into the shipyards of a colony that was deserted eons ago. In the shipyards hangar they discover some ships that could be salvaged. The technicians are trying to get some of them to fly again.<br><br>The following ships are now part of the fleet:<br>%s', // ok
11+
'exo_new_ships_6' => 'We found an enormous spaceship graveyard. Some of the technicians from the expedition fleet were able to get some of the ships to work again.<br><br>The following ships are now part of the fleet:<br>%s', // ok
1112

1213
// found resources
1314
'exp_new_resources_1' => 'On an isolated planetoid we found some easily accessible resources fields and harvested some successfully.<br><br>%s %s have been captured.', // ok
@@ -18,8 +19,8 @@
1819
// found primitive enemy
1920
'exp_primitive_enemy_1' => 'Some primitive barbarians are attacking us with spaceships that can\'t even be named as such. If the fire gets serious we will be forced to fire back.', // ok
2021
'exp_primitive_enemy_2' => '',
21-
'exp_primitive_enemy_3' => 'We caught some radio transmissions from some drunk pirates. Seems like we will be under attack soon.',
22-
'exp_primitive_enemy_4' => '',
22+
'exp_primitive_enemy_3' => 'We caught some radio transmissions from some drunk pirates. Seems like we will be under attack soon.', // ok
23+
'exp_primitive_enemy_4' => 'We needed to fight some pirates which were, fortunately, only a few.', // ok
2324
'exp_primitive_enemy_5' => 'Some really desperate space pirates tried to capture our expedition fleet.', // ok
2425

2526
// found advanced enemy
@@ -39,6 +40,9 @@
3940
// advancement
4041
'exp_faster_1' => 'Your expeditions doesn\'t report any anomalies in the explored sector. But the fleet ran into somo solar wind while returning. This resulted in the return trip being expedited. Your expedition returns home a bit earlier.', // ok
4142

43+
// found object
44+
'exp_found_object_1' => 'A fleeing fleet left an item behind, in order to distract us in aid of their escape.<br><br>%s has been added to the inventory.', // ok
45+
4246
// found nothing
4347
'exp_nothing_1' => '',
4448
'exp_nothing_2' => '',
@@ -59,7 +63,6 @@
5963
'exp_blackholl_1' => 'The fleet was sucked into a black hole is partially destroyed.',
6064
'exp_blackholl_2' => 'The fleet was sucked into a black hole, and was completely destroyed!',
6165
'exp_found_goods' => 'The fleet has discovered an unmanned spacecraft! <br> His scouts have recovered %s de %s, %s de %s, %s de %s y %s de %s.',
62-
'exp_found_ships' => 'Your expedition ran into the shipyards of a colony that was deserted eons ago. In the shipyards hangar they discover some ships that could be salvaged. The technicians are trying to get some of them to fly again.<br><br>The following ships are now part of the fleet:',
6366
'exp_back_home' => 'Your expedition returned to the hangar.',
6467
];
6568

src/upload/application/language/spanish/game/expedition_lang.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'exp_new_ships_3' => 'Nuestra expedición se encontró con un antiguo hangar automático. Algunas de las naves se encuentran todavía en la fase de producción y nuestros técnicos están tratando de reactivar los generadores de energía.<br><br>Las siguientes naves son ahora parte de la flota:<br>%s', // ok
99
'exp_new_ships_4' => 'Encontramos una estación pirata desierta. En el hangar hay estacionadas algunas naves antiguas. Nuestros técnicos están mirando si algunas de ellas son aún útiles.<br><br>Las siguientes naves son ahora parte de la flota:<br>%s', // ok
1010
'exp_new_ships_5' => '',
11+
'exo_new_ships_6' => '',
1112

1213
// found resources
1314
'exp_new_resources_1' => 'En un planetoide abondonado han sido encontradas algunas zonas de recursos fácilmente accesibles y se han recolectado allí algunos recursos satisfactoriamente.<br><br>Se ha capturado %s de %s.', // ok
@@ -39,6 +40,9 @@
3940
// advancement
4041
'exp_faster_1' => '',
4142

43+
// found object
44+
'exp_found_object_1' => '',
45+
4246
// found nothing
4347
'exp_nothing_1' => 'Tu expedición hizo magníficas fotos de una super nova. No se obtuvo nada de la expedición pero al menos hay muchas posibilidades de ganar el concurso "Mejor Foto del Universo" este año.', // ok
4448
'exp_nothing_2' => 'Un ser de pura energía se aseguró que todos los miembros de la expedición solo miraran el hipnotizante patrón de los monitores. Cuando la mayoría de ellos se despejaron de nuevo, la expedición debía ser interrumpida ya que quedaba poco deuterio.', // ok
@@ -59,7 +63,6 @@
5963
'exp_blackholl_1' => 'La flota fue arrastrada hacia un agujero negro, esta parcialmente destruida.',
6064
'exp_blackholl_2' => 'La flota fue arrastrada hacia un agujero negro, y fue completamente destruida!',
6165
'exp_found_goods' => 'La flota ha descubierto una nave no tripulada! <br> Tus exploradores han recuperado %s de %s, %s de %s, %s de %s y %s de %s.',
62-
'exp_found_ships' => 'Tus exploradores han encontrado una flota abandonada, la dominaron y vienen de regreso. <br> Escuadron:',
6366
'exp_back_home' => 'Tu expedición regresó al hangar.',
6467
];
6568

src/upload/application/libraries/DebugLib.php

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
*/
1212
namespace application\libraries;
1313

14+
use application\core\enumerators\ErrorTypesEnumerator as ErrorTypes;
15+
1416
/**
1517
* DebugLib Class
1618
*/
1719
class DebugLib
1820
{
1921
/**
20-
* Array of executed queries
22+
* Contains an array of executed queries
2123
*
2224
* @var array
2325
*/
2426
private $queries = [];
2527

2628
/**
27-
* __construct
29+
* Contains an array of errors
2830
*
29-
* @return void
31+
* @var array
3032
*/
31-
public function __construct()
32-
{
33-
}
33+
private $logs = [];
3434

3535
/**
3636
* dump
@@ -104,6 +104,26 @@ public function echoLog(): void
104104
}
105105
}
106106

107+
/**
108+
* Save errors
109+
*
110+
* @param integer $code
111+
* @param string $description
112+
* @param string $file
113+
* @param integer $line
114+
* @return void
115+
*/
116+
public function log(int $code, string $description, string $file = '', int $line = 0, string $type = 'db'): void
117+
{
118+
$this->logs[] = [
119+
'code' => $code,
120+
'description' => $description,
121+
'file' => $file,
122+
'line' => $line,
123+
'type' => $type,
124+
];
125+
}
126+
107127
/**
108128
* Take different actions like displaying the error, logging the error and sending an email
109129
*
@@ -114,27 +134,34 @@ public function echoLog(): void
114134
* @param string $type
115135
* @return void
116136
*/
117-
public function error(int $code, string $description, string $file = '', int $line = 0, string $type = 'db'): void
137+
public function error(int $code = 0, string $description = '', string $file = '', int $line = 0, string $type = 'db'): void
118138
{
139+
if (count($this->logs) > 0) {
140+
extract($this->logs[0]);
141+
}
142+
143+
$string_code = 'DB Exception';
144+
145+
if ($type != 'db') {
146+
$string_code = ErrorTypes::PHP_ERRORS[$code];
147+
}
148+
119149
if (DEBUG_MODE or (in_array($_SERVER['HTTP_HOST'], ['127.0.0.1', 'localhost']) !== false)) {
120150
echo '<div style="background-color:blue;color:white;position:absolute;width:100%;z-index:999999;text-align:center;bottom:0">
121-
<h2 style="color:red; font-weight:normal">' . $description . '</h2>';
151+
<h2 style="color:white; font-weight:normal">' . $description . '</h2>';
122152

123153
if ($type != 'db') {
124154
echo '<h3>in ' . $file . ' on line ' . $line . '</h3>
125-
<span>Error code: ' . $code . '</span>';
155+
<span>Error code: ' . $string_code . '</span>';
126156
}
127157

128-
echo '<hr>
129-
<h3>Trace (<a href="' . XGP_ROOT . 'admin.php?page=settings">Debug Log</a>):</h3>
130-
<div>' . $this->whereCalled() . '</div>
131-
<br>
158+
echo '<br><br>
132159
</div>';
133160
} else {
134161
$user_ip = $_SERVER['REMOTE_ADDR'];
135162

136163
// format log
137-
$log = '|' . $user_ip . '|' . $type . '|' . $code . '|' . $description . '|' . $this->whereCalled() . '|';
164+
$log = '|' . $user_ip . '|' . $type . '|' . $string_code . '|' . $description . '|' . $this->whereCalled() . '|' . SYSTEM_VERSION . '|';
138165

139166
if (defined('LOG_ERRORS') && LOG_ERRORS != '') {
140167
// log the error
@@ -145,7 +172,7 @@ public function error(int $code, string $description, string $file = '', int $li
145172
if (defined('ERROR_LOGS_MAIL') && ERROR_LOGS_MAIL != '') {
146173
FunctionsLib::sendEmail(
147174
ERROR_LOGS_MAIL,
148-
'[DEBUG][' . $code . ']',
175+
'[DEBUG][' . $string_code . ']',
149176
$log,
150177
[
151178
'mail' => ERROR_LOGS_MAIL,

0 commit comments

Comments
 (0)