|
@@ -6,6 +6,7 @@
|
6
|
6
|
package irc
|
7
|
7
|
|
8
|
8
|
import (
|
|
9
|
+ "bytes"
|
9
|
10
|
"crypto/tls"
|
10
|
11
|
"errors"
|
11
|
12
|
"fmt"
|
|
@@ -21,6 +22,9 @@ import (
|
21
|
22
|
"time"
|
22
|
23
|
|
23
|
24
|
"code.cloudfoundry.org/bytefmt"
|
|
25
|
+ "github.com/goshuirc/irc-go/ircfmt"
|
|
26
|
+ "gopkg.in/yaml.v2"
|
|
27
|
+
|
24
|
28
|
"github.com/oragono/oragono/irc/caps"
|
25
|
29
|
"github.com/oragono/oragono/irc/cloaks"
|
26
|
30
|
"github.com/oragono/oragono/irc/connection_limits"
|
|
@@ -34,7 +38,6 @@ import (
|
34
|
38
|
"github.com/oragono/oragono/irc/mysql"
|
35
|
39
|
"github.com/oragono/oragono/irc/passwd"
|
36
|
40
|
"github.com/oragono/oragono/irc/utils"
|
37
|
|
- "gopkg.in/yaml.v2"
|
38
|
41
|
)
|
39
|
42
|
|
40
|
43
|
// here's how this works: exported (capitalized) members of the config structs
|
|
@@ -1305,3 +1308,34 @@ func compileGuestRegexp(guestFormat string, casemapping Casemapping) (standard,
|
1305
|
1308
|
folded, err = utils.CompileGlob(fmt.Sprintf("%s*%s", initialFolded, finalFolded), false)
|
1306
|
1309
|
return
|
1307
|
1310
|
}
|
|
1311
|
+
|
|
1312
|
+func (config *Config) loadMOTD() error {
|
|
1313
|
+ if config.Server.MOTD != "" {
|
|
1314
|
+ file, err := os.Open(config.Server.MOTD)
|
|
1315
|
+ if err != nil {
|
|
1316
|
+ return err
|
|
1317
|
+ }
|
|
1318
|
+ defer file.Close()
|
|
1319
|
+ contents, err := ioutil.ReadAll(file)
|
|
1320
|
+ if err != nil {
|
|
1321
|
+ return err
|
|
1322
|
+ }
|
|
1323
|
+
|
|
1324
|
+ lines := bytes.Split(contents, []byte{'\n'})
|
|
1325
|
+ for i, line := range lines {
|
|
1326
|
+ lineToSend := string(bytes.TrimRight(line, "\r\n"))
|
|
1327
|
+ if len(lineToSend) == 0 && i == len(lines)-1 {
|
|
1328
|
+ // if the last line of the MOTD was properly terminated with \n,
|
|
1329
|
+ // there's no need to send a blank line to clients
|
|
1330
|
+ continue
|
|
1331
|
+ }
|
|
1332
|
+ if config.Server.MOTDFormatting {
|
|
1333
|
+ lineToSend = ircfmt.Unescape(lineToSend)
|
|
1334
|
+ }
|
|
1335
|
+ // "- " is the required prefix for MOTD
|
|
1336
|
+ lineToSend = fmt.Sprintf("- %s", lineToSend)
|
|
1337
|
+ config.Server.motdLines = append(config.Server.motdLines, lineToSend)
|
|
1338
|
+ }
|
|
1339
|
+ }
|
|
1340
|
+ return nil
|
|
1341
|
+}
|