[98] | 1 | package soju
|
---|
[13] | 2 |
|
---|
| 3 | import (
|
---|
[91] | 4 | "crypto/tls"
|
---|
[112] | 5 | "encoding/base64"
|
---|
[13] | 6 | "fmt"
|
---|
| 7 | "io"
|
---|
| 8 | "net"
|
---|
[108] | 9 | "strconv"
|
---|
[39] | 10 | "strings"
|
---|
[91] | 11 | "time"
|
---|
[13] | 12 |
|
---|
[112] | 13 | "github.com/emersion/go-sasl"
|
---|
[85] | 14 | "golang.org/x/crypto/bcrypt"
|
---|
[13] | 15 | "gopkg.in/irc.v3"
|
---|
| 16 | )
|
---|
| 17 |
|
---|
| 18 | type ircError struct {
|
---|
| 19 | Message *irc.Message
|
---|
| 20 | }
|
---|
| 21 |
|
---|
[85] | 22 | func (err ircError) Error() string {
|
---|
| 23 | return err.Message.String()
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[13] | 26 | func newUnknownCommandError(cmd string) ircError {
|
---|
| 27 | return ircError{&irc.Message{
|
---|
| 28 | Command: irc.ERR_UNKNOWNCOMMAND,
|
---|
| 29 | Params: []string{
|
---|
| 30 | "*",
|
---|
| 31 | cmd,
|
---|
| 32 | "Unknown command",
|
---|
| 33 | },
|
---|
| 34 | }}
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | func newNeedMoreParamsError(cmd string) ircError {
|
---|
| 38 | return ircError{&irc.Message{
|
---|
| 39 | Command: irc.ERR_NEEDMOREPARAMS,
|
---|
| 40 | Params: []string{
|
---|
| 41 | "*",
|
---|
| 42 | cmd,
|
---|
| 43 | "Not enough parameters",
|
---|
| 44 | },
|
---|
| 45 | }}
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[319] | 48 | func newChatHistoryError(subcommand string, target string) ircError {
|
---|
| 49 | return ircError{&irc.Message{
|
---|
| 50 | Command: "FAIL",
|
---|
| 51 | Params: []string{"CHATHISTORY", "MESSAGE_ERROR", subcommand, target, "Messages could not be retrieved"},
|
---|
| 52 | }}
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[85] | 55 | var errAuthFailed = ircError{&irc.Message{
|
---|
| 56 | Command: irc.ERR_PASSWDMISMATCH,
|
---|
| 57 | Params: []string{"*", "Invalid username or password"},
|
---|
| 58 | }}
|
---|
[13] | 59 |
|
---|
[411] | 60 | // ' ' and ':' break the IRC message wire format, '@' and '!' break prefixes,
|
---|
| 61 | // '*' and '?' break masks
|
---|
| 62 | const illegalNickChars = " :@!*?"
|
---|
[404] | 63 |
|
---|
[275] | 64 | // permanentDownstreamCaps is the list of always-supported downstream
|
---|
| 65 | // capabilities.
|
---|
| 66 | var permanentDownstreamCaps = map[string]string{
|
---|
[276] | 67 | "batch": "",
|
---|
| 68 | "cap-notify": "",
|
---|
[275] | 69 | "echo-message": "",
|
---|
| 70 | "message-tags": "",
|
---|
[276] | 71 | "sasl": "PLAIN",
|
---|
| 72 | "server-time": "",
|
---|
[275] | 73 | }
|
---|
| 74 |
|
---|
[292] | 75 | // needAllDownstreamCaps is the list of downstream capabilities that
|
---|
| 76 | // require support from all upstreams to be enabled
|
---|
| 77 | var needAllDownstreamCaps = map[string]string{
|
---|
[419] | 78 | "away-notify": "",
|
---|
| 79 | "extended-join": "",
|
---|
| 80 | "multi-prefix": "",
|
---|
[292] | 81 | }
|
---|
| 82 |
|
---|
[13] | 83 | type downstreamConn struct {
|
---|
[210] | 84 | conn
|
---|
[22] | 85 |
|
---|
[210] | 86 | id uint64
|
---|
| 87 |
|
---|
[100] | 88 | registered bool
|
---|
| 89 | user *user
|
---|
| 90 | nick string
|
---|
| 91 | rawUsername string
|
---|
[168] | 92 | networkName string
|
---|
[183] | 93 | clientName string
|
---|
[100] | 94 | realname string
|
---|
[141] | 95 | hostname string
|
---|
[100] | 96 | password string // empty after authentication
|
---|
| 97 | network *network // can be nil
|
---|
[105] | 98 |
|
---|
[108] | 99 | negociatingCaps bool
|
---|
| 100 | capVersion int
|
---|
[275] | 101 | supportedCaps map[string]string
|
---|
[236] | 102 | caps map[string]bool
|
---|
[108] | 103 |
|
---|
[112] | 104 | saslServer sasl.Server
|
---|
[13] | 105 | }
|
---|
| 106 |
|
---|
[347] | 107 | func newDownstreamConn(srv *Server, ic ircConn, id uint64) *downstreamConn {
|
---|
| 108 | remoteAddr := ic.RemoteAddr().String()
|
---|
[323] | 109 | logger := &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", remoteAddr)}
|
---|
[398] | 110 | options := connOptions{Logger: logger}
|
---|
[55] | 111 | dc := &downstreamConn{
|
---|
[398] | 112 | conn: *newConn(srv, ic, &options),
|
---|
[276] | 113 | id: id,
|
---|
[275] | 114 | supportedCaps: make(map[string]string),
|
---|
[276] | 115 | caps: make(map[string]bool),
|
---|
[22] | 116 | }
|
---|
[323] | 117 | dc.hostname = remoteAddr
|
---|
[141] | 118 | if host, _, err := net.SplitHostPort(dc.hostname); err == nil {
|
---|
| 119 | dc.hostname = host
|
---|
| 120 | }
|
---|
[275] | 121 | for k, v := range permanentDownstreamCaps {
|
---|
| 122 | dc.supportedCaps[k] = v
|
---|
| 123 | }
|
---|
[319] | 124 | if srv.LogPath != "" {
|
---|
| 125 | dc.supportedCaps["draft/chathistory"] = ""
|
---|
| 126 | }
|
---|
[55] | 127 | return dc
|
---|
[22] | 128 | }
|
---|
| 129 |
|
---|
[55] | 130 | func (dc *downstreamConn) prefix() *irc.Prefix {
|
---|
[27] | 131 | return &irc.Prefix{
|
---|
[55] | 132 | Name: dc.nick,
|
---|
[184] | 133 | User: dc.user.Username,
|
---|
[141] | 134 | Host: dc.hostname,
|
---|
[27] | 135 | }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[90] | 138 | func (dc *downstreamConn) forEachNetwork(f func(*network)) {
|
---|
| 139 | if dc.network != nil {
|
---|
| 140 | f(dc.network)
|
---|
| 141 | } else {
|
---|
| 142 | dc.user.forEachNetwork(f)
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[73] | 146 | func (dc *downstreamConn) forEachUpstream(f func(*upstreamConn)) {
|
---|
| 147 | dc.user.forEachUpstream(func(uc *upstreamConn) {
|
---|
[77] | 148 | if dc.network != nil && uc.network != dc.network {
|
---|
[73] | 149 | return
|
---|
| 150 | }
|
---|
| 151 | f(uc)
|
---|
| 152 | })
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[89] | 155 | // upstream returns the upstream connection, if any. If there are zero or if
|
---|
| 156 | // there are multiple upstream connections, it returns nil.
|
---|
| 157 | func (dc *downstreamConn) upstream() *upstreamConn {
|
---|
| 158 | if dc.network == nil {
|
---|
| 159 | return nil
|
---|
| 160 | }
|
---|
[279] | 161 | return dc.network.conn
|
---|
[89] | 162 | }
|
---|
| 163 |
|
---|
[260] | 164 | func isOurNick(net *network, nick string) bool {
|
---|
| 165 | // TODO: this doesn't account for nick changes
|
---|
| 166 | if net.conn != nil {
|
---|
| 167 | return nick == net.conn.nick
|
---|
| 168 | }
|
---|
| 169 | // We're not currently connected to the upstream connection, so we don't
|
---|
| 170 | // know whether this name is our nickname. Best-effort: use the network's
|
---|
| 171 | // configured nickname and hope it was the one being used when we were
|
---|
| 172 | // connected.
|
---|
| 173 | return nick == net.Nick
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[249] | 176 | // marshalEntity converts an upstream entity name (ie. channel or nick) into a
|
---|
| 177 | // downstream entity name.
|
---|
| 178 | //
|
---|
| 179 | // This involves adding a "/<network>" suffix if the entity isn't the current
|
---|
| 180 | // user.
|
---|
[260] | 181 | func (dc *downstreamConn) marshalEntity(net *network, name string) string {
|
---|
[289] | 182 | if isOurNick(net, name) {
|
---|
| 183 | return dc.nick
|
---|
| 184 | }
|
---|
[257] | 185 | if dc.network != nil {
|
---|
[260] | 186 | if dc.network != net {
|
---|
[258] | 187 | panic("soju: tried to marshal an entity for another network")
|
---|
| 188 | }
|
---|
[257] | 189 | return name
|
---|
[119] | 190 | }
|
---|
[260] | 191 | return name + "/" + net.GetName()
|
---|
[119] | 192 | }
|
---|
| 193 |
|
---|
[260] | 194 | func (dc *downstreamConn) marshalUserPrefix(net *network, prefix *irc.Prefix) *irc.Prefix {
|
---|
| 195 | if isOurNick(net, prefix.Name) {
|
---|
[257] | 196 | return dc.prefix()
|
---|
| 197 | }
|
---|
[130] | 198 | if dc.network != nil {
|
---|
[260] | 199 | if dc.network != net {
|
---|
[258] | 200 | panic("soju: tried to marshal a user prefix for another network")
|
---|
| 201 | }
|
---|
[257] | 202 | return prefix
|
---|
[119] | 203 | }
|
---|
[257] | 204 | return &irc.Prefix{
|
---|
[260] | 205 | Name: prefix.Name + "/" + net.GetName(),
|
---|
[257] | 206 | User: prefix.User,
|
---|
| 207 | Host: prefix.Host,
|
---|
| 208 | }
|
---|
[119] | 209 | }
|
---|
| 210 |
|
---|
[249] | 211 | // unmarshalEntity converts a downstream entity name (ie. channel or nick) into
|
---|
| 212 | // an upstream entity name.
|
---|
| 213 | //
|
---|
| 214 | // This involves removing the "/<network>" suffix.
|
---|
[127] | 215 | func (dc *downstreamConn) unmarshalEntity(name string) (*upstreamConn, string, error) {
|
---|
[89] | 216 | if uc := dc.upstream(); uc != nil {
|
---|
| 217 | return uc, name, nil
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[127] | 220 | var conn *upstreamConn
|
---|
[119] | 221 | if i := strings.LastIndexByte(name, '/'); i >= 0 {
|
---|
[127] | 222 | network := name[i+1:]
|
---|
[119] | 223 | name = name[:i]
|
---|
| 224 |
|
---|
| 225 | dc.forEachUpstream(func(uc *upstreamConn) {
|
---|
| 226 | if network != uc.network.GetName() {
|
---|
| 227 | return
|
---|
| 228 | }
|
---|
| 229 | conn = uc
|
---|
| 230 | })
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[127] | 233 | if conn == nil {
|
---|
[73] | 234 | return nil, "", ircError{&irc.Message{
|
---|
| 235 | Command: irc.ERR_NOSUCHCHANNEL,
|
---|
| 236 | Params: []string{name, "No such channel"},
|
---|
| 237 | }}
|
---|
[69] | 238 | }
|
---|
[127] | 239 | return conn, name, nil
|
---|
[69] | 240 | }
|
---|
| 241 |
|
---|
[268] | 242 | func (dc *downstreamConn) unmarshalText(uc *upstreamConn, text string) string {
|
---|
| 243 | if dc.upstream() != nil {
|
---|
| 244 | return text
|
---|
| 245 | }
|
---|
| 246 | // TODO: smarter parsing that ignores URLs
|
---|
| 247 | return strings.ReplaceAll(text, "/"+uc.network.GetName(), "")
|
---|
| 248 | }
|
---|
| 249 |
|
---|
[165] | 250 | func (dc *downstreamConn) readMessages(ch chan<- event) error {
|
---|
[22] | 251 | for {
|
---|
[210] | 252 | msg, err := dc.ReadMessage()
|
---|
[22] | 253 | if err == io.EOF {
|
---|
| 254 | break
|
---|
| 255 | } else if err != nil {
|
---|
| 256 | return fmt.Errorf("failed to read IRC command: %v", err)
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[165] | 259 | ch <- eventDownstreamMessage{msg, dc}
|
---|
[22] | 260 | }
|
---|
| 261 |
|
---|
[45] | 262 | return nil
|
---|
[22] | 263 | }
|
---|
| 264 |
|
---|
[230] | 265 | // SendMessage sends an outgoing message.
|
---|
| 266 | //
|
---|
| 267 | // This can only called from the user goroutine.
|
---|
[55] | 268 | func (dc *downstreamConn) SendMessage(msg *irc.Message) {
|
---|
[230] | 269 | if !dc.caps["message-tags"] {
|
---|
[303] | 270 | if msg.Command == "TAGMSG" {
|
---|
| 271 | return
|
---|
| 272 | }
|
---|
[216] | 273 | msg = msg.Copy()
|
---|
| 274 | for name := range msg.Tags {
|
---|
| 275 | supported := false
|
---|
| 276 | switch name {
|
---|
| 277 | case "time":
|
---|
[230] | 278 | supported = dc.caps["server-time"]
|
---|
[216] | 279 | }
|
---|
| 280 | if !supported {
|
---|
| 281 | delete(msg.Tags, name)
|
---|
| 282 | }
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
[419] | 285 | if msg.Command == "JOIN" && !dc.caps["extended-join"] {
|
---|
| 286 | msg.Params = msg.Params[:1]
|
---|
| 287 | }
|
---|
[216] | 288 |
|
---|
[210] | 289 | dc.conn.SendMessage(msg)
|
---|
[54] | 290 | }
|
---|
| 291 |
|
---|
[428] | 292 | // sendMessageWithID sends an outgoing message with the specified internal ID.
|
---|
| 293 | func (dc *downstreamConn) sendMessageWithID(msg *irc.Message, id string) {
|
---|
| 294 | dc.SendMessage(msg)
|
---|
| 295 |
|
---|
| 296 | if id == "" || !dc.messageSupportsHistory(msg) {
|
---|
| 297 | return
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | dc.sendPing(id)
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | // advanceMessageWithID advances history to the specified message ID without
|
---|
| 304 | // sending a message. This is useful e.g. for self-messages when echo-message
|
---|
| 305 | // isn't enabled.
|
---|
| 306 | func (dc *downstreamConn) advanceMessageWithID(msg *irc.Message, id string) {
|
---|
| 307 | if id == "" || !dc.messageSupportsHistory(msg) {
|
---|
| 308 | return
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | dc.sendPing(id)
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | // ackMsgID acknowledges that a message has been received.
|
---|
| 315 | func (dc *downstreamConn) ackMsgID(id string) {
|
---|
| 316 | netName, entity, _, _, err := parseMsgID(id)
|
---|
| 317 | if err != nil {
|
---|
| 318 | dc.logger.Printf("failed to ACK message ID %q: %v", id, err)
|
---|
| 319 | return
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | network := dc.user.getNetwork(netName)
|
---|
| 323 | if network == nil {
|
---|
| 324 | return
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | history, ok := network.history[entity]
|
---|
| 328 | if !ok {
|
---|
| 329 | return
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | history.clients[dc.clientName] = id
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | func (dc *downstreamConn) sendPing(msgID string) {
|
---|
| 336 | token := "soju-msgid-" + base64.RawURLEncoding.EncodeToString([]byte(msgID))
|
---|
| 337 | dc.SendMessage(&irc.Message{
|
---|
| 338 | Command: "PING",
|
---|
| 339 | Params: []string{token},
|
---|
| 340 | })
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | func (dc *downstreamConn) handlePong(token string) {
|
---|
| 344 | if !strings.HasPrefix(token, "soju-msgid-") {
|
---|
| 345 | dc.logger.Printf("received unrecognized PONG token %q", token)
|
---|
| 346 | return
|
---|
| 347 | }
|
---|
| 348 | token = strings.TrimPrefix(token, "soju-msgid-")
|
---|
| 349 | b, err := base64.RawURLEncoding.DecodeString(token)
|
---|
| 350 | if err != nil {
|
---|
| 351 | dc.logger.Printf("received malformed PONG token: %v", err)
|
---|
| 352 | return
|
---|
| 353 | }
|
---|
| 354 | msgID := string(b)
|
---|
| 355 |
|
---|
| 356 | dc.ackMsgID(msgID)
|
---|
| 357 | }
|
---|
| 358 |
|
---|
[245] | 359 | // marshalMessage re-formats a message coming from an upstream connection so
|
---|
| 360 | // that it's suitable for being sent on this downstream connection. Only
|
---|
[293] | 361 | // messages that may appear in logs are supported, except MODE.
|
---|
[261] | 362 | func (dc *downstreamConn) marshalMessage(msg *irc.Message, net *network) *irc.Message {
|
---|
[227] | 363 | msg = msg.Copy()
|
---|
[261] | 364 | msg.Prefix = dc.marshalUserPrefix(net, msg.Prefix)
|
---|
[245] | 365 |
|
---|
[227] | 366 | switch msg.Command {
|
---|
[303] | 367 | case "PRIVMSG", "NOTICE", "TAGMSG":
|
---|
[261] | 368 | msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
|
---|
[245] | 369 | case "NICK":
|
---|
| 370 | // Nick change for another user
|
---|
[261] | 371 | msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
|
---|
[245] | 372 | case "JOIN", "PART":
|
---|
[261] | 373 | msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
|
---|
[245] | 374 | case "KICK":
|
---|
[261] | 375 | msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
|
---|
| 376 | msg.Params[1] = dc.marshalEntity(net, msg.Params[1])
|
---|
[245] | 377 | case "TOPIC":
|
---|
[261] | 378 | msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
|
---|
[245] | 379 | case "QUIT":
|
---|
[262] | 380 | // This space is intentionally left blank
|
---|
[227] | 381 | default:
|
---|
| 382 | panic(fmt.Sprintf("unexpected %q message", msg.Command))
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[245] | 385 | return msg
|
---|
[227] | 386 | }
|
---|
| 387 |
|
---|
[55] | 388 | func (dc *downstreamConn) handleMessage(msg *irc.Message) error {
|
---|
[13] | 389 | switch msg.Command {
|
---|
[28] | 390 | case "QUIT":
|
---|
[55] | 391 | return dc.Close()
|
---|
[13] | 392 | default:
|
---|
[55] | 393 | if dc.registered {
|
---|
| 394 | return dc.handleMessageRegistered(msg)
|
---|
[13] | 395 | } else {
|
---|
[55] | 396 | return dc.handleMessageUnregistered(msg)
|
---|
[13] | 397 | }
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[55] | 401 | func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
|
---|
[13] | 402 | switch msg.Command {
|
---|
| 403 | case "NICK":
|
---|
[117] | 404 | var nick string
|
---|
| 405 | if err := parseMessageParams(msg, &nick); err != nil {
|
---|
[43] | 406 | return err
|
---|
[13] | 407 | }
|
---|
[404] | 408 | if strings.ContainsAny(nick, illegalNickChars) {
|
---|
| 409 | return ircError{&irc.Message{
|
---|
| 410 | Command: irc.ERR_ERRONEUSNICKNAME,
|
---|
| 411 | Params: []string{dc.nick, nick, "contains illegal characters"},
|
---|
| 412 | }}
|
---|
| 413 | }
|
---|
[117] | 414 | if nick == serviceNick {
|
---|
| 415 | return ircError{&irc.Message{
|
---|
| 416 | Command: irc.ERR_NICKNAMEINUSE,
|
---|
| 417 | Params: []string{dc.nick, nick, "Nickname reserved for bouncer service"},
|
---|
| 418 | }}
|
---|
| 419 | }
|
---|
| 420 | dc.nick = nick
|
---|
[13] | 421 | case "USER":
|
---|
[117] | 422 | if err := parseMessageParams(msg, &dc.rawUsername, nil, nil, &dc.realname); err != nil {
|
---|
[43] | 423 | return err
|
---|
[13] | 424 | }
|
---|
[85] | 425 | case "PASS":
|
---|
| 426 | if err := parseMessageParams(msg, &dc.password); err != nil {
|
---|
| 427 | return err
|
---|
| 428 | }
|
---|
[108] | 429 | case "CAP":
|
---|
| 430 | var subCmd string
|
---|
| 431 | if err := parseMessageParams(msg, &subCmd); err != nil {
|
---|
| 432 | return err
|
---|
| 433 | }
|
---|
| 434 | if err := dc.handleCapCommand(subCmd, msg.Params[1:]); err != nil {
|
---|
| 435 | return err
|
---|
| 436 | }
|
---|
[112] | 437 | case "AUTHENTICATE":
|
---|
[230] | 438 | if !dc.caps["sasl"] {
|
---|
[112] | 439 | return ircError{&irc.Message{
|
---|
[125] | 440 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 441 | Params: []string{"*", "AUTHENTICATE requires the \"sasl\" capability to be enabled"},
|
---|
| 442 | }}
|
---|
| 443 | }
|
---|
| 444 | if len(msg.Params) == 0 {
|
---|
| 445 | return ircError{&irc.Message{
|
---|
[125] | 446 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 447 | Params: []string{"*", "Missing AUTHENTICATE argument"},
|
---|
| 448 | }}
|
---|
| 449 | }
|
---|
| 450 | if dc.nick == "" {
|
---|
| 451 | return ircError{&irc.Message{
|
---|
[125] | 452 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 453 | Params: []string{"*", "Expected NICK command before AUTHENTICATE"},
|
---|
| 454 | }}
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | var resp []byte
|
---|
| 458 | if dc.saslServer == nil {
|
---|
| 459 | mech := strings.ToUpper(msg.Params[0])
|
---|
| 460 | switch mech {
|
---|
| 461 | case "PLAIN":
|
---|
| 462 | dc.saslServer = sasl.NewPlainServer(sasl.PlainAuthenticator(func(identity, username, password string) error {
|
---|
| 463 | return dc.authenticate(username, password)
|
---|
| 464 | }))
|
---|
| 465 | default:
|
---|
| 466 | return ircError{&irc.Message{
|
---|
[125] | 467 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 468 | Params: []string{"*", fmt.Sprintf("Unsupported SASL mechanism %q", mech)},
|
---|
| 469 | }}
|
---|
| 470 | }
|
---|
| 471 | } else if msg.Params[0] == "*" {
|
---|
| 472 | dc.saslServer = nil
|
---|
| 473 | return ircError{&irc.Message{
|
---|
[125] | 474 | Command: irc.ERR_SASLABORTED,
|
---|
[112] | 475 | Params: []string{"*", "SASL authentication aborted"},
|
---|
| 476 | }}
|
---|
| 477 | } else if msg.Params[0] == "+" {
|
---|
| 478 | resp = nil
|
---|
| 479 | } else {
|
---|
| 480 | // TODO: multi-line messages
|
---|
| 481 | var err error
|
---|
| 482 | resp, err = base64.StdEncoding.DecodeString(msg.Params[0])
|
---|
| 483 | if err != nil {
|
---|
| 484 | dc.saslServer = nil
|
---|
| 485 | return ircError{&irc.Message{
|
---|
[125] | 486 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 487 | Params: []string{"*", "Invalid base64-encoded response"},
|
---|
| 488 | }}
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | challenge, done, err := dc.saslServer.Next(resp)
|
---|
| 493 | if err != nil {
|
---|
| 494 | dc.saslServer = nil
|
---|
| 495 | if ircErr, ok := err.(ircError); ok && ircErr.Message.Command == irc.ERR_PASSWDMISMATCH {
|
---|
| 496 | return ircError{&irc.Message{
|
---|
[125] | 497 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 498 | Params: []string{"*", ircErr.Message.Params[1]},
|
---|
| 499 | }}
|
---|
| 500 | }
|
---|
| 501 | dc.SendMessage(&irc.Message{
|
---|
| 502 | Prefix: dc.srv.prefix(),
|
---|
[125] | 503 | Command: irc.ERR_SASLFAIL,
|
---|
[112] | 504 | Params: []string{"*", "SASL error"},
|
---|
| 505 | })
|
---|
| 506 | return fmt.Errorf("SASL authentication failed: %v", err)
|
---|
| 507 | } else if done {
|
---|
| 508 | dc.saslServer = nil
|
---|
| 509 | dc.SendMessage(&irc.Message{
|
---|
| 510 | Prefix: dc.srv.prefix(),
|
---|
[125] | 511 | Command: irc.RPL_LOGGEDIN,
|
---|
[306] | 512 | Params: []string{dc.nick, dc.prefix().String(), dc.user.Username, "You are now logged in"},
|
---|
[112] | 513 | })
|
---|
| 514 | dc.SendMessage(&irc.Message{
|
---|
| 515 | Prefix: dc.srv.prefix(),
|
---|
[125] | 516 | Command: irc.RPL_SASLSUCCESS,
|
---|
[112] | 517 | Params: []string{dc.nick, "SASL authentication successful"},
|
---|
| 518 | })
|
---|
| 519 | } else {
|
---|
| 520 | challengeStr := "+"
|
---|
[135] | 521 | if len(challenge) > 0 {
|
---|
[112] | 522 | challengeStr = base64.StdEncoding.EncodeToString(challenge)
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | // TODO: multi-line messages
|
---|
| 526 | dc.SendMessage(&irc.Message{
|
---|
| 527 | Prefix: dc.srv.prefix(),
|
---|
| 528 | Command: "AUTHENTICATE",
|
---|
| 529 | Params: []string{challengeStr},
|
---|
| 530 | })
|
---|
| 531 | }
|
---|
[13] | 532 | default:
|
---|
[55] | 533 | dc.logger.Printf("unhandled message: %v", msg)
|
---|
[13] | 534 | return newUnknownCommandError(msg.Command)
|
---|
| 535 | }
|
---|
[108] | 536 | if dc.rawUsername != "" && dc.nick != "" && !dc.negociatingCaps {
|
---|
[55] | 537 | return dc.register()
|
---|
[13] | 538 | }
|
---|
| 539 | return nil
|
---|
| 540 | }
|
---|
| 541 |
|
---|
[108] | 542 | func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error {
|
---|
[111] | 543 | cmd = strings.ToUpper(cmd)
|
---|
| 544 |
|
---|
[108] | 545 | replyTo := dc.nick
|
---|
| 546 | if !dc.registered {
|
---|
| 547 | replyTo = "*"
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | switch cmd {
|
---|
| 551 | case "LS":
|
---|
| 552 | if len(args) > 0 {
|
---|
| 553 | var err error
|
---|
| 554 | if dc.capVersion, err = strconv.Atoi(args[0]); err != nil {
|
---|
| 555 | return err
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
[275] | 559 | caps := make([]string, 0, len(dc.supportedCaps))
|
---|
| 560 | for k, v := range dc.supportedCaps {
|
---|
| 561 | if dc.capVersion >= 302 && v != "" {
|
---|
[276] | 562 | caps = append(caps, k+"="+v)
|
---|
[275] | 563 | } else {
|
---|
| 564 | caps = append(caps, k)
|
---|
| 565 | }
|
---|
[112] | 566 | }
|
---|
[108] | 567 |
|
---|
| 568 | // TODO: multi-line replies
|
---|
| 569 | dc.SendMessage(&irc.Message{
|
---|
| 570 | Prefix: dc.srv.prefix(),
|
---|
| 571 | Command: "CAP",
|
---|
| 572 | Params: []string{replyTo, "LS", strings.Join(caps, " ")},
|
---|
| 573 | })
|
---|
| 574 |
|
---|
[275] | 575 | if dc.capVersion >= 302 {
|
---|
| 576 | // CAP version 302 implicitly enables cap-notify
|
---|
| 577 | dc.caps["cap-notify"] = true
|
---|
| 578 | }
|
---|
| 579 |
|
---|
[108] | 580 | if !dc.registered {
|
---|
| 581 | dc.negociatingCaps = true
|
---|
| 582 | }
|
---|
| 583 | case "LIST":
|
---|
| 584 | var caps []string
|
---|
| 585 | for name := range dc.caps {
|
---|
| 586 | caps = append(caps, name)
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | // TODO: multi-line replies
|
---|
| 590 | dc.SendMessage(&irc.Message{
|
---|
| 591 | Prefix: dc.srv.prefix(),
|
---|
| 592 | Command: "CAP",
|
---|
| 593 | Params: []string{replyTo, "LIST", strings.Join(caps, " ")},
|
---|
| 594 | })
|
---|
| 595 | case "REQ":
|
---|
| 596 | if len(args) == 0 {
|
---|
| 597 | return ircError{&irc.Message{
|
---|
| 598 | Command: err_invalidcapcmd,
|
---|
| 599 | Params: []string{replyTo, cmd, "Missing argument in CAP REQ command"},
|
---|
| 600 | }}
|
---|
| 601 | }
|
---|
| 602 |
|
---|
[275] | 603 | // TODO: atomically ack/nak the whole capability set
|
---|
[108] | 604 | caps := strings.Fields(args[0])
|
---|
| 605 | ack := true
|
---|
| 606 | for _, name := range caps {
|
---|
| 607 | name = strings.ToLower(name)
|
---|
| 608 | enable := !strings.HasPrefix(name, "-")
|
---|
| 609 | if !enable {
|
---|
| 610 | name = strings.TrimPrefix(name, "-")
|
---|
| 611 | }
|
---|
| 612 |
|
---|
[275] | 613 | if enable == dc.caps[name] {
|
---|
[108] | 614 | continue
|
---|
| 615 | }
|
---|
| 616 |
|
---|
[275] | 617 | _, ok := dc.supportedCaps[name]
|
---|
| 618 | if !ok {
|
---|
[108] | 619 | ack = false
|
---|
[275] | 620 | break
|
---|
[108] | 621 | }
|
---|
[275] | 622 |
|
---|
| 623 | if name == "cap-notify" && dc.capVersion >= 302 && !enable {
|
---|
| 624 | // cap-notify cannot be disabled with CAP version 302
|
---|
| 625 | ack = false
|
---|
| 626 | break
|
---|
| 627 | }
|
---|
| 628 |
|
---|
| 629 | dc.caps[name] = enable
|
---|
[108] | 630 | }
|
---|
| 631 |
|
---|
| 632 | reply := "NAK"
|
---|
| 633 | if ack {
|
---|
| 634 | reply = "ACK"
|
---|
| 635 | }
|
---|
| 636 | dc.SendMessage(&irc.Message{
|
---|
| 637 | Prefix: dc.srv.prefix(),
|
---|
| 638 | Command: "CAP",
|
---|
| 639 | Params: []string{replyTo, reply, args[0]},
|
---|
| 640 | })
|
---|
| 641 | case "END":
|
---|
| 642 | dc.negociatingCaps = false
|
---|
| 643 | default:
|
---|
| 644 | return ircError{&irc.Message{
|
---|
| 645 | Command: err_invalidcapcmd,
|
---|
| 646 | Params: []string{replyTo, cmd, "Unknown CAP command"},
|
---|
| 647 | }}
|
---|
| 648 | }
|
---|
| 649 | return nil
|
---|
| 650 | }
|
---|
| 651 |
|
---|
[275] | 652 | func (dc *downstreamConn) setSupportedCap(name, value string) {
|
---|
| 653 | prevValue, hasPrev := dc.supportedCaps[name]
|
---|
| 654 | changed := !hasPrev || prevValue != value
|
---|
| 655 | dc.supportedCaps[name] = value
|
---|
| 656 |
|
---|
| 657 | if !dc.caps["cap-notify"] || !changed {
|
---|
| 658 | return
|
---|
| 659 | }
|
---|
| 660 |
|
---|
| 661 | replyTo := dc.nick
|
---|
| 662 | if !dc.registered {
|
---|
| 663 | replyTo = "*"
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | cap := name
|
---|
| 667 | if value != "" && dc.capVersion >= 302 {
|
---|
| 668 | cap = name + "=" + value
|
---|
| 669 | }
|
---|
| 670 |
|
---|
| 671 | dc.SendMessage(&irc.Message{
|
---|
| 672 | Prefix: dc.srv.prefix(),
|
---|
| 673 | Command: "CAP",
|
---|
| 674 | Params: []string{replyTo, "NEW", cap},
|
---|
| 675 | })
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | func (dc *downstreamConn) unsetSupportedCap(name string) {
|
---|
| 679 | _, hasPrev := dc.supportedCaps[name]
|
---|
| 680 | delete(dc.supportedCaps, name)
|
---|
| 681 | delete(dc.caps, name)
|
---|
| 682 |
|
---|
| 683 | if !dc.caps["cap-notify"] || !hasPrev {
|
---|
| 684 | return
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | replyTo := dc.nick
|
---|
| 688 | if !dc.registered {
|
---|
| 689 | replyTo = "*"
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | dc.SendMessage(&irc.Message{
|
---|
| 693 | Prefix: dc.srv.prefix(),
|
---|
| 694 | Command: "CAP",
|
---|
| 695 | Params: []string{replyTo, "DEL", name},
|
---|
| 696 | })
|
---|
| 697 | }
|
---|
| 698 |
|
---|
[276] | 699 | func (dc *downstreamConn) updateSupportedCaps() {
|
---|
[292] | 700 | supportedCaps := make(map[string]bool)
|
---|
| 701 | for cap := range needAllDownstreamCaps {
|
---|
| 702 | supportedCaps[cap] = true
|
---|
| 703 | }
|
---|
[276] | 704 | dc.forEachUpstream(func(uc *upstreamConn) {
|
---|
[292] | 705 | for cap, supported := range supportedCaps {
|
---|
| 706 | supportedCaps[cap] = supported && uc.caps[cap]
|
---|
| 707 | }
|
---|
[276] | 708 | })
|
---|
| 709 |
|
---|
[292] | 710 | for cap, supported := range supportedCaps {
|
---|
| 711 | if supported {
|
---|
| 712 | dc.setSupportedCap(cap, needAllDownstreamCaps[cap])
|
---|
| 713 | } else {
|
---|
| 714 | dc.unsetSupportedCap(cap)
|
---|
| 715 | }
|
---|
[276] | 716 | }
|
---|
| 717 | }
|
---|
| 718 |
|
---|
[296] | 719 | func (dc *downstreamConn) updateNick() {
|
---|
| 720 | if uc := dc.upstream(); uc != nil && uc.nick != dc.nick {
|
---|
| 721 | dc.SendMessage(&irc.Message{
|
---|
| 722 | Prefix: dc.prefix(),
|
---|
| 723 | Command: "NICK",
|
---|
| 724 | Params: []string{uc.nick},
|
---|
| 725 | })
|
---|
| 726 | dc.nick = uc.nick
|
---|
| 727 | }
|
---|
| 728 | }
|
---|
| 729 |
|
---|
[91] | 730 | func sanityCheckServer(addr string) error {
|
---|
| 731 | dialer := net.Dialer{Timeout: 30 * time.Second}
|
---|
| 732 | conn, err := tls.DialWithDialer(&dialer, "tcp", addr, nil)
|
---|
| 733 | if err != nil {
|
---|
| 734 | return err
|
---|
| 735 | }
|
---|
| 736 | return conn.Close()
|
---|
| 737 | }
|
---|
| 738 |
|
---|
[183] | 739 | func unmarshalUsername(rawUsername string) (username, client, network string) {
|
---|
[112] | 740 | username = rawUsername
|
---|
[183] | 741 |
|
---|
| 742 | i := strings.IndexAny(username, "/@")
|
---|
| 743 | j := strings.LastIndexAny(username, "/@")
|
---|
| 744 | if i >= 0 {
|
---|
| 745 | username = rawUsername[:i]
|
---|
[73] | 746 | }
|
---|
[183] | 747 | if j >= 0 {
|
---|
[190] | 748 | if rawUsername[j] == '@' {
|
---|
| 749 | client = rawUsername[j+1:]
|
---|
| 750 | } else {
|
---|
| 751 | network = rawUsername[j+1:]
|
---|
| 752 | }
|
---|
[73] | 753 | }
|
---|
[183] | 754 | if i >= 0 && j >= 0 && i < j {
|
---|
[190] | 755 | if rawUsername[i] == '@' {
|
---|
| 756 | client = rawUsername[i+1 : j]
|
---|
| 757 | } else {
|
---|
| 758 | network = rawUsername[i+1 : j]
|
---|
| 759 | }
|
---|
[183] | 760 | }
|
---|
| 761 |
|
---|
| 762 | return username, client, network
|
---|
[112] | 763 | }
|
---|
[73] | 764 |
|
---|
[168] | 765 | func (dc *downstreamConn) authenticate(username, password string) error {
|
---|
[183] | 766 | username, clientName, networkName := unmarshalUsername(username)
|
---|
[168] | 767 |
|
---|
[173] | 768 | u, err := dc.srv.db.GetUser(username)
|
---|
| 769 | if err != nil {
|
---|
| 770 | dc.logger.Printf("failed authentication for %q: %v", username, err)
|
---|
[168] | 771 | return errAuthFailed
|
---|
| 772 | }
|
---|
| 773 |
|
---|
[322] | 774 | // Password auth disabled
|
---|
| 775 | if u.Password == "" {
|
---|
| 776 | return errAuthFailed
|
---|
| 777 | }
|
---|
| 778 |
|
---|
[173] | 779 | err = bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
|
---|
[168] | 780 | if err != nil {
|
---|
| 781 | dc.logger.Printf("failed authentication for %q: %v", username, err)
|
---|
| 782 | return errAuthFailed
|
---|
| 783 | }
|
---|
| 784 |
|
---|
[173] | 785 | dc.user = dc.srv.getUser(username)
|
---|
| 786 | if dc.user == nil {
|
---|
| 787 | dc.logger.Printf("failed authentication for %q: user not active", username)
|
---|
| 788 | return errAuthFailed
|
---|
| 789 | }
|
---|
[183] | 790 | dc.clientName = clientName
|
---|
[168] | 791 | dc.networkName = networkName
|
---|
| 792 | return nil
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | func (dc *downstreamConn) register() error {
|
---|
| 796 | if dc.registered {
|
---|
| 797 | return fmt.Errorf("tried to register twice")
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | password := dc.password
|
---|
| 801 | dc.password = ""
|
---|
| 802 | if dc.user == nil {
|
---|
| 803 | if err := dc.authenticate(dc.rawUsername, password); err != nil {
|
---|
| 804 | return err
|
---|
| 805 | }
|
---|
| 806 | }
|
---|
| 807 |
|
---|
[183] | 808 | if dc.clientName == "" && dc.networkName == "" {
|
---|
| 809 | _, dc.clientName, dc.networkName = unmarshalUsername(dc.rawUsername)
|
---|
[168] | 810 | }
|
---|
| 811 |
|
---|
| 812 | dc.registered = true
|
---|
[184] | 813 | dc.logger.Printf("registration complete for user %q", dc.user.Username)
|
---|
[168] | 814 | return nil
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | func (dc *downstreamConn) loadNetwork() error {
|
---|
| 818 | if dc.networkName == "" {
|
---|
[112] | 819 | return nil
|
---|
| 820 | }
|
---|
[85] | 821 |
|
---|
[168] | 822 | network := dc.user.getNetwork(dc.networkName)
|
---|
[112] | 823 | if network == nil {
|
---|
[168] | 824 | addr := dc.networkName
|
---|
[112] | 825 | if !strings.ContainsRune(addr, ':') {
|
---|
| 826 | addr = addr + ":6697"
|
---|
| 827 | }
|
---|
| 828 |
|
---|
| 829 | dc.logger.Printf("trying to connect to new network %q", addr)
|
---|
| 830 | if err := sanityCheckServer(addr); err != nil {
|
---|
| 831 | dc.logger.Printf("failed to connect to %q: %v", addr, err)
|
---|
| 832 | return ircError{&irc.Message{
|
---|
| 833 | Command: irc.ERR_PASSWDMISMATCH,
|
---|
[168] | 834 | Params: []string{"*", fmt.Sprintf("Failed to connect to %q", dc.networkName)},
|
---|
[112] | 835 | }}
|
---|
| 836 | }
|
---|
| 837 |
|
---|
[354] | 838 | // Some clients only allow specifying the nickname (and use the
|
---|
| 839 | // nickname as a username too). Strip the network name from the
|
---|
| 840 | // nickname when auto-saving networks.
|
---|
| 841 | nick, _, _ := unmarshalUsername(dc.nick)
|
---|
| 842 |
|
---|
[168] | 843 | dc.logger.Printf("auto-saving network %q", dc.networkName)
|
---|
[112] | 844 | var err error
|
---|
[120] | 845 | network, err = dc.user.createNetwork(&Network{
|
---|
[168] | 846 | Addr: dc.networkName,
|
---|
[354] | 847 | Nick: nick,
|
---|
[120] | 848 | })
|
---|
[112] | 849 | if err != nil {
|
---|
| 850 | return err
|
---|
| 851 | }
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | dc.network = network
|
---|
| 855 | return nil
|
---|
| 856 | }
|
---|
| 857 |
|
---|
[168] | 858 | func (dc *downstreamConn) welcome() error {
|
---|
| 859 | if dc.user == nil || !dc.registered {
|
---|
| 860 | panic("tried to welcome an unregistered connection")
|
---|
[37] | 861 | }
|
---|
| 862 |
|
---|
[168] | 863 | // TODO: doing this might take some time. We should do it in dc.register
|
---|
| 864 | // instead, but we'll potentially be adding a new network and this must be
|
---|
| 865 | // done in the user goroutine.
|
---|
| 866 | if err := dc.loadNetwork(); err != nil {
|
---|
| 867 | return err
|
---|
[85] | 868 | }
|
---|
| 869 |
|
---|
[55] | 870 | dc.SendMessage(&irc.Message{
|
---|
| 871 | Prefix: dc.srv.prefix(),
|
---|
[13] | 872 | Command: irc.RPL_WELCOME,
|
---|
[98] | 873 | Params: []string{dc.nick, "Welcome to soju, " + dc.nick},
|
---|
[54] | 874 | })
|
---|
[55] | 875 | dc.SendMessage(&irc.Message{
|
---|
| 876 | Prefix: dc.srv.prefix(),
|
---|
[13] | 877 | Command: irc.RPL_YOURHOST,
|
---|
[55] | 878 | Params: []string{dc.nick, "Your host is " + dc.srv.Hostname},
|
---|
[54] | 879 | })
|
---|
[55] | 880 | dc.SendMessage(&irc.Message{
|
---|
| 881 | Prefix: dc.srv.prefix(),
|
---|
[13] | 882 | Command: irc.RPL_CREATED,
|
---|
[55] | 883 | Params: []string{dc.nick, "Who cares when the server was created?"},
|
---|
[54] | 884 | })
|
---|
[55] | 885 | dc.SendMessage(&irc.Message{
|
---|
| 886 | Prefix: dc.srv.prefix(),
|
---|
[13] | 887 | Command: irc.RPL_MYINFO,
|
---|
[98] | 888 | Params: []string{dc.nick, dc.srv.Hostname, "soju", "aiwroO", "OovaimnqpsrtklbeI"},
|
---|
[54] | 889 | })
|
---|
[93] | 890 | // TODO: RPL_ISUPPORT
|
---|
[319] | 891 | // TODO: send CHATHISTORY in RPL_ISUPPORT when implemented
|
---|
[55] | 892 | dc.SendMessage(&irc.Message{
|
---|
| 893 | Prefix: dc.srv.prefix(),
|
---|
[13] | 894 | Command: irc.ERR_NOMOTD,
|
---|
[55] | 895 | Params: []string{dc.nick, "No MOTD"},
|
---|
[54] | 896 | })
|
---|
[13] | 897 |
|
---|
[296] | 898 | dc.updateNick()
|
---|
| 899 |
|
---|
[73] | 900 | dc.forEachUpstream(func(uc *upstreamConn) {
|
---|
[30] | 901 | for _, ch := range uc.channels {
|
---|
[284] | 902 | if !ch.complete {
|
---|
| 903 | continue
|
---|
| 904 | }
|
---|
| 905 | if record, ok := uc.network.channels[ch.Name]; ok && record.Detached {
|
---|
| 906 | continue
|
---|
| 907 | }
|
---|
[132] | 908 |
|
---|
[284] | 909 | dc.SendMessage(&irc.Message{
|
---|
| 910 | Prefix: dc.prefix(),
|
---|
| 911 | Command: "JOIN",
|
---|
| 912 | Params: []string{dc.marshalEntity(ch.conn.network, ch.Name)},
|
---|
| 913 | })
|
---|
| 914 |
|
---|
| 915 | forwardChannel(dc, ch)
|
---|
[30] | 916 | }
|
---|
[143] | 917 | })
|
---|
[50] | 918 |
|
---|
[143] | 919 | dc.forEachNetwork(func(net *network) {
|
---|
[253] | 920 | // Only send history if we're the first connected client with that name
|
---|
| 921 | // for the network
|
---|
| 922 | if _, ok := net.offlineClients[dc.clientName]; ok {
|
---|
| 923 | dc.sendNetworkHistory(net)
|
---|
| 924 | delete(net.offlineClients, dc.clientName)
|
---|
[227] | 925 | }
|
---|
[409] | 926 |
|
---|
| 927 | // Fast-forward history to last message
|
---|
| 928 | for target, history := range net.history {
|
---|
| 929 | if ch, ok := net.channels[target]; ok && ch.Detached {
|
---|
| 930 | continue
|
---|
| 931 | }
|
---|
| 932 |
|
---|
[423] | 933 | lastID, err := dc.user.msgStore.LastMsgID(net, target, time.Now())
|
---|
[409] | 934 | if err != nil {
|
---|
| 935 | dc.logger.Printf("failed to get last message ID: %v", err)
|
---|
| 936 | continue
|
---|
| 937 | }
|
---|
| 938 | history.clients[dc.clientName] = lastID
|
---|
| 939 | }
|
---|
[253] | 940 | })
|
---|
[57] | 941 |
|
---|
[253] | 942 | return nil
|
---|
| 943 | }
|
---|
[144] | 944 |
|
---|
[428] | 945 | // messageSupportsHistory checks whether the provided message can be sent as
|
---|
| 946 | // part of an history batch.
|
---|
| 947 | func (dc *downstreamConn) messageSupportsHistory(msg *irc.Message) bool {
|
---|
| 948 | // Don't replay all messages, because that would mess up client
|
---|
| 949 | // state. For instance we just sent the list of users, sending
|
---|
| 950 | // PART messages for one of these users would be incorrect.
|
---|
| 951 | // TODO: add support for draft/event-playback
|
---|
| 952 | switch msg.Command {
|
---|
| 953 | case "PRIVMSG", "NOTICE":
|
---|
| 954 | return true
|
---|
| 955 | }
|
---|
| 956 | return false
|
---|
| 957 | }
|
---|
| 958 |
|
---|
[253] | 959 | func (dc *downstreamConn) sendNetworkHistory(net *network) {
|
---|
[423] | 960 | if dc.caps["draft/chathistory"] || dc.user.msgStore == nil {
|
---|
[319] | 961 | return
|
---|
| 962 | }
|
---|
[253] | 963 | for target, history := range net.history {
|
---|
[284] | 964 | if ch, ok := net.channels[target]; ok && ch.Detached {
|
---|
| 965 | continue
|
---|
| 966 | }
|
---|
| 967 |
|
---|
[409] | 968 | lastDelivered, ok := history.clients[dc.clientName]
|
---|
[253] | 969 | if !ok {
|
---|
| 970 | continue
|
---|
| 971 | }
|
---|
| 972 |
|
---|
[409] | 973 | limit := 4000
|
---|
[423] | 974 | history, err := dc.user.msgStore.LoadLatestID(net, target, lastDelivered, limit)
|
---|
[409] | 975 | if err != nil {
|
---|
| 976 | dc.logger.Printf("failed to send implicit history for %q: %v", target, err)
|
---|
| 977 | continue
|
---|
| 978 | }
|
---|
[253] | 979 |
|
---|
[256] | 980 | batchRef := "history"
|
---|
| 981 | if dc.caps["batch"] {
|
---|
| 982 | dc.SendMessage(&irc.Message{
|
---|
| 983 | Prefix: dc.srv.prefix(),
|
---|
| 984 | Command: "BATCH",
|
---|
[260] | 985 | Params: []string{"+" + batchRef, "chathistory", dc.marshalEntity(net, target)},
|
---|
[256] | 986 | })
|
---|
| 987 | }
|
---|
| 988 |
|
---|
[409] | 989 | for _, msg := range history {
|
---|
[428] | 990 | if !dc.messageSupportsHistory(msg) {
|
---|
[245] | 991 | continue
|
---|
| 992 | }
|
---|
| 993 |
|
---|
[256] | 994 | if dc.caps["batch"] {
|
---|
| 995 | msg.Tags["batch"] = irc.TagValue(batchRef)
|
---|
| 996 | }
|
---|
[261] | 997 | dc.SendMessage(dc.marshalMessage(msg, net))
|
---|
[227] | 998 | }
|
---|
[256] | 999 |
|
---|
| 1000 | if dc.caps["batch"] {
|
---|
| 1001 | dc.SendMessage(&irc.Message{
|
---|
| 1002 | Prefix: dc.srv.prefix(),
|
---|
| 1003 | Command: "BATCH",
|
---|
| 1004 | Params: []string{"-" + batchRef},
|
---|
| 1005 | })
|
---|
| 1006 | }
|
---|
[253] | 1007 | }
|
---|
[13] | 1008 | }
|
---|
| 1009 |
|
---|
[103] | 1010 | func (dc *downstreamConn) runUntilRegistered() error {
|
---|
| 1011 | for !dc.registered {
|
---|
[212] | 1012 | msg, err := dc.ReadMessage()
|
---|
[106] | 1013 | if err != nil {
|
---|
[103] | 1014 | return fmt.Errorf("failed to read IRC command: %v", err)
|
---|
| 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | err = dc.handleMessage(msg)
|
---|
| 1018 | if ircErr, ok := err.(ircError); ok {
|
---|
| 1019 | ircErr.Message.Prefix = dc.srv.prefix()
|
---|
| 1020 | dc.SendMessage(ircErr.Message)
|
---|
| 1021 | } else if err != nil {
|
---|
| 1022 | return fmt.Errorf("failed to handle IRC command %q: %v", msg, err)
|
---|
| 1023 | }
|
---|
| 1024 | }
|
---|
| 1025 |
|
---|
| 1026 | return nil
|
---|
| 1027 | }
|
---|
| 1028 |
|
---|
[55] | 1029 | func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
---|
[13] | 1030 | switch msg.Command {
|
---|
[111] | 1031 | case "CAP":
|
---|
| 1032 | var subCmd string
|
---|
| 1033 | if err := parseMessageParams(msg, &subCmd); err != nil {
|
---|
| 1034 | return err
|
---|
| 1035 | }
|
---|
| 1036 | if err := dc.handleCapCommand(subCmd, msg.Params[1:]); err != nil {
|
---|
| 1037 | return err
|
---|
| 1038 | }
|
---|
[107] | 1039 | case "PING":
|
---|
[412] | 1040 | var source, destination string
|
---|
| 1041 | if err := parseMessageParams(msg, &source); err != nil {
|
---|
| 1042 | return err
|
---|
| 1043 | }
|
---|
| 1044 | if len(msg.Params) > 1 {
|
---|
| 1045 | destination = msg.Params[1]
|
---|
| 1046 | }
|
---|
| 1047 | if destination != "" && destination != dc.srv.Hostname {
|
---|
| 1048 | return ircError{&irc.Message{
|
---|
| 1049 | Command: irc.ERR_NOSUCHSERVER,
|
---|
[413] | 1050 | Params: []string{dc.nick, destination, "No such server"},
|
---|
[412] | 1051 | }}
|
---|
| 1052 | }
|
---|
[107] | 1053 | dc.SendMessage(&irc.Message{
|
---|
| 1054 | Prefix: dc.srv.prefix(),
|
---|
| 1055 | Command: "PONG",
|
---|
[412] | 1056 | Params: []string{dc.srv.Hostname, source},
|
---|
[107] | 1057 | })
|
---|
| 1058 | return nil
|
---|
[428] | 1059 | case "PONG":
|
---|
| 1060 | if len(msg.Params) == 0 {
|
---|
| 1061 | return newNeedMoreParamsError(msg.Command)
|
---|
| 1062 | }
|
---|
| 1063 | token := msg.Params[len(msg.Params)-1]
|
---|
| 1064 | dc.handlePong(token)
|
---|
[42] | 1065 | case "USER":
|
---|
[13] | 1066 | return ircError{&irc.Message{
|
---|
| 1067 | Command: irc.ERR_ALREADYREGISTERED,
|
---|
[55] | 1068 | Params: []string{dc.nick, "You may not reregister"},
|
---|
[13] | 1069 | }}
|
---|
[42] | 1070 | case "NICK":
|
---|
[429] | 1071 | var rawNick string
|
---|
| 1072 | if err := parseMessageParams(msg, &rawNick); err != nil {
|
---|
[90] | 1073 | return err
|
---|
| 1074 | }
|
---|
| 1075 |
|
---|
[429] | 1076 | nick := rawNick
|
---|
[297] | 1077 | var upstream *upstreamConn
|
---|
| 1078 | if dc.upstream() == nil {
|
---|
| 1079 | uc, unmarshaledNick, err := dc.unmarshalEntity(nick)
|
---|
| 1080 | if err == nil { // NICK nick/network: NICK only on a specific upstream
|
---|
| 1081 | upstream = uc
|
---|
| 1082 | nick = unmarshaledNick
|
---|
| 1083 | }
|
---|
| 1084 | }
|
---|
| 1085 |
|
---|
[404] | 1086 | if strings.ContainsAny(nick, illegalNickChars) {
|
---|
| 1087 | return ircError{&irc.Message{
|
---|
| 1088 | Command: irc.ERR_ERRONEUSNICKNAME,
|
---|
[430] | 1089 | Params: []string{dc.nick, rawNick, "contains illegal characters"},
|
---|
[404] | 1090 | }}
|
---|
| 1091 | }
|
---|
[429] | 1092 | if nick == serviceNick {
|
---|
| 1093 | return ircError{&irc.Message{
|
---|
| 1094 | Command: irc.ERR_NICKNAMEINUSE,
|
---|
| 1095 | Params: []string{dc.nick, rawNick, "Nickname reserved for bouncer service"},
|
---|
| 1096 | }}
|
---|
| 1097 | }
|
---|
[404] | 1098 |
|
---|
[90] | 1099 | var err error
|
---|
| 1100 | dc.forEachNetwork(func(n *network) {
|
---|
[297] | 1101 | if err != nil || (upstream != nil && upstream.network != n) {
|
---|
[90] | 1102 | return
|
---|
| 1103 | }
|
---|
| 1104 | n.Nick = nick
|
---|
[421] | 1105 | err = dc.srv.db.StoreNetwork(dc.user.ID, &n.Network)
|
---|
[90] | 1106 | })
|
---|
| 1107 | if err != nil {
|
---|
| 1108 | return err
|
---|
| 1109 | }
|
---|
| 1110 |
|
---|
[73] | 1111 | dc.forEachUpstream(func(uc *upstreamConn) {
|
---|
[297] | 1112 | if upstream != nil && upstream != uc {
|
---|
| 1113 | return
|
---|
| 1114 | }
|
---|
[301] | 1115 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[297] | 1116 | Command: "NICK",
|
---|
| 1117 | Params: []string{nick},
|
---|
| 1118 | })
|
---|
[42] | 1119 | })
|
---|
[296] | 1120 |
|
---|
| 1121 | if dc.upstream() == nil && dc.nick != nick {
|
---|
| 1122 | dc.SendMessage(&irc.Message{
|
---|
| 1123 | Prefix: dc.prefix(),
|
---|
| 1124 | Command: "NICK",
|
---|
| 1125 | Params: []string{nick},
|
---|
| 1126 | })
|
---|
| 1127 | dc.nick = nick
|
---|
| 1128 | }
|
---|
[146] | 1129 | case "JOIN":
|
---|
| 1130 | var namesStr string
|
---|
| 1131 | if err := parseMessageParams(msg, &namesStr); err != nil {
|
---|
[48] | 1132 | return err
|
---|
| 1133 | }
|
---|
| 1134 |
|
---|
[146] | 1135 | var keys []string
|
---|
| 1136 | if len(msg.Params) > 1 {
|
---|
| 1137 | keys = strings.Split(msg.Params[1], ",")
|
---|
| 1138 | }
|
---|
| 1139 |
|
---|
| 1140 | for i, name := range strings.Split(namesStr, ",") {
|
---|
[145] | 1141 | uc, upstreamName, err := dc.unmarshalEntity(name)
|
---|
| 1142 | if err != nil {
|
---|
[158] | 1143 | return err
|
---|
[145] | 1144 | }
|
---|
[48] | 1145 |
|
---|
[146] | 1146 | var key string
|
---|
| 1147 | if len(keys) > i {
|
---|
| 1148 | key = keys[i]
|
---|
| 1149 | }
|
---|
| 1150 |
|
---|
| 1151 | params := []string{upstreamName}
|
---|
| 1152 | if key != "" {
|
---|
| 1153 | params = append(params, key)
|
---|
| 1154 | }
|
---|
[301] | 1155 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[146] | 1156 | Command: "JOIN",
|
---|
| 1157 | Params: params,
|
---|
[145] | 1158 | })
|
---|
[89] | 1159 |
|
---|
[284] | 1160 | ch := &Channel{Name: upstreamName, Key: key, Detached: false}
|
---|
[285] | 1161 | if current, ok := uc.network.channels[ch.Name]; ok && key == "" {
|
---|
| 1162 | // Don't clear the channel key if there's one set
|
---|
| 1163 | // TODO: add a way to unset the channel key
|
---|
| 1164 | ch.Key = current.Key
|
---|
| 1165 | }
|
---|
[222] | 1166 | if err := uc.network.createUpdateChannel(ch); err != nil {
|
---|
| 1167 | dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
|
---|
[89] | 1168 | }
|
---|
| 1169 | }
|
---|
[146] | 1170 | case "PART":
|
---|
| 1171 | var namesStr string
|
---|
| 1172 | if err := parseMessageParams(msg, &namesStr); err != nil {
|
---|
| 1173 | return err
|
---|
| 1174 | }
|
---|
| 1175 |
|
---|
| 1176 | var reason string
|
---|
| 1177 | if len(msg.Params) > 1 {
|
---|
| 1178 | reason = msg.Params[1]
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
| 1181 | for _, name := range strings.Split(namesStr, ",") {
|
---|
| 1182 | uc, upstreamName, err := dc.unmarshalEntity(name)
|
---|
| 1183 | if err != nil {
|
---|
[158] | 1184 | return err
|
---|
[146] | 1185 | }
|
---|
| 1186 |
|
---|
[284] | 1187 | if strings.EqualFold(reason, "detach") {
|
---|
| 1188 | ch := &Channel{Name: upstreamName, Detached: true}
|
---|
| 1189 | if err := uc.network.createUpdateChannel(ch); err != nil {
|
---|
| 1190 | dc.logger.Printf("failed to detach channel %q: %v", upstreamName, err)
|
---|
| 1191 | }
|
---|
| 1192 | } else {
|
---|
| 1193 | params := []string{upstreamName}
|
---|
| 1194 | if reason != "" {
|
---|
| 1195 | params = append(params, reason)
|
---|
| 1196 | }
|
---|
[301] | 1197 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[284] | 1198 | Command: "PART",
|
---|
| 1199 | Params: params,
|
---|
| 1200 | })
|
---|
[146] | 1201 |
|
---|
[284] | 1202 | if err := uc.network.deleteChannel(upstreamName); err != nil {
|
---|
| 1203 | dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err)
|
---|
| 1204 | }
|
---|
[146] | 1205 | }
|
---|
| 1206 | }
|
---|
[159] | 1207 | case "KICK":
|
---|
| 1208 | var channelStr, userStr string
|
---|
| 1209 | if err := parseMessageParams(msg, &channelStr, &userStr); err != nil {
|
---|
| 1210 | return err
|
---|
| 1211 | }
|
---|
| 1212 |
|
---|
| 1213 | channels := strings.Split(channelStr, ",")
|
---|
| 1214 | users := strings.Split(userStr, ",")
|
---|
| 1215 |
|
---|
| 1216 | var reason string
|
---|
| 1217 | if len(msg.Params) > 2 {
|
---|
| 1218 | reason = msg.Params[2]
|
---|
| 1219 | }
|
---|
| 1220 |
|
---|
| 1221 | if len(channels) != 1 && len(channels) != len(users) {
|
---|
| 1222 | return ircError{&irc.Message{
|
---|
| 1223 | Command: irc.ERR_BADCHANMASK,
|
---|
| 1224 | Params: []string{dc.nick, channelStr, "Bad channel mask"},
|
---|
| 1225 | }}
|
---|
| 1226 | }
|
---|
| 1227 |
|
---|
| 1228 | for i, user := range users {
|
---|
| 1229 | var channel string
|
---|
| 1230 | if len(channels) == 1 {
|
---|
| 1231 | channel = channels[0]
|
---|
| 1232 | } else {
|
---|
| 1233 | channel = channels[i]
|
---|
| 1234 | }
|
---|
| 1235 |
|
---|
| 1236 | ucChannel, upstreamChannel, err := dc.unmarshalEntity(channel)
|
---|
| 1237 | if err != nil {
|
---|
| 1238 | return err
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
| 1241 | ucUser, upstreamUser, err := dc.unmarshalEntity(user)
|
---|
| 1242 | if err != nil {
|
---|
| 1243 | return err
|
---|
| 1244 | }
|
---|
| 1245 |
|
---|
| 1246 | if ucChannel != ucUser {
|
---|
| 1247 | return ircError{&irc.Message{
|
---|
| 1248 | Command: irc.ERR_USERNOTINCHANNEL,
|
---|
[400] | 1249 | Params: []string{dc.nick, user, channel, "They are on another network"},
|
---|
[159] | 1250 | }}
|
---|
| 1251 | }
|
---|
| 1252 | uc := ucChannel
|
---|
| 1253 |
|
---|
| 1254 | params := []string{upstreamChannel, upstreamUser}
|
---|
| 1255 | if reason != "" {
|
---|
| 1256 | params = append(params, reason)
|
---|
| 1257 | }
|
---|
[301] | 1258 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[159] | 1259 | Command: "KICK",
|
---|
| 1260 | Params: params,
|
---|
| 1261 | })
|
---|
| 1262 | }
|
---|
[69] | 1263 | case "MODE":
|
---|
[46] | 1264 | var name string
|
---|
| 1265 | if err := parseMessageParams(msg, &name); err != nil {
|
---|
| 1266 | return err
|
---|
| 1267 | }
|
---|
| 1268 |
|
---|
| 1269 | var modeStr string
|
---|
| 1270 | if len(msg.Params) > 1 {
|
---|
| 1271 | modeStr = msg.Params[1]
|
---|
| 1272 | }
|
---|
| 1273 |
|
---|
[139] | 1274 | if name == dc.nick {
|
---|
[46] | 1275 | if modeStr != "" {
|
---|
[73] | 1276 | dc.forEachUpstream(func(uc *upstreamConn) {
|
---|
[301] | 1277 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[69] | 1278 | Command: "MODE",
|
---|
| 1279 | Params: []string{uc.nick, modeStr},
|
---|
| 1280 | })
|
---|
[46] | 1281 | })
|
---|
| 1282 | } else {
|
---|
[55] | 1283 | dc.SendMessage(&irc.Message{
|
---|
| 1284 | Prefix: dc.srv.prefix(),
|
---|
[46] | 1285 | Command: irc.RPL_UMODEIS,
|
---|
[129] | 1286 | Params: []string{dc.nick, ""}, // TODO
|
---|
[54] | 1287 | })
|
---|
[46] | 1288 | }
|
---|
[139] | 1289 | return nil
|
---|
[46] | 1290 | }
|
---|
[139] | 1291 |
|
---|
| 1292 | uc, upstreamName, err := dc.unmarshalEntity(name)
|
---|
| 1293 | if err != nil {
|
---|
| 1294 | return err
|
---|
| 1295 | }
|
---|
| 1296 |
|
---|
| 1297 | if !uc.isChannel(upstreamName) {
|
---|
| 1298 | return ircError{&irc.Message{
|
---|
| 1299 | Command: irc.ERR_USERSDONTMATCH,
|
---|
| 1300 | Params: []string{dc.nick, "Cannot change mode for other users"},
|
---|
| 1301 | }}
|
---|
| 1302 | }
|
---|
| 1303 |
|
---|
| 1304 | if modeStr != "" {
|
---|
| 1305 | params := []string{upstreamName, modeStr}
|
---|
| 1306 | params = append(params, msg.Params[2:]...)
|
---|
[301] | 1307 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[139] | 1308 | Command: "MODE",
|
---|
| 1309 | Params: params,
|
---|
| 1310 | })
|
---|
| 1311 | } else {
|
---|
| 1312 | ch, ok := uc.channels[upstreamName]
|
---|
| 1313 | if !ok {
|
---|
| 1314 | return ircError{&irc.Message{
|
---|
| 1315 | Command: irc.ERR_NOSUCHCHANNEL,
|
---|
| 1316 | Params: []string{dc.nick, name, "No such channel"},
|
---|
| 1317 | }}
|
---|
| 1318 | }
|
---|
| 1319 |
|
---|
| 1320 | if ch.modes == nil {
|
---|
| 1321 | // we haven't received the initial RPL_CHANNELMODEIS yet
|
---|
| 1322 | // ignore the request, we will broadcast the modes later when we receive RPL_CHANNELMODEIS
|
---|
| 1323 | return nil
|
---|
| 1324 | }
|
---|
| 1325 |
|
---|
| 1326 | modeStr, modeParams := ch.modes.Format()
|
---|
| 1327 | params := []string{dc.nick, name, modeStr}
|
---|
| 1328 | params = append(params, modeParams...)
|
---|
| 1329 |
|
---|
| 1330 | dc.SendMessage(&irc.Message{
|
---|
| 1331 | Prefix: dc.srv.prefix(),
|
---|
| 1332 | Command: irc.RPL_CHANNELMODEIS,
|
---|
| 1333 | Params: params,
|
---|
| 1334 | })
|
---|
[162] | 1335 | if ch.creationTime != "" {
|
---|
| 1336 | dc.SendMessage(&irc.Message{
|
---|
| 1337 | Prefix: dc.srv.prefix(),
|
---|
| 1338 | Command: rpl_creationtime,
|
---|
| 1339 | Params: []string{dc.nick, name, ch.creationTime},
|
---|
| 1340 | })
|
---|
| 1341 | }
|
---|
[139] | 1342 | }
|
---|
[160] | 1343 | case "TOPIC":
|
---|
| 1344 | var channel string
|
---|
| 1345 | if err := parseMessageParams(msg, &channel); err != nil {
|
---|
| 1346 | return err
|
---|
| 1347 | }
|
---|
| 1348 |
|
---|
| 1349 | uc, upstreamChannel, err := dc.unmarshalEntity(channel)
|
---|
| 1350 | if err != nil {
|
---|
| 1351 | return err
|
---|
| 1352 | }
|
---|
| 1353 |
|
---|
| 1354 | if len(msg.Params) > 1 { // setting topic
|
---|
| 1355 | topic := msg.Params[1]
|
---|
[301] | 1356 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[160] | 1357 | Command: "TOPIC",
|
---|
| 1358 | Params: []string{upstreamChannel, topic},
|
---|
| 1359 | })
|
---|
| 1360 | } else { // getting topic
|
---|
| 1361 | ch, ok := uc.channels[upstreamChannel]
|
---|
| 1362 | if !ok {
|
---|
| 1363 | return ircError{&irc.Message{
|
---|
| 1364 | Command: irc.ERR_NOSUCHCHANNEL,
|
---|
| 1365 | Params: []string{dc.nick, upstreamChannel, "No such channel"},
|
---|
| 1366 | }}
|
---|
| 1367 | }
|
---|
| 1368 | sendTopic(dc, ch)
|
---|
| 1369 | }
|
---|
[177] | 1370 | case "LIST":
|
---|
| 1371 | // TODO: support ELIST when supported by all upstreams
|
---|
| 1372 |
|
---|
| 1373 | pl := pendingLIST{
|
---|
| 1374 | downstreamID: dc.id,
|
---|
| 1375 | pendingCommands: make(map[int64]*irc.Message),
|
---|
| 1376 | }
|
---|
[298] | 1377 | var upstream *upstreamConn
|
---|
[177] | 1378 | var upstreamChannels map[int64][]string
|
---|
| 1379 | if len(msg.Params) > 0 {
|
---|
[298] | 1380 | uc, upstreamMask, err := dc.unmarshalEntity(msg.Params[0])
|
---|
| 1381 | if err == nil && upstreamMask == "*" { // LIST */network: send LIST only to one network
|
---|
| 1382 | upstream = uc
|
---|
| 1383 | } else {
|
---|
| 1384 | upstreamChannels = make(map[int64][]string)
|
---|
| 1385 | channels := strings.Split(msg.Params[0], ",")
|
---|
| 1386 | for _, channel := range channels {
|
---|
| 1387 | uc, upstreamChannel, err := dc.unmarshalEntity(channel)
|
---|
| 1388 | if err != nil {
|
---|
| 1389 | return err
|
---|
| 1390 | }
|
---|
| 1391 | upstreamChannels[uc.network.ID] = append(upstreamChannels[uc.network.ID], upstreamChannel)
|
---|
[177] | 1392 | }
|
---|
| 1393 | }
|
---|
| 1394 | }
|
---|
| 1395 |
|
---|
| 1396 | dc.user.pendingLISTs = append(dc.user.pendingLISTs, pl)
|
---|
| 1397 | dc.forEachUpstream(func(uc *upstreamConn) {
|
---|
[298] | 1398 | if upstream != nil && upstream != uc {
|
---|
| 1399 | return
|
---|
| 1400 | }
|
---|
[177] | 1401 | var params []string
|
---|
| 1402 | if upstreamChannels != nil {
|
---|
| 1403 | if channels, ok := upstreamChannels[uc.network.ID]; ok {
|
---|
| 1404 | params = []string{strings.Join(channels, ",")}
|
---|
| 1405 | } else {
|
---|
| 1406 | return
|
---|
| 1407 | }
|
---|
| 1408 | }
|
---|
| 1409 | pl.pendingCommands[uc.network.ID] = &irc.Message{
|
---|
| 1410 | Command: "LIST",
|
---|
| 1411 | Params: params,
|
---|
| 1412 | }
|
---|
[181] | 1413 | uc.trySendLIST(dc.id)
|
---|
[177] | 1414 | })
|
---|
[140] | 1415 | case "NAMES":
|
---|
| 1416 | if len(msg.Params) == 0 {
|
---|
| 1417 | dc.SendMessage(&irc.Message{
|
---|
| 1418 | Prefix: dc.srv.prefix(),
|
---|
| 1419 | Command: irc.RPL_ENDOFNAMES,
|
---|
| 1420 | Params: []string{dc.nick, "*", "End of /NAMES list"},
|
---|
| 1421 | })
|
---|
| 1422 | return nil
|
---|
| 1423 | }
|
---|
| 1424 |
|
---|
| 1425 | channels := strings.Split(msg.Params[0], ",")
|
---|
| 1426 | for _, channel := range channels {
|
---|
| 1427 | uc, upstreamChannel, err := dc.unmarshalEntity(channel)
|
---|
| 1428 | if err != nil {
|
---|
| 1429 | return err
|
---|
| 1430 | }
|
---|
| 1431 |
|
---|
| 1432 | ch, ok := uc.channels[upstreamChannel]
|
---|
| 1433 | if ok {
|
---|
| 1434 | sendNames(dc, ch)
|
---|
| 1435 | } else {
|
---|
| 1436 | // NAMES on a channel we have not joined, ask upstream
|
---|
[176] | 1437 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[140] | 1438 | Command: "NAMES",
|
---|
| 1439 | Params: []string{upstreamChannel},
|
---|
| 1440 | })
|
---|
| 1441 | }
|
---|
| 1442 | }
|
---|
[127] | 1443 | case "WHO":
|
---|
| 1444 | if len(msg.Params) == 0 {
|
---|
| 1445 | // TODO: support WHO without parameters
|
---|
| 1446 | dc.SendMessage(&irc.Message{
|
---|
| 1447 | Prefix: dc.srv.prefix(),
|
---|
| 1448 | Command: irc.RPL_ENDOFWHO,
|
---|
[140] | 1449 | Params: []string{dc.nick, "*", "End of /WHO list"},
|
---|
[127] | 1450 | })
|
---|
| 1451 | return nil
|
---|
| 1452 | }
|
---|
| 1453 |
|
---|
| 1454 | // TODO: support WHO masks
|
---|
| 1455 | entity := msg.Params[0]
|
---|
| 1456 |
|
---|
[142] | 1457 | if entity == dc.nick {
|
---|
| 1458 | // TODO: support AWAY (H/G) in self WHO reply
|
---|
| 1459 | dc.SendMessage(&irc.Message{
|
---|
| 1460 | Prefix: dc.srv.prefix(),
|
---|
| 1461 | Command: irc.RPL_WHOREPLY,
|
---|
[184] | 1462 | Params: []string{dc.nick, "*", dc.user.Username, dc.hostname, dc.srv.Hostname, dc.nick, "H", "0 " + dc.realname},
|
---|
[142] | 1463 | })
|
---|
| 1464 | dc.SendMessage(&irc.Message{
|
---|
| 1465 | Prefix: dc.srv.prefix(),
|
---|
| 1466 | Command: irc.RPL_ENDOFWHO,
|
---|
| 1467 | Params: []string{dc.nick, dc.nick, "End of /WHO list"},
|
---|
| 1468 | })
|
---|
| 1469 | return nil
|
---|
| 1470 | }
|
---|
[343] | 1471 | if entity == serviceNick {
|
---|
| 1472 | dc.SendMessage(&irc.Message{
|
---|
| 1473 | Prefix: dc.srv.prefix(),
|
---|
| 1474 | Command: irc.RPL_WHOREPLY,
|
---|
| 1475 | Params: []string{serviceNick, "*", servicePrefix.User, servicePrefix.Host, dc.srv.Hostname, serviceNick, "H", "0 " + serviceRealname},
|
---|
| 1476 | })
|
---|
| 1477 | dc.SendMessage(&irc.Message{
|
---|
| 1478 | Prefix: dc.srv.prefix(),
|
---|
| 1479 | Command: irc.RPL_ENDOFWHO,
|
---|
| 1480 | Params: []string{dc.nick, serviceNick, "End of /WHO list"},
|
---|
| 1481 | })
|
---|
| 1482 | return nil
|
---|
| 1483 | }
|
---|
[142] | 1484 |
|
---|
[127] | 1485 | uc, upstreamName, err := dc.unmarshalEntity(entity)
|
---|
| 1486 | if err != nil {
|
---|
| 1487 | return err
|
---|
| 1488 | }
|
---|
| 1489 |
|
---|
| 1490 | var params []string
|
---|
| 1491 | if len(msg.Params) == 2 {
|
---|
| 1492 | params = []string{upstreamName, msg.Params[1]}
|
---|
| 1493 | } else {
|
---|
| 1494 | params = []string{upstreamName}
|
---|
| 1495 | }
|
---|
| 1496 |
|
---|
[176] | 1497 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[127] | 1498 | Command: "WHO",
|
---|
| 1499 | Params: params,
|
---|
| 1500 | })
|
---|
[128] | 1501 | case "WHOIS":
|
---|
| 1502 | if len(msg.Params) == 0 {
|
---|
| 1503 | return ircError{&irc.Message{
|
---|
| 1504 | Command: irc.ERR_NONICKNAMEGIVEN,
|
---|
| 1505 | Params: []string{dc.nick, "No nickname given"},
|
---|
| 1506 | }}
|
---|
| 1507 | }
|
---|
| 1508 |
|
---|
| 1509 | var target, mask string
|
---|
| 1510 | if len(msg.Params) == 1 {
|
---|
| 1511 | target = ""
|
---|
| 1512 | mask = msg.Params[0]
|
---|
| 1513 | } else {
|
---|
| 1514 | target = msg.Params[0]
|
---|
| 1515 | mask = msg.Params[1]
|
---|
| 1516 | }
|
---|
| 1517 | // TODO: support multiple WHOIS users
|
---|
| 1518 | if i := strings.IndexByte(mask, ','); i >= 0 {
|
---|
| 1519 | mask = mask[:i]
|
---|
| 1520 | }
|
---|
| 1521 |
|
---|
[142] | 1522 | if mask == dc.nick {
|
---|
| 1523 | dc.SendMessage(&irc.Message{
|
---|
| 1524 | Prefix: dc.srv.prefix(),
|
---|
| 1525 | Command: irc.RPL_WHOISUSER,
|
---|
[184] | 1526 | Params: []string{dc.nick, dc.nick, dc.user.Username, dc.hostname, "*", dc.realname},
|
---|
[142] | 1527 | })
|
---|
| 1528 | dc.SendMessage(&irc.Message{
|
---|
| 1529 | Prefix: dc.srv.prefix(),
|
---|
| 1530 | Command: irc.RPL_WHOISSERVER,
|
---|
| 1531 | Params: []string{dc.nick, dc.nick, dc.srv.Hostname, "soju"},
|
---|
| 1532 | })
|
---|
| 1533 | dc.SendMessage(&irc.Message{
|
---|
| 1534 | Prefix: dc.srv.prefix(),
|
---|
| 1535 | Command: irc.RPL_ENDOFWHOIS,
|
---|
| 1536 | Params: []string{dc.nick, dc.nick, "End of /WHOIS list"},
|
---|
| 1537 | })
|
---|
| 1538 | return nil
|
---|
| 1539 | }
|
---|
| 1540 |
|
---|
[128] | 1541 | // TODO: support WHOIS masks
|
---|
| 1542 | uc, upstreamNick, err := dc.unmarshalEntity(mask)
|
---|
| 1543 | if err != nil {
|
---|
| 1544 | return err
|
---|
| 1545 | }
|
---|
| 1546 |
|
---|
| 1547 | var params []string
|
---|
| 1548 | if target != "" {
|
---|
[299] | 1549 | if target == mask { // WHOIS nick nick
|
---|
| 1550 | params = []string{upstreamNick, upstreamNick}
|
---|
| 1551 | } else {
|
---|
| 1552 | params = []string{target, upstreamNick}
|
---|
| 1553 | }
|
---|
[128] | 1554 | } else {
|
---|
| 1555 | params = []string{upstreamNick}
|
---|
| 1556 | }
|
---|
| 1557 |
|
---|
[176] | 1558 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[128] | 1559 | Command: "WHOIS",
|
---|
| 1560 | Params: params,
|
---|
| 1561 | })
|
---|
[58] | 1562 | case "PRIVMSG":
|
---|
| 1563 | var targetsStr, text string
|
---|
| 1564 | if err := parseMessageParams(msg, &targetsStr, &text); err != nil {
|
---|
| 1565 | return err
|
---|
| 1566 | }
|
---|
[303] | 1567 | tags := copyClientTags(msg.Tags)
|
---|
[58] | 1568 |
|
---|
| 1569 | for _, name := range strings.Split(targetsStr, ",") {
|
---|
[117] | 1570 | if name == serviceNick {
|
---|
[431] | 1571 | if dc.caps["echo-message"] {
|
---|
| 1572 | echoTags := tags.Copy()
|
---|
| 1573 | echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
|
---|
| 1574 | dc.SendMessage(&irc.Message{
|
---|
| 1575 | Tags: echoTags,
|
---|
| 1576 | Prefix: dc.prefix(),
|
---|
| 1577 | Command: "PRIVMSG",
|
---|
| 1578 | Params: []string{name, text},
|
---|
| 1579 | })
|
---|
| 1580 | }
|
---|
[117] | 1581 | handleServicePRIVMSG(dc, text)
|
---|
| 1582 | continue
|
---|
| 1583 | }
|
---|
| 1584 |
|
---|
[127] | 1585 | uc, upstreamName, err := dc.unmarshalEntity(name)
|
---|
[58] | 1586 | if err != nil {
|
---|
| 1587 | return err
|
---|
| 1588 | }
|
---|
| 1589 |
|
---|
[95] | 1590 | if upstreamName == "NickServ" {
|
---|
| 1591 | dc.handleNickServPRIVMSG(uc, text)
|
---|
| 1592 | }
|
---|
| 1593 |
|
---|
[268] | 1594 | unmarshaledText := text
|
---|
| 1595 | if uc.isChannel(upstreamName) {
|
---|
| 1596 | unmarshaledText = dc.unmarshalText(uc, text)
|
---|
| 1597 | }
|
---|
[301] | 1598 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[303] | 1599 | Tags: tags,
|
---|
[58] | 1600 | Command: "PRIVMSG",
|
---|
[268] | 1601 | Params: []string{upstreamName, unmarshaledText},
|
---|
[60] | 1602 | })
|
---|
[105] | 1603 |
|
---|
[303] | 1604 | echoTags := tags.Copy()
|
---|
| 1605 | echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
|
---|
[113] | 1606 | echoMsg := &irc.Message{
|
---|
[303] | 1607 | Tags: echoTags,
|
---|
[113] | 1608 | Prefix: &irc.Prefix{
|
---|
| 1609 | Name: uc.nick,
|
---|
| 1610 | User: uc.username,
|
---|
| 1611 | },
|
---|
[114] | 1612 | Command: "PRIVMSG",
|
---|
[113] | 1613 | Params: []string{upstreamName, text},
|
---|
| 1614 | }
|
---|
[239] | 1615 | uc.produce(upstreamName, echoMsg, dc)
|
---|
[58] | 1616 | }
|
---|
[164] | 1617 | case "NOTICE":
|
---|
| 1618 | var targetsStr, text string
|
---|
| 1619 | if err := parseMessageParams(msg, &targetsStr, &text); err != nil {
|
---|
| 1620 | return err
|
---|
| 1621 | }
|
---|
[303] | 1622 | tags := copyClientTags(msg.Tags)
|
---|
[164] | 1623 |
|
---|
| 1624 | for _, name := range strings.Split(targetsStr, ",") {
|
---|
| 1625 | uc, upstreamName, err := dc.unmarshalEntity(name)
|
---|
| 1626 | if err != nil {
|
---|
| 1627 | return err
|
---|
| 1628 | }
|
---|
| 1629 |
|
---|
[268] | 1630 | unmarshaledText := text
|
---|
| 1631 | if uc.isChannel(upstreamName) {
|
---|
| 1632 | unmarshaledText = dc.unmarshalText(uc, text)
|
---|
| 1633 | }
|
---|
[301] | 1634 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[303] | 1635 | Tags: tags,
|
---|
[164] | 1636 | Command: "NOTICE",
|
---|
[268] | 1637 | Params: []string{upstreamName, unmarshaledText},
|
---|
[164] | 1638 | })
|
---|
| 1639 | }
|
---|
[303] | 1640 | case "TAGMSG":
|
---|
| 1641 | var targetsStr string
|
---|
| 1642 | if err := parseMessageParams(msg, &targetsStr); err != nil {
|
---|
| 1643 | return err
|
---|
| 1644 | }
|
---|
| 1645 | tags := copyClientTags(msg.Tags)
|
---|
| 1646 |
|
---|
| 1647 | for _, name := range strings.Split(targetsStr, ",") {
|
---|
| 1648 | uc, upstreamName, err := dc.unmarshalEntity(name)
|
---|
| 1649 | if err != nil {
|
---|
| 1650 | return err
|
---|
| 1651 | }
|
---|
[427] | 1652 | if _, ok := uc.caps["message-tags"]; !ok {
|
---|
| 1653 | continue
|
---|
| 1654 | }
|
---|
[303] | 1655 |
|
---|
| 1656 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
| 1657 | Tags: tags,
|
---|
| 1658 | Command: "TAGMSG",
|
---|
| 1659 | Params: []string{upstreamName},
|
---|
| 1660 | })
|
---|
| 1661 | }
|
---|
[163] | 1662 | case "INVITE":
|
---|
| 1663 | var user, channel string
|
---|
| 1664 | if err := parseMessageParams(msg, &user, &channel); err != nil {
|
---|
| 1665 | return err
|
---|
| 1666 | }
|
---|
| 1667 |
|
---|
| 1668 | ucChannel, upstreamChannel, err := dc.unmarshalEntity(channel)
|
---|
| 1669 | if err != nil {
|
---|
| 1670 | return err
|
---|
| 1671 | }
|
---|
| 1672 |
|
---|
| 1673 | ucUser, upstreamUser, err := dc.unmarshalEntity(user)
|
---|
| 1674 | if err != nil {
|
---|
| 1675 | return err
|
---|
| 1676 | }
|
---|
| 1677 |
|
---|
| 1678 | if ucChannel != ucUser {
|
---|
| 1679 | return ircError{&irc.Message{
|
---|
| 1680 | Command: irc.ERR_USERNOTINCHANNEL,
|
---|
[401] | 1681 | Params: []string{dc.nick, user, channel, "They are on another network"},
|
---|
[163] | 1682 | }}
|
---|
| 1683 | }
|
---|
| 1684 | uc := ucChannel
|
---|
| 1685 |
|
---|
[176] | 1686 | uc.SendMessageLabeled(dc.id, &irc.Message{
|
---|
[163] | 1687 | Command: "INVITE",
|
---|
| 1688 | Params: []string{upstreamUser, upstreamChannel},
|
---|
| 1689 | })
|
---|
[319] | 1690 | case "CHATHISTORY":
|
---|
| 1691 | var subcommand string
|
---|
| 1692 | if err := parseMessageParams(msg, &subcommand); err != nil {
|
---|
| 1693 | return err
|
---|
| 1694 | }
|
---|
| 1695 | var target, criteria, limitStr string
|
---|
| 1696 | if err := parseMessageParams(msg, nil, &target, &criteria, &limitStr); err != nil {
|
---|
| 1697 | return ircError{&irc.Message{
|
---|
| 1698 | Command: "FAIL",
|
---|
| 1699 | Params: []string{"CHATHISTORY", "NEED_MORE_PARAMS", subcommand, "Missing parameters"},
|
---|
| 1700 | }}
|
---|
| 1701 | }
|
---|
| 1702 |
|
---|
[423] | 1703 | if dc.user.msgStore == nil {
|
---|
[319] | 1704 | return ircError{&irc.Message{
|
---|
| 1705 | Command: irc.ERR_UNKNOWNCOMMAND,
|
---|
| 1706 | Params: []string{dc.nick, subcommand, "Unknown command"},
|
---|
| 1707 | }}
|
---|
| 1708 | }
|
---|
| 1709 |
|
---|
| 1710 | uc, entity, err := dc.unmarshalEntity(target)
|
---|
| 1711 | if err != nil {
|
---|
| 1712 | return err
|
---|
| 1713 | }
|
---|
| 1714 |
|
---|
| 1715 | // TODO: support msgid criteria
|
---|
| 1716 | criteriaParts := strings.SplitN(criteria, "=", 2)
|
---|
| 1717 | if len(criteriaParts) != 2 || criteriaParts[0] != "timestamp" {
|
---|
| 1718 | return ircError{&irc.Message{
|
---|
| 1719 | Command: "FAIL",
|
---|
| 1720 | Params: []string{"CHATHISTORY", "UNKNOWN_CRITERIA", criteria, "Unknown criteria"},
|
---|
| 1721 | }}
|
---|
| 1722 | }
|
---|
| 1723 |
|
---|
| 1724 | timestamp, err := time.Parse(serverTimeLayout, criteriaParts[1])
|
---|
| 1725 | if err != nil {
|
---|
| 1726 | return ircError{&irc.Message{
|
---|
| 1727 | Command: "FAIL",
|
---|
| 1728 | Params: []string{"CHATHISTORY", "INVALID_CRITERIA", criteria, "Invalid criteria"},
|
---|
| 1729 | }}
|
---|
| 1730 | }
|
---|
| 1731 |
|
---|
| 1732 | limit, err := strconv.Atoi(limitStr)
|
---|
| 1733 | if err != nil || limit < 0 || limit > dc.srv.HistoryLimit {
|
---|
| 1734 | return ircError{&irc.Message{
|
---|
| 1735 | Command: "FAIL",
|
---|
| 1736 | Params: []string{"CHATHISTORY", "INVALID_LIMIT", limitStr, "Invalid limit"},
|
---|
| 1737 | }}
|
---|
| 1738 | }
|
---|
| 1739 |
|
---|
[387] | 1740 | var history []*irc.Message
|
---|
[319] | 1741 | switch subcommand {
|
---|
| 1742 | case "BEFORE":
|
---|
[423] | 1743 | history, err = dc.user.msgStore.LoadBeforeTime(uc.network, entity, timestamp, limit)
|
---|
[360] | 1744 | case "AFTER":
|
---|
[423] | 1745 | history, err = dc.user.msgStore.LoadAfterTime(uc.network, entity, timestamp, limit)
|
---|
[319] | 1746 | default:
|
---|
[360] | 1747 | // TODO: support LATEST, BETWEEN
|
---|
[319] | 1748 | return ircError{&irc.Message{
|
---|
| 1749 | Command: "FAIL",
|
---|
| 1750 | Params: []string{"CHATHISTORY", "UNKNOWN_COMMAND", subcommand, "Unknown command"},
|
---|
| 1751 | }}
|
---|
| 1752 | }
|
---|
[387] | 1753 | if err != nil {
|
---|
| 1754 | dc.logger.Printf("failed parsing log messages for chathistory: %v", err)
|
---|
| 1755 | return newChatHistoryError(subcommand, target)
|
---|
| 1756 | }
|
---|
| 1757 |
|
---|
| 1758 | batchRef := "history"
|
---|
| 1759 | dc.SendMessage(&irc.Message{
|
---|
| 1760 | Prefix: dc.srv.prefix(),
|
---|
| 1761 | Command: "BATCH",
|
---|
| 1762 | Params: []string{"+" + batchRef, "chathistory", target},
|
---|
| 1763 | })
|
---|
| 1764 |
|
---|
| 1765 | for _, msg := range history {
|
---|
| 1766 | msg.Tags["batch"] = irc.TagValue(batchRef)
|
---|
| 1767 | dc.SendMessage(dc.marshalMessage(msg, uc.network))
|
---|
| 1768 | }
|
---|
| 1769 |
|
---|
| 1770 | dc.SendMessage(&irc.Message{
|
---|
| 1771 | Prefix: dc.srv.prefix(),
|
---|
| 1772 | Command: "BATCH",
|
---|
| 1773 | Params: []string{"-" + batchRef},
|
---|
| 1774 | })
|
---|
[13] | 1775 | default:
|
---|
[55] | 1776 | dc.logger.Printf("unhandled message: %v", msg)
|
---|
[13] | 1777 | return newUnknownCommandError(msg.Command)
|
---|
| 1778 | }
|
---|
[42] | 1779 | return nil
|
---|
[13] | 1780 | }
|
---|
[95] | 1781 |
|
---|
| 1782 | func (dc *downstreamConn) handleNickServPRIVMSG(uc *upstreamConn, text string) {
|
---|
| 1783 | username, password, ok := parseNickServCredentials(text, uc.nick)
|
---|
| 1784 | if !ok {
|
---|
| 1785 | return
|
---|
| 1786 | }
|
---|
| 1787 |
|
---|
[307] | 1788 | // User may have e.g. EXTERNAL mechanism configured. We do not want to
|
---|
| 1789 | // automatically erase the key pair or any other credentials.
|
---|
| 1790 | if uc.network.SASL.Mechanism != "" && uc.network.SASL.Mechanism != "PLAIN" {
|
---|
| 1791 | return
|
---|
| 1792 | }
|
---|
| 1793 |
|
---|
[95] | 1794 | dc.logger.Printf("auto-saving NickServ credentials with username %q", username)
|
---|
| 1795 | n := uc.network
|
---|
| 1796 | n.SASL.Mechanism = "PLAIN"
|
---|
| 1797 | n.SASL.Plain.Username = username
|
---|
| 1798 | n.SASL.Plain.Password = password
|
---|
[421] | 1799 | if err := dc.srv.db.StoreNetwork(dc.user.ID, &n.Network); err != nil {
|
---|
[95] | 1800 | dc.logger.Printf("failed to save NickServ credentials: %v", err)
|
---|
| 1801 | }
|
---|
| 1802 | }
|
---|
| 1803 |
|
---|
| 1804 | func parseNickServCredentials(text, nick string) (username, password string, ok bool) {
|
---|
| 1805 | fields := strings.Fields(text)
|
---|
| 1806 | if len(fields) < 2 {
|
---|
| 1807 | return "", "", false
|
---|
| 1808 | }
|
---|
| 1809 | cmd := strings.ToUpper(fields[0])
|
---|
| 1810 | params := fields[1:]
|
---|
| 1811 | switch cmd {
|
---|
| 1812 | case "REGISTER":
|
---|
| 1813 | username = nick
|
---|
| 1814 | password = params[0]
|
---|
| 1815 | case "IDENTIFY":
|
---|
| 1816 | if len(params) == 1 {
|
---|
| 1817 | username = nick
|
---|
[182] | 1818 | password = params[0]
|
---|
[95] | 1819 | } else {
|
---|
| 1820 | username = params[0]
|
---|
[182] | 1821 | password = params[1]
|
---|
[95] | 1822 | }
|
---|
[182] | 1823 | case "SET":
|
---|
| 1824 | if len(params) == 2 && strings.EqualFold(params[0], "PASSWORD") {
|
---|
| 1825 | username = nick
|
---|
| 1826 | password = params[1]
|
---|
| 1827 | }
|
---|
[340] | 1828 | default:
|
---|
| 1829 | return "", "", false
|
---|
[95] | 1830 | }
|
---|
| 1831 | return username, password, true
|
---|
| 1832 | }
|
---|