]> Cypherpunks.ru repositories - goircd.git/blobdiff - room.go
Additional unittests
[goircd.git] / room.go
diff --git a/room.go b/room.go
index 9e1900206c71bc6be54af15526458798d6deb199..87b35f60b18a69e1f785b4ace86cb693335a252e 100644 (file)
--- a/room.go
+++ b/room.go
@@ -25,12 +25,14 @@ import (
        "strings"
 )
 
+var (
+       RE_ROOM = regexp.MustCompile("^#[^\x00\x07\x0a\x0d ,:/]{1,200}$")
+)
+
 // Sanitize room's name. It can consist of 1 to 50 ASCII symbols
 // with some exclusions. All room names will have "#" prefix.
-func RoomNameSanitize(name string) (n string, valid bool) {
-       n = strings.TrimLeft(strings.ToLower(name), "&#+!")
-       valid, _ = regexp.MatchString("^[^\x00\x07\x0a\x0d ,:/]{1,50}$", n)
-       return "#" + n, valid
+func RoomNameValid(name string) bool {
+       return RE_ROOM.MatchString(name)
 }
 
 type Room struct {
@@ -85,7 +87,7 @@ func (room *Room) Processor(events chan ClientEvent) {
                        room.members[client] = true
                        log.Println(client, "joined", room.name)
                        room.SendTopic(client)
-                       go room.Broadcast(fmt.Sprintf(":%s JOIN %s", client, room.name))
+                       room.Broadcast(fmt.Sprintf(":%s JOIN %s", client, room.name))
                        room.log_sink <- LogEvent{room.name, client.nickname, "joined", true}
                        nicknames := []string{}
                        for member := range room.members {
@@ -161,7 +163,7 @@ func (room *Room) Processor(events chan ClientEvent) {
                        room.StateSave()
                case EVENT_MSG:
                        sep := strings.Index(event.text, " ")
-                       go room.Broadcast(fmt.Sprintf(":%s %s %s :%s", client, event.text[:sep], room.name, event.text[sep+1:]), client)
+                       room.Broadcast(fmt.Sprintf(":%s %s %s :%s", client, event.text[:sep], room.name, event.text[sep+1:]), client)
                        room.log_sink <- LogEvent{room.name, client.nickname, event.text[sep+1:], false}
                }
        }