summaryrefslogtreecommitdiff
path: root/chat/rooms.go
diff options
context:
space:
mode:
Diffstat (limited to 'chat/rooms.go')
-rw-r--r--chat/rooms.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/chat/rooms.go b/chat/rooms.go
index 793f027..849aeb8 100644
--- a/chat/rooms.go
+++ b/chat/rooms.go
@@ -8,6 +8,12 @@ var (
NickAlreadyInUse = errors.New("Nickname is already in use")
RoomIsFull = errors.New("Room is full")
EmptyNick = errors.New("Nickname must not be empty")
+ NickTooLong = errors.New("NIckname is too long")
+)
+
+const (
+ nickLenLimit = 16
+ msgLenLimit = 2000
)
// Room represents a chatroom.
@@ -46,6 +52,12 @@ func (r *Room) leave(nick string) {
func (r *Room) broadcast() {
for m := range r.messages {
+ if len(m.Text) > msgLenLimit {
+ text := []rune(m.Text)
+ text = text[:msgLenLimit]
+ m.Text = string(text) + " (message truncated. was too long)"
+ }
+
for _, buddy := range r.buddies {
buddy.Push(m)
}
@@ -87,6 +99,10 @@ func Join(room, nick string) (*Buddy, *Room, error) {
return nil, nil, EmptyNick
}
+ if len(nick) > nickLenLimit {
+ return nil, nil, NickTooLong
+ }
+
if len(r.buddies) >= perroom {
return nil, nil, RoomIsFull
}