Load longer messages
This commit is contained in:
parent
158189ae7d
commit
56fa617f26
1 changed files with 21 additions and 6 deletions
27
main.go
27
main.go
|
@ -77,16 +77,31 @@ func (c *Client) Send(msgType MessageType, data *string, subType *string, metada
|
|||
return err
|
||||
}
|
||||
|
||||
func (c *Client) rawReceive(messageEnding string) (string, error) {
|
||||
received := ""
|
||||
|
||||
for !strings.HasSuffix(received, messageEnding) {
|
||||
data := make([]byte, 20480)
|
||||
_, err := c.Con.Read(data)
|
||||
if err != nil {
|
||||
return received, err
|
||||
}
|
||||
|
||||
received = received + string(bytes.Trim(data, "\x00"))
|
||||
}
|
||||
|
||||
return received, nil
|
||||
}
|
||||
|
||||
func (c *Client) ReceivePlain() ([]RawMessage, error) {
|
||||
data := make([]byte, 20480)
|
||||
_, err := c.Con.Read(data)
|
||||
received, err := c.rawReceive("}")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
messages := []RawMessage{}
|
||||
|
||||
for _, message := range strings.Split(string(bytes.Trim(data, "\x00")), "}") {
|
||||
for _, message := range strings.Split(received, "}") {
|
||||
if strings.TrimSpace(message) == "" {
|
||||
continue
|
||||
}
|
||||
|
@ -104,15 +119,14 @@ func (c *Client) ReceivePlain() ([]RawMessage, error) {
|
|||
}
|
||||
|
||||
func (c *Client) Receive() ([]RawMessage, error) {
|
||||
data := make([]byte, 20480)
|
||||
_, err := c.Con.Read(data)
|
||||
received, err := c.rawReceive("]")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
messages := []RawMessage{}
|
||||
|
||||
for _, message := range strings.Split(string(bytes.Trim(data, "\x00")), "]") {
|
||||
for _, message := range strings.Split(received, "]") {
|
||||
if strings.TrimSpace(message) == "" {
|
||||
continue
|
||||
}
|
||||
|
@ -174,6 +188,7 @@ func (c *Client) HandshakeLoop(clientVersion string, password string) error {
|
|||
c.Username,
|
||||
password,
|
||||
clientVersion,
|
||||
"",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue