pb.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. "github.com/smallnest/rpcx/client"
  6. "golang.org/x/net/context"
  7. )
  8. const ServiceName = "audioroom"
  9. var consulAddr = common.Default_Consul_Addr
  10. func getClient() client.XClient {
  11. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  12. }
  13. type Request struct {
  14. UserId int `json:",omitempty"`
  15. RoomId int `json:",omitempty"`
  16. GameId int `json:",omitempty"`
  17. Msg string
  18. Data string
  19. }
  20. type Response struct {
  21. Data string
  22. }
  23. func SetConsulAddr(addr string) {
  24. consulAddr = addr
  25. }
  26. // 语聊房消息处理
  27. func OnAudioRoomMsg(userId int, msg, data string) string {
  28. xclient := getClient()
  29. //defer xclient.Close()
  30. args := &Request{
  31. UserId: userId,
  32. Msg: msg,
  33. Data: data,
  34. }
  35. reply := &Response{}
  36. err := xclient.Call(context.Background(), "OnAudioRoomMsg", args, reply)
  37. if err != nil {
  38. log.Debug("audioroom failed to call: %v", err)
  39. common.GetClientPool().RemoveClient(ServiceName)
  40. }
  41. return reply.Data
  42. }
  43. // 获取房间信息
  44. func GetRoom(roomId int) Response_RoomInfo {
  45. xclient := getClient()
  46. //defer xclient.Close()
  47. args := &Request{
  48. RoomId: roomId,
  49. }
  50. reply := &Response_RoomInfo{}
  51. err := xclient.Call(context.Background(), "GetRoom", args, reply)
  52. if err != nil {
  53. log.Debug("audioroom failed to call: %v", err)
  54. common.GetClientPool().RemoveClient(ServiceName)
  55. }
  56. return *reply
  57. }
  58. func ReportUserBet(roomId, roomNo int, gameId int, roomName string, userBets []UserBet, isChipRoom bool) {
  59. xclient := getClient()
  60. args := &Request_ReportUserBet{
  61. RoomId: roomId,
  62. RoomNo: roomNo,
  63. GameId: gameId,
  64. RoomName: roomName,
  65. UserBets: userBets,
  66. IsChipRoom: isChipRoom,
  67. }
  68. err := xclient.Call(context.Background(), "ReportUserBet", args, nil)
  69. if err != nil {
  70. log.Debug("audioroom.ReportUserBet failed to call: %v", err)
  71. common.GetClientPool().RemoveClient(ServiceName)
  72. }
  73. }