2020-02-06 15:18:19 +00:00
|
|
|
package jounce
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net"
|
2020-02-07 10:46:44 +00:00
|
|
|
"strings"
|
2020-02-06 15:18:19 +00:00
|
|
|
|
|
|
|
"gopkg.in/irc.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ircError struct {
|
|
|
|
Message *irc.Message
|
|
|
|
}
|
|
|
|
|
|
|
|
func newUnknownCommandError(cmd string) ircError {
|
|
|
|
return ircError{&irc.Message{
|
|
|
|
Command: irc.ERR_UNKNOWNCOMMAND,
|
|
|
|
Params: []string{
|
|
|
|
"*",
|
|
|
|
cmd,
|
|
|
|
"Unknown command",
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newNeedMoreParamsError(cmd string) ircError {
|
|
|
|
return ircError{&irc.Message{
|
|
|
|
Command: irc.ERR_NEEDMOREPARAMS,
|
|
|
|
Params: []string{
|
|
|
|
"*",
|
|
|
|
cmd,
|
|
|
|
"Not enough parameters",
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err ircError) Error() string {
|
|
|
|
return err.Message.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
type downstreamConn struct {
|
2020-02-17 14:46:29 +00:00
|
|
|
net net.Conn
|
|
|
|
irc *irc.Conn
|
|
|
|
srv *Server
|
|
|
|
logger Logger
|
|
|
|
messages chan *irc.Message
|
|
|
|
consumers chan *RingConsumer
|
|
|
|
closed chan struct{}
|
2020-02-06 20:11:35 +00:00
|
|
|
|
2020-02-06 15:18:19 +00:00
|
|
|
registered bool
|
2020-02-07 10:36:42 +00:00
|
|
|
user *user
|
2020-02-06 15:18:19 +00:00
|
|
|
nick string
|
|
|
|
username string
|
|
|
|
realname string
|
|
|
|
}
|
|
|
|
|
2020-02-06 20:11:35 +00:00
|
|
|
func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
|
2020-02-17 11:36:42 +00:00
|
|
|
dc := &downstreamConn{
|
2020-02-17 14:46:29 +00:00
|
|
|
net: netConn,
|
|
|
|
irc: irc.NewConn(netConn),
|
|
|
|
srv: srv,
|
|
|
|
logger: &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", netConn.RemoteAddr())},
|
|
|
|
messages: make(chan *irc.Message, 64),
|
|
|
|
consumers: make(chan *RingConsumer),
|
|
|
|
closed: make(chan struct{}),
|
2020-02-06 20:11:35 +00:00
|
|
|
}
|
2020-02-06 20:52:04 +00:00
|
|
|
|
|
|
|
go func() {
|
2020-02-17 11:41:27 +00:00
|
|
|
if err := dc.writeMessages(); err != nil {
|
|
|
|
dc.logger.Printf("failed to write message: %v", err)
|
2020-02-06 20:52:04 +00:00
|
|
|
}
|
2020-02-17 11:36:42 +00:00
|
|
|
if err := dc.net.Close(); err != nil {
|
|
|
|
dc.logger.Printf("failed to close connection: %v", err)
|
2020-02-07 11:42:24 +00:00
|
|
|
} else {
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.logger.Printf("connection closed")
|
2020-02-07 11:42:24 +00:00
|
|
|
}
|
2020-02-06 20:52:04 +00:00
|
|
|
}()
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
return dc
|
2020-02-06 20:11:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) prefix() *irc.Prefix {
|
2020-02-06 21:19:31 +00:00
|
|
|
return &irc.Prefix{
|
2020-02-17 11:36:42 +00:00
|
|
|
Name: dc.nick,
|
|
|
|
User: dc.username,
|
2020-02-06 21:19:31 +00:00
|
|
|
// TODO: fill the host?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 14:46:29 +00:00
|
|
|
func (dc *downstreamConn) isClosed() bool {
|
|
|
|
select {
|
|
|
|
case <-dc.closed:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) readMessages() error {
|
|
|
|
dc.logger.Printf("new connection")
|
2020-02-06 20:11:35 +00:00
|
|
|
|
|
|
|
for {
|
2020-02-17 11:36:42 +00:00
|
|
|
msg, err := dc.irc.ReadMessage()
|
2020-02-06 20:11:35 +00:00
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
} else if err != nil {
|
|
|
|
return fmt.Errorf("failed to read IRC command: %v", err)
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
err = dc.handleMessage(msg)
|
2020-02-06 20:11:35 +00:00
|
|
|
if ircErr, ok := err.(ircError); ok {
|
2020-02-17 11:36:42 +00:00
|
|
|
ircErr.Message.Prefix = dc.srv.prefix()
|
|
|
|
dc.SendMessage(ircErr.Message)
|
2020-02-06 20:11:35 +00:00
|
|
|
} else if err != nil {
|
|
|
|
return fmt.Errorf("failed to handle IRC command %q: %v", msg.Command, err)
|
|
|
|
}
|
|
|
|
|
2020-02-17 14:46:29 +00:00
|
|
|
if dc.isClosed() {
|
2020-02-06 20:11:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 11:42:24 +00:00
|
|
|
return nil
|
2020-02-06 20:11:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 11:41:27 +00:00
|
|
|
func (dc *downstreamConn) writeMessages() error {
|
2020-02-17 14:46:29 +00:00
|
|
|
for {
|
|
|
|
var err error
|
|
|
|
var closed bool
|
|
|
|
select {
|
|
|
|
case msg := <-dc.messages:
|
|
|
|
err = dc.irc.WriteMessage(msg)
|
|
|
|
case consumer := <-dc.consumers:
|
|
|
|
for {
|
|
|
|
msg := consumer.Peek()
|
|
|
|
if msg == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
err = dc.irc.WriteMessage(msg)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
consumer.Consume()
|
|
|
|
}
|
|
|
|
case <-dc.closed:
|
|
|
|
closed = true
|
|
|
|
}
|
|
|
|
if err != nil {
|
2020-02-17 11:41:27 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-17 14:46:29 +00:00
|
|
|
if closed {
|
|
|
|
break
|
|
|
|
}
|
2020-02-17 11:41:27 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) Close() error {
|
2020-02-17 14:46:29 +00:00
|
|
|
if dc.isClosed() {
|
2020-02-06 20:52:04 +00:00
|
|
|
return fmt.Errorf("downstream connection already closed")
|
|
|
|
}
|
2020-02-07 10:56:36 +00:00
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
if u := dc.user; u != nil {
|
2020-02-07 10:56:36 +00:00
|
|
|
u.lock.Lock()
|
|
|
|
for i := range u.downstreamConns {
|
2020-02-17 11:36:42 +00:00
|
|
|
if u.downstreamConns[i] == dc {
|
2020-02-07 10:56:36 +00:00
|
|
|
u.downstreamConns = append(u.downstreamConns[:i], u.downstreamConns[i+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u.lock.Unlock()
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|
2020-02-07 10:56:36 +00:00
|
|
|
|
2020-02-17 14:46:29 +00:00
|
|
|
close(dc.closed)
|
2020-02-07 11:42:24 +00:00
|
|
|
return nil
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) SendMessage(msg *irc.Message) {
|
|
|
|
dc.messages <- msg
|
2020-02-17 11:27:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) handleMessage(msg *irc.Message) error {
|
2020-02-06 15:18:19 +00:00
|
|
|
switch msg.Command {
|
2020-02-06 21:22:14 +00:00
|
|
|
case "QUIT":
|
2020-02-17 11:36:42 +00:00
|
|
|
return dc.Close()
|
2020-02-06 15:18:19 +00:00
|
|
|
case "PING":
|
|
|
|
// TODO: handle params
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-06 15:18:19 +00:00
|
|
|
Command: "PONG",
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.srv.Hostname},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-06 20:52:04 +00:00
|
|
|
return nil
|
2020-02-06 15:18:19 +00:00
|
|
|
default:
|
2020-02-17 11:36:42 +00:00
|
|
|
if dc.registered {
|
|
|
|
return dc.handleMessageRegistered(msg)
|
2020-02-06 15:18:19 +00:00
|
|
|
} else {
|
2020-02-17 11:36:42 +00:00
|
|
|
return dc.handleMessageUnregistered(msg)
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
|
2020-02-06 15:18:19 +00:00
|
|
|
switch msg.Command {
|
|
|
|
case "NICK":
|
2020-02-17 11:36:42 +00:00
|
|
|
if err := parseMessageParams(msg, &dc.nick); err != nil {
|
2020-02-07 11:36:02 +00:00
|
|
|
return err
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|
|
|
|
case "USER":
|
2020-02-07 11:36:02 +00:00
|
|
|
var username string
|
2020-02-17 11:36:42 +00:00
|
|
|
if err := parseMessageParams(msg, &username, nil, nil, &dc.realname); err != nil {
|
2020-02-07 11:36:02 +00:00
|
|
|
return err
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.username = "~" + username
|
2020-02-06 15:18:19 +00:00
|
|
|
default:
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.logger.Printf("unhandled message: %v", msg)
|
2020-02-06 15:18:19 +00:00
|
|
|
return newUnknownCommandError(msg.Command)
|
|
|
|
}
|
2020-02-17 11:36:42 +00:00
|
|
|
if dc.username != "" && dc.nick != "" {
|
|
|
|
return dc.register()
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) register() error {
|
|
|
|
u := dc.srv.getUser(strings.TrimPrefix(dc.username, "~"))
|
2020-02-07 10:39:56 +00:00
|
|
|
if u == nil {
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.logger.Printf("failed authentication: unknown username %q", dc.username)
|
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-07 10:36:42 +00:00
|
|
|
Command: irc.ERR_PASSWDMISMATCH,
|
|
|
|
Params: []string{"*", "Invalid username or password"},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-07 10:36:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.registered = true
|
|
|
|
dc.user = u
|
2020-02-06 15:18:19 +00:00
|
|
|
|
2020-02-07 10:56:36 +00:00
|
|
|
u.lock.Lock()
|
2020-02-17 14:46:29 +00:00
|
|
|
firstDownstream := len(u.downstreamConns) == 0
|
2020-02-17 11:36:42 +00:00
|
|
|
u.downstreamConns = append(u.downstreamConns, dc)
|
2020-02-07 10:56:36 +00:00
|
|
|
u.lock.Unlock()
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-06 15:18:19 +00:00
|
|
|
Command: irc.RPL_WELCOME,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, "Welcome to jounce, " + dc.nick},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-06 15:18:19 +00:00
|
|
|
Command: irc.RPL_YOURHOST,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, "Your host is " + dc.srv.Hostname},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-06 15:18:19 +00:00
|
|
|
Command: irc.RPL_CREATED,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, "Who cares when the server was created?"},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-06 15:18:19 +00:00
|
|
|
Command: irc.RPL_MYINFO,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, dc.srv.Hostname, "jounce", "aiwroO", "OovaimnqpsrtklbeI"},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-06 15:18:19 +00:00
|
|
|
Command: irc.ERR_NOMOTD,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, "No MOTD"},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-06 15:18:19 +00:00
|
|
|
|
2020-02-07 10:46:44 +00:00
|
|
|
u.forEachUpstream(func(uc *upstreamConn) {
|
2020-02-06 21:29:24 +00:00
|
|
|
// TODO: fix races accessing upstream connection data
|
|
|
|
for _, ch := range uc.channels {
|
|
|
|
if ch.complete {
|
2020-02-17 11:36:42 +00:00
|
|
|
forwardChannel(dc, ch)
|
2020-02-06 21:29:24 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-07 15:43:14 +00:00
|
|
|
|
2020-02-07 16:15:50 +00:00
|
|
|
// TODO: let clients specify the ring buffer name in their username
|
2020-02-17 14:46:29 +00:00
|
|
|
historyName := ""
|
|
|
|
|
|
|
|
var seqPtr *uint64
|
|
|
|
if firstDownstream {
|
|
|
|
seq, ok := uc.history[historyName]
|
|
|
|
if ok {
|
|
|
|
seqPtr = &seq
|
2020-02-07 15:43:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-17 14:46:29 +00:00
|
|
|
|
2020-02-17 15:09:35 +00:00
|
|
|
consumer, ch := uc.ring.NewConsumer(seqPtr)
|
2020-02-17 14:46:29 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
var closed bool
|
|
|
|
select {
|
|
|
|
case <-ch:
|
|
|
|
dc.consumers <- consumer
|
|
|
|
case <-dc.closed:
|
|
|
|
closed = true
|
|
|
|
}
|
|
|
|
if closed {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
seq := consumer.Close()
|
|
|
|
|
|
|
|
dc.user.lock.Lock()
|
|
|
|
lastDownstream := len(dc.user.downstreamConns) == 0
|
|
|
|
dc.user.lock.Unlock()
|
|
|
|
|
|
|
|
if lastDownstream {
|
|
|
|
uc.history[historyName] = seq
|
|
|
|
}
|
|
|
|
}()
|
2020-02-07 10:46:44 +00:00
|
|
|
})
|
2020-02-07 15:43:14 +00:00
|
|
|
|
2020-02-06 15:18:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
2020-02-06 15:18:19 +00:00
|
|
|
switch msg.Command {
|
2020-02-07 11:19:42 +00:00
|
|
|
case "USER":
|
2020-02-06 15:18:19 +00:00
|
|
|
return ircError{&irc.Message{
|
|
|
|
Command: irc.ERR_ALREADYREGISTERED,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, "You may not reregister"},
|
2020-02-06 15:18:19 +00:00
|
|
|
}}
|
2020-02-07 11:19:42 +00:00
|
|
|
case "NICK":
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.user.forEachUpstream(func(uc *upstreamConn) {
|
2020-02-17 15:17:31 +00:00
|
|
|
uc.SendMessage(msg)
|
2020-02-07 11:19:42 +00:00
|
|
|
})
|
2020-02-07 12:31:09 +00:00
|
|
|
case "JOIN":
|
|
|
|
var name string
|
|
|
|
if err := parseMessageParams(msg, &name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
if ch, _ := dc.user.getChannel(name); ch != nil {
|
2020-02-07 12:31:09 +00:00
|
|
|
break // already joined
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: extract network name from channel name
|
|
|
|
return ircError{&irc.Message{
|
|
|
|
Command: irc.ERR_NOSUCHCHANNEL,
|
|
|
|
Params: []string{name, "Channel name ambiguous"},
|
|
|
|
}}
|
2020-02-07 12:36:32 +00:00
|
|
|
case "PART":
|
|
|
|
var name string
|
|
|
|
if err := parseMessageParams(msg, &name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:36:42 +00:00
|
|
|
ch, err := dc.user.getChannel(name)
|
2020-02-07 12:36:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-17 15:17:31 +00:00
|
|
|
ch.conn.SendMessage(msg)
|
2020-02-07 12:36:32 +00:00
|
|
|
// TODO: remove channel from upstream config
|
2020-02-07 12:08:27 +00:00
|
|
|
case "MODE":
|
|
|
|
var name string
|
|
|
|
if err := parseMessageParams(msg, &name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var modeStr string
|
|
|
|
if len(msg.Params) > 1 {
|
|
|
|
modeStr = msg.Params[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.Prefix.Name != name {
|
2020-02-17 11:36:42 +00:00
|
|
|
ch, err := dc.user.getChannel(name)
|
2020-02-07 12:08:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if modeStr != "" {
|
2020-02-17 15:17:31 +00:00
|
|
|
ch.conn.SendMessage(msg)
|
2020-02-07 12:08:27 +00:00
|
|
|
} else {
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-07 12:08:27 +00:00
|
|
|
Command: irc.RPL_CHANNELMODEIS,
|
|
|
|
Params: []string{ch.Name, string(ch.modes)},
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-07 12:08:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-02-17 11:36:42 +00:00
|
|
|
if name != dc.nick {
|
2020-02-07 12:08:27 +00:00
|
|
|
return ircError{&irc.Message{
|
|
|
|
Command: irc.ERR_USERSDONTMATCH,
|
2020-02-17 11:36:42 +00:00
|
|
|
Params: []string{dc.nick, "Cannot change mode for other users"},
|
2020-02-07 12:08:27 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
if modeStr != "" {
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.user.forEachUpstream(func(uc *upstreamConn) {
|
2020-02-17 15:17:31 +00:00
|
|
|
uc.SendMessage(msg)
|
2020-02-07 12:08:27 +00:00
|
|
|
})
|
|
|
|
} else {
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.srv.prefix(),
|
2020-02-07 12:08:27 +00:00
|
|
|
Command: irc.RPL_UMODEIS,
|
|
|
|
Params: []string{""}, // TODO
|
2020-02-17 11:27:48 +00:00
|
|
|
})
|
2020-02-07 12:08:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-17 14:56:18 +00:00
|
|
|
case "PRIVMSG":
|
|
|
|
var targetsStr, text string
|
|
|
|
if err := parseMessageParams(msg, &targetsStr, &text); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range strings.Split(targetsStr, ",") {
|
|
|
|
ch, err := dc.user.getChannel(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-17 15:17:31 +00:00
|
|
|
ch.conn.SendMessage(&irc.Message{
|
2020-02-17 14:56:18 +00:00
|
|
|
Prefix: msg.Prefix,
|
|
|
|
Command: "PRIVMSG",
|
|
|
|
Params: []string{name, text},
|
2020-02-17 15:17:31 +00:00
|
|
|
})
|
2020-02-17 14:56:18 +00:00
|
|
|
}
|
2020-02-06 15:18:19 +00:00
|
|
|
default:
|
2020-02-17 11:36:42 +00:00
|
|
|
dc.logger.Printf("unhandled message: %v", msg)
|
2020-02-06 15:18:19 +00:00
|
|
|
return newUnknownCommandError(msg.Command)
|
|
|
|
}
|
2020-02-07 11:19:42 +00:00
|
|
|
return nil
|
2020-02-06 15:18:19 +00:00
|
|
|
}
|