1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
function redirectIfDisabled(SmrAccount $account) { |
4
|
|
|
// We skip the redirect for specific disabled reasons, because they are |
5
|
|
|
// handled elsewhere. |
6
|
|
|
$skipReasons = [ |
7
|
|
|
CLOSE_ACCOUNT_INVALID_EMAIL_REASON, |
8
|
|
|
CLOSE_ACCOUNT_BY_REQUEST_REASON, |
9
|
|
|
]; |
10
|
|
|
|
11
|
|
|
$disabled = $account->isDisabled(); |
12
|
|
|
if ($disabled === false || in_array($disabled['Reason'], $skipReasons)) { |
13
|
|
|
return $disabled; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
// Otherwise, we redirect to the login page with a message |
17
|
|
|
$msg = '<span class="red">Your account is disabled!</span><br />Reason: ' . $disabled['Reason'] . '<br /><br />It is set to '; |
18
|
|
|
if ($disabled['Time'] > 0) { |
19
|
|
|
$msg .= 'reopen on ' . date(DEFAULT_DATE_FULL_LONG, $disabled['Time']); |
20
|
|
|
} else { |
21
|
|
|
$msg .= 'never reopen'; |
22
|
|
|
} |
23
|
|
|
$msg .= '.<br />Please contact an admin for further information.'; |
24
|
|
|
|
25
|
|
|
// Destroy the SmrSession, since there is no way to "log off" from the login page |
26
|
|
|
SmrSession::destroy(); |
27
|
|
|
|
28
|
|
|
// Store the message in a session to avoid URL length restrictions |
29
|
|
|
if (session_status() === PHP_SESSION_NONE) { |
30
|
|
|
session_start(); |
31
|
|
|
} |
32
|
|
|
$_SESSION['login_msg'] = $msg; |
33
|
|
|
|
34
|
|
|
header('location: /login.php?status=disabled'); |
35
|
|
|
exit; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function redirectIfOffline(SmrAccount $account) : void { |
39
|
|
|
// Check if the game is offline |
40
|
|
|
$db = new SmrMySqlDatabase(); |
41
|
|
|
$db->query('SELECT * FROM game_disable'); |
42
|
|
|
$offline = $db->nextRecord(); |
43
|
|
|
|
44
|
|
|
// Skip redirect if we're not offline or if account has admin permission |
45
|
|
|
if ($offline === false || $account->hasPermission(PERMISSION_GAME_OPEN_CLOSE)) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// We need to destroy the session so that the login page doesn't |
50
|
|
|
// redirect to the in-game loader (bypassing the server closure). |
51
|
|
|
SmrSession::destroy(); |
52
|
|
|
|
53
|
|
|
// Store the message in a session to avoid URL length restrictions |
54
|
|
|
if (session_status() === PHP_SESSION_NONE) { |
55
|
|
|
session_start(); |
56
|
|
|
} |
57
|
|
|
$_SESSION['login_msg'] = '<span class="red">Space Merchant Realms is temporarily offline.<br />' . $db->getField('reason') . '</span>'; |
58
|
|
|
|
59
|
|
|
header('location: /login.php?status=offline'); |
60
|
|
|
exit; |
61
|
|
|
} |
62
|
|
|
|