From 7206812e266df8d57cd6628e22b9049b6517ebb8 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 27 Mar 2014 12:28:20 +0100 Subject: Forbid empty nicknames --- chat/rooms.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'chat/rooms.go') 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 } -- cgit v1.2.3-54-g00ecf