|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The MIT License (MIT) |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Robert Sardinia |
|
6
|
|
|
* |
|
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
9
|
|
|
* in the Software without restriction, including without limitation the rights |
|
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
12
|
|
|
* furnished to do so, subject to the following conditions: |
|
13
|
|
|
* |
|
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
15
|
|
|
* copies or substantial portions of the Software. |
|
16
|
|
|
* |
|
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
23
|
|
|
* SOFTWARE. |
|
24
|
|
|
*/ |
|
25
|
|
|
use discord\discord; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class auth |
|
29
|
|
|
*/ |
|
30
|
|
|
class auth |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var |
|
34
|
|
|
*/ |
|
35
|
|
|
var $config; |
|
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var |
|
38
|
|
|
*/ |
|
39
|
|
|
var $discord; |
|
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var |
|
42
|
|
|
*/ |
|
43
|
|
|
var $logger; |
|
|
|
|
|
|
44
|
|
|
var $solarSystems; |
|
|
|
|
|
|
45
|
|
|
var $triggers = array(); |
|
|
|
|
|
|
46
|
|
|
var $excludeChannel; |
|
|
|
|
|
|
47
|
|
|
var $nameEnforce; |
|
|
|
|
|
|
48
|
|
|
public $guildID; |
|
49
|
|
|
public $db; |
|
50
|
|
|
public $dbUser; |
|
51
|
|
|
public $dbPass; |
|
52
|
|
|
public $dbName; |
|
53
|
|
|
public $ssoUrl; |
|
54
|
|
|
public $allianceTickers; |
|
55
|
|
|
public $corpTickers; |
|
56
|
|
|
public $authGroups; |
|
57
|
|
|
public $guild; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param $config |
|
61
|
|
|
* @param $discord |
|
62
|
|
|
* @param $logger |
|
63
|
|
|
*/ |
|
64
|
|
|
function init($config, $discord, $logger) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
$this->config = $config; |
|
67
|
|
|
$this->discord = $discord; |
|
68
|
|
|
$this->logger = $logger; |
|
69
|
|
|
$this->db = $config["database"]["host"]; |
|
70
|
|
|
$this->dbUser = $config["database"]["user"]; |
|
71
|
|
|
$this->dbPass = $config["database"]["pass"]; |
|
72
|
|
|
$this->dbName = $config["database"]["database"]; |
|
73
|
|
|
$this->corpTickers = $config["plugins"]["auth"]["corpTickers"]; |
|
74
|
|
|
$this->nameEnforce = $config["plugins"]["auth"]["nameEnforce"]; |
|
75
|
|
|
$this->ssoUrl = $config["plugins"]["auth"]["url"]; |
|
76
|
|
|
$this->excludeChannel = $this->config["bot"]["restrictedChannels"]; |
|
77
|
|
|
$this->authGroups = $config["plugins"]["auth"]["authGroups"]; |
|
78
|
|
|
$this->guild = $config["bot"]["guild"]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* |
|
83
|
|
|
*/ |
|
84
|
|
|
function tick() |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param $msgData |
|
90
|
|
|
* @param $message |
|
91
|
|
|
* @return null |
|
92
|
|
|
*/ |
|
93
|
|
|
function onMessage($msgData, $message) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$channelID = (int)$msgData["message"]["channelID"]; |
|
96
|
|
|
|
|
97
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) { |
|
98
|
|
|
return null; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$this->message = $message; |
|
102
|
|
|
$userID = $msgData["message"]["fromID"]; |
|
103
|
|
|
$userName = $msgData["message"]["from"]; |
|
104
|
|
|
$message = $msgData["message"]["message"]; |
|
105
|
|
|
$channelInfo = $this->message->channel; |
|
106
|
|
|
$guildID = $channelInfo[@guild_id]; |
|
107
|
|
|
$data = command($message, $this->information()["trigger"], $this->config["bot"]["trigger"]); |
|
108
|
|
|
if (isset($data["trigger"])) { |
|
109
|
|
|
if (isset($this->config["bot"]["primary"])) { |
|
110
|
|
|
if ($guildID != $this->config["bot"]["primary"]) { |
|
111
|
|
|
$this->message->reply("**Failure:** The auth code your attempting to use is for another discord server"); |
|
112
|
|
|
return null; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
// If config is outdated |
|
117
|
|
|
if (is_null($this->authGroups)) { |
|
118
|
|
|
$this->message->reply("**Failure:** Please update the bots config to the latest version."); |
|
119
|
|
|
return null; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$code = $data["messageString"]; |
|
123
|
|
|
$result = selectPending($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code); |
|
124
|
|
|
|
|
125
|
|
|
if (strlen($code) < 12) { |
|
126
|
|
|
$this->message->reply("Invalid Code, check " . $this->config["bot"]["trigger"] . "help auth for more info."); |
|
127
|
|
|
return null; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
while ($rows = $result->fetch_assoc()) { |
|
131
|
|
|
$charID = (int)$rows['characterID']; |
|
132
|
|
|
$corpID = (int)$rows['corporationID']; |
|
133
|
|
|
$allianceID = (int)$rows['allianceID']; |
|
134
|
|
|
$url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?ids=$charID"; |
|
135
|
|
|
$xmlCharacter = makeApiRequest($url); |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
// We have an error, show it it |
|
139
|
|
|
if ($xmlCharacter->error) { |
|
140
|
|
|
$this->message->reply("**Failure:** Eve API error, please try again in a little while."); |
|
141
|
|
|
return null; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
// Check that the api is working |
|
145
|
|
|
if (!isset($xmlCharacter->result->rowset->row)) { |
|
146
|
|
|
$this->message->reply("**Failure:** Eve API error, please try again in a little while."); |
|
147
|
|
|
return null; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
//Add corp ticker to name |
|
151
|
|
|
if ($this->corpTickers == 'true') { |
|
152
|
|
|
$url = "https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID={$corpID}"; |
|
153
|
|
|
$xml = makeApiRequest($url); |
|
154
|
|
|
$setTicker = 1; |
|
155
|
|
|
foreach ($xml->result as $corporation) { |
|
156
|
|
|
$corpTicker = $corporation->ticker; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
//Set eve name if nameCheck is true |
|
161
|
|
|
if ($this->nameEnforce == "true") { |
|
162
|
|
|
$nameEnforce = 1; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$allianceRoleSet = 0; |
|
166
|
|
|
$corpRoleSet = 0; |
|
167
|
|
|
|
|
168
|
|
|
foreach ($xmlCharacter->result->rowset->row as $character) { |
|
169
|
|
|
$roles = $this->message->channel->guild->roles; |
|
170
|
|
|
$member = $this->message->channel->guild->members->get("id", $userID); |
|
171
|
|
|
$eveName = $character->attributes()->name; |
|
172
|
|
|
foreach ($this->authGroups as $authGroup) { |
|
173
|
|
|
//Check if corpID matches |
|
174
|
|
|
if ($corpID === $authGroup["corpID"]) { |
|
175
|
|
|
foreach ($roles as $role) { |
|
176
|
|
|
if ($role->name == $authGroup["corpMemberRole"]) { |
|
177
|
|
|
$member->addRole($role); |
|
178
|
|
|
$corpRoleSet = 1; |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
//Check if allianceID matches |
|
183
|
|
|
if ($allianceID === $authGroup["allianceID"] && $authGroup["allianceID"] != 0) { |
|
184
|
|
|
foreach ($roles as $role) { |
|
185
|
|
|
if ($role->name == $authGroup["allyMemberRole"]) { |
|
186
|
|
|
$member->addRole($role); |
|
187
|
|
|
$allianceRoleSet = 1; |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
if ($allianceRoleSet == 1 || $corpRoleSet == 1) { |
|
192
|
|
|
$guild = $this->discord->guilds->get('id', $guildID); |
|
193
|
|
|
insertUser($this->db, $this->dbUser, $this->dbPass, $this->dbName, $userID, $charID, $eveName, 'corp'); |
|
194
|
|
|
disableReg($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code); |
|
195
|
|
|
$msg = ":white_check_mark: **Success:** {$userName} has been successfully authed."; |
|
196
|
|
|
$this->logger->addInfo("auth: {$eveName} authed"); |
|
197
|
|
|
priorityQueueMessage($msg, $channelID, $this->guild); |
|
198
|
|
|
//Add ticker if set and change name if nameEnforce is on |
|
199
|
|
|
if (isset($setTicker) || isset($nameEnforce)) { |
|
200
|
|
|
if (isset($setTicker) && isset($nameEnforce)) { |
|
201
|
|
|
$nick = "[{$corpTicker}] {$eveName}"; |
|
|
|
|
|
|
202
|
|
|
} elseif (!isset($setTicker) && isset($nameEnforce)) { |
|
203
|
|
|
$nick = "{$eveName}"; |
|
204
|
|
|
} elseif (isset($setTicker) && !isset($nameEnforce)) { |
|
205
|
|
|
$nick = "[{$corpTicker}] {$userName}"; |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
if (isset($nick)) { |
|
209
|
|
|
queueRename($userID, $nick, $this->guild); |
|
210
|
|
|
} |
|
211
|
|
|
$guild->members->save($member); |
|
212
|
|
|
return null; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
$this->message->reply("**Failure:** There are no roles available for your corp/alliance."); |
|
216
|
|
|
$this->logger->addInfo("Auth: User was denied due to not being in the correct corp or alliance " . $eveName); |
|
217
|
|
|
return null; |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
$this->message->reply("**Failure:** There was an issue with your code."); |
|
221
|
|
|
$this->logger->addInfo("Auth: User was denied due to not being in the correct corp or alliance " . $userName); |
|
222
|
|
|
return null; |
|
223
|
|
|
} |
|
224
|
|
|
return null; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @return array |
|
229
|
|
|
*/ |
|
230
|
|
View Code Duplication |
function information() |
|
|
|
|
|
|
231
|
|
|
{ |
|
232
|
|
|
return array( |
|
233
|
|
|
"name" => "auth", |
|
234
|
|
|
"trigger" => array($this->config["bot"]["trigger"] . "auth"), |
|
235
|
|
|
"information" => "SSO based auth system. " . $this->ssoUrl . " Visit the link and login with your main EVE account, select the correct character, and put the !auth <string> you receive in chat." |
|
236
|
|
|
); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
function onMessageAdmin() |
|
|
|
|
|
|
240
|
|
|
{ |
|
241
|
|
|
} |
|
242
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.