Changeset 66 in code for trunk/downstream.go


Ignore:
Timestamp:
Feb 18, 2020, 4:07:58 PM (5 years ago)
Author:
contact
Message:

Properly handle PING messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r64 r66  
    196196                return dc.Close()
    197197        case "PING":
    198                 // TODO: handle params
     198                var from, to string
     199                if len(msg.Params) >= 1 {
     200                        from = msg.Params[0]
     201                }
     202                if len(msg.Params) >= 2 {
     203                        to = msg.Params[1]
     204                }
     205
     206                if to != "" && to != dc.srv.Hostname {
     207                        return ircError{&irc.Message{
     208                                Command: irc.ERR_NOSUCHSERVER,
     209                                Params:  []string{to, "No such server"},
     210                        }}
     211                }
     212
     213                params := []string{dc.srv.Hostname}
     214                if from != "" {
     215                        params = append(params, from)
     216                }
    199217                dc.SendMessage(&irc.Message{
    200218                        Prefix:  dc.srv.prefix(),
    201219                        Command: "PONG",
    202                         Params:  []string{dc.srv.Hostname},
     220                        Params:  params,
    203221                })
    204222                return nil
Note: See TracChangeset for help on using the changeset viewer.