123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import { _decorator, Component, Node } from 'cc';
- import { ClientEvent } from '../clientEvent';
- import { Constant } from '../constant';
- import UIDialog from '../Game/UIDialog';
- import { GameMng } from '../GameMng';
- import { UIManager } from '../gcommon/UIManager';
- import { native_manager } from '../native_manager';
- import { Tools } from '../Tools';
- import { setupData } from '../UserData/setupData';
- import gameSocket from './gameSocket';
- const { ccclass, property } = _decorator;
- export class msgManager {
- static login(account){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_LOGON,"userid":"","wx_openid":"","wx_name":"","wx_avatar":"","ios_openid":"","account":account,"verify_code":"1234"})
- gameSocket.Instance.send_cmd(str)
- }
- static wxlogin(nickname,wx_openid,sex,province,city,country,headimgurl){
- 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})
- gameSocket.Instance.send_cmd(str)
- }
- static createRoom(totaltime,everysteptime,firstid,roomtype,countdown,everystepaddtime){
- 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})
- gameSocket.Instance.send_cmd(str)
- }
- static createRoomByRoomType(roomtype){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_CREATE_ROOM,"userid":GameMng._userData.userid,"roomtype":roomtype})
- gameSocket.Instance.send_cmd(str)
- }
- static matching_5_10_20(roomtype){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_MATCHING_5_10_20,"userid":GameMng._userData.userid,"matching_type":roomtype})
- gameSocket.Instance.send_cmd(str)
- }
- static find_matching_5_10_20(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_FIND_MATCHING_5_10_20,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static open_matching_5_10_20(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_OPEN_MATCHING_5_10_20,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static cancel_matching_5_10_20(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_CANCEL_MATCHING_5_10_20,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static joinRoom(roomNumber){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_JOIN_ROOM,"userid":GameMng._userData.userid,"roomid":roomNumber})
- gameSocket.Instance.send_cmd(str)
- }
- static ready(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_READY,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static kickRival(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_KICK_ROOM,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static quitRoom(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_QUIT_ROOM,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static sendPlayChess(setup:setupData){
- 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})
- gameSocket.Instance.send_cmd(str)
- }
- static final_game(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_FINAL_GAME,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static renshu_game(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_REN_SHU_GAME,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static heqi_game(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HE_QI_GAME,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static qingqiu_heqi_game(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HEQI_QINGQIU,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static tongzhi_heqi_game(type:number){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HEQI_TONGZHI,"userid":GameMng._userData.userid,"type":type})
- gameSocket.Instance.send_cmd(str)
- }
- static qingqiu_huiqi_game(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HUIQI_QINGQIU,"userid":GameMng._userData.userid})
- gameSocket.Instance.send_cmd(str)
- }
- static tongzhi_huiqi_game(type:number){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_HUIQI_TONGZHI,"userid":GameMng._userData.userid,"type":type})
- gameSocket.Instance.send_cmd(str)
- }
- static ad_tongbi(type:number){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.ADS_TONG_QIAN,"userid":GameMng._userData.userid,"type":type})
- gameSocket.Instance.send_cmd(str)
- }
- static relink(){
- let str = JSON.stringify( {"action":Constant.EVENT_TYPE.MSG_RELINK,"userid":GameMng._userData.userid})
- console.log("发送一次重连请求",str)
- gameSocket.Instance.send_cmd(str)
- }
- static recv(json_data){
- console.log("接收消息",json_data)
- let json = JSON.parse(json_data)
- if(json.code!=10000){
- UIManager.removeLoadingLayer()
- UIManager.removeWaitViewLayer()
-
- UIDialog.Show(()=>{
- if(json.code===Constant.ERROR_CODE.ERROR_TONG_BI_BU_ZU){
- native_manager.showRewardVideo()
- }
- },()=>{
-
- },json.message,UIManager.Instance.TopLayer,false)
- }else{
- if(json.action!=null&&json.content!=""){
- console.log("json.action",json.action)
- ClientEvent.dispatchEvent(json.action,json.content)
- }else{
- console.error("recv json_data.data error!",json)
- }
- }
-
- }
- static reConnect(){
- gameSocket.Instance.connect(Tools.makeUrl())
- }
- }
|