Пример #1
0
    /// <summary>
    /// 登录大厅服务器
    /// </summary>
    /// <param name="req"></param>
    public void LoginToServer(LoginSR.SendLogin req, CallBack call)
    {
        LoginModel.Inst.LoginData = req;
        //连接服务器
        ConnectServer(() =>
        {
            //服务器连接成功后登录服务器
            NetProcess.SendRequest <LoginSR.SendLogin>(req, ProtoIdMap.CMD_Login, (msg) =>
            {
                LoginSR.LoginBack data = msg.Read <LoginSR.LoginBack>();
                if (data.code == 1)
                {
                    if (Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.OSXEditor)
                    {
                        SixqinSDKManager.Inst.SendMsg(SixqinSDKManager.GET_INSTALL_DATA);//发送扫二维码添加的好友
                    }
                    PlayerModel.Inst.Token    = data.data.userInfo.token;
                    PlayerModel.Inst.UserInfo = data.data.userInfo;
                    if (Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.OSXEditor)
                    {
                        //SixqinSDKManager.Inst.InitJPUSH(PlayerModel.Inst.UserInfo.userId);//初始化jpush
                    }
                    ////公众号
                    //PlayerModel.Inst.PublicSign = data.data.publicSign;
                    //广播
                    MainViewModel.Inst.BroadMessage.Clear();

                    Global.Inst.GetController <MainController>().SendGetNotice();
                    if (!string.IsNullOrEmpty(data.roomId))//在房间中
                    {
                        Global.Inst.GetController <XXGoldFlowerGameController>().SendJoinRoomReq(data.roomId);
                    }
                    else
                    {
                        if (call != null)
                        {
                            call();
                        }
                    }
                }
                else if (data.code == 12)
                {
                    PlayerModel.Inst.Token    = data.data.userInfo.token;
                    PlayerModel.Inst.UserInfo = data.data.userInfo;
                    if (Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.OSXEditor)
                    {
                        SixqinSDKManager.Inst.InitJPUSH(PlayerModel.Inst.UserInfo.userId);//初始化jpush
                    }
                    Global.Inst.GetController <GamePatternController>().ConnectGameServer(data.data.gameServer.ip, int.Parse(data.data.gameServer.port));
                }
                else
                {
                    GameUtils.ShowErrorTips(data.code);
                }
            });
        });
    }
Пример #2
0
    /// <summary>
    /// 登录到大厅
    /// </summary>
    public void LoginToMainServer(string ip, int port)
    {
        LoginSR.SendLogin req = new LoginSR.SendLogin();
        req.token = PlayerModel.Inst.Token;
        if (string.IsNullOrEmpty(req.token))
        {
            return;
        }
        NetProcess.SendRequest <LoginSR.SendLogin>(req, ProtoIdMap.CMD_Login, (msg) =>
        {
            LoginSR.LoginBack data = msg.Read <LoginSR.LoginBack>();
            if (data.code == 1)
            {
                Scene now = SceneManager.GetActiveScene();
                if (now.name != "HALL" && now.name != "Start")
                {
                    SceneManager.LoadScene("HALL");
                    GC.Collect();
                    Resources.UnloadUnusedAssets();
                }

                MainViewModel.Inst.mNowIp   = ip;
                MainViewModel.Inst.mNowPort = port;

                PlayerModel.Inst.Token    = data.data.userInfo.token;
                PlayerModel.Inst.UserInfo = data.data.userInfo;
                SendGetNotice();
                OpenWindow();

                List <string> names = new List <string>();
                names.Add(typeof(MainView).Name);
                BaseView.CloseAllViewBut(names);
            }
            else
            {
                if (data.code == 2)
                {
                    Global.Inst.GetController <CommonTipsController>().ShowTips("您的登录已过期,请重新登录", "确定", true, () =>
                    {
                        Global.Inst.GetController <LoginController>().LoginOut();
                    }, null, null, "登录异常");
                }
                else
                {
                    GameUtils.ShowErrorTips(data.code);
                }
            }
        });
    }