summaryrefslogtreecommitdiff
path: root/rooms.go
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-03-25 14:08:06 +0100
committerKevin Chabowski <kevin@kch42.de>2014-03-25 14:08:06 +0100
commit734f6e92016ca875ad56ff7e423a0872648c012f (patch)
treeb753861d68e32462af5d8cab445b77b9abcede0b /rooms.go
parent472848fc93accb200ea2dedc46fdaa4e5d71d266 (diff)
downloadsimplechat-734f6e92016ca875ad56ff7e423a0872648c012f.tar.gz
simplechat-734f6e92016ca875ad56ff7e423a0872648c012f.tar.bz2
simplechat-734f6e92016ca875ad56ff7e423a0872648c012f.zip
Fixed some compile errors
Diffstat (limited to 'rooms.go')
-rw-r--r--rooms.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/rooms.go b/rooms.go
index 723fc98..ff441f2 100644
--- a/rooms.go
+++ b/rooms.go
@@ -6,14 +6,15 @@ import (
type Room struct {
Messages chan Message
- Buddies map[string]Buddy
+ Buddies map[string]*Buddy
}
func NewRoom() (r *Room) {
r = new(Room)
r.Messages = make(chan Message)
- r.Buddies = make(map[string]Buddy)
+ r.Buddies = make(map[string]*Buddy)
go r.Broadcast()
+ return
}
func (r *Room) Leave(nick string) {
@@ -21,13 +22,13 @@ func (r *Room) Leave(nick string) {
return
}
- delete(r.Buddies[nick])
+ delete(r.Buddies, nick)
if len(r.Buddies) == 0 {
close(r.Messages)
} else {
r.Messages <- Message{
Type: MsgLeave,
- From: nick,
+ User: nick,
}
}
}
@@ -47,7 +48,7 @@ func (r *Room) ListBuddies() (buddies []string) {
return
}
-var rooms = make(map[string]Room)
+var rooms = make(map[string]*Room)
func Join(room, nick string) (*Buddy, *Room, error) {
r, ok := rooms[room]
@@ -57,19 +58,19 @@ func Join(room, nick string) (*Buddy, *Room, error) {
}
if _, there := r.Buddies[nick]; there {
- return nil, room, errors.New("Nickname is already in use")
+ return nil, nil, errors.New("Nickname is already in use")
}
if len(r.Buddies) >= *perroom {
- return nil, room, errors.New("Room is full")
+ return nil, nil, errors.New("Room is full")
}
r.Messages <- Message{
Type: MsgJoin,
- From: nick,
+ User: nick,
}
b := NewBuddy(nick, r)
r.Buddies[nick] = b
- return b, nil
+ return b, r, nil
}