privateroom.pb.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. status_client "bet24.com/servers/micros/privateroom/status/client"
  6. status_server "bet24.com/servers/micros/privateroom/status/server"
  7. "context"
  8. "fmt"
  9. "github.com/smallnest/rpcx/client"
  10. "os"
  11. "time"
  12. )
  13. const ServiceName = "privateroom"
  14. var consulAddr = common.Default_Consul_Addr
  15. func getClient() client.XClient {
  16. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  17. }
  18. type Request struct {
  19. Name string
  20. UserId int
  21. GameId int
  22. GameName string
  23. Addr string
  24. TableId int
  25. RoomNo int
  26. Status int
  27. YyfUid int
  28. RuleName string
  29. RuleDesc string
  30. RuleData string
  31. Online int
  32. Target int
  33. UserCount int
  34. Fee int
  35. Prize int
  36. RoomType string
  37. PlayTimeout int
  38. TableUserCount int
  39. NickName string
  40. FaceId int
  41. FaceUrl string
  42. ChairId int
  43. Score int
  44. BaseScore int
  45. SetCount int
  46. Winners []int
  47. SecAfter int
  48. IsPublic bool
  49. ExtraInfo string
  50. }
  51. type Response struct {
  52. Data string
  53. RoomNo int
  54. ErrorMsg string
  55. Status int
  56. Success bool
  57. RetCode int
  58. User *RoomUser
  59. Fee int
  60. Prize int
  61. }
  62. func SetConsulAddr(addr string) {
  63. consulAddr = addr
  64. }
  65. func SayHello(name string) string {
  66. xclient := getClient()
  67. //defer xclient.Close()
  68. args := &Request{
  69. Name: name,
  70. }
  71. reply := &Response{}
  72. err := xclient.Call(context.Background(), "SayHello", args, reply)
  73. if err != nil {
  74. log.Debug("privateroom failed to call: %v", err)
  75. common.GetClientPool().RemoveClient(ServiceName)
  76. return ""
  77. }
  78. log.Debug("SayHello return %s", reply.Data)
  79. return reply.Data
  80. }
  81. func CreatePrivateRoomByGameServer(userId int, gameId int, gameName string, addr string, tableId int) (int, string) {
  82. xclient := getClient()
  83. args := &Request{
  84. UserId: userId,
  85. GameId: gameId,
  86. GameName: gameName,
  87. Addr: addr,
  88. TableId: tableId,
  89. }
  90. reply := &Response{}
  91. err := xclient.Call(context.Background(), "CreatePrivateRoomByGameServer", args, reply)
  92. if err != nil {
  93. log.Debug("privateroom failed to call: %v", err)
  94. common.GetClientPool().RemoveClient(ServiceName)
  95. return 0, "server error"
  96. }
  97. return reply.RoomNo, reply.ErrorMsg
  98. }
  99. func GetPrivateRoomInfo(roomNo int) string {
  100. xclient := getClient()
  101. args := &Request{
  102. RoomNo: roomNo,
  103. }
  104. reply := &Response{}
  105. err := xclient.Call(context.Background(), "GetPrivateRoomInfo", args, reply)
  106. if err != nil {
  107. log.Debug("privateroom failed to call: %v", err)
  108. common.GetClientPool().RemoveClient(ServiceName)
  109. return ""
  110. }
  111. return reply.Data
  112. }
  113. func GetUserRooms(userId int) string {
  114. xclient := getClient()
  115. args := &Request{
  116. UserId: userId,
  117. }
  118. reply := &Response{}
  119. err := xclient.Call(context.Background(), "GetUserRooms", args, reply)
  120. if err != nil {
  121. log.Debug("privateroom failed to call: %v", err)
  122. return ""
  123. }
  124. return reply.Data
  125. }
  126. func SetRoomStatus(roomNo, status int) {
  127. xclient := getClient()
  128. args := &Request{
  129. RoomNo: roomNo,
  130. Status: status,
  131. }
  132. err := xclient.Call(context.Background(), "SetRoomStatus", args, nil)
  133. if err != nil {
  134. common.GetClientPool().RemoveClient(ServiceName)
  135. log.Debug("privateroom failed to call: %v", err)
  136. }
  137. }
  138. func GetRoomStatus(roomNo int) int {
  139. xclient := getClient()
  140. args := &Request{
  141. RoomNo: roomNo,
  142. }
  143. reply := &Response{}
  144. err := xclient.Call(context.Background(), "GetRoomStatus", args, reply)
  145. if err != nil {
  146. common.GetClientPool().RemoveClient(ServiceName)
  147. log.Debug("privateroom failed to call: %v", err)
  148. return 0
  149. }
  150. return reply.Status
  151. }
  152. func RegisterGameRule(addr string, gameId int, gameName string, ruleName, ruleDesc, ruleData string) {
  153. //log.Debug("RegisterGameRule %s", addr)
  154. xclient := getClient()
  155. args := &Request{
  156. Addr: addr,
  157. GameId: gameId,
  158. GameName: gameName,
  159. RuleName: ruleName,
  160. RuleDesc: ruleDesc,
  161. RuleData: ruleData,
  162. }
  163. reply := &Response{}
  164. err := xclient.Call(context.Background(), "RegisterGameRule", args, reply)
  165. if err != nil {
  166. common.GetClientPool().RemoveClient(ServiceName)
  167. log.Debug("privateroom failed to call: %v", err)
  168. }
  169. }
  170. func UpdateServerOnline(addr string, online int) {
  171. xclient := getClient()
  172. args := &Request{
  173. Addr: addr,
  174. Online: online,
  175. }
  176. err := xclient.Call(context.Background(), "UpdateServerOnline", args, nil)
  177. if err != nil {
  178. log.Debug("privateroom failed to call: %v", err)
  179. }
  180. }
  181. func UnregisterServer(addr string) {
  182. xclient := getClient()
  183. args := &Request{
  184. Addr: addr,
  185. }
  186. err := xclient.Call(context.Background(), "UnregisterServer", args, nil)
  187. if err != nil {
  188. common.GetClientPool().RemoveClient(ServiceName)
  189. log.Debug("privateroom failed to call: %v", err)
  190. }
  191. }
  192. func GetPrivateRoomRules(gameId int) string {
  193. xclient := getClient()
  194. args := &Request{
  195. GameId: gameId,
  196. }
  197. reply := &Response{}
  198. err := xclient.Call(context.Background(), "GetPrivateRoomRules", args, reply)
  199. if err != nil {
  200. common.GetClientPool().RemoveClient(ServiceName)
  201. log.Debug("privateroom failed to call: %v", err)
  202. return ""
  203. }
  204. return reply.Data
  205. }
  206. func CreatePrivateRoomByUser(userId int, gameId int, ruleName string, target int, userCount int, fee int,
  207. prize int, roomType string, playTimeout int, isPublic bool, extraInfo string,yyfUid int) (int, string) {
  208. xclient := getClient()
  209. args := &Request{
  210. UserId: userId,
  211. GameId: gameId,
  212. RuleName: ruleName,
  213. Target: target,
  214. UserCount: userCount,
  215. Fee: fee,
  216. Prize: prize,
  217. RoomType: roomType,
  218. PlayTimeout: playTimeout,
  219. IsPublic: isPublic,
  220. ExtraInfo: extraInfo,
  221. YyfUid: yyfUid,
  222. }
  223. reply := &Response{}
  224. err := xclient.Call(context.Background(), "CreatePrivateRoomByUser", args, reply)
  225. if err != nil {
  226. common.GetClientPool().RemoveClient(ServiceName)
  227. log.Debug("privateroom failed to call: %v", err)
  228. return 0, "server error"
  229. }
  230. return reply.RoomNo, reply.ErrorMsg
  231. }
  232. func ClosePrivateRoom(roomNo int) bool {
  233. if roomNo == 0 {
  234. return false
  235. }
  236. xclient := getClient()
  237. args := &Request{
  238. RoomNo: roomNo,
  239. }
  240. reply := &Response{}
  241. err := xclient.Call(context.Background(), "ClosePrivateRoom", args, reply)
  242. if err != nil {
  243. common.GetClientPool().RemoveClient(ServiceName)
  244. log.Debug("privateroom failed to call: %v", err)
  245. return false
  246. }
  247. return reply.Success
  248. }
  249. func DismissPrivateRoom(roomNo int) bool {
  250. xclient := getClient()
  251. args := &Request{
  252. RoomNo: roomNo,
  253. }
  254. reply := &Response{}
  255. err := xclient.Call(context.Background(), "DismissPrivatRoom", args, reply)
  256. if err != nil {
  257. common.GetClientPool().RemoveClient(ServiceName)
  258. log.Debug("privateroom failed to call: %v", err)
  259. return false
  260. }
  261. return reply.Success
  262. }
  263. func UserRequestSit(roomNo int, userId int, nickName string, faceId int, faceUrl string, chairId int, score, baseScore, setCount int,yyfUid int) string {
  264. xclient := getClient()
  265. args := &Request{
  266. RoomNo: roomNo,
  267. UserId: userId,
  268. NickName: nickName,
  269. FaceId: faceId,
  270. FaceUrl: faceUrl,
  271. ChairId: chairId,
  272. Score: score,
  273. BaseScore: baseScore,
  274. SetCount: setCount,
  275. YyfUid: yyfUid,
  276. }
  277. reply := &Response{}
  278. err := xclient.Call(context.Background(), "UserRequestSit", args, reply)
  279. if err != nil {
  280. log.Debug("privateroom failed to call: %v", err)
  281. return "server error"
  282. }
  283. return reply.Data
  284. }
  285. func UserSit(roomNo int, userId int, chairId int) int {
  286. xclient := getClient()
  287. args := &Request{
  288. RoomNo: roomNo,
  289. UserId: userId,
  290. ChairId: chairId,
  291. }
  292. reply := &Response{}
  293. err := xclient.Call(context.Background(), "UserSit", args, reply)
  294. if err != nil {
  295. common.GetClientPool().RemoveClient(ServiceName)
  296. log.Debug("privateroom failed to call: %v", err)
  297. return -1
  298. }
  299. return reply.RetCode
  300. }
  301. func UserChangeChair(roomNo int, userId int, chairId int) bool {
  302. xclient := getClient()
  303. args := &Request{
  304. RoomNo: roomNo,
  305. UserId: userId,
  306. ChairId: chairId,
  307. }
  308. reply := &Response{}
  309. err := xclient.Call(context.Background(), "UserChangeChair", args, reply)
  310. if err != nil {
  311. common.GetClientPool().RemoveClient(ServiceName)
  312. log.Debug("privateroom failed to call: %v", err)
  313. return false
  314. }
  315. return reply.Success
  316. }
  317. func UserLeave(roomNo int, userId int) bool {
  318. xclient := getClient()
  319. args := &Request{
  320. RoomNo: roomNo,
  321. UserId: userId,
  322. }
  323. reply := &Response{}
  324. err := xclient.Call(context.Background(), "UserLeave", args, reply)
  325. if err != nil {
  326. common.GetClientPool().RemoveClient(ServiceName)
  327. log.Debug("privateroom failed to call: %v", err)
  328. return false
  329. }
  330. return reply.Success
  331. }
  332. func UpdateUserGameScore(roomNo, userId, scoreDelta int) {
  333. xclient := getClient()
  334. args := &Request{
  335. RoomNo: roomNo,
  336. UserId: userId,
  337. Score: scoreDelta,
  338. }
  339. err := xclient.Call(context.Background(), "UpdateUserGameScore", args, nil)
  340. if err != nil {
  341. common.GetClientPool().RemoveClient(ServiceName)
  342. log.Debug("privateroom failed to call: %v", err)
  343. }
  344. }
  345. func SetWinners(roomNo int, winners []int) {
  346. xclient := getClient()
  347. args := &Request{
  348. RoomNo: roomNo,
  349. Winners: winners,
  350. }
  351. reply := &Response{}
  352. err := xclient.Call(context.Background(), "SetWinners", args, reply)
  353. if err != nil {
  354. common.GetClientPool().RemoveClient(ServiceName)
  355. log.Debug("privateroom failed to call: %v", err)
  356. }
  357. }
  358. func GetHistory(userId int) string {
  359. xclient := getClient()
  360. args := &Request{
  361. UserId: userId,
  362. }
  363. reply := &Response{}
  364. err := xclient.Call(context.Background(), "GetHistory", args, reply)
  365. if err != nil {
  366. common.GetClientPool().RemoveClient(ServiceName)
  367. log.Debug("privateroom failed to call: %v", err)
  368. return ""
  369. }
  370. return reply.Data
  371. }
  372. func GetPlayingRoomNo(userId int) string {
  373. xclient := getClient()
  374. args := &Request{
  375. UserId: userId,
  376. }
  377. reply := &Response{}
  378. err := xclient.Call(context.Background(), "GetPlayingRoomNo", args, reply)
  379. if err != nil {
  380. common.GetClientPool().RemoveClient(ServiceName)
  381. log.Debug("privateroom failed to call: %v", err)
  382. return ""
  383. }
  384. return reply.Data
  385. }
  386. func IsGameRuleValid(gameId int, gameRule string, target int, tableUserCount int, playTime int) bool {
  387. xclient := getClient()
  388. args := &Request{
  389. GameId: gameId,
  390. RuleName: gameRule,
  391. Target: target,
  392. TableUserCount: tableUserCount,
  393. PlayTimeout: playTime,
  394. }
  395. reply := &Response{}
  396. err := xclient.Call(context.Background(), "IsGameRuleValid", args, reply)
  397. if err != nil {
  398. common.GetClientPool().RemoveClient(ServiceName)
  399. log.Debug("privateroom failed to call: %v", err)
  400. return false
  401. }
  402. return reply.Success
  403. }
  404. func ForceUserEnter(userId int, roomNo int, chairId int, secAfter int) {
  405. xclient := getClient()
  406. args := &Request{
  407. RoomNo: roomNo,
  408. UserId: userId,
  409. ChairId: chairId,
  410. SecAfter: secAfter,
  411. }
  412. err := xclient.Call(context.Background(), "ForceUserEnter", args, nil)
  413. if err != nil {
  414. common.GetClientPool().RemoveClient(ServiceName)
  415. log.Debug("privateroom failed to call: %v", err)
  416. }
  417. }
  418. func GetPrivateRoomsByGameId(gameId int, userId int) string {
  419. xclient := getClient()
  420. args := &Request{
  421. GameId: gameId,
  422. UserId: userId,
  423. }
  424. reply := &Response{}
  425. err := xclient.Call(context.Background(), "GetPrivateRoomsByGameId", args, reply)
  426. if err != nil {
  427. log.Debug("privateroom failed to call: %v", err)
  428. common.GetClientPool().RemoveClient(ServiceName)
  429. return ""
  430. }
  431. return reply.Data
  432. }
  433. func RegisterServerStatus(receiver status_client.IPrivateServerStatusReceiver, roomstatus_receiver IPrivateRoomStatusReceiver, port int, moduleName string) {
  434. if port == 0 {
  435. port = os.Getpid()
  436. }
  437. addr := fmt.Sprintf("%s_%d_%s", common.GetLocalIp(), port, moduleName)
  438. //log.Debug("privateroom.RegisterServerStatus %s", addr)
  439. go status_server.Run(addr, consulAddr, receiver, roomstatus_receiver)
  440. for {
  441. xclient := getClient()
  442. args := &Request{
  443. Addr: addr,
  444. }
  445. //log.Release("notification.Subscribe %s", addr)
  446. err := xclient.Call(context.Background(), "RegisterServerStatus", args, nil)
  447. if err != nil {
  448. log.Debug("Subscribe failed to call: %v", err)
  449. common.GetClientPool().RemoveClient(ServiceName)
  450. }
  451. time.Sleep(10 * time.Second)
  452. }
  453. }
  454. func UserSubscribeRoomStatus(userId int) {
  455. xclient := getClient()
  456. args := &Request{
  457. UserId: userId,
  458. }
  459. reply := &Response{}
  460. err := xclient.Call(context.Background(), "UserSubscribeRoomStatus", args, reply)
  461. if err != nil {
  462. log.Debug("privateroom failed to call: %v", err)
  463. common.GetClientPool().RemoveClient(ServiceName)
  464. }
  465. }
  466. func UserDesubscribeRoomStatus(userId int) {
  467. xclient := getClient()
  468. args := &Request{
  469. UserId: userId,
  470. }
  471. err := xclient.Call(context.Background(), "UserDesubscribeRoomStatus", args, nil)
  472. if err != nil {
  473. log.Debug("privateroom failed to call: %v", err)
  474. common.GetClientPool().RemoveClient(ServiceName)
  475. }
  476. }
  477. func GetCallList() string {
  478. xclient := getClient()
  479. args := &Request{}
  480. reply := &Response{}
  481. err := xclient.Call(context.Background(), "GetCallList", args, reply)
  482. if err != nil {
  483. log.Debug("privateroom failed to call: %v", err)
  484. common.GetClientPool().RemoveClient(ServiceName)
  485. return ""
  486. }
  487. return reply.Data
  488. }
  489. func PrivateRoomCall(userId int, roomNo int) {
  490. xclient := getClient()
  491. args := &Request{
  492. UserId: userId,
  493. RoomNo: roomNo,
  494. }
  495. err := xclient.Call(context.Background(), "PrivateRoomCall", args, nil)
  496. if err != nil {
  497. log.Debug("privateroom failed to call: %v", err)
  498. common.GetClientPool().RemoveClient(ServiceName)
  499. }
  500. }
  501. func GetUserRoomInfo(userId int, roomNo int) *RoomUser {
  502. xclient := getClient()
  503. args := &Request{
  504. UserId: userId,
  505. RoomNo: roomNo,
  506. }
  507. reply := &Response{}
  508. err := xclient.Call(context.Background(), "GetUserRoomInfo", args, reply)
  509. if err != nil {
  510. log.Debug("privateroom failed to call: %v", err)
  511. common.GetClientPool().RemoveClient(ServiceName)
  512. return nil
  513. }
  514. return reply.User
  515. }
  516. func GetRoomType(roomNo int) string {
  517. xclient := getClient()
  518. args := &Request{
  519. RoomNo: roomNo,
  520. }
  521. reply := &Response{}
  522. err := xclient.Call(context.Background(), "GetRoomType", args, reply)
  523. if err != nil {
  524. log.Debug("privateroom failed to call: %v", err)
  525. common.GetClientPool().RemoveClient(ServiceName)
  526. return ""
  527. }
  528. return reply.Data
  529. }
  530. func GetFeeAndPrize(roomNo int, userId int) (int, int) {
  531. xclient := getClient()
  532. args := &Request{
  533. RoomNo: roomNo,
  534. UserId: userId,
  535. }
  536. reply := &Response{}
  537. err := xclient.Call(context.Background(), "GetUserFeeAndPrize", args, reply)
  538. if err != nil {
  539. log.Debug("privateroom failed to call: %v", err)
  540. common.GetClientPool().RemoveClient(ServiceName)
  541. return 0, 0
  542. }
  543. return reply.Fee, reply.Prize
  544. }