]> git.r.bdr.sh - rbdr/mobius/blobdiff - client.go
Cleanup and error handling
[rbdr/mobius] / client.go
index 0c8cdb025ec90f2c7b589f5ba55deb76a8c02e3d..79f623a9f31d74bcec1138ef1fbc8ecf2d8d78bb 100644 (file)
--- a/client.go
+++ b/client.go
@@ -44,6 +44,12 @@ type ClientPrefs struct {
        Tracker   string     `yaml:"Tracker"`
 }
 
        Tracker   string     `yaml:"Tracker"`
 }
 
+func (cp *ClientPrefs) IconBytes() []byte {
+       iconBytes := make([]byte, 2)
+       binary.BigEndian.PutUint16(iconBytes, uint16(cp.IconID))
+       return iconBytes
+}
+
 func readConfig(cfgPath string) (*ClientPrefs, error) {
        fh, err := os.Open(cfgPath)
        if err != nil {
 func readConfig(cfgPath string) (*ClientPrefs, error) {
        fh, err := os.Open(cfgPath)
        if err != nil {
@@ -62,10 +68,8 @@ func readConfig(cfgPath string) (*ClientPrefs, error) {
 type Client struct {
        DebugBuf    *DebugBuffer
        Connection  net.Conn
 type Client struct {
        DebugBuf    *DebugBuffer
        Connection  net.Conn
-       UserName    []byte
        Login       *[]byte
        Password    *[]byte
        Login       *[]byte
        Password    *[]byte
-       Icon        *[]byte
        Flags       *[]byte
        ID          *[]byte
        Version     []byte
        Flags       *[]byte
        ID          *[]byte
        Version     []byte
@@ -461,7 +465,6 @@ func (ui *UI) Start() {
 
 func NewClient(username string, logger *zap.SugaredLogger) *Client {
        c := &Client{
 
 func NewClient(username string, logger *zap.SugaredLogger) *Client {
        c := &Client{
-               Icon:        &[]byte{0x07, 0xd7},
                Logger:      logger,
                activeTasks: make(map[uint32]*Transaction),
                Handlers:    clientHandlers,
                Logger:      logger,
                activeTasks: make(map[uint32]*Transaction),
                Handlers:    clientHandlers,
@@ -685,15 +688,15 @@ func (c *Client) renderUserList() {
        for _, u := range c.UserList {
                flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(u.Flags)))
                if flagBitmap.Bit(userFlagAdmin) == 1 {
        for _, u := range c.UserList {
                flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(u.Flags)))
                if flagBitmap.Bit(userFlagAdmin) == 1 {
-                       fmt.Fprintf(c.UI.userList, "[red::b]%s[-:-:-]\n", u.Name)
+                       _, _ = fmt.Fprintf(c.UI.userList, "[red::b]%s[-:-:-]\n", u.Name)
                } else {
                } else {
-                       fmt.Fprintf(c.UI.userList, "%s\n", u.Name)
+                       _, _ = fmt.Fprintf(c.UI.userList, "%s\n", u.Name)
                }
        }
 }
 
 func handleClientChatMsg(c *Client, t *Transaction) (res []Transaction, err error) {
                }
        }
 }
 
 func handleClientChatMsg(c *Client, t *Transaction) (res []Transaction, err error) {
-       fmt.Fprintf(c.UI.chatBox, "%s \n", t.GetField(fieldData).Data)
+       _, _ = fmt.Fprintf(c.UI.chatBox, "%s \n", t.GetField(fieldData).Data)
 
        return res, err
 }
 
        return res, err
 }
@@ -717,7 +720,7 @@ func handleClientTranShowAgreement(c *Client, t *Transaction) (res []Transaction
                                        *NewTransaction(
                                                tranAgreed, nil,
                                                NewField(fieldUserName, []byte(c.pref.Username)),
                                        *NewTransaction(
                                                tranAgreed, nil,
                                                NewField(fieldUserName, []byte(c.pref.Username)),
-                                               NewField(fieldUserIconID, *c.Icon),
+                                               NewField(fieldUserIconID, c.pref.IconBytes()),
                                                NewField(fieldUserFlags, []byte{0x00, 0x00}),
                                                NewField(fieldOptions, []byte{0x00, 0x00}),
                                        ),
                                                NewField(fieldUserFlags, []byte{0x00, 0x00}),
                                                NewField(fieldOptions, []byte{0x00, 0x00}),
                                        ),
@@ -726,7 +729,7 @@ func handleClientTranShowAgreement(c *Client, t *Transaction) (res []Transaction
                                c.UI.Pages.HidePage("agreement")
                                c.UI.App.SetFocus(c.UI.chatInput)
                        } else {
                                c.UI.Pages.HidePage("agreement")
                                c.UI.App.SetFocus(c.UI.chatInput)
                        } else {
-                               c.Disconnect()
+                               _ = c.Disconnect()
                                c.UI.Pages.SwitchToPage("home")
                        }
                },
                                c.UI.Pages.SwitchToPage("home")
                        }
                },
@@ -838,7 +841,7 @@ func (c *Client) LogIn(login string, password string) error {
                *NewTransaction(
                        tranLogin, nil,
                        NewField(fieldUserName, []byte(c.pref.Username)),
                *NewTransaction(
                        tranLogin, nil,
                        NewField(fieldUserName, []byte(c.pref.Username)),
-                       NewField(fieldUserIconID, []byte{0x07, 0xd1}),
+                       NewField(fieldUserIconID, c.pref.IconBytes()),
                        NewField(fieldUserLogin, []byte(NegatedUserString([]byte(login)))),
                        NewField(fieldUserPassword, []byte(NegatedUserString([]byte(password)))),
                        NewField(fieldVersion, []byte{0, 2}),
                        NewField(fieldUserLogin, []byte(NegatedUserString([]byte(login)))),
                        NewField(fieldUserPassword, []byte(NegatedUserString([]byte(password)))),
                        NewField(fieldVersion, []byte{0, 2}),