1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Smr\Pages\Player; |
4
|
|
|
|
5
|
|
|
use AbstractSmrPlayer; |
6
|
|
|
use Smr\Database; |
7
|
|
|
use Smr\Page\PlayerPageProcessor; |
8
|
|
|
use Smr\Request; |
9
|
|
|
use SmrAlliance; |
10
|
|
|
|
11
|
|
|
class AllianceGovernanceProcessor extends PlayerPageProcessor { |
12
|
|
|
|
13
|
|
|
public function __construct( |
14
|
|
|
private readonly int $allianceID |
15
|
|
|
) {} |
16
|
|
|
|
17
|
|
|
public function build(AbstractSmrPlayer $player): never { |
18
|
|
|
$alliance_id = $this->allianceID; |
19
|
|
|
|
20
|
|
|
if (Request::has('description')) { |
21
|
|
|
$description = Request::get('description'); |
22
|
|
|
} |
23
|
|
|
if (Request::has('discord_server')) { |
24
|
|
|
$discordServer = Request::get('discord_server'); |
25
|
|
|
} |
26
|
|
|
if (Request::has('discord_channel')) { |
27
|
|
|
$discordChannel = Request::get('discord_channel'); |
28
|
|
|
} |
29
|
|
|
if (Request::has('irc')) { |
30
|
|
|
$irc = Request::get('irc'); |
31
|
|
|
} |
32
|
|
|
if (Request::has('mod')) { |
33
|
|
|
$mod = Request::get('mod'); |
34
|
|
|
} |
35
|
|
|
if (Request::has('url')) { |
36
|
|
|
$url = Request::get('url'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// Prevent XSS attacks |
40
|
|
|
if (isset($url) && preg_match('/"/', $url)) { |
41
|
|
|
create_error('You cannot use a " in the image link!'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$alliance = SmrAlliance::getAlliance($alliance_id, $player->getGameID()); |
45
|
|
|
if (Request::has('recruit_type')) { |
46
|
|
|
$recruitType = Request::get('recruit_type'); |
47
|
|
|
$password = Request::get('password', ''); |
48
|
|
|
$alliance->setRecruitType($recruitType, $password); |
49
|
|
|
} |
50
|
|
|
if (isset($description)) { |
51
|
|
|
$alliance->setAllianceDescription($description, $player); |
52
|
|
|
} |
53
|
|
|
if (isset($discordServer)) { |
54
|
|
|
$alliance->setDiscordServer($discordServer); |
55
|
|
|
} |
56
|
|
|
if (isset($discordChannel)) { |
57
|
|
|
if (empty($discordChannel)) { |
58
|
|
|
$alliance->setDiscordChannel(null); |
59
|
|
|
} else { |
60
|
|
|
// no duplicates in a given game |
61
|
|
|
$db = Database::getInstance(); |
62
|
|
|
$dbResult = $db->read('SELECT 1 FROM alliance WHERE discord_channel =' . $db->escapeString($discordChannel) . ' AND game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' AND alliance_id != ' . $db->escapeNumber($alliance->getAllianceID()) . ' LIMIT 1'); |
63
|
|
|
if ($dbResult->hasRecord()) { |
64
|
|
|
create_error('Another alliance is already using that Discord Channel ID!'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$alliance->setDiscordChannel($discordChannel); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
if (isset($irc)) { |
71
|
|
|
$alliance->setIrcChannel($irc); |
72
|
|
|
} |
73
|
|
|
if (isset($mod)) { |
74
|
|
|
$alliance->setMotD($mod); |
75
|
|
|
} |
76
|
|
|
if (isset($url)) { |
77
|
|
|
$alliance->setImageURL($url); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$alliance->update(); |
81
|
|
|
$container = new AllianceRoster($alliance_id); |
82
|
|
|
$container->go(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|