broadcast.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package broadcast
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/gamelist"
  5. "bet24.com/servers/coreservice/serviceconfig"
  6. notification "bet24.com/servers/micros/notification/proto"
  7. robot "bet24.com/servers/micros/userservices/proto"
  8. "bet24.com/utils"
  9. "encoding/json"
  10. "fmt"
  11. "strings"
  12. )
  13. // userId=用户ID(-1=系统 >0用户) gameId=游戏ID priority=优先级 msg=消息 ext=扩展信息
  14. func SendBroadcast(userId, gameId, priority int, msg, ext string) {
  15. //购买, 通知客户端
  16. d, _ := json.Marshal(notification.NotificationBroadcast{
  17. GameID: gameId,
  18. UserId: userId,
  19. Msg: msg,
  20. Priority: priority,
  21. Ext: ext,
  22. })
  23. notification.AddNotification(-1, notification.Notification_Broadcast, string(d))
  24. // log.Debug("SendBroadcast %s", msg)
  25. /*// 世界聊天频道
  26. chat.SendChatMsg(
  27. chat.Channel_World,
  28. -1,
  29. 0,
  30. 2,
  31. 1,
  32. -1,
  33. "Siaran",
  34. "",
  35. msg,
  36. "127.0.0.1")
  37. return*/
  38. }
  39. func SendGameWinBroadcast(userId int, userName string, score int, gameId int, gameName string) {
  40. if score < serviceconfig.Server.MinWinBroadcast {
  41. return
  42. }
  43. // 机器人不广播
  44. if robot.IsRobot(userId) {
  45. return
  46. }
  47. scoreStr := utils.FormatScore(score)
  48. gameWinString := serviceconfig.Server.GameWinString
  49. if gameWinString == "" {
  50. gameWinString = "menang <color=#04ff0a>%s</color> di <color=#ffafd8>%s</color>. Datang dan tantang!"
  51. }
  52. gi := gamelist.GetGame(gameId)
  53. if gi != nil {
  54. gameName = gi.ChineseName
  55. } else {
  56. log.Debug("SendGameWinBroadcast failed to find game of gameId[%d]", gameId)
  57. }
  58. var str string
  59. varCount := strings.Count(gameWinString, "%")
  60. if varCount == 2 {
  61. str = fmt.Sprintf(gameWinString, scoreStr, gameName)
  62. } else if varCount == 3 {
  63. str = fmt.Sprintf(gameWinString, gameName, scoreStr, userName)
  64. }
  65. SendBroadcast(userId, gameId, 0, str, "")
  66. }