From 74f01b3117ae49d2d42facc362d8c932f5769d9d Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Tue, 25 Mar 2014 13:30:20 +0100 Subject: We need the room too when joining --- buddy.go | 5 +++++ rooms.go | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/buddy.go b/buddy.go index 0d1fb0c..750e424 100644 --- a/buddy.go +++ b/buddy.go @@ -3,8 +3,13 @@ package main type Buddy struct { Nick string Receive chan Message + room *Room } func NewBuddy(nick string, room *Room) *Buddy { // TODO: Implement me! } + +func (b *Buddy) Leave() { + b.room.Leave(b.Nick) +} diff --git a/rooms.go b/rooms.go index 6a5accd..e7512ee 100644 --- a/rooms.go +++ b/rooms.go @@ -42,7 +42,7 @@ func (r *Room) Broadcast() { var rooms = make(map[string]Room) -func Join(room, nick string) (*Buddy, error) { +func Join(room, nick string) (*Buddy, *Room, error) { r, ok := rooms[room] if !ok { r = NewRoom() @@ -50,11 +50,11 @@ func Join(room, nick string) (*Buddy, error) { } if _, there := r.Buddies[nick]; there { - return nil, errors.New("Nickname is already in use") + return nil, room, errors.New("Nickname is already in use") } if len(r.Buddies) >= *perroom { - return nil, errors.New("Room is full") + return nil, room, errors.New("Room is full") } r.Messages <- Message{ -- cgit v1.2.3-70-g09d2