servicecontext.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package svc
  2. import (
  3. treemap "github.com/liyue201/gostl/ds/map"
  4. "github.com/liyue201/gostl/ds/set"
  5. "ylink/comm/kafka"
  6. "ylink/comm/model"
  7. "ylink/core/inner/rpc/internal/config"
  8. "ylink/core/inner/rpc/internal/ext"
  9. )
  10. type ServiceContext struct {
  11. Config config.Config
  12. KqMsgBoxProducer *kafka.Producer
  13. }
  14. func NewServiceContext(c config.Config) *ServiceContext {
  15. fetchCsCenterInfo()
  16. ext.Game2PlayerStatMap = treemap.New(treemap.WithGoroutineSafe())
  17. ext.CsStatSet = set.New(set.WithGoroutineSafe())
  18. return &ServiceContext{
  19. Config: c,
  20. KqMsgBoxProducer: kafka.NewKafkaProducer(c.KqMsgBoxProducerConf.Brokers, c.KqMsgBoxProducerConf.Topic),
  21. }
  22. }
  23. func fetchCsCenterInfo() {
  24. // mock info
  25. mockInfo()
  26. }
  27. func mockInfo() {
  28. ext.Game2PlayerMap = treemap.New(treemap.WithGoroutineSafe())
  29. ext.CsMap = treemap.New(treemap.WithGoroutineSafe())
  30. // 已连接的映射
  31. // 专属客服映射
  32. game1231P2cMap := treemap.New(treemap.WithGoroutineSafe())
  33. game1231P2cMap.Insert("player1231", "cs_1231")
  34. game1231P2cMap.Insert("player1111", "cs_2222")
  35. game1111P2cMap := treemap.New(treemap.WithGoroutineSafe())
  36. game1111P2cMap.Insert("player1231", "cs_1111")
  37. ext.Game2PlayerMap.Insert("game1231", game1231P2cMap)
  38. ext.Game2PlayerMap.Insert("game1111", game1111P2cMap)
  39. ext.CsMap.Insert("cs_1231", &model.CsInfo{
  40. CsId: "cs_1231",
  41. CsNickname: "客服1231",
  42. CsAvatarUrl: "https://www.baidu.com",
  43. CsSignature: "我是客服1231",
  44. OnlineStatus: 1,
  45. })
  46. ext.CsMap.Insert("cs_1111", &model.CsInfo{
  47. CsId: "cs_1111",
  48. CsNickname: "客服1111",
  49. CsAvatarUrl: "https://www.baidu.com",
  50. CsSignature: "我是客服1111",
  51. OnlineStatus: 1,
  52. })
  53. ext.CsMap.Insert("cs_2222", &model.CsInfo{
  54. CsId: "cs_2222",
  55. CsNickname: "客服2222",
  56. CsAvatarUrl: "https://www.baidu.com",
  57. CsSignature: "我是客服2222",
  58. OnlineStatus: 0,
  59. })
  60. }