Changeset 159 in code for trunk/downstream.go


Ignore:
Timestamp:
Mar 25, 2020, 11:15:26 PM (5 years ago)
Author:
delthas
Message:

Add KICK support

Downstream and upstream message handling are slightly different because
downstreams can send KICK messages with multiple channels or users,
while upstreams can only send KICK messages with one channel and one
user (according to the RFC).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r158 r159  
    904904                        }
    905905                }
     906        case "KICK":
     907                var channelStr, userStr string
     908                if err := parseMessageParams(msg, &channelStr, &userStr); err != nil {
     909                        return err
     910                }
     911
     912                channels := strings.Split(channelStr, ",")
     913                users := strings.Split(userStr, ",")
     914
     915                var reason string
     916                if len(msg.Params) > 2 {
     917                        reason = msg.Params[2]
     918                }
     919
     920                if len(channels) != 1 && len(channels) != len(users) {
     921                        return ircError{&irc.Message{
     922                                Command: irc.ERR_BADCHANMASK,
     923                                Params:  []string{dc.nick, channelStr, "Bad channel mask"},
     924                        }}
     925                }
     926
     927                for i, user := range users {
     928                        var channel string
     929                        if len(channels) == 1 {
     930                                channel = channels[0]
     931                        } else {
     932                                channel = channels[i]
     933                        }
     934
     935                        ucChannel, upstreamChannel, err := dc.unmarshalEntity(channel)
     936                        if err != nil {
     937                                return err
     938                        }
     939
     940                        ucUser, upstreamUser, err := dc.unmarshalEntity(user)
     941                        if err != nil {
     942                                return err
     943                        }
     944
     945                        if ucChannel != ucUser {
     946                                return ircError{&irc.Message{
     947                                        Command: irc.ERR_USERNOTINCHANNEL,
     948                                        Params:  []string{dc.nick, user, channel, "They aren't on that channel"},
     949                                }}
     950                        }
     951                        uc := ucChannel
     952
     953                        params := []string{upstreamChannel, upstreamUser}
     954                        if reason != "" {
     955                                params = append(params, reason)
     956                        }
     957                        uc.SendMessage(&irc.Message{
     958                                Command: "KICK",
     959                                Params:  params,
     960                        })
     961                }
    906962        case "MODE":
    907963                var name string
Note: See TracChangeset for help on using the changeset viewer.