summaryrefslogtreecommitdiffstats
path: root/irc/irc.go
diff options
context:
space:
mode:
authorRobert Gerus <arachnist@i.am-a.cat>2015-12-23 20:26:57 +0100
committerRobert Gerus <arachnist@i.am-a.cat>2015-12-23 20:26:57 +0100
commita7eefc7daf05bae8e83ef96f65b288215459f7a6 (patch)
treecf79b5a4eb1b21f01f29aac6ac3f930b885d89d0 /irc/irc.go
parent09286f3defa2f9368b645a4905a19cb0f521dafd (diff)
downloadgorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.tar.gz
gorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.tar.bz2
gorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.tar.xz
gorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.zip
Give explicit notice on message truncation.
Fixes #1
Diffstat (limited to 'irc/irc.go')
-rw-r--r--irc/irc.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/irc/irc.go b/irc/irc.go
index 24f9d3d..b4505af 100644
--- a/irc/irc.go
+++ b/irc/irc.go
@@ -11,6 +11,7 @@ import (
"net"
"sync"
"time"
+ "unicode/utf8"
"github.com/arachnist/dyncfg"
)
@@ -39,9 +40,28 @@ 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
+ }
+ }
+ } else {
+ c.writer.WriteString(msg.String() + endline)
+ log.Println(c.network, "-->", msg.String())
+ c.writer.Flush()
+ }
}
// Receiver receives IRC messages from server, logs their contents, sets message