summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Gerus <arachnist@i.am-a.cat>2015-12-23 20:57:31 +0100
committerRobert Gerus <arachnist@i.am-a.cat>2015-12-23 20:57:31 +0100
commit4998f0b548eb00ad92ed696f7e34cb746d5b4293 (patch)
tree0d0e60467996b1a3eb12d085ed83f1abce0314d7
parent95e143e1c646dcfce1c8a9823e38b6683564f656 (diff)
downloadgorepost-4998f0b548eb00ad92ed696f7e34cb746d5b4293.tar.gz
gorepost-4998f0b548eb00ad92ed696f7e34cb746d5b4293.tar.bz2
gorepost-4998f0b548eb00ad92ed696f7e34cb746d5b4293.zip
Last change was overcomplicated.
-rw-r--r--irc/irc.go27
-rw-r--r--irc/message.go5
2 files changed, 12 insertions, 20 deletions
diff --git a/irc/irc.go b/irc/irc.go
index b4505af..cbcc337 100644
--- a/irc/irc.go
+++ b/irc/irc.go
@@ -11,7 +11,6 @@ import (
"net"
"sync"
"time"
- "unicode/utf8"
"github.com/arachnist/dyncfg"
)
@@ -40,27 +39,15 @@ type Connection struct {
func (c *Connection) Sender(msg Message) {
c.l.Lock()
defer c.l.Unlock()
+ c.writer.WriteString(msg.String() + endline)
+ log.Println(c.network, "-->", msg.String())
+ c.writer.Flush()
if msg.WireLen() > maxLength {
- currLen := 0
- for i, ch := range msg.String() {
- currLen += utf8.RuneLen(ch)
- if currLen > maxLength {
- c.writer.WriteString(msg.String()[:i] + endline)
- log.Println(c.network, "-->", msg.String())
- c.writer.Flush()
- // eh, it is a bit naive to assume that we won't explode again…
- if msg.Command == "PRIVMSG" { // we don't care otherwise
- newMsg := msg
- newMsg.Trailing = "Message truncated"
- go c.Sender(newMsg)
- }
- return
- }
+ if msg.Command == "PRIVMSG" { // we don't care otherwise
+ newMsg := msg
+ newMsg.Trailing = "Message truncated"
+ go c.Sender(newMsg)
}
- } else {
- c.writer.WriteString(msg.String() + endline)
- log.Println(c.network, "-->", msg.String())
- c.writer.Flush()
}
}
diff --git a/irc/message.go b/irc/message.go
index e1d448b..8d98ae8 100644
--- a/irc/message.go
+++ b/irc/message.go
@@ -288,6 +288,11 @@ func (m *Message) Bytes() []byte {
buffer.WriteString(m.Trailing)
}
+ // We need the limit the buffer length.
+ if buffer.Len() > (maxLength) {
+ buffer.Truncate(maxLength)
+ }
+
return buffer.Bytes()
}