msgManager.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { _decorator, Component, Node } from 'cc';
  2. import { ClientEvent } from '../clientEvent';
  3. import { Constant } from '../constant';
  4. import UIDialog from '../Game/UIDialog';
  5. import { GameMng } from '../GameMng';
  6. import { UIManager } from '../gcommon/UIManager';
  7. import { native_manager } from '../native_manager';
  8. import { Tools } from '../Tools';
  9. import { setupData } from '../UserData/setupData';
  10. import gameSocket from './gameSocket';
  11. const { ccclass, property } = _decorator;
  12. export class msgManager {
  13. static login(account){
  14. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_LOGON,"userid":"","wx_openid":"","wx_name":"","wx_avatar":"","ios_openid":"","account":account,"verify_code":"1234"})
  15. gameSocket.Instance.send_cmd(str)
  16. }
  17. static wxlogin(nickname,wx_openid,sex,province,city,country,headimgurl){
  18. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_LOGON,"userid":"","wx_openid":wx_openid,"wx_name":nickname,"wx_avatar":headimgurl,"ios_openid":"","account":"","verify_code":"1234","sex":sex,"province":province,"city":city,"country":country})
  19. gameSocket.Instance.send_cmd(str)
  20. }
  21. static createRoom(totaltime,everysteptime,firstid,roomtype,countdown,everystepaddtime){
  22. let str = JSON.stringify( {"countdown":countdown,"everystepaddtime":everystepaddtime,"action":Constant.EVENT_TYPE.MSG_CREATE_ROOM,"userid":GameMng._userData.userid,"totaltime":totaltime,"everysteptime":everysteptime,"firstid":firstid,"roomtype":roomtype})
  23. gameSocket.Instance.send_cmd(str)
  24. }
  25. static createRoomByRoomType(roomtype){
  26. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_CREATE_ROOM,"userid":GameMng._userData.userid,"roomtype":roomtype})
  27. gameSocket.Instance.send_cmd(str)
  28. }
  29. static matching_5_10_20(roomtype){
  30. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_MATCHING_5_10_20,"userid":GameMng._userData.userid,"matching_type":roomtype})
  31. gameSocket.Instance.send_cmd(str)
  32. }
  33. static find_matching_5_10_20(){
  34. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_FIND_MATCHING_5_10_20,"userid":GameMng._userData.userid})
  35. gameSocket.Instance.send_cmd(str)
  36. }
  37. static open_matching_5_10_20(){
  38. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_OPEN_MATCHING_5_10_20,"userid":GameMng._userData.userid})
  39. gameSocket.Instance.send_cmd(str)
  40. }
  41. static cancel_matching_5_10_20(){
  42. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_CANCEL_MATCHING_5_10_20,"userid":GameMng._userData.userid})
  43. gameSocket.Instance.send_cmd(str)
  44. }
  45. static joinRoom(roomNumber){
  46. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_JOIN_ROOM,"userid":GameMng._userData.userid,"roomid":roomNumber})
  47. gameSocket.Instance.send_cmd(str)
  48. }
  49. static ready(){
  50. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_READY,"userid":GameMng._userData.userid})
  51. gameSocket.Instance.send_cmd(str)
  52. }
  53. static kickRival(){
  54. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_KICK_ROOM,"userid":GameMng._userData.userid})
  55. gameSocket.Instance.send_cmd(str)
  56. }
  57. static quitRoom(){
  58. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_QUIT_ROOM,"userid":GameMng._userData.userid})
  59. gameSocket.Instance.send_cmd(str)
  60. }
  61. static sendPlayChess(setup:setupData){
  62. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_OWN_PLAYCHESS,"userid":GameMng._userData.userid,"src_pos":setup.src_pos,"dec_pos":setup.dec_pos,"chess_whole":setup.chess_whole,"des_who":setup.des_who,"robot_data":setup.robot_data,"is_mate":setup.is_mate})
  63. gameSocket.Instance.send_cmd(str)
  64. }
  65. static final_game(){
  66. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_FINAL_GAME,"userid":GameMng._userData.userid})
  67. gameSocket.Instance.send_cmd(str)
  68. }
  69. static renshu_game(){
  70. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_REN_SHU_GAME,"userid":GameMng._userData.userid})
  71. gameSocket.Instance.send_cmd(str)
  72. }
  73. static heqi_game(){
  74. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HE_QI_GAME,"userid":GameMng._userData.userid})
  75. gameSocket.Instance.send_cmd(str)
  76. }
  77. static qingqiu_heqi_game(){
  78. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HEQI_QINGQIU,"userid":GameMng._userData.userid})
  79. gameSocket.Instance.send_cmd(str)
  80. }
  81. static tongzhi_heqi_game(type:number){
  82. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HEQI_TONGZHI,"userid":GameMng._userData.userid,"type":type})
  83. gameSocket.Instance.send_cmd(str)
  84. }
  85. static qingqiu_huiqi_game(){
  86. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HUIQI_QINGQIU,"userid":GameMng._userData.userid})
  87. gameSocket.Instance.send_cmd(str)
  88. }
  89. static tongzhi_huiqi_game(type:number){
  90. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HUIQI_TONGZHI,"userid":GameMng._userData.userid,"type":type})
  91. gameSocket.Instance.send_cmd(str)
  92. }
  93. static ad_tongbi(type:number){
  94. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.ADS_TONG_QIAN,"userid":GameMng._userData.userid,"type":type})
  95. gameSocket.Instance.send_cmd(str)
  96. }
  97. static relink(){
  98. let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_RELINK,"userid":GameMng._userData.userid})
  99. console.log("发送一次重连请求",str)
  100. gameSocket.Instance.send_cmd(str)
  101. }
  102. static recv(json_data){
  103. console.log("接收消息",json_data)
  104. let json = JSON.parse(json_data)
  105. if(json.code!=10000){
  106. UIManager.removeLoadingLayer()
  107. UIManager.removeWaitViewLayer()
  108. UIDialog.Show(()=>{
  109. if(json.code===Constant.ERROR_CODE.ERROR_TONG_BI_BU_ZU){
  110. native_manager.showRewardVideo()
  111. }
  112. },()=>{
  113. },json.message,UIManager.Instance.TopLayer,false)
  114. }else{
  115. if(json.action!=null&&json.content!=""){
  116. console.log("json.action",json.action)
  117. ClientEvent.dispatchEvent(json.action,json.content)
  118. }else{
  119. console.error("recv json_data.data error!",json)
  120. }
  121. }
  122. }
  123. static reConnect(){
  124. gameSocket.Instance.connect(Tools.makeUrl())
  125. }
  126. }