base_role.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package role
  2. import (
  3. "log"
  4. "time"
  5. )
  6. type baseRole struct {
  7. /*
  8. 基础角色
  9. */
  10. Id string
  11. LoginTimeStamp int64 // 登录时间戳
  12. LastTalkTimeStamp int64 // 最近发言时间戳
  13. connChan chan int32 // 连接channel,释放则断开连接
  14. Stream interface{} // 连接stream流
  15. logOutChan chan interface{}
  16. }
  17. func (sel *baseRole) SetChan(connChan chan int32) {
  18. /*
  19. 设置连接信号
  20. */
  21. sel.connChan = connChan
  22. }
  23. func (sel *baseRole) RefreshTalkTimeStamp() {
  24. /*
  25. 刷新发言时间
  26. */
  27. nowStamp := time.Now().Unix()
  28. sel.LastTalkTimeStamp = nowStamp
  29. }
  30. func (sel *baseRole) StopChan(reason int32) {
  31. /*
  32. 发送信号:断开连接
  33. */
  34. if sel.connChan == nil {
  35. return
  36. }
  37. log.Printf("<baseRole.StopChan> id:%s, reason:%d \n", sel.Id, reason)
  38. sel.connChan <- reason
  39. close(sel.connChan)
  40. sel.connChan = nil
  41. }
  42. func (sel *baseRole) WaitLogOut() <-chan interface{} {
  43. return sel.logOutChan
  44. }
  45. func (sel *baseRole) Final() {
  46. sel.logOutChan <- true
  47. log.Println("<baseRole.Final> id:", sel.Id)
  48. }