1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class CloakController {
21:
22: 23: 24: 25:
26: public $moduleName;
27:
28:
29: public $chatBot;
30:
31:
32: public $settingManager;
33:
34:
35: public $db;
36:
37:
38: public $text;
39:
40:
41: public $util;
42:
43:
44: public $altsController;
45:
46: 47: 48:
49: public function setup() {
50: $this->db->loadSQLFile($this->moduleName, 'org_city');
51:
52: $this->settingManager->add($this->moduleName, "showcloakstatus", "Show cloak status to players at logon", "edit", "options", "1", "Never;When cloak is down;Always", "0;1;2");
53: $this->settingManager->add($this->moduleName, "cloak_reminder_interval", "How often to spam guild channel when cloak is down", "edit", "time", "5m", "2m;5m;10m;15m;20m");
54: }
55:
56: 57: 58: 59:
60: public function cloakCommand($message, $channel, $sender, $sendto, $args) {
61: $data = $this->db->query("SELECT * FROM org_city_<myname> WHERE `action` = 'on' OR `action` = 'off' ORDER BY `time` DESC LIMIT 20");
62: if (count($data) == 0) {
63: $msg = "Unknown status on cloak!";
64: } else {
65: $row = array_shift($data);
66: $timeSinceChange = time() - $row->time;
67: $timeString = $this->util->unixtimeToReadable(3600 - $timeSinceChange, false);
68:
69: if ($timeSinceChange >= 3600 && $row->action == "off") {
70: $msg = "The cloaking device is <orange>disabled<end>. It is possible to enable it.";
71: } else if ($timeSinceChange < 3600 && $row->action == "off") {
72: $msg = "The cloaking device is <orange>disabled<end>. It is possible in $timeString to enable it.";
73: } else if ($timeSinceChange >= 3600 && $row->action == "on") {
74: $msg = "The cloaking device is <green>enabled<end>. It is possible to disable it.";
75: } else if ($timeSinceChange < 3600 && $row->action == "on") {
76: $msg = "The cloaking device is <green>enabled<end>. It is possible in $timeString to disable it.";
77: }
78:
79: $list = "Time: <highlight>" . $this->util->date($row->time) . "<end>\n";
80: $list .= "Action: <highlight>Cloaking device turned " . $row->action . "<end>\n";
81: $list .= "Character: <highlight>" . $row->player . "<end>\n\n";
82:
83: forEach ($data as $row) {
84: $list .= "Time: <highlight>" . $this->util->date($row->time) . "<end>\n";
85: $list .= "Action: <highlight>Cloaking device turned " . $row->action . "<end>\n";
86: $list .= "Character: <highlight>" . $row->player . "<end>\n\n";
87: }
88: $msg .= " " . $this->text->makeBlob("Cloak History", $list);
89: }
90: $sendto->reply($msg);
91: }
92:
93: 94: 95: 96:
97: public function cloakRaiseCommand($message, $channel, $sender, $sendto, $args) {
98: $row = $this->db->queryRow("SELECT * FROM org_city_<myname> WHERE `action` = 'on' OR `action` = 'off' ORDER BY `time` DESC LIMIT 1");
99:
100: if ($row->action == "on") {
101: $msg = "The cloaking device is already <green>enabled<end>.";
102: } else {
103: $this->db->exec("INSERT INTO org_city_<myname> (`time`, `action`, `player`) VALUES (?, ?, ?)", time(), 'on', $sender . '*');
104: $msg = "The cloaking device has been manually enabled in the bot (you must still enable the cloak if it's disabled).";
105: }
106:
107: $sendto->reply($msg);
108: }
109:
110: 111: 112: 113:
114: public function recordCloakChangesEvent($eventObj) {
115: if (!$this->util->isValidSender($eventObj->sender) && preg_match("/^(.+) turned the cloaking device in your city (on|off).$/i", $eventObj->message, $arr)) {
116: $this->db->exec("INSERT INTO org_city_<myname> (`time`, `action`, `player`) VALUES (?, ?, ?)", time(), $arr[2], $arr[1]);
117: }
118: }
119:
120: 121: 122: 123:
124: public function checkTimerEvent($eventObj) {
125: $row = $this->db->queryRow("SELECT * FROM org_city_<myname> ORDER BY `time` DESC LIMIT 1");
126: if ($row !== null) {
127: $timeSinceChange = time() - $row->time;
128: if ($row->action == "off") {
129:
130:
131: $interval = $this->settingManager->get('cloak_reminder_interval');
132: if ($timeSinceChange >= 60*60 && ($timeSinceChange % $interval >= 0 && $timeSinceChange % $interval <= 60 )) {
133: $timeString = $this->util->unixtimeToReadable(time() - $row->time, false);
134: $this->chatBot->sendGuild("The cloaking device was disabled by <highlight>{$row->player}<end> $timeString ago. It is possible to enable it.");
135: }
136: } else if ($row->action == "on") {
137: if ($timeSinceChange >= 60*60 && $timeSinceChange < 61*60) {
138: $this->chatBot->sendGuild("The cloaking device was enabled one hour ago. Alien attacks can now be initiated.");
139: }
140: }
141: }
142: }
143:
144: 145: 146: 147:
148: public function cloakReminderEvent($eventObj) {
149:
150: $row = $this->db->queryRow("SELECT * FROM org_city_<myname> WHERE `action` = 'on' OR `action` = 'off' ORDER BY `time` DESC LIMIT 1");
151: if ($row !== null) {
152: $msg = "";
153:
154: if ($row->action == "off") {
155: $timeSinceChange = time() - $row->time;
156: $timeString = $this->util->unixtimeToReadable(3600 - $timeSinceChange, false);
157:
158:
159: if ($timeSinceChange >= 49*60 && $timeSinceChange <= 50*60) {
160: $msg = "The cloaking device is <orange>disabled<end>. It is possible in $timeString to enable it.";
161: } else if ($timeSinceChange >= 58*60 && $timeSinceChange <= 59*60) {
162:
163: $msg = "The cloaking device is <orange>disabled<end>. It is possible in $timeString to enable it.";
164: } else if ($timeSinceChange >= 59*60 && ($timeSinceChange % (60*5) >= 0 && $timeSinceChange % (60*5) <= 60 )) {
165:
166:
167: $msg = "The cloaking device is <orange>disabled<end>. Please enable it now.";
168: }
169:
170: if ($msg) {
171:
172: $altInfo = $this->altsController->getAltInfo($row->player);
173: forEach ($altInfo->getOnlineAlts() as $name) {
174: $this->chatBot->sendTell($msg, $name);
175: }
176: }
177: }
178: }
179: }
180:
181: 182: 183: 184:
185: public function cityGuildLogonEvent($eventObj) {
186: if ($this->chatBot->isReady() && isset($this->chatBot->guildmembers[$eventObj->sender])) {
187: $row = $this->db->queryRow("SELECT * FROM org_city_<myname> WHERE `action` = 'on' OR `action` = 'off' ORDER BY `time` DESC LIMIT 0, 20 ");
188:
189: $case = 0;
190: if ($row !== null) {
191: $timeSinceChange = time() - $row->time;
192: $timeString = $this->util->unixtimeToReadable(3600 - $timeSinceChange, false);
193:
194: if ($timeSinceChange >= 60*60 && $row->action == "off") {
195: $case = 1;
196: $msg = "The cloaking device is <orange>disabled<end>. It is possible to enable it.";
197: } else if ($timeSinceChange < 60*30 && $row->action == "off") {
198: $case = 1;
199: $msg = "<red>RAID IN PROGRESS! DO NOT ENTER CITY!</red>";
200: } else if ($timeSinceChange < 60*60 && $row->action == "off") {
201: $msg = "Cloaking device is <orange>disabled<end>. It is possible in $timeString to enable it.";
202: $case = 1;
203: } else if ($timeSinceChange >= 60*60 && $row->action == "on") {
204: $msg = "The cloaking device is <green>enabled<end>. It is possible to disable it.";
205: $case = 2;
206: } else if ($timeSinceChange < 60*60 && $row->action == "on") {
207: $msg = "The cloaking device is <green>enabled<end>. It is possible in $timeString to disable it.";
208: $case = 2;
209: } else {
210: $msg = "Unknown status on city cloak!";
211: $case = 1;
212: }
213:
214: if ($case <= $this->settingManager->get("showcloakstatus")) {
215: $this->chatBot->sendTell($msg, $eventObj->sender);
216: }
217: }
218: }
219: }
220: }
221: