-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgateway.php
267 lines (237 loc) · 7.29 KB
/
gateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
include "src/module.php";
include "gateway.config.php";
global $cf,$sql,$gw,$sql,$sqlip,$sqluser,$sqlpass,$sqldb,$server,$port,$batch;
// Server config
$server = $cf['serverip'];
$port = $cf['port'];
$me = $cf['nick'];
$myident = $cf['ident'];
$myhost = $cf['host'];
$mygecos = $cf['realname'];
$mypass = $cf['password'];
$caps = $cf['caps'];
// SQL config
$sqlip = $cf['sqlip'];
$sqluser = $cf['sqluser'];
$sqlpass = $cf['sqlpass'];
$sqldb = $cf['sqldb'];
start:
$gw = new Bot($server,$port,$me,$myident,$mygecos,$caps,$mypass);
$sql = new SQL($sqlip,$sqluser,$sqlpass,$sqldb);
hook::run("preconnect", array("parc" => NULL));
while ($socket) {
while ($input = fgets($socket, 1000)) {
if ($cf['debugmode'] == "on") { echo $input."\n"; }
flush();
$strippem = ircstrip(str_replace('\n','',str_replace('\r','',$input)));
$splittem = explode(' ',$strippem);
// If the server pings us
if ($splittem[0] == 'PING') {
// Ping it back
$gw->sendraw("PONG ".$splittem[1]);
hook::run("ping", array("ping" => $splittem[1]));
}
elseif ($splittem[0] == 'ERROR') {
hook::run("error", array("errstring" => $input));
if (strpos($input,'Throttled') !== false) {
$gw->hear("Uh-oh, we've been throttled! Waiting 40 seconds and starting again.");
sleep(40);
$gw->shout("Reconnecting...");
goto start;
}
elseif (strpos($input,'Timeout') !== false) {
$gw->hear("Hmmmm. It seems there was a problem. Please check config.conf that 'nick', 'ident' and 'realname' are correct");
die();
}
elseif (strpos($input,'brb lmoa') !== false) {
$gw->hear("Looks like we've been asked to restart! Lets go! Pewpewpew!");
goto start;
}
else {
$gw->hear("Unknown exit issue! Restarting");
goto start;
}
}
elseif ($splittem[0] != 'PING') {
//account for message-tags
$tagmsg = NULL;
if ($splittem[0][0] == '@'){
$tagmsg = $splittem[0];
$strippem = ltrim(str_replace($tagmsg,"",$strippem)," ");
$splittem = explode(" ",$strippem);
}
// Split our variables up into easy-to-use syntax imo tbh uno init anorl lmao
if (IsServer($splittem[0]) == 'true') { $nick = ltrim($splittem[0],':'); }
elseif (IsServer($splittem[0]) == 'false') {
$nick = get_string_between($splittem[0],':', '!');
$ident = get_string_between($splittem[0],'!', '@');
$hostmask = get_string_between($splittem[0].' ','@', ' ');
}
if (isset($splittem[2])) { $sp = $splittem[0].' '.$splittem[1].' '.$splittem[2]; }
if (isset($splittem[3])) {
$parc = ircstrip(ltrim(str_replace($sp,'',$strippem),' :'));
$parv = explode(' ',$parc);
$cmd = (!empty($splittem[3])) ? strtolower($parv[0]) : NULL;
$str = ($cmd !== 'NULL') ? str_replace($cmd,'',$parc) : NULL;
}
if (isset($splittem[2])) { $dest = ltrim($splittem[2],':'); }
$action = $splittem[1] ?? NULL;
$fullstr = $strippem;
/* Important variable description
**
** $nick represents nick of event trigger
** $ident represents ident of nick
** $hostmask represents hostmask of nick
**
** $action represents the type of action (PRIVMSG, JOIN, PART, QUIT, etc)
** $dest represents the place of the event trigger - for example, if ($dest == $me) <- Private message.
** or, if ($dest == '#staff') <- staff room
**
** $parc is the entire parameter string ($cmd + $str)
** $parv is an array of params in $parc
** $cmd is the first param in the input string ($parv[0]) (must be lowercase)
** $str is the string that follows after the $cmd ($parv[1], $parv[2] etc)
**
** $fullstr is the full RAW string from start to finish. (rarely used)
**
** To call an error, set $error = "Your error";
** An $error will abort the script and will be logged.
** Don't abort the script unless absolutely necessary!
**
** To call a warning, it's the same. $warning = "Your warning";
** A $warning will be outputted in your 'statchan' and the console and logged.
**
*/
// we gonna forward the whole string to the num4ric h00k
/* debugging area
$gw->shout("Nick: $nick");
$gw->shout("Action: $action");
$gw->shout("Parc: $parc");
*/
if (is_numeric($action)) {
hook::run("numeric", array("numeric" => $action, "parc" => $fullstr));
}
if ($fullstr == 'AUTHENTICATE +') {
hook::run("auth", array("nick" => $nick));
$gw->hear('The server wants us to send our login credentials.');
$gw->sasl($me,$mypass);
$gw->shout('Sent our login credentials. Fingers crossed!');
}
// if we sasl'd, end cap req fam
elseif ($action == 'CAP' && $cmd == 'ls'){
$gw->send_cap_req($str);
}
elseif ($action == '903' && $parc = "SASL authentication successful") { $gw->sendraw("CAP END"); }
elseif ($action == "001"){
hook::run("connect",array(
"nick" => $nick)
);
}
elseif ($action == "PRIVMSG"){
if (isset($batch) || strpos($tagmsg,$batch[$dest]) !== false && $cf['ignoreplayback'] == true){ goto end; }
hook::run("privmsg",array(
"nick" => $nick,
"ident" => $ident ?? 'NULL',
"hostmask" => $hostmask,
"dest" => $dest,
"parc" => $parc,
"mtags" => $tagmsg)
);
}
elseif ($action == "NOTICE"){
if (isset($tagmsg) || strpos($tagmsg,$batch[$dest]) !== false && $cf['ignoreplayback'] == true){ goto end; }
hook::run("notice",array(
"nick" => $nick,
"hostmask" => $hostmask ?? 'NULL',
"ident" => $ident ?? 'NULL',
"dest" => $dest,
"parc" => $parc,
"mtags" => $tagmsg)
);
}
elseif ($action == "JOIN"){
hook::run("join",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"dest" => $dest,
"mtags" => $tagmsg)
);
}
elseif ($action == "PART") {
hook::run("part",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"dest" => $dest,
"mtags" => $tagmsg)
);
}
elseif ($action == "QUIT") {
hook::run("quit",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"reason" => $parc,
"mtags" => $tagmsg)
);
}
elseif ($action == "MODE") {
hook::run("mode",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"dest" => $dest,
"parc" => $parc,
"mtags" => $tagmsg)
);
}
// only available if away-notify is in your caps
elseif ($action == "AWAY") {
hook::run("away",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"dest" => $dest,
"parc" => $parc,
"mtags" => $tagmsg)
);
}
elseif ($action == "CHGHOST"){
hook::run("chghost",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"dest" => $dest,
"parc" => $parc)
);
}
elseif ($action == "BATCH"){
hook::run("batch",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"parc" => $dest." ".$parc)
);
}
elseif ($action == "NICK"){
hook::run("batch",array(
"nick" => $nick,
"ident" => $ident,
"hostmask" => $hostmask,
"parc" => $parc)
);
}
}
end:
// variable cleanup.
$nick = NULL; $ident = NULL;
$hostmask = NULL; $parv = NULL;
$parc = NULL; $dest = NULL;
$cmd = NULL; $str = NULL;
$fullstr = NULL; $action = NULL;
$tagmsg = NULL;
}
}
?>