]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/client.go
Merge pull request #49 from jhalter/fix_1.2.3_client_no_agreement_behavior
[rbdr/mobius] / hotline / client.go
index 24df7c35aa8caddf1c6084d96d2860dc1883bb0e..c32256298def76bf16373d678d985071ecc8f308 100644 (file)
@@ -103,8 +103,7 @@ func NewClient(cfgPath string, logger *zap.SugaredLogger) *Client {
 
        prefs, err := readConfig(cfgPath)
        if err != nil {
 
        prefs, err := readConfig(cfgPath)
        if err != nil {
-               fmt.Printf("unable to read config file %s", cfgPath)
-               os.Exit(1)
+               logger.Fatal(fmt.Sprintf("unable to read config file %s\n", cfgPath))
        }
        c.pref = prefs
 
        }
        c.pref = prefs
 
@@ -120,7 +119,7 @@ func (db *DebugBuffer) Write(p []byte) (int, error) {
        return db.TextView.Write(p)
 }
 
        return db.TextView.Write(p)
 }
 
-// Sync is a noop function that exists to satisfy the zapcore.WriteSyncer interface
+// Sync is a noop function that dataFile to satisfy the zapcore.WriteSyncer interface
 func (db *DebugBuffer) Sync() error {
        return nil
 }
 func (db *DebugBuffer) Sync() error {
        return nil
 }
@@ -398,54 +397,6 @@ func handleNotifyDeleteUser(c *Client, t *Transaction) (res []Transaction, err e
        return res, err
 }
 
        return res, err
 }
 
-const readBuffSize = 1024000 // 1KB - TODO: what should this be?
-
-func (c *Client) ReadLoop() error {
-       tranBuff := make([]byte, 0)
-       tReadlen := 0
-       // Infinite loop where take action on incoming client requests until the connection is closed
-       for {
-               buf := make([]byte, readBuffSize)
-               tranBuff = tranBuff[tReadlen:]
-
-               readLen, err := c.Connection.Read(buf)
-               if err != nil {
-                       return err
-               }
-               tranBuff = append(tranBuff, buf[:readLen]...)
-
-               // We may have read multiple requests worth of bytes from Connection.Read.  readTransactions splits them
-               // into a slice of transactions
-               var transactions []Transaction
-               if transactions, tReadlen, err = readTransactions(tranBuff); err != nil {
-                       c.Logger.Errorw("Error handling transaction", "err", err)
-               }
-
-               // iterate over all of the transactions that were parsed from the byte slice and handle them
-               for _, t := range transactions {
-                       if err := c.HandleTransaction(&t); err != nil {
-                               c.Logger.Errorw("Error handling transaction", "err", err)
-                       }
-               }
-       }
-}
-
-func (c *Client) GetTransactions() error {
-       tranBuff := make([]byte, 0)
-       tReadlen := 0
-
-       buf := make([]byte, readBuffSize)
-       tranBuff = tranBuff[tReadlen:]
-
-       readLen, err := c.Connection.Read(buf)
-       if err != nil {
-               return err
-       }
-       tranBuff = append(tranBuff, buf[:readLen]...)
-
-       return nil
-}
-
 func handleClientGetUserNameList(c *Client, t *Transaction) (res []Transaction, err error) {
        var users []User
        for _, field := range t.Fields {
 func handleClientGetUserNameList(c *Client, t *Transaction) (res []Transaction, err error) {
        var users []User
        for _, field := range t.Fields {
@@ -634,7 +585,6 @@ func (c *Client) LogIn(login string, password string) error {
                        NewField(fieldUserIconID, c.pref.IconBytes()),
                        NewField(fieldUserLogin, negateString([]byte(login))),
                        NewField(fieldUserPassword, negateString([]byte(password))),
                        NewField(fieldUserIconID, c.pref.IconBytes()),
                        NewField(fieldUserLogin, negateString([]byte(login))),
                        NewField(fieldUserPassword, negateString([]byte(password))),
-                       NewField(fieldVersion, []byte{0, 2}),
                ),
        )
 }
                ),
        )
 }
@@ -676,10 +626,7 @@ func (c *Client) HandleTransaction(t *Transaction) error {
        }
 
        requestNum := binary.BigEndian.Uint16(t.Type)
        }
 
        requestNum := binary.BigEndian.Uint16(t.Type)
-       c.Logger.Infow(
-               "Received Transaction",
-               "RequestType", requestNum,
-       )
+       c.Logger.Debugw("Received Transaction", "RequestType", requestNum)
 
        if handler, ok := c.Handlers[requestNum]; ok {
                outT, _ := handler.Handle(c, t)
 
        if handler, ok := c.Handlers[requestNum]; ok {
                outT, _ := handler.Handle(c, t)