diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2023-04-19 17:51:12 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2023-04-19 17:51:12 -0700 |
| commit | 902b8ac1e0d96f6c88a9bd352cb32b6bf69105d0 (patch) | |
| tree | d826f43e7178a271dec86baf1cfb7beea1a82c91 /hotline/client.go | |
| parent | aeb97482e923b5c441dd59e3ca4a7e275ac2b4c2 (diff) | |
Minor cleanup
Diffstat (limited to 'hotline/client.go')
| -rw-r--r-- | hotline/client.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/hotline/client.go b/hotline/client.go index 3598a00..f3e83c8 100644 --- a/hotline/client.go +++ b/hotline/client.go @@ -601,21 +601,18 @@ func (c *Client) LogIn(login string, password string) error { func (c *Client) Send(t Transaction) error { requestNum := binary.BigEndian.Uint16(t.Type) - tID := binary.BigEndian.Uint32(t.ID) - - // handler := TransactionHandlers[requestNum] // if transaction is NOT reply, add it to the list to transactions we're expecting a response for if t.IsReply == 0 { - c.activeTasks[tID] = &t + c.activeTasks[binary.BigEndian.Uint32(t.ID)] = &t } - var n int - var err error b, err := t.MarshalBinary() if err != nil { return err } + + var n int if n, err = c.Connection.Write(b); err != nil { return err } @@ -635,18 +632,17 @@ func (c *Client) HandleTransaction(t *Transaction) error { t.Type = origT.Type } - requestNum := binary.BigEndian.Uint16(t.Type) - c.Logger.Debugw("Received Transaction", "RequestType", requestNum) - - if handler, ok := c.Handlers[requestNum]; ok { + if handler, ok := c.Handlers[binary.BigEndian.Uint16(t.Type)]; ok { outT, _ := handler(c, t) for _, t := range outT { - c.Send(t) + if err := c.Send(t); err != nil { + return err + } } } else { c.Logger.Debugw( "Unimplemented transaction type received", - "RequestID", requestNum, + "RequestID", t.Type, "TransactionID", t.ID, ) } |