This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
/
common.php
219 lines (175 loc) · 5.65 KB
/
common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* 2Moons
* by Jan-Otto Kröpke 2009-2016
*
* For the full copyright and license information, please view the LICENSE
*
* @package 2Moons
* @author Jan-Otto Kröpke <[email protected]>
* @copyright 2009 Lucky
* @copyright 2016 Jan-Otto Kröpke <[email protected]>
* @licence MIT
* @version 1.8.0
* @link https://github.com/jkroepke/2Moons
*/
if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
exit('You cannot set the GLOBALS-array from outside the script.');
}
$composerAutoloader = __DIR__.'/../vendor/autoload.php';
if (file_exists($composerAutoloader)) {
require $composerAutoloader;
}
if (function_exists('mb_internal_encoding')) {
mb_internal_encoding("UTF-8");
}
ignore_user_abort(true);
error_reporting(E_ALL & ~E_STRICT);
// If date.timezone is invalid
date_default_timezone_set(@date_default_timezone_get());
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=UTF-8');
define('TIMESTAMP', time());
require 'includes/constants.php';
ini_set('log_errors', 'On');
ini_set('error_log', 'includes/error.log');
require 'includes/GeneralFunctions.php';
set_exception_handler('exceptionHandler');
set_error_handler('errorHandler');
require 'includes/classes/ArrayUtil.class.php';
require 'includes/classes/Cache.class.php';
require 'includes/classes/Database.class.php';
require 'includes/classes/Config.class.php';
require 'includes/classes/class.FleetFunctions.php';
require 'includes/classes/HTTP.class.php';
require 'includes/classes/Language.class.php';
require 'includes/classes/PlayerUtil.class.php';
require 'includes/classes/Session.class.php';
require 'includes/classes/Universe.class.php';
require 'includes/classes/class.theme.php';
require 'includes/classes/class.template.php';
// Say Browsers to Allow ThirdParty Cookies (Thanks to morktadela)
HTTP::sendHeader('P3P', 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
define('AJAX_REQUEST', HTTP::_GP('ajax', 0));
$THEME = new Theme();
if (MODE === 'INSTALL')
{
return;
}
if(!file_exists('includes/config.php') || filesize('includes/config.php') === 0) {
HTTP::redirectTo('install/index.php');
}
try {
$sql = "SELECT dbVersion FROM %%SYSTEM%%;";
$dbVersion = Database::get()->selectSingle($sql, array(), 'dbVersion');
$dbNeedsUpgrade = $dbVersion < DB_VERSION_REQUIRED;
} catch (Exception $e) {
$dbNeedsUpgrade = true;
}
if ($dbNeedsUpgrade) {
HTTP::redirectTo('install/index.php?mode=upgrade');
}
if(defined('DATABASE_VERSION') && DATABASE_VERSION === 'OLD')
{
/* For our old Admin panel */
require 'includes/classes/Database_BC.class.php';
$DATABASE = new Database_BC();
$dbTableNames = Database::get()->getDbTableNames();
$dbTableNames = array_combine($dbTableNames['keys'], $dbTableNames['names']);
foreach($dbTableNames as $dbAlias => $dbName)
{
define(substr($dbAlias, 2, -2), $dbName);
}
}
$config = Config::get();
date_default_timezone_set($config->timezone);
if (MODE === 'INGAME' || MODE === 'ADMIN' || MODE === 'CRON')
{
$session = Session::load();
if(!$session->isValidSession())
{
$session->delete();
HTTP::redirectTo('index.php?code=3');
}
require 'includes/vars.php';
require 'includes/classes/class.BuildFunctions.php';
require 'includes/classes/class.PlanetRessUpdate.php';
if(!AJAX_REQUEST && MODE === 'INGAME' && isModuleAvailable(MODULE_FLEET_EVENTS)) {
require('includes/FleetHandler.php');
}
$db = Database::get();
$sql = "SELECT
user.*,
COUNT(message.message_id) as messages
FROM %%USERS%% as user
LEFT JOIN %%MESSAGES%% as message ON message.message_owner = user.id AND message.message_unread = :unread
WHERE user.id = :userId
GROUP BY message.message_owner;";
$USER = $db->selectSingle($sql, array(
':unread' => 1,
':userId' => $session->userId
));
if(empty($USER))
{
HTTP::redirectTo('index.php?code=3');
}
$LNG = new Language($USER['lang']);
$LNG->includeData(array('L18N', 'INGAME', 'TECH', 'CUSTOM'));
$THEME->setUserTheme($USER['dpath']);
if($config->game_disable == 0 && $USER['authlevel'] == AUTH_USR) {
ShowErrorPage::printError($LNG['sys_closed_game'].'<br><br>'.$config->close_reason, false);
}
if($USER['bana'] == 1) {
ShowErrorPage::printError("<font size=\"6px\">".$LNG['css_account_banned_message']."</font><br><br>".sprintf($LNG['css_account_banned_expire'], _date($LNG['php_tdformat'], $USER['banaday'], $USER['timezone']))."<br><br>".$LNG['css_goto_homeside'], false);
}
if (MODE === 'INGAME')
{
$universeAmount = count(Universe::availableUniverses());
if(Universe::current() != $USER['universe'] && $universeAmount > 1)
{
HTTP::redirectToUniverse($USER['universe']);
}
$session->selectActivePlanet();
$sql = "SELECT * FROM %%PLANETS%% WHERE id = :planetId;";
$PLANET = $db->selectSingle($sql, array(
':planetId' => $session->planetId,
));
if(empty($PLANET))
{
$sql = "SELECT * FROM %%PLANETS%% WHERE id = :planetId;";
$PLANET = $db->selectSingle($sql, array(
':planetId' => $USER['id_planet'],
));
if(empty($PLANET))
{
throw new Exception("Main Planet does not exist!");
}
else
{
$session->planetId = $USER['id_planet'];
}
}
$USER['factor'] = getFactors($USER);
$USER['PLANETS'] = getPlanets($USER);
}
elseif (MODE === 'ADMIN')
{
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$USER['rights'] = unserialize($USER['rights']);
$LNG->includeData(array('ADMIN', 'CUSTOM'));
}
}
elseif(MODE === 'LOGIN')
{
$LNG = new Language();
$LNG->getUserAgentLanguage();
$LNG->includeData(array('L18N', 'INGAME', 'PUBLIC', 'CUSTOM'));
}
elseif(MODE === 'CHAT')
{
$session = Session::load();
if(!$session->isValidSession())
{
HTTP::redirectTo('index.php?code=3');
}
}