msgManager.ts 5.8 KB

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