Fixed unkeyed room mode getting

This commit is contained in:
Sergey Matveev 2015-10-13 09:37:03 +03:00
parent 3cee88801c
commit 158ab243b2
3 changed files with 8 additions and 9 deletions

View File

@ -258,7 +258,7 @@ func HandlerJoin(client *Client, cmd string) {
} }
for roomExisting, roomSink = range roomSinks { for roomExisting, roomSink = range roomSinks {
if room == *roomExisting.name { if room == *roomExisting.name {
if (roomExisting.key != nil) && (*roomExisting.key != key) { if (*roomExisting.key != "") && (*roomExisting.key != key) {
goto Denied goto Denied
} }
roomSink <- ClientEvent{client, EventNew, ""} roomSink <- ClientEvent{client, EventNew, ""}

13
room.go
View File

@ -53,9 +53,11 @@ func (room Room) String() string {
func NewRoom(name string) *Room { func NewRoom(name string) *Room {
topic := "" topic := ""
key := ""
return &Room{ return &Room{
name: &name, name: &name,
topic: &topic, topic: &topic,
key: &key,
members: make(map[*Client]struct{}), members: make(map[*Client]struct{}),
} }
} }
@ -79,11 +81,7 @@ func (room *Room) Broadcast(msg string, clientToIgnore ...*Client) {
} }
func (room *Room) StateSave() { func (room *Room) StateSave() {
var key string stateSink <- StateEvent{*room.name, *room.topic, *room.key}
if room.key != nil {
key = *room.key
}
stateSink <- StateEvent{*room.name, *room.topic, key}
} }
func (room *Room) Processor(events <-chan ClientEvent) { func (room *Room) Processor(events <-chan ClientEvent) {
@ -155,7 +153,7 @@ func (room *Room) Processor(events <-chan ClientEvent) {
case EventMode: case EventMode:
if event.text == "" { if event.text == "" {
mode := "+" mode := "+"
if room.key != nil { if *room.key != "" {
mode = mode + "k" mode = mode + "k"
} }
client.Msg(fmt.Sprintf("324 %s %s %s", *client.nickname, *room.name, mode)) 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) msg = fmt.Sprintf(":%s MODE %s +k %s", client, *room.name, *room.key)
msgLog = "set channel key to " + *room.key msgLog = "set channel key to " + *room.key
} else { } else {
room.key = nil key := ""
room.key = &key
msg = fmt.Sprintf(":%s MODE %s -k", client, *room.name) msg = fmt.Sprintf(":%s MODE %s -k", client, *room.name)
msgLog = "removed channel key" msgLog = "removed channel key"
} }

View File

@ -222,7 +222,7 @@ func TestJoin(t *testing.T) {
if r := <-conn.outbound; r != ":nick2!foo2@someclient MODE #barenc -k\r\n" { if r := <-conn.outbound; r != ":nick2!foo2@someclient MODE #barenc -k\r\n" {
t.Fatal("remove #barenc key", r) t.Fatal("remove #barenc key", r)
} }
if rooms["#barenc"].key != nil { if *rooms["#barenc"].key != "" {
t.Fatal("removing key from #barenc") t.Fatal("removing key from #barenc")
} }
if r := <-logSink; (r.what != "removed channel key") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) { if r := <-logSink; (r.what != "removed channel key") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {