|
@@ -31,10 +31,11 @@ import (
|
31
|
31
|
)
|
32
|
32
|
|
33
|
33
|
var (
|
|
34
|
+ // common error line to sub values into
|
|
35
|
+ errorMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "%s ")}[0]).Line()
|
|
36
|
+
|
34
|
37
|
// common error responses
|
35
|
|
- tooManyClientsMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Too many clients from your network")}[0]).Line()
|
36
|
|
- couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
|
37
|
|
- bannedFromServerMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "You are banned from this server (%s)")}[0]).Line()
|
|
38
|
+ couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
|
38
|
39
|
)
|
39
|
40
|
|
40
|
41
|
const (
|
|
@@ -275,7 +276,8 @@ func (server *Server) Run() {
|
275
|
276
|
|
276
|
277
|
isBanned, banMsg := server.checkBans(ipaddr)
|
277
|
278
|
if isBanned {
|
278
|
|
- conn.Conn.Write(banMsg)
|
|
279
|
+ // this might not show up properly on some clients, but our objective here is just to close the connection out before it has a load impact on us
|
|
280
|
+ conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
|
279
|
281
|
conn.Conn.Close()
|
280
|
282
|
continue
|
281
|
283
|
}
|
|
@@ -289,11 +291,11 @@ func (server *Server) Run() {
|
289
|
291
|
}
|
290
|
292
|
}
|
291
|
293
|
|
292
|
|
-func (server *Server) checkBans(ipaddr net.IP) (banned bool, message []byte) {
|
|
294
|
+func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
293
|
295
|
// check DLINEs
|
294
|
296
|
isBanned, info := server.dlines.CheckIP(ipaddr)
|
295
|
297
|
if isBanned {
|
296
|
|
- return true, []byte(info.BanMessage(bannedFromServerMsg))
|
|
298
|
+ return true, info.BanMessage("You are banned from this server (%s)")
|
297
|
299
|
}
|
298
|
300
|
|
299
|
301
|
// check connection limits
|
|
@@ -302,8 +304,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message []byte) {
|
302
|
304
|
server.connectionLimitsMutex.Unlock()
|
303
|
305
|
if err != nil {
|
304
|
306
|
// too many connections from one client, tell the client and close the connection
|
305
|
|
- // this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
|
306
|
|
- return true, []byte(tooManyClientsMsg)
|
|
307
|
+ return true, "Too many clients from your network"
|
307
|
308
|
}
|
308
|
309
|
|
309
|
310
|
// check connection throttle
|
|
@@ -323,10 +324,10 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message []byte) {
|
323
|
324
|
server.connectionThrottle.ResetFor(ipaddr)
|
324
|
325
|
|
325
|
326
|
// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
|
326
|
|
- return true, []byte(server.connectionThrottle.BanMessageBytes)
|
|
327
|
+ return true, server.connectionThrottle.BanMessage
|
327
|
328
|
}
|
328
|
329
|
|
329
|
|
- return false, nil
|
|
330
|
+ return false, ""
|
330
|
331
|
}
|
331
|
332
|
|
332
|
333
|
//
|
|
@@ -2196,7 +2197,7 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
2196
|
2197
|
|
2197
|
2198
|
isBanned, banMsg := server.checkBans(parsedProxiedIP)
|
2198
|
2199
|
if isBanned {
|
2199
|
|
- client.Quit(string(banMsg))
|
|
2200
|
+ client.Quit(banMsg)
|
2200
|
2201
|
return true
|
2201
|
2202
|
}
|
2202
|
2203
|
|