Flags *[]byte
UserName []byte
Account *Account
- IdleTime *int
+ IdleTime int
Server *Server
Version *[]byte
Idle bool
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
}
Flags *[]byte
UserName []byte
Account *Account
- IdleTime *int
+ IdleTime int
Server *Server
Version *[]byte
Idle bool
Flags: tt.fields.Flags,
UserName: tt.fields.UserName,
Account: tt.fields.Account,
- IdleTime: tt.fields.IdleTime,
Server: tt.fields.Server,
Version: tt.fields.Version,
Idle: tt.fields.Idle,
s.mux.Lock()
for _, c := range s.Clients {
- *c.IdleTime += idleCheckInterval
- if *c.IdleTime > userIdleSeconds && !c.Idle {
+ c.IdleTime += idleCheckInterval
+ if c.IdleTime > userIdleSeconds && !c.Idle {
c.Idle = true
flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
Connection: conn,
Server: s,
Version: &[]byte{},
- IdleTime: new(int),
AutoReply: &[]byte{},
Transfers: make(map[int][]*FileTransfer),
Agreed: false,
*s.NextGuestID++
ID := *s.NextGuestID
- *clientConn.IdleTime = 0
-
binary.BigEndian.PutUint16(*clientConn.ID, ID)
s.Clients[ID] = clientConn
return res, err
}
-// HandleKeepAlive response to keepalive transactions with an empty reply
-// HL 1.9.2 Client sends keepalive msg every 3 minutes
-// HL 1.2.3 Client doesn't send keepalives
+// HandleKeepAlive responds to keepalive transactions with an empty reply
+// * HL 1.9.2 Client sends keepalive msg every 3 minutes
+// * HL 1.2.3 Client doesn't send keepalives
func HandleKeepAlive(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
res = append(res, cc.NewReply(t))