X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/72dd37f1abb2b550aaaac48eac677403d5664797..decc2fbf5db4a05aec93462ad35d890930bddd04:/hotline/client_conn.go diff --git a/hotline/client_conn.go b/hotline/client_conn.go index 367b70f..b43a6ff 100644 --- a/hotline/client_conn.go +++ b/hotline/client_conn.go @@ -31,12 +31,13 @@ type ClientConn struct { Flags *[]byte UserName []byte Account *Account - IdleTime *int + IdleTime int Server *Server Version *[]byte Idle bool AutoReply *[]byte Transfers map[int][]*FileTransfer + Agreed bool } func (cc *ClientConn) sendAll(t int, fields ...Field) { @@ -102,28 +103,28 @@ func (cc *ClientConn) handleTransaction(transaction *Transaction) error { cc.Server.mux.Lock() defer cc.Server.mux.Unlock() - // if user was idle and this is a non-keepalive transaction - if *cc.IdleTime > userIdleSeconds && requestNum != tranKeepAlive { - flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags))) - flagBitmap.SetBit(flagBitmap, userFlagAway, 0) - binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64())) - cc.Idle = false - //*cc.IdleTime = 0 - - cc.sendAll( - tranNotifyChangeUser, - NewField(fieldUserID, *cc.ID), - NewField(fieldUserFlags, *cc.Flags), - NewField(fieldUserName, cc.UserName), - NewField(fieldUserIconID, *cc.Icon), - ) - - //return nil + if requestNum != tranKeepAlive { + // reset the user idle timer + cc.IdleTime = 0 + + // if user was previously idle, mark as not idle and notify other connected clients that + // the user is no longer away + if cc.Idle { + flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags))) + flagBitmap.SetBit(flagBitmap, userFlagAway, 0) + binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64())) + cc.Idle = false + + cc.sendAll( + tranNotifyChangeUser, + NewField(fieldUserID, *cc.ID), + NewField(fieldUserFlags, *cc.Flags), + NewField(fieldUserName, cc.UserName), + NewField(fieldUserIconID, *cc.Icon), + ) + } } - // TODO: Don't we need to skip this if requestNum == tranKeepalive ?? - *cc.IdleTime = 0 - return nil } @@ -168,7 +169,7 @@ func (cc ClientConn) Disconnect() { // NotifyOthers sends transaction t to other clients connected to the server func (cc ClientConn) NotifyOthers(t Transaction) { for _, c := range sortedClients(cc.Server.Clients) { - if c.ID != cc.ID { + if c.ID != cc.ID && c.Agreed { t.clientID = c.ID cc.Server.outbox <- t }