hid: add support for customized replies

This commit is contained in:
Přemysl Eric Janouch 2018-08-03 21:44:58 +02:00
parent 4d8376fd3c
commit 4cd460886e
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 41 additions and 5 deletions

View File

@ -1081,8 +1081,10 @@ func (c *client) setPingTimer() {
func (c *client) makeReply(id int, ap ...interface{}) string {
s := fmt.Sprintf(":%s %03d %s ", serverName, id, c.nicknameOrStar())
a := fmt.Sprintf(defaultReplies[id], ap...)
return s + a
if reply, ok := catalog[id]; ok {
return s + fmt.Sprintf(reply, ap...)
}
return s + fmt.Sprintf(defaultReplies[id], ap...)
}
// XXX: This way simple static analysis cannot typecheck the arguments, so we
@ -3150,9 +3152,43 @@ func ircInitializeTLS() error {
}
func ircInitializeCatalog() error {
// TODO: Not going to use catgets but a simple text file with basic
// checking whether the index is used by this daemon at all should do.
return nil
configCatalog := config["catalog"]
if configCatalog == "" {
return nil
}
path := resolveFilename(configCatalog, resolveRelativeConfigFilename)
if path == "" {
return fmt.Errorf("cannot find file: %s", configCatalog)
}
f, err := os.Open(path)
if err != nil {
return fmt.Errorf("failed reading the MOTD file: %s", err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
catalog = make(map[int]string)
for lineNo := 1; scanner.Scan(); lineNo++ {
line := strings.TrimLeft(scanner.Text(), " \t")
if line == "" || strings.HasPrefix(line, "#") {
continue
}
delim := strings.IndexAny(line, " \t")
if delim < 0 {
return fmt.Errorf("%s:%d: malformed line", path, lineNo)
}
id, err := strconv.ParseUint(line[:delim], 10, 16)
if err != nil {
return fmt.Errorf("%s:%d: %s", path, lineNo, err)
}
catalog[int(id)] = line[delim+1:]
}
return scanner.Err()
}
func ircInitializeMOTD() error {