summaryrefslogtreecommitdiff
path: root/chat/rooms.go
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-03-27 12:28:20 +0100
committerKevin Chabowski <kevin@kch42.de>2014-03-27 23:51:07 +0100
commit7206812e266df8d57cd6628e22b9049b6517ebb8 (patch)
tree205b05c9b8def160bbe3a7fd07e363abb64195af /chat/rooms.go
parentdfd11c94c1ad5261caa43128a39fcce550edf61d (diff)
downloadsimplechat-7206812e266df8d57cd6628e22b9049b6517ebb8.tar.gz
simplechat-7206812e266df8d57cd6628e22b9049b6517ebb8.tar.bz2
simplechat-7206812e266df8d57cd6628e22b9049b6517ebb8.zip
Forbid empty nicknames
Diffstat (limited to 'chat/rooms.go')
-rw-r--r--chat/rooms.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/chat/rooms.go b/chat/rooms.go
index 1991d77..793f027 100644
--- a/chat/rooms.go
+++ b/chat/rooms.go
@@ -7,6 +7,7 @@ import (
var (
NickAlreadyInUse = errors.New("Nickname is already in use")
RoomIsFull = errors.New("Room is full")
+ EmptyNick = errors.New("Nickname must not be empty")
)
// Room represents a chatroom.
@@ -31,6 +32,7 @@ func (r *Room) leave(nick string) {
}
delete(r.buddies, nick)
+
if len(r.buddies) == 0 {
close(r.messages)
delete(rooms, r.name)
@@ -81,6 +83,10 @@ func Join(room, nick string) (*Buddy, *Room, error) {
return nil, nil, NickAlreadyInUse
}
+ if nick == "" {
+ return nil, nil, EmptyNick
+ }
+
if len(r.buddies) >= perroom {
return nil, nil, RoomIsFull
}