3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

client: Add SendForceTrailing function, to force the last param to be a trailing

This commit is contained in:
Daniel Oaks 2017-01-20 23:51:36 +10:00
parent 63ee5f6fde
commit b257c5955e

View File

@ -12,6 +12,7 @@ import (
"net" "net"
"runtime/debug" "runtime/debug"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/DanielOaks/girc-go/ircmsg" "github.com/DanielOaks/girc-go/ircmsg"
@ -535,6 +536,16 @@ func (client *Client) SendFromClient(msgid string, from *Client, tags *map[strin
// Send sends an IRC line to the client. // Send sends an IRC line to the client.
func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
return client.send(false, tags, prefix, command, params...)
}
// SendForceTrailing sends an IRC line to the client, forcing the last param to be a trailing.
// This is a hack. However, there are clients that treat special chars differently.
func (client *Client) SendForceTrailing(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
return client.send(true, tags, prefix, command, params...)
}
func (client *Client) send(forceTrailing bool, tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
// attach server-time // attach server-time
if client.capabilities[ServerTime] { if client.capabilities[ServerTime] {
if tags == nil { if tags == nil {
@ -544,6 +555,16 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
} }
} }
// force trailing
var usedSpaceHack bool
if forceTrailing && len(params) > 0 {
lastParam := params[len(params)-1]
if !strings.Contains(lastParam, " ") {
params[len(params)-1] = lastParam + " "
usedSpaceHack = true
}
}
// send out the message // send out the message
message := ircmsg.MakeMessage(tags, prefix, command, params...) message := ircmsg.MakeMessage(tags, prefix, command, params...)
maxlenTags, maxlenRest := client.maxlens() maxlenTags, maxlenRest := client.maxlens()
@ -559,6 +580,12 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
client.socket.Write(line) client.socket.Write(line)
return err return err
} }
// strip space hack if we used it
if usedSpaceHack {
line = line[:len(line)-3] + "\r\n"
}
client.socket.Write(line) client.socket.Write(line)
return nil return nil
} }