]> Cypherpunks.ru repositories - goircd.git/blobdiff - daemon.go
ISON command support
[goircd.git] / daemon.go
index 80a3229b4f7ec9735617d5b9835c5a76f7c4c80f..1af9712616a383ad1a3b869bf3143e85756dd037 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -67,7 +67,7 @@ func SendMotd(client *Client) {
                return
        }
        client.ReplyNicknamed("375", "- "+*hostname+" Message of the day -")
-       for _, s := range strings.Split(strings.Trim(string(motdText), "\n"), "\n") {
+       for _, s := range strings.Split(strings.TrimSuffix(string(motdText), "\n"), "\n") {
                client.ReplyNicknamed("372", "- "+s)
        }
        client.ReplyNicknamed("376", "End of /MOTD command")
@@ -162,6 +162,7 @@ func ClientRegister(client *Client, cmd string, cols []string) {
                nickname := cols[1]
                // Compatibility with some clients prepending colons to nickname
                nickname = strings.TrimPrefix(nickname, ":")
+               nickname = strings.ToLower(nickname)
                for existingClient := range clients {
                        if *existingClient.nickname == nickname {
                                client.ReplyParts("433", "*", nickname, "Nickname is already in use")
@@ -258,7 +259,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, ""}
@@ -308,6 +309,14 @@ func Processor(events chan ClientEvent, finished chan struct{}) {
                                        }
                                }
                        }
+                       for rn, r := range rooms {
+                               if *statedir == "" && len(r.members) == 0 {
+                                       log.Println(rn, "emptied room")
+                                       delete(rooms, rn)
+                                       close(roomSinks[r])
+                                       delete(roomSinks, r)
+                               }
+                       }
                case EventTerm:
                        for _, sink := range roomSinks {
                                sink <- ClientEvent{eventType: EventTerm}
@@ -477,6 +486,22 @@ func Processor(events chan ClientEvent, finished chan struct{}) {
                                cols := strings.Split(cols[1], " ")
                                nicknames := strings.Split(cols[len(cols)-1], ",")
                                SendWhois(client, nicknames)
+                       case "ISON":
+                               if len(cols) == 1 || len(cols[1]) < 1 {
+                                       client.ReplyNotEnoughParameters("ISON")
+                                       continue
+                               }
+                               nicksKnown := make(map[string]struct{})
+                               for c := range clients {
+                                       nicksKnown[*c.nickname] = struct{}{}
+                               }
+                               var nicksExists []string
+                               for _, nickname := range strings.Split(cols[1], " ") {
+                                       if _, exists := nicksKnown[nickname]; exists {
+                                               nicksExists = append(nicksExists, nickname)
+                                       }
+                               }
+                               client.ReplyNicknamed("303", strings.Join(nicksExists, " "))
                        case "VERSION":
                                var debug string
                                if *verbose {