user_privateroom.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package gatesink
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "bet24.com/log"
  8. "bet24.com/servers/fishhall/config"
  9. client "bet24.com/servers/micros/privateroom/proto"
  10. utils2 "bet24.com/servers/insecureframe/gate/Utils"
  11. )
  12. func (this *user) onPrivateRoomMsg(msg, data string) {
  13. switch msg {
  14. case "getPrivateRoomRules":
  15. this.getPrivateRoomRules(msg, data)
  16. case "getPrivateRoomInfo":
  17. this.getPrivateRoomInfo(msg, data)
  18. case "createPrivateRoom":
  19. this.createPrivateRoom(msg, data)
  20. case "getMyPrivateRooms":
  21. this.getMyPrivateRooms(msg, data)
  22. case "enterPrivateRoom":
  23. this.enterPrivateRoom(msg, data)
  24. case "leavePrivateRoom":
  25. this.leavePrivateRoom(msg, data)
  26. case "getPrivateRoomHistory":
  27. this.getPrivateRoomHistory(msg)
  28. case "getPlayingPrivateRoom":
  29. this.getPlayingPrivateRoom(msg)
  30. case "getPrivateRoomsByGameId":
  31. this.getPrivateRoomsByGameId(msg, data)
  32. case "subscribePrivateRoomStatus":
  33. this.subscribePrivateRoomStatus()
  34. case "desubscribePrivateRoomStatus":
  35. this.desubscribePrivateRoomStatus()
  36. case "getPrivateRoomCallList":
  37. this.getPrivateRoomCallList(msg)
  38. case "PrivateRoomCallForUser":
  39. this.privateRoomCallForUser(msg, data)
  40. }
  41. }
  42. func (this *user) enterPrivateRoom(msg, data string) {
  43. // 这里可能包含chairId
  44. slice := strings.Split(data, ",")
  45. roomNo, err := strconv.Atoi(slice[0])
  46. if err != nil {
  47. log.Release("gatesink.enterPrivateRoom %v", err)
  48. this.WriteMsg(msg, "invalid argument")
  49. return
  50. }
  51. chairId := -1
  52. if len(slice) > 1 {
  53. chairId, err = strconv.Atoi(slice[1])
  54. if err != nil {
  55. chairId = -1
  56. }
  57. }
  58. if this.isGuest() && config.HallConfig.GuestPriveRoomClose > 0 {
  59. this.WriteMsg(msg, "not for guest users")
  60. return
  61. }
  62. this.WriteMsg(msg,
  63. client.UserRequestSit(roomNo,
  64. this.getUserId(),
  65. this.getNickName(),
  66. this.getFaceId(),
  67. this.getFaceUrl(),
  68. chairId, 0, 0, 0,this.getYyfUid()))
  69. }
  70. func (this *user) leavePrivateRoom(msg, data string) {
  71. roomNo, err := strconv.Atoi(data)
  72. if err != nil {
  73. log.Debug("gatesink.leavePrivateRoom %v %s", err, data)
  74. return
  75. }
  76. client.UserLeave(roomNo, this.getUserId())
  77. }
  78. func (this *user) getMyPrivateRooms(msg, data string) {
  79. this.WriteMsg(msg, client.GetUserRooms(this.getUserId()))
  80. }
  81. type createInfo struct {
  82. GameId int // 游戏ID
  83. GameRule string // 规则名
  84. Target int // 结束目标,hand为局数,domino为胜利分数
  85. UserCount int // 游戏人数
  86. PlayTime int
  87. Fee int // 报名费
  88. Prize int // 奖金
  89. IsPublic bool
  90. ExtraInfo string
  91. ChatRoomId int
  92. }
  93. func (this *user) createPrivateRoom(msg, data string) {
  94. var req createInfo
  95. if err := json.Unmarshal([]byte(data), &req); err != nil {
  96. retData := fmt.Sprintf("user.createPrivateRoom unmarshal data fail %v", err)
  97. log.Release(retData)
  98. this.WriteMsg(msg, retData)
  99. return
  100. }
  101. if this.isGuest() && config.HallConfig.GuestPriveRoomClose > 0 {
  102. this.WriteMsg(msg, "not for guest users")
  103. return
  104. }
  105. roomNo, errMsg := client.CreatePrivateRoomByUser(this.getUserId(),
  106. req.GameId, req.GameRule, req.Target, req.UserCount, req.Fee, req.Prize,
  107. client.RoomType_Normal, req.PlayTime, req.IsPublic, req.ExtraInfo,this.getYyfUid())
  108. this.WriteMsg(msg, fmt.Sprintf(`{"RoomNo":%d,"ErrMsg":"%s"}`, roomNo, errMsg))
  109. //room.RoomType = RoomIn
  110. //room.ChatRoomId = int(*req.ChatRoomId)
  111. //房间内开房的话,则直接拉人
  112. result := utils2.ChatRoomBroadcast(req.ChatRoomId, 1,int(roomNo))
  113. fmt.Printf("拉房结果===",result)
  114. //utils2.ChatRoomBroadcast(int(*req.ChatRoomId), 1, room.Id)
  115. }
  116. func (this *user) getPrivateRoomRules(msg, data string) {
  117. gameId, err := strconv.Atoi(data)
  118. if err != nil {
  119. log.Debug("gatesink.getPrivateRoomRules %v", err)
  120. gameId = 0
  121. }
  122. rules := client.GetPrivateRoomRules(gameId)
  123. if rules == "" {
  124. log.Debug("user.getPrivateRoomRules failed %v", rules)
  125. }
  126. this.WriteMsg(msg, rules)
  127. }
  128. func (this *user) getPrivateRoomInfo(msg, data string) {
  129. roomNo, err := strconv.Atoi(data)
  130. if err != nil {
  131. log.Debug("gatesink.getPrivateRoomInfo %v", err)
  132. return
  133. }
  134. roomdata := client.GetPrivateRoomInfo(roomNo)
  135. if roomdata == "" {
  136. log.Debug("user.getPrivateRoomInfo failed %v", roomdata)
  137. }
  138. this.WriteMsg(msg, roomdata)
  139. }
  140. func (this *user) getPrivateRoomHistory(msg string) {
  141. roomdata := client.GetHistory(this.getUserId())
  142. if roomdata == "" {
  143. log.Debug("user.getPrivateRoomHistory failed %v", roomdata)
  144. }
  145. this.WriteMsg(msg, roomdata)
  146. }
  147. func (this *user) getPlayingPrivateRoom(msg string) {
  148. this.WriteMsg(msg, client.GetPlayingRoomNo(this.getUserId()))
  149. }
  150. func (this *user) getPrivateRoomsByGameId(msg, data string) {
  151. gameId, err := strconv.Atoi(data)
  152. if err != nil {
  153. log.Debug("gatesink.getPrivateRoomsByGameId %v", err)
  154. gameId = 0
  155. }
  156. rooms := client.GetPrivateRoomsByGameId(gameId, this.getUserId())
  157. if rooms == "" {
  158. log.Debug("user.getPrivateRoomsByGameId failed %v", rooms)
  159. }
  160. this.WriteMsg(msg, rooms)
  161. }
  162. func (this *user) subscribePrivateRoomStatus() {
  163. client.UserSubscribeRoomStatus(this.getUserId())
  164. }
  165. func (this *user) desubscribePrivateRoomStatus() {
  166. client.UserDesubscribeRoomStatus(this.getUserId())
  167. }
  168. func (this *user) getPrivateRoomCallList(msg string) {
  169. this.WriteMsg(msg, client.GetCallList())
  170. }
  171. func (this *user) privateRoomCallForUser(msg, data string) {
  172. roomNo, err := strconv.Atoi(data)
  173. if err != nil {
  174. log.Debug("gatesink.privateRoomCallForUser %v", err)
  175. return
  176. }
  177. client.PrivateRoomCall(this.getUserId(), roomNo)
  178. }