2014-02-09 07:53:42 -08:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
2014-03-01 14:34:51 -08:00
|
|
|
"code.google.com/p/gcfg"
|
|
|
|
"errors"
|
2014-02-23 22:21:39 -08:00
|
|
|
"log"
|
2014-02-09 07:53:42 -08:00
|
|
|
)
|
|
|
|
|
2014-03-01 14:34:51 -08:00
|
|
|
type PassConfig struct {
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conf *PassConfig) PasswordBytes() []byte {
|
2014-03-02 11:41:24 -08:00
|
|
|
bytes, err := DecodePassword(conf.Password)
|
2014-02-23 22:21:39 -08:00
|
|
|
if err != nil {
|
2014-03-05 23:07:55 -08:00
|
|
|
log.Fatal("decode password error: ", err)
|
2014-02-23 22:21:39 -08:00
|
|
|
}
|
|
|
|
return bytes
|
|
|
|
}
|
|
|
|
|
2014-02-09 07:53:42 -08:00
|
|
|
type Config struct {
|
2014-03-01 14:34:51 -08:00
|
|
|
Server struct {
|
|
|
|
PassConfig
|
|
|
|
Database string
|
|
|
|
Listen []string
|
|
|
|
MOTD string
|
|
|
|
Name string
|
|
|
|
}
|
2014-02-25 11:11:34 -08:00
|
|
|
|
2014-03-01 14:34:51 -08:00
|
|
|
Operator map[string]*PassConfig
|
2014-02-09 10:07:40 -08:00
|
|
|
|
2014-03-01 14:34:51 -08:00
|
|
|
Debug struct {
|
|
|
|
Net bool
|
|
|
|
Client bool
|
|
|
|
Channel bool
|
|
|
|
Server bool
|
|
|
|
}
|
2014-02-23 22:21:39 -08:00
|
|
|
}
|
|
|
|
|
2014-03-01 14:34:51 -08:00
|
|
|
func (conf *Config) Operators() map[string][]byte {
|
2014-02-24 09:41:09 -08:00
|
|
|
operators := make(map[string][]byte)
|
2014-03-01 14:34:51 -08:00
|
|
|
for name, opConf := range conf.Operator {
|
|
|
|
operators[name] = opConf.PasswordBytes()
|
2014-02-24 09:41:09 -08:00
|
|
|
}
|
|
|
|
return operators
|
|
|
|
}
|
|
|
|
|
2014-02-23 22:21:39 -08:00
|
|
|
func LoadConfig(filename string) (config *Config, err error) {
|
2014-02-09 07:53:42 -08:00
|
|
|
config = &Config{}
|
2014-03-01 14:34:51 -08:00
|
|
|
err = gcfg.ReadFileInto(config, filename)
|
2014-02-09 07:53:42 -08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2014-03-01 14:34:51 -08:00
|
|
|
if config.Server.Name == "" {
|
|
|
|
err = errors.New("server.name missing")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if config.Server.Database == "" {
|
|
|
|
err = errors.New("server.database missing")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(config.Server.Listen) == 0 {
|
|
|
|
err = errors.New("server.listen missing")
|
2014-02-10 13:52:28 -08:00
|
|
|
return
|
|
|
|
}
|
2014-02-09 07:53:42 -08:00
|
|
|
return
|
|
|
|
}
|