Преглед на файлове

Merge pull request #1170 from slingamn/motd

fix #1167
tags/v2.2.0-rc1
Shivaram Lingamneni преди 4 години
родител
ревизия
e44fbc3845
No account linked to committer's email address
променени са 2 файла, в които са добавени 36 реда и са изтрити 31 реда
  1. 35
    1
      irc/config.go
  2. 1
    30
      irc/server.go

+ 35
- 1
irc/config.go Целия файл

@@ -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
+}

+ 1
- 30
irc/server.go Целия файл

@@ -6,7 +6,6 @@
6 6
 package irc
7 7
 
8 8
 import (
9
-	"bufio"
10 9
 	"fmt"
11 10
 	"net"
12 11
 	"net/http"
@@ -21,6 +20,7 @@ import (
21 20
 	"unsafe"
22 21
 
23 22
 	"github.com/goshuirc/irc-go/ircfmt"
23
+
24 24
 	"github.com/oragono/oragono/irc/caps"
25 25
 	"github.com/oragono/oragono/irc/connection_limits"
26 26
 	"github.com/oragono/oragono/irc/history"
@@ -667,35 +667,6 @@ func (server *Server) setupPprofListener(config *Config) {
667 667
 	}
668 668
 }
669 669
 
670
-func (config *Config) loadMOTD() (err error) {
671
-	if config.Server.MOTD != "" {
672
-		file, err := os.Open(config.Server.MOTD)
673
-		if err == nil {
674
-			defer file.Close()
675
-
676
-			reader := bufio.NewReader(file)
677
-			for {
678
-				line, err := reader.ReadString('\n')
679
-				if err != nil {
680
-					break
681
-				}
682
-				line = strings.TrimRight(line, "\r\n")
683
-
684
-				if config.Server.MOTDFormatting {
685
-					line = ircfmt.Unescape(line)
686
-				}
687
-
688
-				// "- " is the required prefix for MOTD, we just add it here to make
689
-				// bursting it out to clients easier
690
-				line = fmt.Sprintf("- %s", line)
691
-
692
-				config.Server.motdLines = append(config.Server.motdLines, line)
693
-			}
694
-		}
695
-	}
696
-	return
697
-}
698
-
699 670
 func (server *Server) loadDatastore(config *Config) error {
700 671
 	// open the datastore and load server state for which it (rather than config)
701 672
 	// is the source of truth

Loading…
Отказ
Запис