fix: fixed some stuff

* include token when replying to a PING with a PONG
* fixed parsing of a single param with a colon
* fixed client's SendCommand() to properly send single and multi param
  messages
This commit is contained in:
2022-01-03 23:59:52 +02:00
parent 042af16c09
commit 327f59a14c
3 changed files with 27 additions and 10 deletions
+21 -9
View File
@@ -89,17 +89,29 @@ func (c Client) SendCommand(cmd string, params ...string) {
}
paramsString := ""
if len(params) > 0 {
paramsString = " " + strings.Join(params, " ")
}
// if we have more than 1 param then replace the last param's space with a " :"
// if we have more than 1 param
if len(params) > 1 {
i := strings.LastIndex(paramsString, " ")
paramsString = paramsString[:i] + strings.Replace(paramsString[i:], " ", " :", 1)
// if we have more exactly 1 param and it contains spaces, we prepend colon to the param
} else if len(params) == 1 && strings.Contains(params[0], " ") {
paramsString = ":" + paramsString
lastParam := params[len(params)-1]
// if the last param is a trailing param
// we prepend a colon to it
if strings.Contains(lastParam, " ") {
lastParam = " :" + lastParam
} else {
lastParam = " " + lastParam
}
paramsString = " " + strings.Join(params[:len(params)-1], " ")
paramsString += lastParam
// if we have exactly 1 param
} else if len(params) == 1 {
// if this 1 param contains spaces, we prepend a colon
if strings.Contains(params[0], " ") {
paramsString = " :" + params[0]
} else {
paramsString = " " + params[0]
}
}
if c.TlsConn != nil {