handler.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package handler
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/audioroom/handler/admin"
  5. "bet24.com/servers/micros/audioroom/handler/config"
  6. "bet24.com/servers/micros/audioroom/handler/game"
  7. "bet24.com/servers/micros/audioroom/handler/income"
  8. "bet24.com/servers/micros/audioroom/handler/manager"
  9. "bet24.com/servers/micros/audioroom/handler/message"
  10. pb "bet24.com/servers/micros/audioroom/proto"
  11. "golang.org/x/net/context"
  12. "math/rand"
  13. "time"
  14. )
  15. var instance *audioroom
  16. type audioroom struct {
  17. logPrint bool // 日志打印
  18. }
  19. func GetInstance() *audioroom {
  20. if instance == nil {
  21. instance = newHandler()
  22. }
  23. return instance
  24. }
  25. func newHandler() *audioroom {
  26. ret := new(audioroom)
  27. ret.ctor()
  28. return ret
  29. }
  30. func (g *audioroom) ctor() {
  31. rand.Seed(time.Now().Unix())
  32. // 加载配置管理器
  33. config.LoadConfigMgr()
  34. // 加载房间管理器
  35. manager.Run()
  36. // 加载游戏管理器
  37. game.Run()
  38. // 加载收益管理器
  39. income.Run()
  40. // 加载后台控制器
  41. admin.LoadAdminMgr()
  42. // 加载后台管理器
  43. manager.LoadAdminRoomMgr()
  44. }
  45. func Dump(cmd, param1, param2 string) {
  46. GetInstance().dump(cmd, param1, param2)
  47. }
  48. func (this *audioroom) dump(cmd, param1, param2 string) {
  49. switch cmd {
  50. case "room":
  51. manager.DumpRoom(param1, param2)
  52. case "user":
  53. manager.DumpUser(param1, param2)
  54. case "game":
  55. game.Dump(param1, param2)
  56. case "income":
  57. income.Dump(param1, param2)
  58. case "log":
  59. if param1 == "open" {
  60. this.logPrint = true
  61. log.Debug("消息指令跟踪已开启...")
  62. } else {
  63. this.logPrint = false
  64. log.Debug("消息指令跟踪已关闭!")
  65. }
  66. case "exit":
  67. manager.ClearRoomMic()
  68. default:
  69. log.Release("audioroom.Dump unhandled cmd %s", cmd)
  70. }
  71. }
  72. // 指令消息处理
  73. func (this *audioroom) OnAudioRoomMsg(ctx context.Context, req *pb.Request, resp *pb.Response) error {
  74. resp.Data = message.MessageHandler(req.UserId, req.Msg, req.Data)
  75. // 打印日志
  76. if this.logPrint {
  77. switch req.Msg {
  78. case "AudioRoomDealApplyOnMic":
  79. log.Debug("OnAudioRoomMsg request=%+v ==> resp.Data=%s", req, req.Data)
  80. default:
  81. log.Debug("OnAudioRoomMsg request=%+v", req)
  82. }
  83. }
  84. return nil
  85. }
  86. // 获取房间信息
  87. func (this *audioroom) GetRoom(ctx context.Context, req *pb.Request, rsp *pb.Response_RoomInfo) error {
  88. rsp.RoomInfo = manager.GetRoomInfo(req.RoomId)
  89. return nil
  90. }
  91. // 上报用户投注日志
  92. func (this *audioroom) ReportUserBet(ctx context.Context, req *pb.Request_ReportUserBet, rsp *pb.Response) error {
  93. game.ReportUserBet(req.RoomId, req.RoomNo, req.GameId, req.RoomName, req.IsChipRoom, req.UserBets)
  94. return nil
  95. }