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 {
if room == *roomExisting.name {
if (roomExisting.key != nil) && (*roomExisting.key != key) {
if (*roomExisting.key != "") && (*roomExisting.key != key) {
goto Denied
}
roomSink <- ClientEvent{client, EventNew, ""}

13
room.go
View File

@ -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"
}

View File

@ -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) {