diff --git a/daemon.go b/daemon.go index 80a3229..57797c7 100644 --- a/daemon.go +++ b/daemon.go @@ -258,7 +258,7 @@ func HandlerJoin(client *Client, cmd string) { } for roomExisting, roomSink = range roomSinks { if room == *roomExisting.name { - if (roomExisting.key != nil) && (*roomExisting.key != key) { + if (*roomExisting.key != "") && (*roomExisting.key != key) { goto Denied } roomSink <- ClientEvent{client, EventNew, ""} diff --git a/room.go b/room.go index 3da5a3d..2a5f22a 100644 --- a/room.go +++ b/room.go @@ -53,9 +53,11 @@ func (room Room) String() string { func NewRoom(name string) *Room { topic := "" + key := "" return &Room{ name: &name, topic: &topic, + key: &key, members: make(map[*Client]struct{}), } } @@ -79,11 +81,7 @@ func (room *Room) Broadcast(msg string, clientToIgnore ...*Client) { } func (room *Room) StateSave() { - var key string - if room.key != nil { - key = *room.key - } - stateSink <- StateEvent{*room.name, *room.topic, key} + stateSink <- StateEvent{*room.name, *room.topic, *room.key} } func (room *Room) Processor(events <-chan ClientEvent) { @@ -155,7 +153,7 @@ func (room *Room) Processor(events <-chan ClientEvent) { case EventMode: if event.text == "" { mode := "+" - if room.key != nil { + if *room.key != "" { mode = mode + "k" } client.Msg(fmt.Sprintf("324 %s %s %s", *client.nickname, *room.name, mode)) @@ -186,7 +184,8 @@ func (room *Room) Processor(events <-chan ClientEvent) { msg = fmt.Sprintf(":%s MODE %s +k %s", client, *room.name, *room.key) msgLog = "set channel key to " + *room.key } else { - room.key = nil + key := "" + room.key = &key msg = fmt.Sprintf(":%s MODE %s -k", client, *room.name) msgLog = "removed channel key" } diff --git a/room_test.go b/room_test.go index 342e58c..8d6decc 100644 --- a/room_test.go +++ b/room_test.go @@ -222,7 +222,7 @@ func TestJoin(t *testing.T) { if r := <-conn.outbound; r != ":nick2!foo2@someclient MODE #barenc -k\r\n" { t.Fatal("remove #barenc key", r) } - if rooms["#barenc"].key != nil { + if *rooms["#barenc"].key != "" { t.Fatal("removing key from #barenc") } if r := <-logSink; (r.what != "removed channel key") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {