summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2015-10-13 09:37:03 +0300
committerSergey Matveev <stargrave@stargrave.org>2015-10-13 09:37:03 +0300
commit158ab243b29e99bfbe7a78ee48662fb132b47704 (patch)
tree75f02b080524d770a1dd282e129f2f6ee1ecb22c
parent3cee88801ca07e8d17ed86a5ca46c759329a11e8 (diff)
downloadgoircd-158ab243b29e99bfbe7a78ee48662fb132b47704.tar.xz
Fixed unkeyed room mode getting
-rw-r--r--daemon.go2
-rw-r--r--room.go13
-rw-r--r--room_test.go2
3 files changed, 8 insertions, 9 deletions
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) {