aboutsummaryrefslogtreecommitdiff
path: root/hotline/client_conn.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-05-27 10:44:52 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-05-27 10:44:52 -0700
commit61c272e101b6f0444c7b2a666b0b5e828ba6db03 (patch)
treec9bc0c571cbfb63c70b37eb5e39ae797714fc756 /hotline/client_conn.go
parent6f0f1ef7c51f8d495a5818c4864650a7e1cfc8ef (diff)
Simplify user idle check
Diffstat (limited to 'hotline/client_conn.go')
-rw-r--r--hotline/client_conn.go38
1 files changed, 19 insertions, 19 deletions
diff --git a/hotline/client_conn.go b/hotline/client_conn.go
index 8e9a614..b43a6ff 100644
--- a/hotline/client_conn.go
+++ b/hotline/client_conn.go
@@ -31,7 +31,7 @@ type ClientConn struct {
Flags *[]byte
UserName []byte
Account *Account
- IdleTime *int
+ IdleTime int
Server *Server
Version *[]byte
Idle bool
@@ -103,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
+ if requestNum != tranKeepAlive {
+ // reset the user idle timer
+ cc.IdleTime = 0
- cc.sendAll(
- tranNotifyChangeUser,
- NewField(fieldUserID, *cc.ID),
- NewField(fieldUserFlags, *cc.Flags),
- NewField(fieldUserName, cc.UserName),
- NewField(fieldUserIconID, *cc.Icon),
- )
+ // 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
- //return nil
+ 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
}