[98] | 1 | package soju
|
---|
[13] | 2 |
|
---|
| 3 | import (
|
---|
[307] | 4 | "crypto"
|
---|
| 5 | "crypto/sha256"
|
---|
[13] | 6 | "crypto/tls"
|
---|
[307] | 7 | "crypto/x509"
|
---|
[95] | 8 | "encoding/base64"
|
---|
[155] | 9 | "errors"
|
---|
[13] | 10 | "fmt"
|
---|
| 11 | "io"
|
---|
| 12 | "net"
|
---|
[19] | 13 | "strconv"
|
---|
[17] | 14 | "strings"
|
---|
[19] | 15 | "time"
|
---|
[288] | 16 | "unicode"
|
---|
| 17 | "unicode/utf8"
|
---|
[13] | 18 |
|
---|
[95] | 19 | "github.com/emersion/go-sasl"
|
---|
[13] | 20 | "gopkg.in/irc.v3"
|
---|
| 21 | )
|
---|
| 22 |
|
---|
[282] | 23 | // permanentUpstreamCaps is the static list of upstream capabilities always
|
---|
| 24 | // requested when supported.
|
---|
| 25 | var permanentUpstreamCaps = map[string]bool{
|
---|
| 26 | "away-notify": true,
|
---|
| 27 | "batch": true,
|
---|
[419] | 28 | "extended-join": true,
|
---|
[448] | 29 | "invite-notify": true,
|
---|
[282] | 30 | "labeled-response": true,
|
---|
| 31 | "message-tags": true,
|
---|
[292] | 32 | "multi-prefix": true,
|
---|
[282] | 33 | "server-time": true,
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[399] | 36 | type registrationError string
|
---|
| 37 |
|
---|
| 38 | func (err registrationError) Error() string {
|
---|
| 39 | return fmt.Sprintf("registration error: %v", string(err))
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[19] | 42 | type upstreamChannel struct {
|
---|
[162] | 43 | Name string
|
---|
| 44 | conn *upstreamConn
|
---|
| 45 | Topic string
|
---|
[405] | 46 | TopicWho *irc.Prefix
|
---|
[162] | 47 | TopicTime time.Time
|
---|
| 48 | Status channelStatus
|
---|
| 49 | modes channelModes
|
---|
| 50 | creationTime string
|
---|
[292] | 51 | Members map[string]*memberships
|
---|
[162] | 52 | complete bool
|
---|
[435] | 53 | detachTimer *time.Timer
|
---|
[19] | 54 | }
|
---|
| 55 |
|
---|
[435] | 56 | func (uc *upstreamChannel) updateAutoDetach(dur time.Duration) {
|
---|
| 57 | if uc.detachTimer != nil {
|
---|
| 58 | uc.detachTimer.Stop()
|
---|
| 59 | uc.detachTimer = nil
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | if dur == 0 {
|
---|
| 63 | return
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | uc.detachTimer = time.AfterFunc(dur, func() {
|
---|
| 67 | uc.conn.network.user.events <- eventChannelDetach{
|
---|
| 68 | uc: uc.conn,
|
---|
| 69 | name: uc.Name,
|
---|
| 70 | }
|
---|
| 71 | })
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[13] | 74 | type upstreamConn struct {
|
---|
[210] | 75 | conn
|
---|
[16] | 76 |
|
---|
[210] | 77 | network *network
|
---|
| 78 | user *user
|
---|
| 79 |
|
---|
[16] | 80 | serverName string
|
---|
| 81 | availableUserModes string
|
---|
[139] | 82 | availableChannelModes map[byte]channelModeType
|
---|
| 83 | availableChannelTypes string
|
---|
| 84 | availableMemberships []membership
|
---|
[460] | 85 | isupport map[string]*string
|
---|
[19] | 86 |
|
---|
[277] | 87 | registered bool
|
---|
| 88 | nick string
|
---|
| 89 | username string
|
---|
| 90 | realname string
|
---|
| 91 | modes userModes
|
---|
| 92 | channels map[string]*upstreamChannel
|
---|
| 93 | supportedCaps map[string]string
|
---|
[278] | 94 | caps map[string]bool
|
---|
[277] | 95 | batches map[string]batch
|
---|
| 96 | away bool
|
---|
[278] | 97 | nextLabelID uint64
|
---|
[95] | 98 |
|
---|
| 99 | saslClient sasl.Client
|
---|
| 100 | saslStarted bool
|
---|
[177] | 101 |
|
---|
| 102 | // set of LIST commands in progress, per downstream
|
---|
| 103 | pendingLISTDownstreamSet map[uint64]struct{}
|
---|
[13] | 104 | }
|
---|
| 105 |
|
---|
[77] | 106 | func connectToUpstream(network *network) (*upstreamConn, error) {
|
---|
| 107 | logger := &prefixLogger{network.user.srv.Logger, fmt.Sprintf("upstream %q: ", network.Addr)}
|
---|
[33] | 108 |
|
---|
[352] | 109 | dialer := net.Dialer{Timeout: connectTimeout}
|
---|
[269] | 110 |
|
---|
[457] | 111 | u, err := network.URL()
|
---|
[352] | 112 | if err != nil {
|
---|
[457] | 113 | return nil, err
|
---|
[352] | 114 | }
|
---|
[206] | 115 |
|
---|
[269] | 116 | var netConn net.Conn
|
---|
[352] | 117 | switch u.Scheme {
|
---|
[269] | 118 | case "ircs":
|
---|
[352] | 119 | addr := u.Host
|
---|
[381] | 120 | host, _, err := net.SplitHostPort(u.Host)
|
---|
| 121 | if err != nil {
|
---|
| 122 | host = u.Host
|
---|
| 123 | addr = u.Host + ":6697"
|
---|
[269] | 124 | }
|
---|
| 125 |
|
---|
| 126 | logger.Printf("connecting to TLS server at address %q", addr)
|
---|
[307] | 127 |
|
---|
[455] | 128 | tlsConfig := &tls.Config{ServerName: host, NextProtos: []string{"irc"}}
|
---|
[307] | 129 | if network.SASL.Mechanism == "EXTERNAL" {
|
---|
| 130 | if network.SASL.External.CertBlob == nil {
|
---|
| 131 | return nil, fmt.Errorf("missing certificate for authentication")
|
---|
| 132 | }
|
---|
| 133 | if network.SASL.External.PrivKeyBlob == nil {
|
---|
| 134 | return nil, fmt.Errorf("missing private key for authentication")
|
---|
| 135 | }
|
---|
| 136 | key, err := x509.ParsePKCS8PrivateKey(network.SASL.External.PrivKeyBlob)
|
---|
| 137 | if err != nil {
|
---|
| 138 | return nil, fmt.Errorf("failed to parse private key: %v", err)
|
---|
| 139 | }
|
---|
[381] | 140 | tlsConfig.Certificates = []tls.Certificate{
|
---|
| 141 | {
|
---|
| 142 | Certificate: [][]byte{network.SASL.External.CertBlob},
|
---|
| 143 | PrivateKey: key.(crypto.PrivateKey),
|
---|
[307] | 144 | },
|
---|
| 145 | }
|
---|
| 146 | logger.Printf("using TLS client certificate %x", sha256.Sum256(network.SASL.External.CertBlob))
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[381] | 149 | netConn, err = dialer.Dial("tcp", addr)
|
---|
[352] | 150 | if err != nil {
|
---|
| 151 | return nil, fmt.Errorf("failed to dial %q: %v", addr, err)
|
---|
| 152 | }
|
---|
[381] | 153 |
|
---|
| 154 | // Don't do the TLS handshake immediately, because we need to register
|
---|
| 155 | // the new connection with identd ASAP. See:
|
---|
| 156 | // https://todo.sr.ht/~emersion/soju/69#event-41859
|
---|
| 157 | netConn = tls.Client(netConn, tlsConfig)
|
---|
[270] | 158 | case "irc+insecure":
|
---|
[352] | 159 | addr := u.Host
|
---|
[351] | 160 | if _, _, err := net.SplitHostPort(addr); err != nil {
|
---|
[270] | 161 | addr = addr + ":6667"
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | logger.Printf("connecting to plain-text server at address %q", addr)
|
---|
| 165 | netConn, err = dialer.Dial("tcp", addr)
|
---|
[352] | 166 | if err != nil {
|
---|
| 167 | return nil, fmt.Errorf("failed to dial %q: %v", addr, err)
|
---|
| 168 | }
|
---|
[369] | 169 | case "irc+unix", "unix":
|
---|
[353] | 170 | logger.Printf("connecting to Unix socket at path %q", u.Path)
|
---|
| 171 | netConn, err = dialer.Dial("unix", u.Path)
|
---|
| 172 | if err != nil {
|
---|
| 173 | return nil, fmt.Errorf("failed to connect to Unix socket %q: %v", u.Path, err)
|
---|
| 174 | }
|
---|
[269] | 175 | default:
|
---|
[352] | 176 | return nil, fmt.Errorf("failed to dial %q: unknown scheme: %v", network.Addr, u.Scheme)
|
---|
[269] | 177 | }
|
---|
[33] | 178 |
|
---|
[398] | 179 | options := connOptions{
|
---|
[402] | 180 | Logger: logger,
|
---|
[398] | 181 | RateLimitDelay: upstreamMessageDelay,
|
---|
| 182 | RateLimitBurst: upstreamMessageBurst,
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[55] | 185 | uc := &upstreamConn{
|
---|
[398] | 186 | conn: *newConn(network.user.srv, newNetIRCConn(netConn), &options),
|
---|
[177] | 187 | network: network,
|
---|
| 188 | user: network.user,
|
---|
| 189 | channels: make(map[string]*upstreamChannel),
|
---|
[277] | 190 | supportedCaps: make(map[string]string),
|
---|
[278] | 191 | caps: make(map[string]bool),
|
---|
[177] | 192 | batches: make(map[string]batch),
|
---|
| 193 | availableChannelTypes: stdChannelTypes,
|
---|
| 194 | availableChannelModes: stdChannelModes,
|
---|
| 195 | availableMemberships: stdMemberships,
|
---|
[460] | 196 | isupport: make(map[string]*string),
|
---|
[177] | 197 | pendingLISTDownstreamSet: make(map[uint64]struct{}),
|
---|
[33] | 198 | }
|
---|
[55] | 199 | return uc, nil
|
---|
[33] | 200 | }
|
---|
| 201 |
|
---|
[73] | 202 | func (uc *upstreamConn) forEachDownstream(f func(*downstreamConn)) {
|
---|
[218] | 203 | uc.network.forEachDownstream(f)
|
---|
[73] | 204 | }
|
---|
| 205 |
|
---|
[161] | 206 | func (uc *upstreamConn) forEachDownstreamByID(id uint64, f func(*downstreamConn)) {
|
---|
[155] | 207 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 208 | if id != 0 && id != dc.id {
|
---|
| 209 | return
|
---|
| 210 | }
|
---|
| 211 | f(dc)
|
---|
| 212 | })
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[55] | 215 | func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) {
|
---|
| 216 | ch, ok := uc.channels[name]
|
---|
[19] | 217 | if !ok {
|
---|
| 218 | return nil, fmt.Errorf("unknown channel %q", name)
|
---|
| 219 | }
|
---|
| 220 | return ch, nil
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[129] | 223 | func (uc *upstreamConn) isChannel(entity string) bool {
|
---|
[454] | 224 | return strings.ContainsRune(uc.availableChannelTypes, rune(entity[0]))
|
---|
[129] | 225 | }
|
---|
| 226 |
|
---|
[181] | 227 | func (uc *upstreamConn) getPendingLIST() *pendingLIST {
|
---|
[177] | 228 | for _, pl := range uc.user.pendingLISTs {
|
---|
| 229 | if _, ok := pl.pendingCommands[uc.network.ID]; !ok {
|
---|
| 230 | continue
|
---|
| 231 | }
|
---|
| 232 | return &pl
|
---|
| 233 | }
|
---|
| 234 | return nil
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[181] | 237 | func (uc *upstreamConn) endPendingLISTs(all bool) (found bool) {
|
---|
[177] | 238 | found = false
|
---|
| 239 | for i := 0; i < len(uc.user.pendingLISTs); i++ {
|
---|
| 240 | pl := uc.user.pendingLISTs[i]
|
---|
| 241 | if _, ok := pl.pendingCommands[uc.network.ID]; !ok {
|
---|
| 242 | continue
|
---|
| 243 | }
|
---|
| 244 | delete(pl.pendingCommands, uc.network.ID)
|
---|
| 245 | if len(pl.pendingCommands) == 0 {
|
---|
| 246 | uc.user.pendingLISTs = append(uc.user.pendingLISTs[:i], uc.user.pendingLISTs[i+1:]...)
|
---|
| 247 | i--
|
---|
| 248 | uc.forEachDownstreamByID(pl.downstreamID, func(dc *downstreamConn) {
|
---|
| 249 | dc.SendMessage(&irc.Message{
|
---|
| 250 | Prefix: dc.srv.prefix(),
|
---|
| 251 | Command: irc.RPL_LISTEND,
|
---|
| 252 | Params: []string{dc.nick, "End of /LIST"},
|
---|
| 253 | })
|
---|
| 254 | })
|
---|
| 255 | }
|
---|
| 256 | found = true
|
---|
| 257 | if !all {
|
---|
| 258 | delete(uc.pendingLISTDownstreamSet, pl.downstreamID)
|
---|
| 259 | uc.user.forEachUpstream(func(uc *upstreamConn) {
|
---|
[181] | 260 | uc.trySendLIST(pl.downstreamID)
|
---|
[177] | 261 | })
|
---|
| 262 | return
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 | return
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[181] | 268 | func (uc *upstreamConn) trySendLIST(downstreamID uint64) {
|
---|
[177] | 269 | if _, ok := uc.pendingLISTDownstreamSet[downstreamID]; ok {
|
---|
| 270 | // a LIST command is already pending
|
---|
| 271 | // we will try again when that command is completed
|
---|
| 272 | return
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | for _, pl := range uc.user.pendingLISTs {
|
---|
| 276 | if pl.downstreamID != downstreamID {
|
---|
| 277 | continue
|
---|
| 278 | }
|
---|
| 279 | // this is the first pending LIST command list of the downstream
|
---|
| 280 | listCommand, ok := pl.pendingCommands[uc.network.ID]
|
---|
| 281 | if !ok {
|
---|
| 282 | // there is no command for this upstream in these LIST commands
|
---|
| 283 | // do not send anything
|
---|
| 284 | continue
|
---|
| 285 | }
|
---|
| 286 | // there is a command for this upstream in these LIST commands
|
---|
| 287 | // send it now
|
---|
| 288 |
|
---|
| 289 | uc.SendMessageLabeled(downstreamID, listCommand)
|
---|
| 290 |
|
---|
| 291 | uc.pendingLISTDownstreamSet[downstreamID] = struct{}{}
|
---|
| 292 | return
|
---|
| 293 | }
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[292] | 296 | func (uc *upstreamConn) parseMembershipPrefix(s string) (ms *memberships, nick string) {
|
---|
| 297 | memberships := make(memberships, 0, 4)
|
---|
| 298 | i := 0
|
---|
[139] | 299 | for _, m := range uc.availableMemberships {
|
---|
[292] | 300 | if i >= len(s) {
|
---|
| 301 | break
|
---|
[139] | 302 | }
|
---|
[292] | 303 | if s[i] == m.Prefix {
|
---|
| 304 | memberships = append(memberships, m)
|
---|
| 305 | i++
|
---|
| 306 | }
|
---|
[139] | 307 | }
|
---|
[292] | 308 | return &memberships, s[i:]
|
---|
[139] | 309 | }
|
---|
| 310 |
|
---|
[288] | 311 | func isWordBoundary(r rune) bool {
|
---|
| 312 | switch r {
|
---|
| 313 | case '-', '_', '|':
|
---|
| 314 | return false
|
---|
| 315 | case '\u00A0':
|
---|
| 316 | return true
|
---|
| 317 | default:
|
---|
| 318 | return !unicode.IsLetter(r) && !unicode.IsNumber(r)
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | func isHighlight(text, nick string) bool {
|
---|
| 323 | for {
|
---|
| 324 | i := strings.Index(text, nick)
|
---|
| 325 | if i < 0 {
|
---|
| 326 | return false
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | // Detect word boundaries
|
---|
| 330 | var left, right rune
|
---|
| 331 | if i > 0 {
|
---|
| 332 | left, _ = utf8.DecodeLastRuneInString(text[:i])
|
---|
| 333 | }
|
---|
| 334 | if i < len(text) {
|
---|
| 335 | right, _ = utf8.DecodeRuneInString(text[i+len(nick):])
|
---|
| 336 | }
|
---|
| 337 | if isWordBoundary(left) && isWordBoundary(right) {
|
---|
| 338 | return true
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | text = text[i+len(nick):]
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[55] | 345 | func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
|
---|
[155] | 346 | var label string
|
---|
| 347 | if l, ok := msg.GetTag("label"); ok {
|
---|
| 348 | label = l
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[153] | 351 | var msgBatch *batch
|
---|
| 352 | if batchName, ok := msg.GetTag("batch"); ok {
|
---|
| 353 | b, ok := uc.batches[batchName]
|
---|
| 354 | if !ok {
|
---|
| 355 | return fmt.Errorf("unexpected batch reference: batch was not defined: %q", batchName)
|
---|
| 356 | }
|
---|
| 357 | msgBatch = &b
|
---|
[155] | 358 | if label == "" {
|
---|
| 359 | label = msgBatch.Label
|
---|
| 360 | }
|
---|
[443] | 361 | delete(msg.Tags, "batch")
|
---|
[153] | 362 | }
|
---|
| 363 |
|
---|
[161] | 364 | var downstreamID uint64 = 0
|
---|
[155] | 365 | if label != "" {
|
---|
| 366 | var labelOffset uint64
|
---|
[161] | 367 | n, err := fmt.Sscanf(label, "sd-%d-%d", &downstreamID, &labelOffset)
|
---|
[155] | 368 | if err == nil && n < 2 {
|
---|
| 369 | err = errors.New("not enough arguments")
|
---|
| 370 | }
|
---|
| 371 | if err != nil {
|
---|
| 372 | return fmt.Errorf("unexpected message label: invalid downstream reference for label %q: %v", label, err)
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[216] | 376 | if _, ok := msg.Tags["time"]; !ok {
|
---|
[240] | 377 | msg.Tags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
|
---|
[216] | 378 | }
|
---|
| 379 |
|
---|
[13] | 380 | switch msg.Command {
|
---|
| 381 | case "PING":
|
---|
[60] | 382 | uc.SendMessage(&irc.Message{
|
---|
[13] | 383 | Command: "PONG",
|
---|
[68] | 384 | Params: msg.Params,
|
---|
[60] | 385 | })
|
---|
[33] | 386 | return nil
|
---|
[303] | 387 | case "NOTICE", "PRIVMSG", "TAGMSG":
|
---|
[273] | 388 | if msg.Prefix == nil {
|
---|
| 389 | return fmt.Errorf("expected a prefix")
|
---|
| 390 | }
|
---|
| 391 |
|
---|
[286] | 392 | var entity, text string
|
---|
[303] | 393 | if msg.Command != "TAGMSG" {
|
---|
| 394 | if err := parseMessageParams(msg, &entity, &text); err != nil {
|
---|
| 395 | return err
|
---|
| 396 | }
|
---|
| 397 | } else {
|
---|
| 398 | if err := parseMessageParams(msg, &entity); err != nil {
|
---|
| 399 | return err
|
---|
| 400 | }
|
---|
[286] | 401 | }
|
---|
| 402 |
|
---|
| 403 | if msg.Prefix.Name == serviceNick {
|
---|
| 404 | uc.logger.Printf("skipping %v from soju's service: %v", msg.Command, msg)
|
---|
| 405 | break
|
---|
| 406 | }
|
---|
| 407 | if entity == serviceNick {
|
---|
| 408 | uc.logger.Printf("skipping %v to soju's service: %v", msg.Command, msg)
|
---|
| 409 | break
|
---|
| 410 | }
|
---|
| 411 |
|
---|
[171] | 412 | if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message
|
---|
[239] | 413 | uc.produce("", msg, nil)
|
---|
[303] | 414 | } else { // regular user message
|
---|
[217] | 415 | target := entity
|
---|
| 416 | if target == uc.nick {
|
---|
[178] | 417 | target = msg.Prefix.Name
|
---|
| 418 | }
|
---|
[287] | 419 |
|
---|
[435] | 420 | if ch, ok := uc.network.channels[target]; ok {
|
---|
| 421 | if ch.Detached {
|
---|
| 422 | uc.handleDetachedMessage(msg.Prefix.Name, text, ch)
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | highlight := msg.Prefix.Name != uc.nick && isHighlight(text, uc.nick)
|
---|
| 426 | if ch.DetachOn == FilterMessage || ch.DetachOn == FilterDefault || (ch.DetachOn == FilterHighlight && highlight) {
|
---|
| 427 | uc.updateChannelAutoDetach(target)
|
---|
| 428 | }
|
---|
[287] | 429 | }
|
---|
[435] | 430 |
|
---|
| 431 | uc.produce(target, msg, nil)
|
---|
[171] | 432 | }
|
---|
[92] | 433 | case "CAP":
|
---|
[95] | 434 | var subCmd string
|
---|
| 435 | if err := parseMessageParams(msg, nil, &subCmd); err != nil {
|
---|
| 436 | return err
|
---|
[92] | 437 | }
|
---|
[95] | 438 | subCmd = strings.ToUpper(subCmd)
|
---|
| 439 | subParams := msg.Params[2:]
|
---|
| 440 | switch subCmd {
|
---|
| 441 | case "LS":
|
---|
| 442 | if len(subParams) < 1 {
|
---|
| 443 | return newNeedMoreParamsError(msg.Command)
|
---|
| 444 | }
|
---|
[281] | 445 | caps := subParams[len(subParams)-1]
|
---|
[95] | 446 | more := len(subParams) >= 2 && msg.Params[len(subParams)-2] == "*"
|
---|
[92] | 447 |
|
---|
[281] | 448 | uc.handleSupportedCaps(caps)
|
---|
[92] | 449 |
|
---|
[95] | 450 | if more {
|
---|
| 451 | break // wait to receive all capabilities
|
---|
| 452 | }
|
---|
| 453 |
|
---|
[281] | 454 | uc.requestCaps()
|
---|
[152] | 455 |
|
---|
[95] | 456 | if uc.requestSASL() {
|
---|
| 457 | break // we'll send CAP END after authentication is completed
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[92] | 460 | uc.SendMessage(&irc.Message{
|
---|
| 461 | Command: "CAP",
|
---|
| 462 | Params: []string{"END"},
|
---|
| 463 | })
|
---|
[95] | 464 | case "ACK", "NAK":
|
---|
| 465 | if len(subParams) < 1 {
|
---|
| 466 | return newNeedMoreParamsError(msg.Command)
|
---|
| 467 | }
|
---|
| 468 | caps := strings.Fields(subParams[0])
|
---|
| 469 |
|
---|
| 470 | for _, name := range caps {
|
---|
| 471 | if err := uc.handleCapAck(strings.ToLower(name), subCmd == "ACK"); err != nil {
|
---|
| 472 | return err
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 |
|
---|
[281] | 476 | if uc.registered {
|
---|
| 477 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 478 | dc.updateSupportedCaps()
|
---|
| 479 | })
|
---|
| 480 | }
|
---|
| 481 | case "NEW":
|
---|
| 482 | if len(subParams) < 1 {
|
---|
| 483 | return newNeedMoreParamsError(msg.Command)
|
---|
| 484 | }
|
---|
| 485 | uc.handleSupportedCaps(subParams[0])
|
---|
| 486 | uc.requestCaps()
|
---|
| 487 | case "DEL":
|
---|
| 488 | if len(subParams) < 1 {
|
---|
| 489 | return newNeedMoreParamsError(msg.Command)
|
---|
| 490 | }
|
---|
| 491 | caps := strings.Fields(subParams[0])
|
---|
| 492 |
|
---|
| 493 | for _, c := range caps {
|
---|
| 494 | delete(uc.supportedCaps, c)
|
---|
| 495 | delete(uc.caps, c)
|
---|
| 496 | }
|
---|
| 497 |
|
---|
| 498 | if uc.registered {
|
---|
| 499 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 500 | dc.updateSupportedCaps()
|
---|
| 501 | })
|
---|
| 502 | }
|
---|
[95] | 503 | default:
|
---|
| 504 | uc.logger.Printf("unhandled message: %v", msg)
|
---|
[92] | 505 | }
|
---|
[95] | 506 | case "AUTHENTICATE":
|
---|
| 507 | if uc.saslClient == nil {
|
---|
| 508 | return fmt.Errorf("received unexpected AUTHENTICATE message")
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | // TODO: if a challenge is 400 bytes long, buffer it
|
---|
| 512 | var challengeStr string
|
---|
| 513 | if err := parseMessageParams(msg, &challengeStr); err != nil {
|
---|
| 514 | uc.SendMessage(&irc.Message{
|
---|
| 515 | Command: "AUTHENTICATE",
|
---|
| 516 | Params: []string{"*"},
|
---|
| 517 | })
|
---|
| 518 | return err
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | var challenge []byte
|
---|
| 522 | if challengeStr != "+" {
|
---|
| 523 | var err error
|
---|
| 524 | challenge, err = base64.StdEncoding.DecodeString(challengeStr)
|
---|
| 525 | if err != nil {
|
---|
| 526 | uc.SendMessage(&irc.Message{
|
---|
| 527 | Command: "AUTHENTICATE",
|
---|
| 528 | Params: []string{"*"},
|
---|
| 529 | })
|
---|
| 530 | return err
|
---|
| 531 | }
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | var resp []byte
|
---|
| 535 | var err error
|
---|
| 536 | if !uc.saslStarted {
|
---|
| 537 | _, resp, err = uc.saslClient.Start()
|
---|
| 538 | uc.saslStarted = true
|
---|
| 539 | } else {
|
---|
| 540 | resp, err = uc.saslClient.Next(challenge)
|
---|
| 541 | }
|
---|
| 542 | if err != nil {
|
---|
| 543 | uc.SendMessage(&irc.Message{
|
---|
| 544 | Command: "AUTHENTICATE",
|
---|
| 545 | Params: []string{"*"},
|
---|
| 546 | })
|
---|
| 547 | return err
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | // TODO: send response in multiple chunks if >= 400 bytes
|
---|
| 551 | var respStr = "+"
|
---|
[318] | 552 | if len(resp) != 0 {
|
---|
[95] | 553 | respStr = base64.StdEncoding.EncodeToString(resp)
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | uc.SendMessage(&irc.Message{
|
---|
| 557 | Command: "AUTHENTICATE",
|
---|
| 558 | Params: []string{respStr},
|
---|
| 559 | })
|
---|
[125] | 560 | case irc.RPL_LOGGEDIN:
|
---|
[95] | 561 | var account string
|
---|
| 562 | if err := parseMessageParams(msg, nil, nil, &account); err != nil {
|
---|
| 563 | return err
|
---|
| 564 | }
|
---|
| 565 | uc.logger.Printf("logged in with account %q", account)
|
---|
[125] | 566 | case irc.RPL_LOGGEDOUT:
|
---|
[95] | 567 | uc.logger.Printf("logged out")
|
---|
[125] | 568 | case irc.ERR_NICKLOCKED, irc.RPL_SASLSUCCESS, irc.ERR_SASLFAIL, irc.ERR_SASLTOOLONG, irc.ERR_SASLABORTED:
|
---|
[95] | 569 | var info string
|
---|
| 570 | if err := parseMessageParams(msg, nil, &info); err != nil {
|
---|
| 571 | return err
|
---|
| 572 | }
|
---|
| 573 | switch msg.Command {
|
---|
[125] | 574 | case irc.ERR_NICKLOCKED:
|
---|
[95] | 575 | uc.logger.Printf("invalid nick used with SASL authentication: %v", info)
|
---|
[125] | 576 | case irc.ERR_SASLFAIL:
|
---|
[95] | 577 | uc.logger.Printf("SASL authentication failed: %v", info)
|
---|
[125] | 578 | case irc.ERR_SASLTOOLONG:
|
---|
[95] | 579 | uc.logger.Printf("SASL message too long: %v", info)
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | uc.saslClient = nil
|
---|
| 583 | uc.saslStarted = false
|
---|
| 584 |
|
---|
| 585 | uc.SendMessage(&irc.Message{
|
---|
| 586 | Command: "CAP",
|
---|
| 587 | Params: []string{"END"},
|
---|
| 588 | })
|
---|
[14] | 589 | case irc.RPL_WELCOME:
|
---|
[55] | 590 | uc.registered = true
|
---|
| 591 | uc.logger.Printf("connection registered")
|
---|
[19] | 592 |
|
---|
[310] | 593 | if len(uc.network.channels) > 0 {
|
---|
[350] | 594 | var channels, keys []string
|
---|
[310] | 595 | for _, ch := range uc.network.channels {
|
---|
[350] | 596 | channels = append(channels, ch.Name)
|
---|
[310] | 597 | keys = append(keys, ch.Key)
|
---|
| 598 | }
|
---|
[350] | 599 |
|
---|
| 600 | for _, msg := range join(channels, keys) {
|
---|
| 601 | uc.SendMessage(msg)
|
---|
| 602 | }
|
---|
[19] | 603 | }
|
---|
[16] | 604 | case irc.RPL_MYINFO:
|
---|
[139] | 605 | if err := parseMessageParams(msg, nil, &uc.serverName, nil, &uc.availableUserModes, nil); err != nil {
|
---|
[43] | 606 | return err
|
---|
[16] | 607 | }
|
---|
[139] | 608 | case irc.RPL_ISUPPORT:
|
---|
| 609 | if err := parseMessageParams(msg, nil, nil); err != nil {
|
---|
| 610 | return err
|
---|
[16] | 611 | }
|
---|
[463] | 612 |
|
---|
| 613 | var downstreamIsupport []string
|
---|
[139] | 614 | for _, token := range msg.Params[1 : len(msg.Params)-1] {
|
---|
| 615 | parameter := token
|
---|
[460] | 616 | var negate, hasValue bool
|
---|
| 617 | var value string
|
---|
[139] | 618 | if strings.HasPrefix(token, "-") {
|
---|
| 619 | negate = true
|
---|
| 620 | token = token[1:]
|
---|
[459] | 621 | } else if i := strings.IndexByte(token, '='); i >= 0 {
|
---|
| 622 | parameter = token[:i]
|
---|
| 623 | value = token[i+1:]
|
---|
[460] | 624 | hasValue = true
|
---|
[139] | 625 | }
|
---|
[460] | 626 |
|
---|
| 627 | if hasValue {
|
---|
| 628 | uc.isupport[parameter] = &value
|
---|
| 629 | } else if !negate {
|
---|
| 630 | uc.isupport[parameter] = nil
|
---|
| 631 | } else {
|
---|
| 632 | delete(uc.isupport, parameter)
|
---|
| 633 | }
|
---|
| 634 |
|
---|
[462] | 635 | var err error
|
---|
| 636 | switch parameter {
|
---|
| 637 | case "CHANMODES":
|
---|
| 638 | if !negate {
|
---|
| 639 | err = uc.handleChanModes(value)
|
---|
| 640 | } else {
|
---|
| 641 | uc.availableChannelModes = stdChannelModes
|
---|
| 642 | }
|
---|
| 643 | case "CHANTYPES":
|
---|
| 644 | if !negate {
|
---|
[139] | 645 | uc.availableChannelTypes = value
|
---|
[462] | 646 | } else {
|
---|
| 647 | uc.availableChannelTypes = stdChannelTypes
|
---|
[139] | 648 | }
|
---|
[462] | 649 | case "PREFIX":
|
---|
| 650 | if !negate {
|
---|
| 651 | err = uc.handleMemberships(value)
|
---|
| 652 | } else {
|
---|
| 653 | uc.availableMemberships = stdMemberships
|
---|
| 654 | }
|
---|
[139] | 655 | }
|
---|
[462] | 656 | if err != nil {
|
---|
| 657 | return err
|
---|
| 658 | }
|
---|
[463] | 659 |
|
---|
| 660 | if passthroughIsupport[parameter] {
|
---|
| 661 | downstreamIsupport = append(downstreamIsupport, token)
|
---|
| 662 | }
|
---|
[139] | 663 | }
|
---|
[463] | 664 |
|
---|
| 665 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 666 | if dc.network == nil {
|
---|
| 667 | return
|
---|
| 668 | }
|
---|
| 669 | msgs := generateIsupport(dc.srv.prefix(), dc.nick, downstreamIsupport)
|
---|
| 670 | for _, msg := range msgs {
|
---|
| 671 | dc.SendMessage(msg)
|
---|
| 672 | }
|
---|
| 673 | })
|
---|
[153] | 674 | case "BATCH":
|
---|
| 675 | var tag string
|
---|
| 676 | if err := parseMessageParams(msg, &tag); err != nil {
|
---|
| 677 | return err
|
---|
| 678 | }
|
---|
| 679 |
|
---|
| 680 | if strings.HasPrefix(tag, "+") {
|
---|
| 681 | tag = tag[1:]
|
---|
| 682 | if _, ok := uc.batches[tag]; ok {
|
---|
| 683 | return fmt.Errorf("unexpected BATCH reference tag: batch was already defined: %q", tag)
|
---|
| 684 | }
|
---|
| 685 | var batchType string
|
---|
| 686 | if err := parseMessageParams(msg, nil, &batchType); err != nil {
|
---|
| 687 | return err
|
---|
| 688 | }
|
---|
[155] | 689 | label := label
|
---|
| 690 | if label == "" && msgBatch != nil {
|
---|
| 691 | label = msgBatch.Label
|
---|
| 692 | }
|
---|
[153] | 693 | uc.batches[tag] = batch{
|
---|
| 694 | Type: batchType,
|
---|
| 695 | Params: msg.Params[2:],
|
---|
| 696 | Outer: msgBatch,
|
---|
[155] | 697 | Label: label,
|
---|
[153] | 698 | }
|
---|
| 699 | } else if strings.HasPrefix(tag, "-") {
|
---|
| 700 | tag = tag[1:]
|
---|
| 701 | if _, ok := uc.batches[tag]; !ok {
|
---|
| 702 | return fmt.Errorf("unknown BATCH reference tag: %q", tag)
|
---|
| 703 | }
|
---|
| 704 | delete(uc.batches, tag)
|
---|
| 705 | } else {
|
---|
| 706 | return fmt.Errorf("unexpected BATCH reference tag: missing +/- prefix: %q", tag)
|
---|
| 707 | }
|
---|
[42] | 708 | case "NICK":
|
---|
[83] | 709 | if msg.Prefix == nil {
|
---|
| 710 | return fmt.Errorf("expected a prefix")
|
---|
| 711 | }
|
---|
| 712 |
|
---|
[43] | 713 | var newNick string
|
---|
| 714 | if err := parseMessageParams(msg, &newNick); err != nil {
|
---|
| 715 | return err
|
---|
[42] | 716 | }
|
---|
| 717 |
|
---|
[244] | 718 | me := false
|
---|
[55] | 719 | if msg.Prefix.Name == uc.nick {
|
---|
| 720 | uc.logger.Printf("changed nick from %q to %q", uc.nick, newNick)
|
---|
[244] | 721 | me = true
|
---|
[55] | 722 | uc.nick = newNick
|
---|
[42] | 723 | }
|
---|
| 724 |
|
---|
[55] | 725 | for _, ch := range uc.channels {
|
---|
[292] | 726 | if memberships, ok := ch.Members[msg.Prefix.Name]; ok {
|
---|
[42] | 727 | delete(ch.Members, msg.Prefix.Name)
|
---|
[292] | 728 | ch.Members[newNick] = memberships
|
---|
[215] | 729 | uc.appendLog(ch.Name, msg)
|
---|
[42] | 730 | }
|
---|
| 731 | }
|
---|
[82] | 732 |
|
---|
[244] | 733 | if !me {
|
---|
[82] | 734 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
[261] | 735 | dc.SendMessage(dc.marshalMessage(msg, uc.network))
|
---|
[82] | 736 | })
|
---|
[296] | 737 | } else {
|
---|
| 738 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 739 | dc.updateNick()
|
---|
| 740 | })
|
---|
[82] | 741 | }
|
---|
[69] | 742 | case "JOIN":
|
---|
| 743 | if msg.Prefix == nil {
|
---|
| 744 | return fmt.Errorf("expected a prefix")
|
---|
| 745 | }
|
---|
[42] | 746 |
|
---|
[43] | 747 | var channels string
|
---|
| 748 | if err := parseMessageParams(msg, &channels); err != nil {
|
---|
| 749 | return err
|
---|
[19] | 750 | }
|
---|
[34] | 751 |
|
---|
[43] | 752 | for _, ch := range strings.Split(channels, ",") {
|
---|
[55] | 753 | if msg.Prefix.Name == uc.nick {
|
---|
| 754 | uc.logger.Printf("joined channel %q", ch)
|
---|
| 755 | uc.channels[ch] = &upstreamChannel{
|
---|
[34] | 756 | Name: ch,
|
---|
[55] | 757 | conn: uc,
|
---|
[292] | 758 | Members: make(map[string]*memberships),
|
---|
[34] | 759 | }
|
---|
[435] | 760 | uc.updateChannelAutoDetach(ch)
|
---|
[139] | 761 |
|
---|
| 762 | uc.SendMessage(&irc.Message{
|
---|
| 763 | Command: "MODE",
|
---|
| 764 | Params: []string{ch},
|
---|
| 765 | })
|
---|
[34] | 766 | } else {
|
---|
[55] | 767 | ch, err := uc.getChannel(ch)
|
---|
[34] | 768 | if err != nil {
|
---|
| 769 | return err
|
---|
| 770 | }
|
---|
[294] | 771 | ch.Members[msg.Prefix.Name] = &memberships{}
|
---|
[19] | 772 | }
|
---|
[69] | 773 |
|
---|
[245] | 774 | chMsg := msg.Copy()
|
---|
| 775 | chMsg.Params[0] = ch
|
---|
| 776 | uc.produce(ch, chMsg, nil)
|
---|
[19] | 777 | }
|
---|
[69] | 778 | case "PART":
|
---|
| 779 | if msg.Prefix == nil {
|
---|
| 780 | return fmt.Errorf("expected a prefix")
|
---|
| 781 | }
|
---|
[34] | 782 |
|
---|
[43] | 783 | var channels string
|
---|
| 784 | if err := parseMessageParams(msg, &channels); err != nil {
|
---|
| 785 | return err
|
---|
[34] | 786 | }
|
---|
| 787 |
|
---|
[43] | 788 | for _, ch := range strings.Split(channels, ",") {
|
---|
[55] | 789 | if msg.Prefix.Name == uc.nick {
|
---|
| 790 | uc.logger.Printf("parted channel %q", ch)
|
---|
[435] | 791 | if uch, ok := uc.channels[ch]; ok {
|
---|
| 792 | delete(uc.channels, ch)
|
---|
| 793 | uch.updateAutoDetach(0)
|
---|
| 794 | }
|
---|
[34] | 795 | } else {
|
---|
[55] | 796 | ch, err := uc.getChannel(ch)
|
---|
[34] | 797 | if err != nil {
|
---|
| 798 | return err
|
---|
| 799 | }
|
---|
| 800 | delete(ch.Members, msg.Prefix.Name)
|
---|
| 801 | }
|
---|
[69] | 802 |
|
---|
[245] | 803 | chMsg := msg.Copy()
|
---|
| 804 | chMsg.Params[0] = ch
|
---|
| 805 | uc.produce(ch, chMsg, nil)
|
---|
[34] | 806 | }
|
---|
[159] | 807 | case "KICK":
|
---|
| 808 | if msg.Prefix == nil {
|
---|
| 809 | return fmt.Errorf("expected a prefix")
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | var channel, user string
|
---|
| 813 | if err := parseMessageParams(msg, &channel, &user); err != nil {
|
---|
| 814 | return err
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | if user == uc.nick {
|
---|
| 818 | uc.logger.Printf("kicked from channel %q by %s", channel, msg.Prefix.Name)
|
---|
| 819 | delete(uc.channels, channel)
|
---|
| 820 | } else {
|
---|
| 821 | ch, err := uc.getChannel(channel)
|
---|
| 822 | if err != nil {
|
---|
| 823 | return err
|
---|
| 824 | }
|
---|
| 825 | delete(ch.Members, user)
|
---|
| 826 | }
|
---|
| 827 |
|
---|
[245] | 828 | uc.produce(channel, msg, nil)
|
---|
[83] | 829 | case "QUIT":
|
---|
| 830 | if msg.Prefix == nil {
|
---|
| 831 | return fmt.Errorf("expected a prefix")
|
---|
| 832 | }
|
---|
| 833 |
|
---|
| 834 | if msg.Prefix.Name == uc.nick {
|
---|
| 835 | uc.logger.Printf("quit")
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | for _, ch := range uc.channels {
|
---|
[178] | 839 | if _, ok := ch.Members[msg.Prefix.Name]; ok {
|
---|
| 840 | delete(ch.Members, msg.Prefix.Name)
|
---|
| 841 |
|
---|
[215] | 842 | uc.appendLog(ch.Name, msg)
|
---|
[178] | 843 | }
|
---|
[83] | 844 | }
|
---|
| 845 |
|
---|
| 846 | if msg.Prefix.Name != uc.nick {
|
---|
| 847 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
[261] | 848 | dc.SendMessage(dc.marshalMessage(msg, uc.network))
|
---|
[83] | 849 | })
|
---|
| 850 | }
|
---|
[19] | 851 | case irc.RPL_TOPIC, irc.RPL_NOTOPIC:
|
---|
[43] | 852 | var name, topic string
|
---|
| 853 | if err := parseMessageParams(msg, nil, &name, &topic); err != nil {
|
---|
| 854 | return err
|
---|
[19] | 855 | }
|
---|
[55] | 856 | ch, err := uc.getChannel(name)
|
---|
[19] | 857 | if err != nil {
|
---|
| 858 | return err
|
---|
| 859 | }
|
---|
| 860 | if msg.Command == irc.RPL_TOPIC {
|
---|
[43] | 861 | ch.Topic = topic
|
---|
[19] | 862 | } else {
|
---|
| 863 | ch.Topic = ""
|
---|
| 864 | }
|
---|
| 865 | case "TOPIC":
|
---|
[405] | 866 | if msg.Prefix == nil {
|
---|
| 867 | return fmt.Errorf("expected a prefix")
|
---|
| 868 | }
|
---|
| 869 |
|
---|
[43] | 870 | var name string
|
---|
[74] | 871 | if err := parseMessageParams(msg, &name); err != nil {
|
---|
[43] | 872 | return err
|
---|
[19] | 873 | }
|
---|
[55] | 874 | ch, err := uc.getChannel(name)
|
---|
[19] | 875 | if err != nil {
|
---|
| 876 | return err
|
---|
| 877 | }
|
---|
| 878 | if len(msg.Params) > 1 {
|
---|
| 879 | ch.Topic = msg.Params[1]
|
---|
[405] | 880 | ch.TopicWho = msg.Prefix.Copy()
|
---|
| 881 | ch.TopicTime = time.Now() // TODO use msg.Tags["time"]
|
---|
[19] | 882 | } else {
|
---|
| 883 | ch.Topic = ""
|
---|
| 884 | }
|
---|
[245] | 885 | uc.produce(ch.Name, msg, nil)
|
---|
[139] | 886 | case "MODE":
|
---|
| 887 | var name, modeStr string
|
---|
| 888 | if err := parseMessageParams(msg, &name, &modeStr); err != nil {
|
---|
| 889 | return err
|
---|
| 890 | }
|
---|
| 891 |
|
---|
| 892 | if !uc.isChannel(name) { // user mode change
|
---|
| 893 | if name != uc.nick {
|
---|
| 894 | return fmt.Errorf("received MODE message for unknown nick %q", name)
|
---|
| 895 | }
|
---|
| 896 | return uc.modes.Apply(modeStr)
|
---|
| 897 | // TODO: notify downstreams about user mode change?
|
---|
| 898 | } else { // channel mode change
|
---|
| 899 | ch, err := uc.getChannel(name)
|
---|
| 900 | if err != nil {
|
---|
| 901 | return err
|
---|
| 902 | }
|
---|
| 903 |
|
---|
[293] | 904 | needMarshaling, err := applyChannelModes(ch, modeStr, msg.Params[2:])
|
---|
| 905 | if err != nil {
|
---|
| 906 | return err
|
---|
[139] | 907 | }
|
---|
| 908 |
|
---|
[293] | 909 | uc.appendLog(ch.Name, msg)
|
---|
| 910 |
|
---|
[338] | 911 | if ch, ok := uc.network.channels[name]; !ok || !ch.Detached {
|
---|
| 912 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 913 | params := make([]string, len(msg.Params))
|
---|
| 914 | params[0] = dc.marshalEntity(uc.network, name)
|
---|
| 915 | params[1] = modeStr
|
---|
| 916 |
|
---|
| 917 | copy(params[2:], msg.Params[2:])
|
---|
| 918 | for i, modeParam := range params[2:] {
|
---|
| 919 | if _, ok := needMarshaling[i]; ok {
|
---|
| 920 | params[2+i] = dc.marshalEntity(uc.network, modeParam)
|
---|
| 921 | }
|
---|
[293] | 922 | }
|
---|
| 923 |
|
---|
[338] | 924 | dc.SendMessage(&irc.Message{
|
---|
| 925 | Prefix: dc.marshalUserPrefix(uc.network, msg.Prefix),
|
---|
| 926 | Command: "MODE",
|
---|
| 927 | Params: params,
|
---|
| 928 | })
|
---|
[293] | 929 | })
|
---|
[338] | 930 | }
|
---|
[139] | 931 | }
|
---|
| 932 | case irc.RPL_UMODEIS:
|
---|
| 933 | if err := parseMessageParams(msg, nil); err != nil {
|
---|
| 934 | return err
|
---|
| 935 | }
|
---|
| 936 | modeStr := ""
|
---|
| 937 | if len(msg.Params) > 1 {
|
---|
| 938 | modeStr = msg.Params[1]
|
---|
| 939 | }
|
---|
| 940 |
|
---|
| 941 | uc.modes = ""
|
---|
| 942 | if err := uc.modes.Apply(modeStr); err != nil {
|
---|
| 943 | return err
|
---|
| 944 | }
|
---|
| 945 | // TODO: send RPL_UMODEIS to downstream connections when applicable
|
---|
| 946 | case irc.RPL_CHANNELMODEIS:
|
---|
| 947 | var channel string
|
---|
| 948 | if err := parseMessageParams(msg, nil, &channel); err != nil {
|
---|
| 949 | return err
|
---|
| 950 | }
|
---|
| 951 | modeStr := ""
|
---|
| 952 | if len(msg.Params) > 2 {
|
---|
| 953 | modeStr = msg.Params[2]
|
---|
| 954 | }
|
---|
| 955 |
|
---|
| 956 | ch, err := uc.getChannel(channel)
|
---|
| 957 | if err != nil {
|
---|
| 958 | return err
|
---|
| 959 | }
|
---|
| 960 |
|
---|
| 961 | firstMode := ch.modes == nil
|
---|
| 962 | ch.modes = make(map[byte]string)
|
---|
[293] | 963 | if _, err := applyChannelModes(ch, modeStr, msg.Params[3:]); err != nil {
|
---|
[139] | 964 | return err
|
---|
| 965 | }
|
---|
| 966 | if firstMode {
|
---|
[338] | 967 | if c, ok := uc.network.channels[channel]; !ok || !c.Detached {
|
---|
| 968 | modeStr, modeParams := ch.modes.Format()
|
---|
[139] | 969 |
|
---|
[338] | 970 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 971 | params := []string{dc.nick, dc.marshalEntity(uc.network, channel), modeStr}
|
---|
| 972 | params = append(params, modeParams...)
|
---|
[139] | 973 |
|
---|
[338] | 974 | dc.SendMessage(&irc.Message{
|
---|
| 975 | Prefix: dc.srv.prefix(),
|
---|
| 976 | Command: irc.RPL_CHANNELMODEIS,
|
---|
| 977 | Params: params,
|
---|
| 978 | })
|
---|
[139] | 979 | })
|
---|
[338] | 980 | }
|
---|
[139] | 981 | }
|
---|
[162] | 982 | case rpl_creationtime:
|
---|
| 983 | var channel, creationTime string
|
---|
| 984 | if err := parseMessageParams(msg, nil, &channel, &creationTime); err != nil {
|
---|
| 985 | return err
|
---|
| 986 | }
|
---|
| 987 |
|
---|
| 988 | ch, err := uc.getChannel(channel)
|
---|
| 989 | if err != nil {
|
---|
| 990 | return err
|
---|
| 991 | }
|
---|
| 992 |
|
---|
| 993 | firstCreationTime := ch.creationTime == ""
|
---|
| 994 | ch.creationTime = creationTime
|
---|
| 995 | if firstCreationTime {
|
---|
| 996 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 997 | dc.SendMessage(&irc.Message{
|
---|
| 998 | Prefix: dc.srv.prefix(),
|
---|
| 999 | Command: rpl_creationtime,
|
---|
[403] | 1000 | Params: []string{dc.nick, dc.marshalEntity(uc.network, ch.Name), creationTime},
|
---|
[162] | 1001 | })
|
---|
| 1002 | })
|
---|
| 1003 | }
|
---|
[19] | 1004 | case rpl_topicwhotime:
|
---|
[43] | 1005 | var name, who, timeStr string
|
---|
| 1006 | if err := parseMessageParams(msg, nil, &name, &who, &timeStr); err != nil {
|
---|
| 1007 | return err
|
---|
[19] | 1008 | }
|
---|
[55] | 1009 | ch, err := uc.getChannel(name)
|
---|
[19] | 1010 | if err != nil {
|
---|
| 1011 | return err
|
---|
| 1012 | }
|
---|
[405] | 1013 | firstTopicWhoTime := ch.TopicWho == nil
|
---|
| 1014 | ch.TopicWho = irc.ParsePrefix(who)
|
---|
[43] | 1015 | sec, err := strconv.ParseInt(timeStr, 10, 64)
|
---|
[19] | 1016 | if err != nil {
|
---|
| 1017 | return fmt.Errorf("failed to parse topic time: %v", err)
|
---|
| 1018 | }
|
---|
| 1019 | ch.TopicTime = time.Unix(sec, 0)
|
---|
[405] | 1020 | if firstTopicWhoTime {
|
---|
| 1021 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 1022 | topicWho := dc.marshalUserPrefix(uc.network, ch.TopicWho)
|
---|
| 1023 | dc.SendMessage(&irc.Message{
|
---|
| 1024 | Prefix: dc.srv.prefix(),
|
---|
| 1025 | Command: rpl_topicwhotime,
|
---|
| 1026 | Params: []string{
|
---|
| 1027 | dc.nick,
|
---|
| 1028 | dc.marshalEntity(uc.network, ch.Name),
|
---|
| 1029 | topicWho.String(),
|
---|
| 1030 | timeStr,
|
---|
| 1031 | },
|
---|
| 1032 | })
|
---|
| 1033 | })
|
---|
| 1034 | }
|
---|
[177] | 1035 | case irc.RPL_LIST:
|
---|
| 1036 | var channel, clients, topic string
|
---|
| 1037 | if err := parseMessageParams(msg, nil, &channel, &clients, &topic); err != nil {
|
---|
| 1038 | return err
|
---|
| 1039 | }
|
---|
| 1040 |
|
---|
[181] | 1041 | pl := uc.getPendingLIST()
|
---|
[177] | 1042 | if pl == nil {
|
---|
| 1043 | return fmt.Errorf("unexpected RPL_LIST: no matching pending LIST")
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
| 1046 | uc.forEachDownstreamByID(pl.downstreamID, func(dc *downstreamConn) {
|
---|
| 1047 | dc.SendMessage(&irc.Message{
|
---|
| 1048 | Prefix: dc.srv.prefix(),
|
---|
| 1049 | Command: irc.RPL_LIST,
|
---|
[260] | 1050 | Params: []string{dc.nick, dc.marshalEntity(uc.network, channel), clients, topic},
|
---|
[177] | 1051 | })
|
---|
| 1052 | })
|
---|
| 1053 | case irc.RPL_LISTEND:
|
---|
[181] | 1054 | ok := uc.endPendingLISTs(false)
|
---|
[177] | 1055 | if !ok {
|
---|
| 1056 | return fmt.Errorf("unexpected RPL_LISTEND: no matching pending LIST")
|
---|
| 1057 | }
|
---|
[19] | 1058 | case irc.RPL_NAMREPLY:
|
---|
[43] | 1059 | var name, statusStr, members string
|
---|
| 1060 | if err := parseMessageParams(msg, nil, &statusStr, &name, &members); err != nil {
|
---|
| 1061 | return err
|
---|
[19] | 1062 | }
|
---|
[140] | 1063 |
|
---|
| 1064 | ch, ok := uc.channels[name]
|
---|
| 1065 | if !ok {
|
---|
| 1066 | // NAMES on a channel we have not joined, forward to downstream
|
---|
[161] | 1067 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1068 | channel := dc.marshalEntity(uc.network, name)
|
---|
[174] | 1069 | members := splitSpace(members)
|
---|
[140] | 1070 | for i, member := range members {
|
---|
[292] | 1071 | memberships, nick := uc.parseMembershipPrefix(member)
|
---|
| 1072 | members[i] = memberships.Format(dc) + dc.marshalEntity(uc.network, nick)
|
---|
[140] | 1073 | }
|
---|
| 1074 | memberStr := strings.Join(members, " ")
|
---|
| 1075 |
|
---|
| 1076 | dc.SendMessage(&irc.Message{
|
---|
| 1077 | Prefix: dc.srv.prefix(),
|
---|
| 1078 | Command: irc.RPL_NAMREPLY,
|
---|
| 1079 | Params: []string{dc.nick, statusStr, channel, memberStr},
|
---|
| 1080 | })
|
---|
| 1081 | })
|
---|
| 1082 | return nil
|
---|
[19] | 1083 | }
|
---|
| 1084 |
|
---|
[43] | 1085 | status, err := parseChannelStatus(statusStr)
|
---|
[19] | 1086 | if err != nil {
|
---|
| 1087 | return err
|
---|
| 1088 | }
|
---|
| 1089 | ch.Status = status
|
---|
| 1090 |
|
---|
[174] | 1091 | for _, s := range splitSpace(members) {
|
---|
[292] | 1092 | memberships, nick := uc.parseMembershipPrefix(s)
|
---|
| 1093 | ch.Members[nick] = memberships
|
---|
[19] | 1094 | }
|
---|
| 1095 | case irc.RPL_ENDOFNAMES:
|
---|
[43] | 1096 | var name string
|
---|
| 1097 | if err := parseMessageParams(msg, nil, &name); err != nil {
|
---|
| 1098 | return err
|
---|
[25] | 1099 | }
|
---|
[140] | 1100 |
|
---|
| 1101 | ch, ok := uc.channels[name]
|
---|
| 1102 | if !ok {
|
---|
| 1103 | // NAMES on a channel we have not joined, forward to downstream
|
---|
[161] | 1104 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1105 | channel := dc.marshalEntity(uc.network, name)
|
---|
[140] | 1106 |
|
---|
| 1107 | dc.SendMessage(&irc.Message{
|
---|
| 1108 | Prefix: dc.srv.prefix(),
|
---|
| 1109 | Command: irc.RPL_ENDOFNAMES,
|
---|
| 1110 | Params: []string{dc.nick, channel, "End of /NAMES list"},
|
---|
| 1111 | })
|
---|
| 1112 | })
|
---|
| 1113 | return nil
|
---|
[25] | 1114 | }
|
---|
| 1115 |
|
---|
[34] | 1116 | if ch.complete {
|
---|
| 1117 | return fmt.Errorf("received unexpected RPL_ENDOFNAMES")
|
---|
| 1118 | }
|
---|
[25] | 1119 | ch.complete = true
|
---|
[27] | 1120 |
|
---|
[338] | 1121 | if c, ok := uc.network.channels[name]; !ok || !c.Detached {
|
---|
| 1122 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 1123 | forwardChannel(dc, ch)
|
---|
| 1124 | })
|
---|
| 1125 | }
|
---|
[127] | 1126 | case irc.RPL_WHOREPLY:
|
---|
| 1127 | var channel, username, host, server, nick, mode, trailing string
|
---|
| 1128 | if err := parseMessageParams(msg, nil, &channel, &username, &host, &server, &nick, &mode, &trailing); err != nil {
|
---|
| 1129 | return err
|
---|
| 1130 | }
|
---|
| 1131 |
|
---|
| 1132 | parts := strings.SplitN(trailing, " ", 2)
|
---|
| 1133 | if len(parts) != 2 {
|
---|
| 1134 | return fmt.Errorf("received malformed RPL_WHOREPLY: wrong trailing parameter: %s", trailing)
|
---|
| 1135 | }
|
---|
| 1136 | realname := parts[1]
|
---|
| 1137 | hops, err := strconv.Atoi(parts[0])
|
---|
| 1138 | if err != nil {
|
---|
| 1139 | return fmt.Errorf("received malformed RPL_WHOREPLY: wrong hop count: %s", parts[0])
|
---|
| 1140 | }
|
---|
| 1141 | hops++
|
---|
| 1142 |
|
---|
| 1143 | trailing = strconv.Itoa(hops) + " " + realname
|
---|
| 1144 |
|
---|
[161] | 1145 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[127] | 1146 | channel := channel
|
---|
| 1147 | if channel != "*" {
|
---|
[260] | 1148 | channel = dc.marshalEntity(uc.network, channel)
|
---|
[127] | 1149 | }
|
---|
[260] | 1150 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[127] | 1151 | dc.SendMessage(&irc.Message{
|
---|
| 1152 | Prefix: dc.srv.prefix(),
|
---|
| 1153 | Command: irc.RPL_WHOREPLY,
|
---|
| 1154 | Params: []string{dc.nick, channel, username, host, server, nick, mode, trailing},
|
---|
| 1155 | })
|
---|
| 1156 | })
|
---|
| 1157 | case irc.RPL_ENDOFWHO:
|
---|
| 1158 | var name string
|
---|
| 1159 | if err := parseMessageParams(msg, nil, &name); err != nil {
|
---|
| 1160 | return err
|
---|
| 1161 | }
|
---|
| 1162 |
|
---|
[161] | 1163 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[127] | 1164 | name := name
|
---|
| 1165 | if name != "*" {
|
---|
| 1166 | // TODO: support WHO masks
|
---|
[260] | 1167 | name = dc.marshalEntity(uc.network, name)
|
---|
[127] | 1168 | }
|
---|
| 1169 | dc.SendMessage(&irc.Message{
|
---|
| 1170 | Prefix: dc.srv.prefix(),
|
---|
| 1171 | Command: irc.RPL_ENDOFWHO,
|
---|
[142] | 1172 | Params: []string{dc.nick, name, "End of /WHO list"},
|
---|
[127] | 1173 | })
|
---|
| 1174 | })
|
---|
[128] | 1175 | case irc.RPL_WHOISUSER:
|
---|
| 1176 | var nick, username, host, realname string
|
---|
| 1177 | if err := parseMessageParams(msg, nil, &nick, &username, &host, nil, &realname); err != nil {
|
---|
| 1178 | return err
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
[161] | 1181 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1182 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[128] | 1183 | dc.SendMessage(&irc.Message{
|
---|
| 1184 | Prefix: dc.srv.prefix(),
|
---|
| 1185 | Command: irc.RPL_WHOISUSER,
|
---|
| 1186 | Params: []string{dc.nick, nick, username, host, "*", realname},
|
---|
| 1187 | })
|
---|
| 1188 | })
|
---|
| 1189 | case irc.RPL_WHOISSERVER:
|
---|
| 1190 | var nick, server, serverInfo string
|
---|
| 1191 | if err := parseMessageParams(msg, nil, &nick, &server, &serverInfo); err != nil {
|
---|
| 1192 | return err
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[161] | 1195 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1196 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[128] | 1197 | dc.SendMessage(&irc.Message{
|
---|
| 1198 | Prefix: dc.srv.prefix(),
|
---|
| 1199 | Command: irc.RPL_WHOISSERVER,
|
---|
| 1200 | Params: []string{dc.nick, nick, server, serverInfo},
|
---|
| 1201 | })
|
---|
| 1202 | })
|
---|
| 1203 | case irc.RPL_WHOISOPERATOR:
|
---|
| 1204 | var nick string
|
---|
| 1205 | if err := parseMessageParams(msg, nil, &nick); err != nil {
|
---|
| 1206 | return err
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
[161] | 1209 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1210 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[128] | 1211 | dc.SendMessage(&irc.Message{
|
---|
| 1212 | Prefix: dc.srv.prefix(),
|
---|
| 1213 | Command: irc.RPL_WHOISOPERATOR,
|
---|
| 1214 | Params: []string{dc.nick, nick, "is an IRC operator"},
|
---|
| 1215 | })
|
---|
| 1216 | })
|
---|
| 1217 | case irc.RPL_WHOISIDLE:
|
---|
| 1218 | var nick string
|
---|
| 1219 | if err := parseMessageParams(msg, nil, &nick, nil); err != nil {
|
---|
| 1220 | return err
|
---|
| 1221 | }
|
---|
| 1222 |
|
---|
[161] | 1223 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1224 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[128] | 1225 | params := []string{dc.nick, nick}
|
---|
| 1226 | params = append(params, msg.Params[2:]...)
|
---|
| 1227 | dc.SendMessage(&irc.Message{
|
---|
| 1228 | Prefix: dc.srv.prefix(),
|
---|
| 1229 | Command: irc.RPL_WHOISIDLE,
|
---|
| 1230 | Params: params,
|
---|
| 1231 | })
|
---|
| 1232 | })
|
---|
| 1233 | case irc.RPL_WHOISCHANNELS:
|
---|
| 1234 | var nick, channelList string
|
---|
| 1235 | if err := parseMessageParams(msg, nil, &nick, &channelList); err != nil {
|
---|
| 1236 | return err
|
---|
| 1237 | }
|
---|
[174] | 1238 | channels := splitSpace(channelList)
|
---|
[128] | 1239 |
|
---|
[161] | 1240 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1241 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[128] | 1242 | channelList := make([]string, len(channels))
|
---|
| 1243 | for i, channel := range channels {
|
---|
[139] | 1244 | prefix, channel := uc.parseMembershipPrefix(channel)
|
---|
[260] | 1245 | channel = dc.marshalEntity(uc.network, channel)
|
---|
[292] | 1246 | channelList[i] = prefix.Format(dc) + channel
|
---|
[128] | 1247 | }
|
---|
| 1248 | channels := strings.Join(channelList, " ")
|
---|
| 1249 | dc.SendMessage(&irc.Message{
|
---|
| 1250 | Prefix: dc.srv.prefix(),
|
---|
| 1251 | Command: irc.RPL_WHOISCHANNELS,
|
---|
| 1252 | Params: []string{dc.nick, nick, channels},
|
---|
| 1253 | })
|
---|
| 1254 | })
|
---|
| 1255 | case irc.RPL_ENDOFWHOIS:
|
---|
| 1256 | var nick string
|
---|
| 1257 | if err := parseMessageParams(msg, nil, &nick); err != nil {
|
---|
| 1258 | return err
|
---|
| 1259 | }
|
---|
| 1260 |
|
---|
[161] | 1261 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
[260] | 1262 | nick := dc.marshalEntity(uc.network, nick)
|
---|
[128] | 1263 | dc.SendMessage(&irc.Message{
|
---|
| 1264 | Prefix: dc.srv.prefix(),
|
---|
| 1265 | Command: irc.RPL_ENDOFWHOIS,
|
---|
[142] | 1266 | Params: []string{dc.nick, nick, "End of /WHOIS list"},
|
---|
[128] | 1267 | })
|
---|
| 1268 | })
|
---|
[115] | 1269 | case "INVITE":
|
---|
[273] | 1270 | var nick, channel string
|
---|
[115] | 1271 | if err := parseMessageParams(msg, &nick, &channel); err != nil {
|
---|
| 1272 | return err
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
[448] | 1275 | weAreInvited := nick == uc.nick
|
---|
| 1276 |
|
---|
[115] | 1277 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
[448] | 1278 | if !weAreInvited && !dc.caps["invite-notify"] {
|
---|
| 1279 | return
|
---|
| 1280 | }
|
---|
[115] | 1281 | dc.SendMessage(&irc.Message{
|
---|
[260] | 1282 | Prefix: dc.marshalUserPrefix(uc.network, msg.Prefix),
|
---|
[115] | 1283 | Command: "INVITE",
|
---|
[260] | 1284 | Params: []string{dc.marshalEntity(uc.network, nick), dc.marshalEntity(uc.network, channel)},
|
---|
[115] | 1285 | })
|
---|
| 1286 | })
|
---|
[163] | 1287 | case irc.RPL_INVITING:
|
---|
[273] | 1288 | var nick, channel string
|
---|
[304] | 1289 | if err := parseMessageParams(msg, nil, &nick, &channel); err != nil {
|
---|
[163] | 1290 | return err
|
---|
| 1291 | }
|
---|
| 1292 |
|
---|
| 1293 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
| 1294 | dc.SendMessage(&irc.Message{
|
---|
| 1295 | Prefix: dc.srv.prefix(),
|
---|
| 1296 | Command: irc.RPL_INVITING,
|
---|
[260] | 1297 | Params: []string{dc.nick, dc.marshalEntity(uc.network, nick), dc.marshalEntity(uc.network, channel)},
|
---|
[163] | 1298 | })
|
---|
| 1299 | })
|
---|
[272] | 1300 | case irc.RPL_AWAY:
|
---|
| 1301 | var nick, reason string
|
---|
| 1302 | if err := parseMessageParams(msg, nil, &nick, &reason); err != nil {
|
---|
| 1303 | return err
|
---|
| 1304 | }
|
---|
| 1305 |
|
---|
[274] | 1306 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
[272] | 1307 | dc.SendMessage(&irc.Message{
|
---|
| 1308 | Prefix: dc.srv.prefix(),
|
---|
| 1309 | Command: irc.RPL_AWAY,
|
---|
| 1310 | Params: []string{dc.nick, dc.marshalEntity(uc.network, nick), reason},
|
---|
| 1311 | })
|
---|
| 1312 | })
|
---|
[276] | 1313 | case "AWAY":
|
---|
| 1314 | if msg.Prefix == nil {
|
---|
| 1315 | return fmt.Errorf("expected a prefix")
|
---|
| 1316 | }
|
---|
| 1317 |
|
---|
| 1318 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 1319 | if !dc.caps["away-notify"] {
|
---|
| 1320 | return
|
---|
| 1321 | }
|
---|
| 1322 | dc.SendMessage(&irc.Message{
|
---|
| 1323 | Prefix: dc.marshalUserPrefix(uc.network, msg.Prefix),
|
---|
| 1324 | Command: "AWAY",
|
---|
| 1325 | Params: msg.Params,
|
---|
| 1326 | })
|
---|
| 1327 | })
|
---|
[300] | 1328 | case irc.RPL_BANLIST, irc.RPL_INVITELIST, irc.RPL_EXCEPTLIST:
|
---|
| 1329 | var channel, mask string
|
---|
| 1330 | if err := parseMessageParams(msg, nil, &channel, &mask); err != nil {
|
---|
| 1331 | return err
|
---|
| 1332 | }
|
---|
| 1333 | var addNick, addTime string
|
---|
| 1334 | if len(msg.Params) >= 5 {
|
---|
| 1335 | addNick = msg.Params[3]
|
---|
| 1336 | addTime = msg.Params[4]
|
---|
| 1337 | }
|
---|
| 1338 |
|
---|
| 1339 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
| 1340 | channel := dc.marshalEntity(uc.network, channel)
|
---|
| 1341 |
|
---|
| 1342 | var params []string
|
---|
| 1343 | if addNick != "" && addTime != "" {
|
---|
| 1344 | addNick := dc.marshalEntity(uc.network, addNick)
|
---|
| 1345 | params = []string{dc.nick, channel, mask, addNick, addTime}
|
---|
| 1346 | } else {
|
---|
| 1347 | params = []string{dc.nick, channel, mask}
|
---|
| 1348 | }
|
---|
| 1349 |
|
---|
| 1350 | dc.SendMessage(&irc.Message{
|
---|
| 1351 | Prefix: dc.srv.prefix(),
|
---|
| 1352 | Command: msg.Command,
|
---|
| 1353 | Params: params,
|
---|
| 1354 | })
|
---|
| 1355 | })
|
---|
| 1356 | case irc.RPL_ENDOFBANLIST, irc.RPL_ENDOFINVITELIST, irc.RPL_ENDOFEXCEPTLIST:
|
---|
| 1357 | var channel, trailing string
|
---|
| 1358 | if err := parseMessageParams(msg, nil, &channel, &trailing); err != nil {
|
---|
| 1359 | return err
|
---|
| 1360 | }
|
---|
| 1361 |
|
---|
| 1362 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
| 1363 | upstreamChannel := dc.marshalEntity(uc.network, channel)
|
---|
| 1364 | dc.SendMessage(&irc.Message{
|
---|
| 1365 | Prefix: dc.srv.prefix(),
|
---|
| 1366 | Command: msg.Command,
|
---|
| 1367 | Params: []string{dc.nick, upstreamChannel, trailing},
|
---|
| 1368 | })
|
---|
| 1369 | })
|
---|
[302] | 1370 | case irc.ERR_UNKNOWNCOMMAND, irc.RPL_TRYAGAIN:
|
---|
| 1371 | var command, reason string
|
---|
| 1372 | if err := parseMessageParams(msg, nil, &command, &reason); err != nil {
|
---|
| 1373 | return err
|
---|
| 1374 | }
|
---|
| 1375 |
|
---|
| 1376 | if command == "LIST" {
|
---|
| 1377 | ok := uc.endPendingLISTs(false)
|
---|
| 1378 | if !ok {
|
---|
| 1379 | return fmt.Errorf("unexpected response for LIST: %q: no matching pending LIST", msg.Command)
|
---|
| 1380 | }
|
---|
| 1381 | }
|
---|
| 1382 |
|
---|
[355] | 1383 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
| 1384 | dc.SendMessage(&irc.Message{
|
---|
| 1385 | Prefix: uc.srv.prefix(),
|
---|
| 1386 | Command: msg.Command,
|
---|
| 1387 | Params: []string{dc.nick, command, reason},
|
---|
[302] | 1388 | })
|
---|
[355] | 1389 | })
|
---|
[155] | 1390 | case "ACK":
|
---|
| 1391 | // Ignore
|
---|
[198] | 1392 | case irc.RPL_NOWAWAY, irc.RPL_UNAWAY:
|
---|
| 1393 | // Ignore
|
---|
[16] | 1394 | case irc.RPL_YOURHOST, irc.RPL_CREATED:
|
---|
[14] | 1395 | // Ignore
|
---|
| 1396 | case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME:
|
---|
| 1397 | // Ignore
|
---|
| 1398 | case irc.RPL_MOTDSTART, irc.RPL_MOTD, irc.RPL_ENDOFMOTD:
|
---|
| 1399 | // Ignore
|
---|
[177] | 1400 | case irc.RPL_LISTSTART:
|
---|
| 1401 | // Ignore
|
---|
[14] | 1402 | case rpl_localusers, rpl_globalusers:
|
---|
| 1403 | // Ignore
|
---|
[96] | 1404 | case irc.RPL_STATSVLINE, rpl_statsping, irc.RPL_STATSBLINE, irc.RPL_STATSDLINE:
|
---|
[14] | 1405 | // Ignore
|
---|
[390] | 1406 | case "ERROR":
|
---|
| 1407 | var text string
|
---|
| 1408 | if err := parseMessageParams(msg, &text); err != nil {
|
---|
| 1409 | return err
|
---|
| 1410 | }
|
---|
| 1411 | return fmt.Errorf("fatal server error: %v", text)
|
---|
[389] | 1412 | case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP:
|
---|
[342] | 1413 | if !uc.registered {
|
---|
[399] | 1414 | text := msg.Params[len(msg.Params)-1]
|
---|
| 1415 | return registrationError(text)
|
---|
[342] | 1416 | }
|
---|
| 1417 | fallthrough
|
---|
[13] | 1418 | default:
|
---|
[95] | 1419 | uc.logger.Printf("unhandled message: %v", msg)
|
---|
[355] | 1420 |
|
---|
| 1421 | uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
---|
| 1422 | // best effort marshaling for unknown messages, replies and errors:
|
---|
| 1423 | // most numerics start with the user nick, marshal it if that's the case
|
---|
| 1424 | // otherwise, conservately keep the params without marshaling
|
---|
| 1425 | params := msg.Params
|
---|
| 1426 | if _, err := strconv.Atoi(msg.Command); err == nil { // numeric
|
---|
| 1427 | if len(msg.Params) > 0 && isOurNick(uc.network, msg.Params[0]) {
|
---|
| 1428 | params[0] = dc.nick
|
---|
[302] | 1429 | }
|
---|
[355] | 1430 | }
|
---|
| 1431 | dc.SendMessage(&irc.Message{
|
---|
| 1432 | Prefix: uc.srv.prefix(),
|
---|
| 1433 | Command: msg.Command,
|
---|
| 1434 | Params: params,
|
---|
[302] | 1435 | })
|
---|
[355] | 1436 | })
|
---|
[13] | 1437 | }
|
---|
[14] | 1438 | return nil
|
---|
[13] | 1439 | }
|
---|
| 1440 |
|
---|
[435] | 1441 | func (uc *upstreamConn) handleDetachedMessage(sender string, text string, ch *Channel) {
|
---|
| 1442 | highlight := sender != uc.nick && isHighlight(text, uc.nick)
|
---|
| 1443 | if ch.RelayDetached == FilterMessage || ((ch.RelayDetached == FilterHighlight || ch.RelayDetached == FilterDefault) && highlight) {
|
---|
| 1444 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
| 1445 | if highlight {
|
---|
| 1446 | sendServiceNOTICE(dc, fmt.Sprintf("highlight in %v: <%v> %v", dc.marshalEntity(uc.network, ch.Name), sender, text))
|
---|
| 1447 | } else {
|
---|
| 1448 | sendServiceNOTICE(dc, fmt.Sprintf("message in %v: <%v> %v", dc.marshalEntity(uc.network, ch.Name), sender, text))
|
---|
| 1449 | }
|
---|
| 1450 | })
|
---|
| 1451 | }
|
---|
| 1452 | if ch.ReattachOn == FilterMessage || (ch.ReattachOn == FilterHighlight && highlight) {
|
---|
| 1453 | uc.network.attach(ch)
|
---|
| 1454 | if err := uc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
|
---|
| 1455 | uc.logger.Printf("failed to update channel %q: %v", ch.Name, err)
|
---|
| 1456 | }
|
---|
| 1457 | }
|
---|
| 1458 | }
|
---|
| 1459 |
|
---|
[458] | 1460 | func (uc *upstreamConn) handleChanModes(s string) error {
|
---|
| 1461 | parts := strings.SplitN(s, ",", 5)
|
---|
| 1462 | if len(parts) < 4 {
|
---|
| 1463 | return fmt.Errorf("malformed ISUPPORT CHANMODES value: %v", s)
|
---|
| 1464 | }
|
---|
| 1465 | modes := make(map[byte]channelModeType)
|
---|
| 1466 | for i, mt := range []channelModeType{modeTypeA, modeTypeB, modeTypeC, modeTypeD} {
|
---|
| 1467 | for j := 0; j < len(parts[i]); j++ {
|
---|
| 1468 | mode := parts[i][j]
|
---|
| 1469 | modes[mode] = mt
|
---|
| 1470 | }
|
---|
| 1471 | }
|
---|
| 1472 | uc.availableChannelModes = modes
|
---|
| 1473 | return nil
|
---|
| 1474 | }
|
---|
| 1475 |
|
---|
| 1476 | func (uc *upstreamConn) handleMemberships(s string) error {
|
---|
| 1477 | if s == "" {
|
---|
| 1478 | uc.availableMemberships = nil
|
---|
| 1479 | return nil
|
---|
| 1480 | }
|
---|
| 1481 |
|
---|
| 1482 | if s[0] != '(' {
|
---|
| 1483 | return fmt.Errorf("malformed ISUPPORT PREFIX value: %v", s)
|
---|
| 1484 | }
|
---|
| 1485 | sep := strings.IndexByte(s, ')')
|
---|
| 1486 | if sep < 0 || len(s) != sep*2 {
|
---|
| 1487 | return fmt.Errorf("malformed ISUPPORT PREFIX value: %v", s)
|
---|
| 1488 | }
|
---|
| 1489 | memberships := make([]membership, len(s)/2-1)
|
---|
| 1490 | for i := range memberships {
|
---|
| 1491 | memberships[i] = membership{
|
---|
| 1492 | Mode: s[i+1],
|
---|
| 1493 | Prefix: s[sep+i+1],
|
---|
| 1494 | }
|
---|
| 1495 | }
|
---|
| 1496 | uc.availableMemberships = memberships
|
---|
| 1497 | return nil
|
---|
| 1498 | }
|
---|
| 1499 |
|
---|
[281] | 1500 | func (uc *upstreamConn) handleSupportedCaps(capsStr string) {
|
---|
| 1501 | caps := strings.Fields(capsStr)
|
---|
| 1502 | for _, s := range caps {
|
---|
| 1503 | kv := strings.SplitN(s, "=", 2)
|
---|
| 1504 | k := strings.ToLower(kv[0])
|
---|
| 1505 | var v string
|
---|
| 1506 | if len(kv) == 2 {
|
---|
| 1507 | v = kv[1]
|
---|
| 1508 | }
|
---|
| 1509 | uc.supportedCaps[k] = v
|
---|
| 1510 | }
|
---|
| 1511 | }
|
---|
| 1512 |
|
---|
| 1513 | func (uc *upstreamConn) requestCaps() {
|
---|
| 1514 | var requestCaps []string
|
---|
[282] | 1515 | for c := range permanentUpstreamCaps {
|
---|
[281] | 1516 | if _, ok := uc.supportedCaps[c]; ok && !uc.caps[c] {
|
---|
| 1517 | requestCaps = append(requestCaps, c)
|
---|
| 1518 | }
|
---|
| 1519 | }
|
---|
| 1520 |
|
---|
| 1521 | if uc.requestSASL() && !uc.caps["sasl"] {
|
---|
| 1522 | requestCaps = append(requestCaps, "sasl")
|
---|
| 1523 | }
|
---|
| 1524 |
|
---|
[282] | 1525 | if len(requestCaps) == 0 {
|
---|
| 1526 | return
|
---|
| 1527 | }
|
---|
| 1528 |
|
---|
| 1529 | uc.SendMessage(&irc.Message{
|
---|
| 1530 | Command: "CAP",
|
---|
| 1531 | Params: []string{"REQ", strings.Join(requestCaps, " ")},
|
---|
| 1532 | })
|
---|
| 1533 | }
|
---|
| 1534 |
|
---|
| 1535 | func (uc *upstreamConn) requestSASL() bool {
|
---|
| 1536 | if uc.network.SASL.Mechanism == "" {
|
---|
| 1537 | return false
|
---|
| 1538 | }
|
---|
| 1539 |
|
---|
| 1540 | v, ok := uc.supportedCaps["sasl"]
|
---|
| 1541 | if !ok {
|
---|
| 1542 | return false
|
---|
| 1543 | }
|
---|
| 1544 | if v != "" {
|
---|
| 1545 | mechanisms := strings.Split(v, ",")
|
---|
| 1546 | found := false
|
---|
| 1547 | for _, mech := range mechanisms {
|
---|
| 1548 | if strings.EqualFold(mech, uc.network.SASL.Mechanism) {
|
---|
| 1549 | found = true
|
---|
| 1550 | break
|
---|
| 1551 | }
|
---|
| 1552 | }
|
---|
| 1553 | if !found {
|
---|
| 1554 | return false
|
---|
| 1555 | }
|
---|
| 1556 | }
|
---|
| 1557 |
|
---|
| 1558 | return true
|
---|
| 1559 | }
|
---|
| 1560 |
|
---|
| 1561 | func (uc *upstreamConn) handleCapAck(name string, ok bool) error {
|
---|
| 1562 | uc.caps[name] = ok
|
---|
| 1563 |
|
---|
| 1564 | switch name {
|
---|
| 1565 | case "sasl":
|
---|
| 1566 | if !ok {
|
---|
| 1567 | uc.logger.Printf("server refused to acknowledge the SASL capability")
|
---|
| 1568 | return nil
|
---|
| 1569 | }
|
---|
| 1570 |
|
---|
| 1571 | auth := &uc.network.SASL
|
---|
| 1572 | switch auth.Mechanism {
|
---|
| 1573 | case "PLAIN":
|
---|
| 1574 | uc.logger.Printf("starting SASL PLAIN authentication with username %q", auth.Plain.Username)
|
---|
| 1575 | uc.saslClient = sasl.NewPlainClient("", auth.Plain.Username, auth.Plain.Password)
|
---|
[307] | 1576 | case "EXTERNAL":
|
---|
| 1577 | uc.logger.Printf("starting SASL EXTERNAL authentication")
|
---|
| 1578 | uc.saslClient = sasl.NewExternalClient("")
|
---|
[282] | 1579 | default:
|
---|
| 1580 | return fmt.Errorf("unsupported SASL mechanism %q", name)
|
---|
| 1581 | }
|
---|
| 1582 |
|
---|
[281] | 1583 | uc.SendMessage(&irc.Message{
|
---|
[282] | 1584 | Command: "AUTHENTICATE",
|
---|
| 1585 | Params: []string{auth.Mechanism},
|
---|
[281] | 1586 | })
|
---|
[282] | 1587 | default:
|
---|
| 1588 | if permanentUpstreamCaps[name] {
|
---|
| 1589 | break
|
---|
| 1590 | }
|
---|
| 1591 | uc.logger.Printf("received CAP ACK/NAK for a cap we don't support: %v", name)
|
---|
[281] | 1592 | }
|
---|
[282] | 1593 | return nil
|
---|
[281] | 1594 | }
|
---|
| 1595 |
|
---|
[174] | 1596 | func splitSpace(s string) []string {
|
---|
| 1597 | return strings.FieldsFunc(s, func(r rune) bool {
|
---|
| 1598 | return r == ' '
|
---|
| 1599 | })
|
---|
| 1600 | }
|
---|
| 1601 |
|
---|
[55] | 1602 | func (uc *upstreamConn) register() {
|
---|
[77] | 1603 | uc.nick = uc.network.Nick
|
---|
[457] | 1604 | uc.username = uc.network.GetUsername()
|
---|
| 1605 | uc.realname = uc.network.GetRealname()
|
---|
[77] | 1606 |
|
---|
[60] | 1607 | uc.SendMessage(&irc.Message{
|
---|
[92] | 1608 | Command: "CAP",
|
---|
| 1609 | Params: []string{"LS", "302"},
|
---|
| 1610 | })
|
---|
| 1611 |
|
---|
[93] | 1612 | if uc.network.Pass != "" {
|
---|
| 1613 | uc.SendMessage(&irc.Message{
|
---|
| 1614 | Command: "PASS",
|
---|
| 1615 | Params: []string{uc.network.Pass},
|
---|
| 1616 | })
|
---|
| 1617 | }
|
---|
| 1618 |
|
---|
[92] | 1619 | uc.SendMessage(&irc.Message{
|
---|
[13] | 1620 | Command: "NICK",
|
---|
[69] | 1621 | Params: []string{uc.nick},
|
---|
[60] | 1622 | })
|
---|
| 1623 | uc.SendMessage(&irc.Message{
|
---|
[13] | 1624 | Command: "USER",
|
---|
[77] | 1625 | Params: []string{uc.username, "0", "*", uc.realname},
|
---|
[60] | 1626 | })
|
---|
[44] | 1627 | }
|
---|
[13] | 1628 |
|
---|
[197] | 1629 | func (uc *upstreamConn) runUntilRegistered() error {
|
---|
| 1630 | for !uc.registered {
|
---|
[212] | 1631 | msg, err := uc.ReadMessage()
|
---|
[197] | 1632 | if err != nil {
|
---|
| 1633 | return fmt.Errorf("failed to read message: %v", err)
|
---|
| 1634 | }
|
---|
| 1635 |
|
---|
| 1636 | if err := uc.handleMessage(msg); err != nil {
|
---|
[399] | 1637 | if _, ok := err.(registrationError); ok {
|
---|
| 1638 | return err
|
---|
| 1639 | } else {
|
---|
| 1640 | msg.Tags = nil // prevent message tags from cluttering logs
|
---|
| 1641 | return fmt.Errorf("failed to handle message %q: %v", msg, err)
|
---|
| 1642 | }
|
---|
[197] | 1643 | }
|
---|
| 1644 | }
|
---|
| 1645 |
|
---|
[263] | 1646 | for _, command := range uc.network.ConnectCommands {
|
---|
| 1647 | m, err := irc.ParseMessage(command)
|
---|
| 1648 | if err != nil {
|
---|
| 1649 | uc.logger.Printf("failed to parse connect command %q: %v", command, err)
|
---|
| 1650 | } else {
|
---|
| 1651 | uc.SendMessage(m)
|
---|
| 1652 | }
|
---|
| 1653 | }
|
---|
| 1654 |
|
---|
[197] | 1655 | return nil
|
---|
| 1656 | }
|
---|
| 1657 |
|
---|
[165] | 1658 | func (uc *upstreamConn) readMessages(ch chan<- event) error {
|
---|
[13] | 1659 | for {
|
---|
[210] | 1660 | msg, err := uc.ReadMessage()
|
---|
[13] | 1661 | if err == io.EOF {
|
---|
| 1662 | break
|
---|
| 1663 | } else if err != nil {
|
---|
| 1664 | return fmt.Errorf("failed to read IRC command: %v", err)
|
---|
| 1665 | }
|
---|
| 1666 |
|
---|
[165] | 1667 | ch <- eventUpstreamMessage{msg, uc}
|
---|
[13] | 1668 | }
|
---|
| 1669 |
|
---|
[45] | 1670 | return nil
|
---|
[13] | 1671 | }
|
---|
[60] | 1672 |
|
---|
[303] | 1673 | func (uc *upstreamConn) SendMessage(msg *irc.Message) {
|
---|
| 1674 | if !uc.caps["message-tags"] {
|
---|
| 1675 | msg = msg.Copy()
|
---|
| 1676 | msg.Tags = nil
|
---|
| 1677 | }
|
---|
| 1678 |
|
---|
| 1679 | uc.conn.SendMessage(msg)
|
---|
| 1680 | }
|
---|
| 1681 |
|
---|
[176] | 1682 | func (uc *upstreamConn) SendMessageLabeled(downstreamID uint64, msg *irc.Message) {
|
---|
[278] | 1683 | if uc.caps["labeled-response"] {
|
---|
[155] | 1684 | if msg.Tags == nil {
|
---|
| 1685 | msg.Tags = make(map[string]irc.TagValue)
|
---|
| 1686 | }
|
---|
[176] | 1687 | msg.Tags["label"] = irc.TagValue(fmt.Sprintf("sd-%d-%d", downstreamID, uc.nextLabelID))
|
---|
[161] | 1688 | uc.nextLabelID++
|
---|
[155] | 1689 | }
|
---|
| 1690 | uc.SendMessage(msg)
|
---|
| 1691 | }
|
---|
[178] | 1692 |
|
---|
[428] | 1693 | // appendLog appends a message to the log file.
|
---|
| 1694 | //
|
---|
| 1695 | // The internal message ID is returned. If the message isn't recorded in the
|
---|
| 1696 | // log file, an empty string is returned.
|
---|
| 1697 | func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) (msgID string) {
|
---|
[423] | 1698 | if uc.user.msgStore == nil {
|
---|
[428] | 1699 | return ""
|
---|
[178] | 1700 | }
|
---|
[468] | 1701 | if entity == "NickServ" {
|
---|
| 1702 | // The messages sent/received from NickServ may contain
|
---|
| 1703 | // security-related information (like passwords). Don't store these.
|
---|
| 1704 | return ""
|
---|
| 1705 | }
|
---|
[215] | 1706 |
|
---|
[284] | 1707 | detached := false
|
---|
| 1708 | if ch, ok := uc.network.channels[entity]; ok {
|
---|
| 1709 | detached = ch.Detached
|
---|
| 1710 | }
|
---|
| 1711 |
|
---|
[451] | 1712 | delivered, ok := uc.network.delivered[entity]
|
---|
[253] | 1713 | if !ok {
|
---|
[423] | 1714 | lastID, err := uc.user.msgStore.LastMsgID(uc.network, entity, time.Now())
|
---|
[409] | 1715 | if err != nil {
|
---|
| 1716 | uc.logger.Printf("failed to log message: failed to get last message ID: %v", err)
|
---|
[428] | 1717 | return ""
|
---|
[409] | 1718 | }
|
---|
| 1719 |
|
---|
[451] | 1720 | delivered = make(map[string]string)
|
---|
| 1721 | uc.network.delivered[entity] = delivered
|
---|
[253] | 1722 |
|
---|
| 1723 | for clientName, _ := range uc.network.offlineClients {
|
---|
[451] | 1724 | delivered[clientName] = lastID
|
---|
[253] | 1725 | }
|
---|
[284] | 1726 |
|
---|
| 1727 | if detached {
|
---|
| 1728 | // If the channel is detached, online clients act as offline
|
---|
| 1729 | // clients too
|
---|
| 1730 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
[451] | 1731 | delivered[dc.clientName] = lastID
|
---|
[284] | 1732 | })
|
---|
| 1733 | }
|
---|
[253] | 1734 | }
|
---|
| 1735 |
|
---|
[423] | 1736 | msgID, err := uc.user.msgStore.Append(uc.network, entity, msg)
|
---|
[409] | 1737 | if err != nil {
|
---|
| 1738 | uc.logger.Printf("failed to log message: %v", err)
|
---|
[428] | 1739 | return ""
|
---|
[409] | 1740 | }
|
---|
[406] | 1741 |
|
---|
[428] | 1742 | return msgID
|
---|
[253] | 1743 | }
|
---|
| 1744 |
|
---|
[409] | 1745 | // produce appends a message to the logs and forwards it to connected downstream
|
---|
| 1746 | // connections.
|
---|
[245] | 1747 | //
|
---|
| 1748 | // If origin is not nil and origin doesn't support echo-message, the message is
|
---|
| 1749 | // forwarded to all connections except origin.
|
---|
[239] | 1750 | func (uc *upstreamConn) produce(target string, msg *irc.Message, origin *downstreamConn) {
|
---|
[428] | 1751 | var msgID string
|
---|
[239] | 1752 | if target != "" {
|
---|
[428] | 1753 | msgID = uc.appendLog(target, msg)
|
---|
[239] | 1754 | }
|
---|
| 1755 |
|
---|
[284] | 1756 | // Don't forward messages if it's a detached channel
|
---|
| 1757 | if ch, ok := uc.network.channels[target]; ok && ch.Detached {
|
---|
| 1758 | return
|
---|
| 1759 | }
|
---|
| 1760 |
|
---|
[227] | 1761 | uc.forEachDownstream(func(dc *downstreamConn) {
|
---|
[238] | 1762 | if dc != origin || dc.caps["echo-message"] {
|
---|
[428] | 1763 | dc.sendMessageWithID(dc.marshalMessage(msg, uc.network), msgID)
|
---|
| 1764 | } else {
|
---|
| 1765 | dc.advanceMessageWithID(msg, msgID)
|
---|
[238] | 1766 | }
|
---|
[227] | 1767 | })
|
---|
[226] | 1768 | }
|
---|
| 1769 |
|
---|
[198] | 1770 | func (uc *upstreamConn) updateAway() {
|
---|
| 1771 | away := true
|
---|
| 1772 | uc.forEachDownstream(func(*downstreamConn) {
|
---|
| 1773 | away = false
|
---|
| 1774 | })
|
---|
| 1775 | if away == uc.away {
|
---|
| 1776 | return
|
---|
| 1777 | }
|
---|
| 1778 | if away {
|
---|
| 1779 | uc.SendMessage(&irc.Message{
|
---|
| 1780 | Command: "AWAY",
|
---|
| 1781 | Params: []string{"Auto away"},
|
---|
| 1782 | })
|
---|
| 1783 | } else {
|
---|
| 1784 | uc.SendMessage(&irc.Message{
|
---|
| 1785 | Command: "AWAY",
|
---|
| 1786 | })
|
---|
| 1787 | }
|
---|
| 1788 | uc.away = away
|
---|
| 1789 | }
|
---|
[435] | 1790 |
|
---|
| 1791 | func (uc *upstreamConn) updateChannelAutoDetach(name string) {
|
---|
| 1792 | if uch, ok := uc.channels[name]; ok {
|
---|
| 1793 | if ch, ok := uc.network.channels[name]; ok && !ch.Detached {
|
---|
| 1794 | uch.updateAutoDetach(ch.DetachAfter)
|
---|
| 1795 | }
|
---|
| 1796 | }
|
---|
| 1797 | }
|
---|