X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=daemon.go;h=a5b2d77dcd822d257132fe045cee53473bf89757;hp=487e5876ff5605d47db4adb93fd3734238affecf;hb=59a6cddf54c13b63990d2c1bdc708d6b9ddb5b5f;hpb=1331f317fba7c877c196b67eca6434d763b35d02 diff --git a/daemon.go b/daemon.go index 487e587..a5b2d77 100644 --- a/daemon.go +++ b/daemon.go @@ -35,6 +35,10 @@ const ( ALIVENESS_CHECK = time.Second * 10 // Client's aliveness check period ) +var ( + RE_NICKNAME = regexp.MustCompile("^[a-zA-Z0-9-]{1,9}$") +) + type Daemon struct { hostname string motd string @@ -80,7 +84,7 @@ func (daemon *Daemon) SendMotd(client *Client) { } client.ReplyNicknamed("375", "- "+daemon.hostname+" Message of the day -") - for _, s := range bytes.Split(motd, []byte("\n")) { + for _, s := range bytes.Split(bytes.TrimRight(motd, "\n"), []byte("\n")) { client.ReplyNicknamed("372", "- "+string(s)) } client.ReplyNicknamed("376", "End of /MOTD command") @@ -153,19 +157,16 @@ func (daemon *Daemon) ClientRegister(client *Client, command string, cols []stri client.ReplyParts("431", "No nickname given") return } - nickname := strings.ToLower(cols[1]) - nickname_found := false + nickname := cols[1] for client := range daemon.clients { if client.nickname == nickname { - nickname_found = true + client.ReplyParts("433", "*", nickname, "Nickname is already in use") + return } } - if nickname_found { - client.ReplyParts("433", "*", cols[1], "Nickname is already in use") - return - } - if ok, _ := regexp.MatchString("^[^_-][_a-z0-9-]{1,50}$", nickname); !ok { + if !RE_NICKNAME.MatchString(nickname) { client.ReplyParts("432", "*", cols[1], "Erroneous nickname") + return } client.nickname = nickname case "USER": @@ -213,8 +214,7 @@ func (daemon *Daemon) HandlerJoin(client *Client, cmd string) { keys = []string{} } for n, room := range rooms { - room, valid := RoomNameSanitize(room) - if !valid { + if !RoomNameValid(room) { client.ReplyNoChannel(room) continue } @@ -239,7 +239,6 @@ func (daemon *Daemon) HandlerJoin(client *Client, cmd string) { } if denied { client.ReplyNicknamed("475", room, "Cannot join channel (+k) - bad key") - continue } if denied || joined { continue @@ -247,6 +246,7 @@ func (daemon *Daemon) HandlerJoin(client *Client, cmd string) { room_new, room_sink := daemon.RoomRegister(room) if key != "" { room_new.key = key + room_new.StateSave() } room_sink <- ClientEvent{client, EVENT_NEW, ""} } @@ -326,7 +326,7 @@ func (daemon *Daemon) Processor(events chan ClientEvent) { } continue } - room, _ := RoomNameSanitize(cols[0]) + room := cols[0] r, found := daemon.rooms[room] if !found { client.ReplyNoChannel(room) @@ -345,10 +345,10 @@ func (daemon *Daemon) Processor(events chan ClientEvent) { continue } for _, room := range strings.Split(cols[1], ",") { - room, _ = RoomNameSanitize(room) r, found := daemon.rooms[room] if !found { client.ReplyNoChannel(room) + continue } daemon.room_sinks[r] <- ClientEvent{client, EVENT_DEL, ""} } @@ -382,7 +382,6 @@ func (daemon *Daemon) Processor(events chan ClientEvent) { if msg != "" { continue } - target, _ = RoomNameSanitize(target) r, found := daemon.rooms[target] if !found { client.ReplyNoNickChan(target) @@ -394,10 +393,10 @@ func (daemon *Daemon) Processor(events chan ClientEvent) { continue } cols = strings.SplitN(cols[1], " ", 2) - room, _ := RoomNameSanitize(cols[0]) - r, found := daemon.rooms[room] + r, found := daemon.rooms[cols[0]] if !found { - client.ReplyNoChannel(room) + client.ReplyNoChannel(cols[0]) + continue } var change string if len(cols) > 1 { @@ -411,10 +410,11 @@ func (daemon *Daemon) Processor(events chan ClientEvent) { client.ReplyNotEnoughParameters("WHO") continue } - room, _ := RoomNameSanitize(strings.Split(cols[1], " ")[0]) + room := strings.Split(cols[1], " ")[0] r, found := daemon.rooms[room] if !found { client.ReplyNoChannel(room) + continue } daemon.room_sinks[r] <- ClientEvent{client, EVENT_WHO, ""} case "WHOIS":