1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Asylamba\Classes\Worker; |
4
|
|
|
|
5
|
|
|
use Asylamba\Classes\Library\Security; |
6
|
|
|
|
7
|
|
|
class API { |
8
|
|
|
# API user |
9
|
|
|
/** @var string **/ |
10
|
|
|
private $path; |
11
|
|
|
/** @var string **/ |
12
|
|
|
private $serverId; |
13
|
|
|
/** @var string **/ |
14
|
|
|
private $key; |
15
|
|
|
|
16
|
|
|
public $query; |
17
|
|
|
public $data; |
18
|
|
|
|
19
|
|
|
const TEMPLATE_INACTIVE_PLAYER = 51; |
20
|
|
|
const TEMPLATE_SPONSORSHIP = 52; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param Security $security |
24
|
|
|
* @param string $serverId |
25
|
|
|
* @param string $apiKey |
26
|
|
|
* @param string $getOutRoot |
27
|
|
|
*/ |
28
|
|
|
public function __construct(Security $security, $serverId, $apiKey, $getOutRoot) { |
29
|
|
|
$this->path = $getOutRoot; |
30
|
|
|
$this->serverId = $serverId; |
31
|
|
|
$this->key = $apiKey; |
32
|
|
|
$this->security = $security; |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function query($api, $args) { |
36
|
|
|
$targ = ''; |
37
|
|
|
$ch = curl_init(); |
38
|
|
|
|
39
|
|
|
foreach ($args as $k => $v) { |
40
|
|
|
$targ .= $k . '-' . $v . '/'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->query = $this->path . 'api/s-' . $this->serverId . '/a-' . $this->security->crypt('a-' . $api . '/' . $targ, $this->key); |
44
|
|
|
|
45
|
|
|
curl_setopt($ch, CURLOPT_URL, $this->query); |
46
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER , TRUE); |
|
|
|
|
47
|
|
|
$answer = curl_exec($ch); |
48
|
|
|
curl_close($ch); |
49
|
|
|
|
50
|
|
|
if ($answer !== FALSE) { |
51
|
|
|
$this->data = unserialize($answer); |
52
|
|
|
return TRUE; |
53
|
|
|
} else { |
54
|
|
|
return FALSE; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function userExist($bindkey) { |
59
|
|
|
if ($this->query('userexist', array('bindkey' => $bindkey))) { |
60
|
|
|
if ($this->data['statement'] == 'success') { |
61
|
|
|
return TRUE; |
62
|
|
|
} else { |
63
|
|
|
return FALSE; |
64
|
|
|
} |
65
|
|
|
} else { |
66
|
|
|
return FALSE; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function confirmInscription($bindkey) { |
71
|
|
|
if ($this->query('confirminscription', array('bindkey' => $bindkey, 'serverid' => $this->serverId))) { |
72
|
|
|
if ($this->data['statement'] == 'success') { |
73
|
|
|
return TRUE; |
74
|
|
|
} else { |
75
|
|
|
return FALSE; |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
return FALSE; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function confirmConnection($bindkey) { |
83
|
|
|
if ($this->query('confirmconnection', array('bindkey' => $bindkey, 'serverid' => $this->serverId))) { |
84
|
|
|
if ($this->data['statement'] == 'success') { |
85
|
|
|
return TRUE; |
86
|
|
|
} else { |
87
|
|
|
return FALSE; |
88
|
|
|
} |
89
|
|
|
} else { |
90
|
|
|
return FALSE; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function playerIsDead($bindkey, $serverId) { |
95
|
|
|
if ($this->query('playerisdead', array('bindkey' => $bindkey, 'serverid' => $serverId))) { |
96
|
|
|
if ($this->data['statement'] == 'success') { |
97
|
|
|
return TRUE; |
98
|
|
|
} else { |
99
|
|
|
return FALSE; |
100
|
|
|
} |
101
|
|
|
} else { |
102
|
|
|
return FALSE; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function sendMail($bindkey, $template) { |
107
|
|
|
if ($this->query('sendmail', array('bindkey' => $bindkey, 'serverid' => $this->serverId, 'template' => $template))) { |
108
|
|
|
if ($this->data['statement'] == 'success') { |
109
|
|
|
return TRUE; |
110
|
|
|
} else { |
111
|
|
|
return FALSE; |
112
|
|
|
} |
113
|
|
|
} else { |
114
|
|
|
return FALSE; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function sendMail2($email, $serverId, $template, $playerId) { |
119
|
|
|
if ($this->query('sendmail2', array('email' => $email, 'serverid' => $serverId, 'template' => $template, 'playerid' => $playerId))) { |
120
|
|
|
if ($this->data['statement'] == 'success') { |
121
|
|
|
return TRUE; |
122
|
|
|
} else { |
123
|
|
|
return FALSE; |
124
|
|
|
} |
125
|
|
|
} else { |
126
|
|
|
return FALSE; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function abandonServer($bindkey) { |
131
|
|
|
if ($this->query('abandonserver', array('bindkey' => $bindkey, 'serverid' => $this->serverId))) { |
132
|
|
|
if ($this->data['statement'] == 'success') { |
133
|
|
|
return TRUE; |
134
|
|
|
} else { |
135
|
|
|
return FALSE; |
136
|
|
|
} |
137
|
|
|
} else { |
138
|
|
|
return FALSE; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: