package main import ( "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/timer" "time" ) const ( SessionAttributeClientAccountId int = iota // 账号 SessionAttributeUser SessionAttributePingTimer ) func StartSessionPingTimer(s *netlib.Session, act timer.TimerAction, ud interface{}, interval time.Duration, times int) bool { StopSessionPingTimer(s) if hTimer, ok := timer.StartTimer(act, ud, interval, times); ok { s.SetAttribute(SessionAttributePingTimer, hTimer) return true } return false } func StopSessionPingTimer(s *netlib.Session) { if h, ok := s.GetAttribute(SessionAttributePingTimer).(timer.TimerHandle); ok { if h != timer.TimerHandle(0) { timer.StopTimer(h) s.RemoveAttribute(SessionAttributePingTimer) } } }