X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=daemon.go;h=1f979ce6ea4f7c4dd295c5f4924b8ab477bdd845;hp=1f142c2c13f9917c8e986627ff3529f560fd45aa;hb=41f96494948d1f9f1e0c3066099e0bd9ad0ee8dd;hpb=c1d256aaa0af4e0cb3649552e5067a9ec3bc94d5 diff --git a/daemon.go b/daemon.go index 1f142c2..1f979ce 100644 --- a/daemon.go +++ b/daemon.go @@ -18,11 +18,9 @@ along with this program. If not, see . package main import ( - "bytes" "fmt" - "io" + "io/ioutil" "log" - "os" "regexp" "sort" "strings" @@ -72,29 +70,23 @@ func (daemon *Daemon) SendLusers(client *Client) { } func (daemon *Daemon) SendMotd(client *Client) { - if daemon.motd != "" { - fd, err := os.Open(daemon.motd) - if err == nil { - defer fd.Close() - motd := []byte{} - var err error - for err != io.EOF { - buf := make([]byte, 1024) - _, err = fd.Read(buf) - motd = append(motd, bytes.TrimRight(buf, "\x00")...) - } + if len(daemon.motd) == 0 { + client.ReplyNicknamed("422", "MOTD File is missing") + return + } - client.ReplyNicknamed("375", "- "+daemon.hostname+" Message of the day -") - for _, s := range bytes.Split(bytes.TrimRight(motd, "\n"), []byte("\n")) { - client.ReplyNicknamed("372", "- "+string(s)) - } - client.ReplyNicknamed("376", "End of /MOTD command") - return - } else { - log.Println("Can not open motd file", daemon.motd, err) - } + motd, err := ioutil.ReadFile(daemon.motd) + if err != nil { + log.Printf("Can not read motd file %s: %v", daemon.motd, err) + client.ReplyNicknamed("422", "Error reading MOTD File") + return + } + + client.ReplyNicknamed("375", "- "+daemon.hostname+" Message of the day -") + for _, s := range strings.Split(strings.Trim(string(motd), "\n"), "\n") { + client.ReplyNicknamed("372", "- "+string(s)) } - client.ReplyNicknamed("422", "MOTD File is missing") + client.ReplyNicknamed("376", "End of /MOTD command") } func (daemon *Daemon) SendWhois(client *Client, nicknames []string) {