We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php declare(strict_types=1); |
||||
2 | |||||
3 | use Smr\Database; |
||||
4 | use Smr\Irc\CallbackEvent; |
||||
5 | |||||
6 | /** |
||||
7 | * Very important! |
||||
8 | * If we do not answer the ping from server we will be disconnected |
||||
9 | * |
||||
10 | * @param resource $fp |
||||
11 | */ |
||||
12 | function server_ping($fp, string $rdata): bool { |
||||
13 | global $last_ping; |
||||
14 | |||||
15 | if (preg_match('/^PING\s:(.*)\s/i', $rdata, $msg)) { |
||||
16 | |||||
17 | $server = $msg[1]; |
||||
18 | |||||
19 | // remember the last time we got a ping from the server |
||||
20 | $last_ping = time(); |
||||
21 | |||||
22 | // This message is very spammy |
||||
23 | if (defined('IRC_BOT_VERBOSE_PING') && IRC_BOT_VERBOSE_PING) { |
||||
24 | echo_r('[PING] from ' . $server); |
||||
25 | } |
||||
26 | |||||
27 | fwrite($fp, 'PONG ' . $server . EOL); |
||||
28 | return true; |
||||
29 | } |
||||
30 | |||||
31 | return false; |
||||
32 | } |
||||
33 | |||||
34 | /** |
||||
35 | * Part of a whois msg |
||||
36 | * |
||||
37 | * @param resource $fp |
||||
38 | */ |
||||
39 | function server_msg_307($fp, string $rdata): bool { |
||||
0 ignored issues
–
show
|
|||||
40 | |||||
41 | // :alpha.theairlock.net 307 Caretaker MrSpock :is identified for this nick |
||||
42 | if (preg_match('/^:(.*) 307 ' . IRC_BOT_NICK . ' (.*) :is identified for this nick\s/i', $rdata, $msg)) { |
||||
43 | |||||
44 | $server = $msg[1]; |
||||
45 | $nick = $msg[2]; |
||||
46 | |||||
47 | echo_r('[SERVER_307] ' . $server . ' said that ' . $nick . ' is registered'); |
||||
48 | |||||
49 | $db = Database::getInstance(); |
||||
50 | $dbResult = $db->read('SELECT * FROM irc_seen WHERE nick = ' . $db->escapeString($nick)); |
||||
51 | foreach ($dbResult->records() as $dbRecord) { |
||||
52 | $seen_id = $dbRecord->getInt('seen_id'); |
||||
53 | |||||
54 | $db->write('UPDATE irc_seen SET ' . |
||||
55 | 'registered = 1 ' . |
||||
56 | 'WHERE seen_id = ' . $seen_id); |
||||
57 | } |
||||
58 | |||||
59 | return true; |
||||
60 | } |
||||
61 | |||||
62 | return false; |
||||
63 | } |
||||
64 | |||||
65 | /** |
||||
66 | * End of whois list |
||||
67 | * |
||||
68 | * @param resource $fp |
||||
69 | */ |
||||
70 | function server_msg_318($fp, string $rdata): bool { |
||||
71 | |||||
72 | // :ice.coldfront.net 318 Caretaker MrSpock :End of /WHOIS list. |
||||
73 | if (preg_match('/^:(.*) 318 ' . IRC_BOT_NICK . ' (.*) :End of \/WHOIS list\.\s/i', $rdata, $msg)) { |
||||
74 | |||||
75 | $server = $msg[1]; |
||||
76 | $nick = $msg[2]; |
||||
77 | |||||
78 | echo_r('[SERVER_318] ' . $server . ' end of /WHOIS for ' . $nick); |
||||
79 | |||||
80 | $db = Database::getInstance(); |
||||
81 | |||||
82 | $dbResult = $db->read('SELECT * FROM irc_seen WHERE nick = ' . $db->escapeString($nick) . ' AND registered IS NULL'); |
||||
83 | foreach ($dbResult->records() as $dbRecord) { |
||||
84 | $seen_id = $dbRecord->getInt('seen_id'); |
||||
85 | |||||
86 | $db->write('UPDATE irc_seen SET ' . |
||||
87 | 'registered = 0 ' . |
||||
88 | 'WHERE seen_id = ' . $seen_id); |
||||
89 | } |
||||
90 | |||||
91 | foreach (CallbackEvent::getAll() as $event) { |
||||
92 | |||||
93 | // is that a callback for our nick? |
||||
94 | if ($event->type == 'MSG_318' && $event->nick == $nick) { |
||||
95 | |||||
96 | CallbackEvent::remove($event); |
||||
97 | |||||
98 | // so we should do a callback but need to check first if the guy has registered |
||||
99 | $dbResult = $db->read('SELECT 1 FROM irc_seen WHERE nick = ' . $db->escapeString($nick) . ' AND registered = 1 AND channel = ' . $db->escapeString($event->channel)); |
||||
100 | if ($dbResult->hasRecord()) { |
||||
101 | //Forward to a NICKSERV INFO call. |
||||
102 | fwrite($fp, 'NICKSERV INFO ' . $nick . EOL); |
||||
103 | CallbackEvent::add(new CallbackEvent( |
||||
104 | type: 'NICKSERV_INFO', |
||||
105 | channel: $event->channel, |
||||
106 | nick: $event->nick, |
||||
107 | callback: $event->callback, |
||||
108 | time: time(), |
||||
109 | validate: $event->validate |
||||
110 | )); |
||||
111 | } elseif ($event->validate) { |
||||
112 | fwrite($fp, 'PRIVMSG ' . $event->channel . ' :' . $nick . ', you are not using a registered nick. Please identify with NICKSERV and try the last command again.' . EOL); |
||||
113 | } |
||||
114 | |||||
115 | } |
||||
116 | |||||
117 | } |
||||
118 | |||||
119 | return true; |
||||
120 | } |
||||
121 | |||||
122 | return false; |
||||
123 | } |
||||
124 | |||||
125 | /** |
||||
126 | * Response to WHO |
||||
127 | * |
||||
128 | * @param resource $fp |
||||
129 | */ |
||||
130 | function server_msg_352($fp, string $rdata): bool { |
||||
0 ignored issues
–
show
The parameter
$fp is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
131 | |||||
132 | // :ice.coldfront.net 352 Caretaker #KMFDM caretaker coldfront-425DB813.dip.t-dialin.net ice.coldfront.net Caretaker Hr :0 Official SMR bot |
||||
133 | if (preg_match('/^:(.*?) 352 ' . IRC_BOT_NICK . ' (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?)$/i', $rdata, $msg)) { |
||||
134 | |||||
135 | $channel = $msg[2]; |
||||
136 | $user = $msg[3]; |
||||
137 | $host = $msg[4]; |
||||
138 | $nick = $msg[6]; |
||||
139 | |||||
140 | echo_r('[WHO] ' . $channel . ': ' . $nick); |
||||
141 | |||||
142 | $db = Database::getInstance(); |
||||
143 | |||||
144 | // check if we have seen this user before |
||||
145 | $dbResult = $db->read('SELECT * FROM irc_seen WHERE nick = ' . $db->escapeString($nick) . ' AND channel = ' . $db->escapeString($channel)); |
||||
146 | |||||
147 | if ($dbResult->hasRecord()) { |
||||
148 | // exiting nick? |
||||
149 | $seen_id = $dbResult->record()->getInt('seen_id'); |
||||
150 | |||||
151 | $db->write('UPDATE irc_seen SET ' . |
||||
152 | 'signed_on = ' . time() . ', ' . |
||||
153 | 'signed_off = 0, ' . |
||||
154 | 'user = ' . $db->escapeString($user) . ', ' . |
||||
155 | 'host = ' . $db->escapeString($host) . ', ' . |
||||
156 | 'registered = NULL ' . |
||||
157 | 'WHERE seen_id = ' . $seen_id); |
||||
158 | |||||
159 | } else { |
||||
160 | // new nick? |
||||
161 | $db->insert('irc_seen', [ |
||||
162 | 'nick' => $db->escapeString($nick), |
||||
163 | 'user' => $db->escapeString($user), |
||||
164 | 'host' => $db->escapeString($host), |
||||
165 | 'channel' => $db->escapeString($channel), |
||||
166 | 'signed_on' => $db->escapeNumber(time()), |
||||
167 | ]); |
||||
168 | } |
||||
169 | |||||
170 | return true; |
||||
171 | } |
||||
172 | |||||
173 | return false; |
||||
174 | } |
||||
175 | |||||
176 | /** |
||||
177 | * Unknown user |
||||
178 | * |
||||
179 | * @param resource $fp |
||||
180 | */ |
||||
181 | function server_msg_401($fp, string $rdata): bool { |
||||
0 ignored issues
–
show
The parameter
$fp is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
182 | |||||
183 | // :ice.coldfront.net 401 Caretaker MrSpock :No such nick/channel |
||||
184 | if (preg_match('/^:(.*) 401 ' . IRC_BOT_NICK . ' (.*) :No such nick\/channel\s/i', $rdata, $msg)) { |
||||
185 | |||||
186 | $server = $msg[1]; |
||||
187 | $nick = $msg[2]; |
||||
188 | |||||
189 | echo_r('[SERVER_401] ' . $server . ' said: "No such nick/channel" for ' . $nick); |
||||
190 | |||||
191 | $db = Database::getInstance(); |
||||
192 | |||||
193 | // get the user in question |
||||
194 | $dbResult = $db->read('SELECT * FROM irc_seen WHERE nick = ' . $db->escapeString($nick) . ' AND signed_off = 0'); |
||||
195 | if ($dbResult->hasRecord()) { |
||||
196 | $seen_id = $dbResult->record()->getInt('seen_id'); |
||||
197 | |||||
198 | // maybe he left without us noticing, so we fix this now |
||||
199 | $db->write('UPDATE irc_seen SET ' . |
||||
200 | 'signed_off = ' . time() . ', ' . |
||||
201 | 'WHERE seen_id = ' . $seen_id); |
||||
202 | |||||
203 | } |
||||
204 | |||||
205 | return true; |
||||
206 | } |
||||
207 | |||||
208 | return false; |
||||
209 | } |
||||
210 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.