guild_model.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package model
  2. import (
  3. "rocommon"
  4. "rocommon/rpc"
  5. "rocommon/util"
  6. "roserver/baseserver/model"
  7. "roserver/serverproto"
  8. "runtime/debug"
  9. )
  10. var (
  11. updateList []interface{}
  12. GuildMag *GuildManager
  13. GuildBattleMag *GuildBattleManager
  14. )
  15. type GuildUpdate struct {
  16. rocommon.UpdateModule //eventqueue.go
  17. }
  18. func (this *GuildUpdate) Init() {
  19. //
  20. GuildMag = newGuildManager()
  21. updateList = append(updateList, GuildMag)
  22. GuildBattleMag = newGuildBattleManager()
  23. updateList = append(updateList, GuildBattleMag)
  24. }
  25. func (this *GuildUpdate) Update(ms uint64) {
  26. defer func() {
  27. //打印奔溃信息
  28. if err := recover(); err != nil {
  29. util.InfoF("onError data=%v \n%s\n", err, string(debug.Stack()))
  30. }
  31. }()
  32. //对管理器进行更新操作
  33. for _, data := range updateList {
  34. data.(rocommon.UpdateLogic).Update(ms)
  35. }
  36. }
  37. func SendSocial(msg interface{}) bool {
  38. data, meta, err := rpc.EncodeMessage(msg)
  39. if err != nil {
  40. util.InfoF("[SendSocial] EncodeMessage err:%v %v", err, msg)
  41. return false
  42. }
  43. socialNode := model.SelectServiceNode(model.SERVICE_NODE_TYPE_SOCIAL_STR, 0)
  44. if socialNode == "" {
  45. util.InfoF("[SendSocial] social node not exist msg:%v", msg)
  46. return false
  47. }
  48. socialSess := model.GetServiceNode(socialNode)
  49. if socialSess == nil {
  50. util.ErrorF("[SendSocial] social session not exist:%v", socialSess)
  51. } else {
  52. //如果玩家信息存在,ClientId中存放的是玩家ID,否则存放的是玩家的gate sessionId
  53. socialSess.Send(&serverproto.ServiceTransmitAck{
  54. MsgId: uint32(meta.ID),
  55. MsgData: data,
  56. })
  57. }
  58. return true
  59. }
  60. func SendToAllGame(msg interface{}) {
  61. data, info, err := rpc.EncodeMessage(msg)
  62. if err != nil {
  63. util.InfoF("[SendGame]EncodeMessage err:%v %v", err, msg)
  64. return
  65. }
  66. sendMsg := &serverproto.ServiceTransmitAck{
  67. MsgId: uint32(info.ID),
  68. MsgData: data,
  69. }
  70. serviceList := model.GetAllServiceNodeByName(model.SERVICE_NODE_TYPE_GAME_STR)
  71. if len(serviceList) > 0 {
  72. for _, node := range serviceList {
  73. gameSess := model.GetServiceNode(node)
  74. if gameSess != nil {
  75. gameSess.Send(sendMsg)
  76. }
  77. }
  78. }
  79. }