X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=events.go;h=bc659a6c9eeb0e8302d6e55abecb492245622707;hp=0921069d2cf21748e6bcd34fae076dff206cc44e;hb=186ec4b4bd91f9fd101b2f62d30c0f2bd4ed50ce;hpb=41f96494948d1f9f1e0c3066099e0bd9ad0ee8dd diff --git a/events.go b/events.go index 0921069..bc659a6 100644 --- a/events.go +++ b/events.go @@ -1,6 +1,6 @@ /* goircd -- minimalistic simple Internet Relay Chat (IRC) server -Copyright (C) 2014 Sergey Matveev +Copyright (C) 2014-2015 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,6 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + package main import ( @@ -27,26 +28,26 @@ import ( ) const ( - EVENT_NEW = iota - EVENT_DEL = iota - EVENT_MSG = iota - EVENT_TOPIC = iota - EVENT_WHO = iota - EVENT_MODE = iota - FORMAT_MSG = "[%s] <%s> %s\n" - FORMAT_META = "[%s] * %s %s\n" + EventNew = iota + EventDel = iota + EventMsg = iota + EventTopic = iota + EventWho = iota + EventMode = iota + FormatMsg = "[%s] <%s> %s\n" + FormatMeta = "[%s] * %s %s\n" ) // Client events going from each of client // They can be either NEW, DEL or unparsed MSG type ClientEvent struct { - client *Client - event_type int - text string + client *Client + eventType int + text string } func (m ClientEvent) String() string { - return string(m.event_type) + ": " + m.client.String() + ": " + m.text + return string(m.eventType) + ": " + m.client.String() + ": " + m.text } // Logging in-room events @@ -65,17 +66,20 @@ func Logger(logdir string, events <-chan LogEvent) { mode := os.O_CREATE | os.O_WRONLY | os.O_APPEND perm := os.FileMode(0660) var format string + var logfile string + var fd *os.File + var err error for event := range events { - logfile := path.Join(logdir, event.where) - fd, err := os.OpenFile(logfile, mode, perm) + logfile = path.Join(logdir, event.where + ".log") + fd, err = os.OpenFile(logfile, mode, perm) if err != nil { log.Println("Can not open logfile", logfile, err) continue } if event.meta { - format = FORMAT_META + format = FormatMeta } else { - format = FORMAT_MSG + format = FormatMsg } _, err = fd.WriteString(fmt.Sprintf(format, time.Now(), event.who, event.what)) fd.Close() @@ -95,10 +99,13 @@ type StateEvent struct { // Room states shows that either topic or key has been changed // Each room's state is written to separate file in statedir func StateKeeper(statedir string, events <-chan StateEvent) { + var fn string + var data string + var err error for event := range events { - fn := path.Join(statedir, event.where) - data := event.topic + "\n" + event.key + "\n" - err := ioutil.WriteFile(fn, []byte(data), os.FileMode(0660)) + fn = path.Join(statedir, event.where) + data = event.topic + "\n" + event.key + "\n" + err = ioutil.WriteFile(fn, []byte(data), os.FileMode(0660)) if err != nil { log.Printf("Can not write statefile %s: %v", fn, err) }