|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 01.10.2017 13:12 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Common\Tools; |
|
7
|
|
|
|
|
8
|
|
|
use \classConfig; |
|
9
|
|
|
use \SN; |
|
10
|
|
|
|
|
11
|
|
|
class VersionCheckerDeprecated { |
|
12
|
|
|
/** |
|
13
|
|
|
* @var classConfig $config |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $config; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int $versionCheckResult |
|
19
|
|
|
*/ |
|
20
|
|
|
public $versionCheckResult = SNC_VER_ERROR_CONNECT; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array $registerResult |
|
24
|
|
|
*/ |
|
25
|
|
|
public $registerResult = []; |
|
26
|
|
|
|
|
27
|
|
|
public static function performCheckVersion() { |
|
28
|
|
|
$that = new static(); |
|
29
|
|
|
$that->checkVersion(SNC_MODE_VERSION_CHECK); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public static function handleCall() { |
|
33
|
|
|
$that = new static(); |
|
34
|
|
|
|
|
35
|
|
|
$mode = sys_get_param_int('mode'); |
|
36
|
|
|
$ajax = sys_get_param_int('ajax'); |
|
37
|
|
|
|
|
38
|
|
|
$that->preventDualRegistration($mode, $ajax); |
|
39
|
|
|
|
|
40
|
|
|
$that->checkVersion($mode); |
|
41
|
|
|
|
|
42
|
|
|
$that->processRegistration($mode); |
|
43
|
|
|
|
|
44
|
|
|
if ($ajax) { |
|
45
|
|
|
define('IN_AJAX', true); |
|
46
|
|
|
print($that->versionCheckResult); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function __construct() { |
|
51
|
|
|
$this->config = SN::$config; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param int $mode - SNC_MODE_xxx constants |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function checkVersion($mode) { |
|
58
|
|
|
$this->processContent(sn_get_url_contents($this->generateUrl($mode))); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param int $mode - SNC_MODE_xxx constants |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function generateUrl($mode, $debug = false) { |
|
67
|
|
|
$rootServerUrl = $debug ? 'http://localhost/supernova_site/' : 'http://supernova.ws/'; |
|
68
|
|
|
$thisSiteUrl = $debug ? 'http://supernova.ws/' : SN_ROOT_VIRTUAL; |
|
69
|
|
|
|
|
70
|
|
|
$url = |
|
71
|
|
|
$rootServerUrl . 'version_check.php' |
|
72
|
|
|
. '?mode=' . $mode |
|
73
|
|
|
. '&db=' . DB_VERSION |
|
74
|
|
|
. '&release=' . SN_RELEASE |
|
75
|
|
|
. '&version=' . SN_VERSION |
|
76
|
|
|
. '&key=' . urlencode($this->config->server_updater_key) |
|
77
|
|
|
. '&id=' . urlencode($this->config->server_updater_id) |
|
78
|
|
|
. ($mode == SNC_MODE_REGISTER ? "&name=" . urlencode($this->config->game_name) . "&url=" . urlencode($thisSiteUrl) : ''); |
|
79
|
|
|
|
|
80
|
|
|
return $url; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param $content |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function processContent($content) { |
|
87
|
|
|
if (!$content) { |
|
88
|
|
|
$this->versionCheckResult = SNC_VER_ERROR_CONNECT; |
|
89
|
|
|
} else { |
|
90
|
|
|
if (($decoded = json_decode($content, true)) !== null) { |
|
91
|
|
|
$this->versionCheckResult = isset($decoded['version_check']) ? $decoded['version_check'] : SNC_VER_UNKNOWN_RESPONSE; |
|
92
|
|
|
$this->registerResult = is_array($decoded['site']) ? $decoded['site'] : []; |
|
93
|
|
|
} else { |
|
94
|
|
|
$this->versionCheckResult = $content; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$this->config->pass()->server_updater_check_last = SN_TIME_NOW; |
|
99
|
|
|
$this->config->pass()->server_updater_check_result = $this->versionCheckResult; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param $mode |
|
104
|
|
|
* @param $ajax |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function preventDualRegistration($mode, $ajax) { |
|
107
|
|
|
if ($mode == SNC_MODE_REGISTER && ($this->config->server_updater_key || $this->config->server_updater_id)) { |
|
108
|
|
|
if ($ajax) { |
|
109
|
|
|
print(SNC_VER_REGISTER_ERROR_REGISTERED); |
|
110
|
|
|
} |
|
111
|
|
|
die(); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param $mode |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function processRegistration($mode) { |
|
119
|
|
|
if ($mode == SNC_MODE_REGISTER) { |
|
120
|
|
|
$this->versionCheckResult = isset($this->registerResult['result']) ? $this->registerResult['result'] : SNC_VER_UNKNOWN_RESPONSE; |
|
121
|
|
|
|
|
122
|
|
|
if ($this->registerResult['result'] == SNC_VER_REGISTER_REGISTERED && $this->registerResult['site_key'] && $this->registerResult['site_id']) { |
|
123
|
|
|
$this->config->pass()->server_updater_key = $this->registerResult['site_key']; |
|
124
|
|
|
$this->config->pass()->server_updater_id = $this->registerResult['site_id']; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.