CombineServerDataMgr.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local CombineServerDataMgr = class('CombineServerDataMgr', require('DataBase'))
  2. function CombineServerDataMgr:ctor()
  3. end
  4. function CombineServerDataMgr:Clear()
  5. self.nextTime = nil
  6. end
  7. function CombineServerDataMgr:Destroy()
  8. self.nextTime = nil
  9. self:UnRegisterNetEvents()
  10. end
  11. function CombineServerDataMgr:RegisterNetEvents()
  12. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_COMBINE_SERVER_ONLINE_NTF, self.OnCombineServerOnlineNtf, self)
  13. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_COMBINE_SERVER_INFO_ACK, self.OnCombineServerInfoAck, self)
  14. end
  15. function CombineServerDataMgr:UnRegisterNetEvents()
  16. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_COMBINE_SERVER_ONLINE_NTF)
  17. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_COMBINE_SERVER_INFO_ACK)
  18. end
  19. function CombineServerDataMgr:OnCombineServerOnlineNtf(data)
  20. if ManagerContainer.NetManager:IsErrorData(data) then
  21. return
  22. end
  23. local nextTime = data.combine_time
  24. local changed = (nextTime ~= self.nextTime)
  25. self.nextTime = nextTime
  26. if changed then
  27. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.COMBINE_SERVER_TIME_CHANGED)
  28. end
  29. end
  30. function CombineServerDataMgr:OnCombineServerInfoAck(data)
  31. if ManagerContainer.NetManager:IsErrorData(data) then
  32. return
  33. end
  34. local nextTime = data.combine_time
  35. local changed = (nextTime ~= self.nextTime)
  36. self.nextTime = nextTime
  37. if changed then
  38. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.COMBINE_SERVER_TIME_CHANGED)
  39. end
  40. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.COMBINE_SERVER_CONTENT_CHANGED, data.notice)
  41. end
  42. function CombineServerDataMgr:SendCombineServerInfoReq()
  43. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_COMBINE_SERVER_INFO_REQ)
  44. end
  45. function CombineServerDataMgr:GetNextTime()
  46. return self.nextTime
  47. end
  48. return CombineServerDataMgr