Example #1
0
 private void OnRegCallBack(CallBackArgs obj)
 {
     if (obj.IsError)
     {
         Debug.Log("发送消息失败");
     }
     else
     {
         RetValue ret = LitJson.JsonMapper.ToObject <RetValue>(obj.Json);
         if (ret.IsError)
         {
             Debug.Log(ret.ErrorMsg);
         }
         else
         {
             RetAccountEntity accountEntity = LitJson.JsonMapper.ToObject <RetAccountEntity>(ret.RetData.ToString());
             Global.Instance.AccountEntity = accountEntity;
             SetLastGameServer(accountEntity);
             if (isAutoLogOn)
             {
             }
             else
             {
                 string userName = regView.UserNameInput.text;
                 string pwd      = regView.PwdInput.text;
                 PlayerPrefs.SetInt(ConstDefine.PlayerPrefs_AccountID_Key, accountEntity.Id);
                 PlayerPrefs.SetString(ConstDefine.PlayerPrefs_UserName_Key, userName);
                 PlayerPrefs.SetString(ConstDefine.PlayerPrefs_Pwd_Key, pwd);
             }
             regView.CloseAndOpenNextView(UIViewType.GameServerEnter);
             Debug.Log("注册成功" + ret.RetData);
         }
     }
 }
    /// <summary>
    /// 当注册完毕后的回调
    /// </summary>
    /// <param name="obj"></param>
    private void OnRegCallback(NetWorkHttp.CallBackArgs obj)
    {
        if (obj.HasError)
        {
            LogError(obj.ErrorMsg);
        }
        else
        {
            ReturnValue      returnValue      = LitJson.JsonMapper.ToObject <ReturnValue>(obj.Value);
            RetAccountEntity retAccountEntity = LitJson.JsonMapper.ToObject <RetAccountEntity>(returnValue.Value.ToString());
            GlobalInit.Instance.m_currentAccountEntity = retAccountEntity;
            Log("注册成功" + retAccountEntity.LastServerName);
            Stat.Reg(retAccountEntity.Id, resiterView.txt_AccountInpField.text);

            //本地缓存玩家的帐号和密码
            PlayerPrefs.SetInt(ConstDefine.LogOn_AccountID, retAccountEntity.Id);

            PlayerPrefs.SetString(ConstDefine.LogOn_AccountID, resiterView.txt_AccountInpField.text);

            PlayerPrefs.SetString(ConstDefine.LogOn_AccountID, resiterView.txt_PwdInpField.text);


            WindowUIMgr.Instance.CloseWindow(WindowUIType.Reg);

            GameServerCtrl.Instance.OpenView(WindowUIType.GameServerEnter);
        }
    }
        // POST: api/Account
        public RetValue Post([FromBody] string value)
        {
            RetValue ret      = new RetValue();
            JsonData jsonData = JsonMapper.ToObject(value);
            //1.验证时间戳
            //2.验证签名
            int    type     = Convert.ToInt32(jsonData["Type"].ToString());
            string userName = jsonData["UserName"].ToString();
            string pwd      = jsonData["Pwd"].ToString();
            //客户端时间戳
            long t = Convert.ToInt64(jsonData["t"].ToString());
            //签名
            string sign = jsonData["sign"].ToString();
            //客户端驱动id
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["DeviceModel"].ToString();
            long   st = MFDSAUtil.GetTimestamp();

            //第一重检验
            //if (st - t > 300)
            //{
            //    ret.IsError = true;
            //    ret.ErrorMsg = "请求失败";
            //    return ret;
            //}
            //第二重检验
            if (string.Format("{0},{1}", deviceIdentifier, t) != sign)
            {
                ret.IsError  = true;
                ret.ErrorMsg = "请求失败";
                return(ret);
            }

            if (type == 0)
            {
                string ChannelId         = JsonMapper.ToObject(value)["Channelld"].ToString();
                MFReturnValue <int> ret2 = AccountCacheModel.Instance.Register(userName, pwd, ChannelId, deviceIdentifier, deviceModel);
                ret.IsError  = ret2.HasError;
                ret.ErrorMsg = ret2.Message;
                AccountEntity entity = AccountCacheModel.Instance.GetEntity(ret2.Value);
                ret.RetData = JsonMapper.ToJson(new RetAccountEntity(entity));
            }
            else
            {
                AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel);
                if (entity != null)
                {
                    ret.IsError = false;
                    ret.RetData = entity.Id;
                }
                else
                {
                    ret.IsError  = true;
                    ret.ErrorMsg = "账号或者密码错误";
                }
                RetAccountEntity retEnitity = new RetAccountEntity(entity);
                ret.RetData = JsonMapper.ToJson(retEnitity);
            }
            return(ret);
        }
Example #4
0
    private void SetLastGameServer(RetAccountEntity accountEntity)
    {
        RetGameserverEntity serverEntity = new RetGameserverEntity();

        serverEntity.Id   = accountEntity.LastServerId;
        serverEntity.Name = accountEntity.LastServerName;
        serverEntity.Ip   = accountEntity.LastServerIP;
        serverEntity.Port = accountEntity.LastServerPort;
        Global.Instance.GameServerEntiry = serverEntity;
    }
    /// <summary>
    /// 更新进入的最后的服务器
    /// </summary>
    /// <param name="accountEntity"></param>
    /// <param name="serverEntity"></param>
    private void UpdatelastServer(RetAccountEntity accountEntity, RetGameserverEntity serverEntity)
    {
        Dictionary <string, object> msg = new Dictionary <string, object>();

        msg.Add("Type", "2");
        msg.Add("UserID", accountEntity.Id);
        msg.Add("LastServerId", serverEntity.Id);
        msg.Add("LastServerName", serverEntity.Name);
        NetWorkHttp.Instance.SendData(Global.Instance.WeAccountUrl + "api/gameserver", UpdateLastServerCallBack, isPost: true, dic: msg);
    }
    /// <summary>
    /// 设置已经选择的服务器信息
    /// </summary>
    /// <param name="entity"></param>
    private void SetCurrentSelectGameServer(RetAccountEntity entity)
    {
        RetGameServerEntity serverEntity = new RetGameServerEntity
        {
            Id   = entity.Id,
            Name = entity.LastServerName,
            Ip   = entity.LastServerIP,
            Port = entity.LastServerPort
        };

        GlobalInit.Instance.m_currentSelectGameServer = serverEntity;
    }
Example #7
0
    /// <summary>
    /// 把最后登录的服务器信息存入数据库
    /// </summary>
    private void UpdateLastLogOnServer(RetAccountEntity retAccount, RetGameServerEntity retGameServer)
    {
        Dictionary <string, object> dic = new Dictionary <string, object>();

        {
            dic["Type"]           = 2;
            dic["userId"]         = retAccount.Id;
            dic["lastServerId"]   = retGameServer.Id;
            dic["lastServerName"] = retGameServer.Name;
        }

        NetWorkHttp.Instance.SendData(GlobalInit.WebAccountUrl + "api/GameServer", true, dic, OnUpdateLastLogServerCallback);
    }
Example #8
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="channelId"></param>
        /// <param name="access_token"></param>
        /// <param name="openid"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private string GetUserInfo(short channelId, string access_token, string openid, object parameter)
        {
            string url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}",
                                       access_token, openid);

            string   content = NetWorkHttp.Instance.HttpGet(url);
            JsonData data    = JsonMapper.ToObject(content);

            string nickname   = data["nickname"].ToString(); //昵称
            string sex        = data["sex"].ToString();
            string language   = data["language"].ToString();
            string city       = data["city"].ToString();
            string province   = data["province"].ToString();
            string country    = data["country"].ToString();
            string headimgurl = data["headimgurl"].ToString(); //头像图片
            string privilege  = data["privilege"].ToString();
            string unionid    = data["unionid"].ToString();    //微信返回的唯一id

            string[] arr = parameter as string[];

            AccountEntity entity = AccountCacheModel.Instance.LogOn(unionid, unionid, arr[0], arr[1]);

            if (entity != null)
            {
                //如果账户存在 返回账户信息
                RetAccountEntity retAccountEntity = new RetAccountEntity(entity);
                retAccountEntity.SDKNickName = nickname;
                return(JsonMapper.ToJson(retAccountEntity));
            }
            else
            {
                //账户不存在 进行注册
                MFReturnValue <int> retValue = AccountCacheModel.Instance.Register(unionid, unionid, channelId, arr[0], arr[1]);

                int           userID        = retValue.Value;
                AccountEntity accountentity = AccountCacheModel.Instance.GetEntity(userID);

                RetAccountEntity retAccountEntity = new RetAccountEntity(accountentity);
                retAccountEntity.SDKNickName = nickname;
                return(JsonMapper.ToJson(retAccountEntity));
            }
        }
    /// <summary>
    /// 点击登录之后服务器对客户端的回调处理
    /// </summary>
    /// <param name="obj"></param>
    private void OnLogOnCallback(NetWorkHttp.CallBackArgs obj)
    {
        if (obj.HasError)
        {
            Debug.Log(obj.ErrorMsg);
        }
        else
        {
            ReturnValue @return = LitJson.JsonMapper.ToObject <ReturnValue>(obj.Value);
            if (@return.HasError)
            {
                ShowMessage("温馨提示", "你输入的帐号不存在");
                Debug.Log(@return.ErroMsg);
            }
            else
            {
                RetAccountEntity retAccountEntity = LitJson.JsonMapper.ToObject <RetAccountEntity>(@return.Value.ToString());

                GlobalInit.Instance.m_currentAccountEntity = retAccountEntity;

                SetCurrentSelectGameServer(retAccountEntity);

                string userName = "";
                if (m_isAutoLogOn)
                {
                    userName = PlayerPrefs.GetString(ConstDefine.LogOn_AccountUserName);
                    Stat.LogOn(PlayerPrefs.GetInt(ConstDefine.LogOn_AccountID), PlayerPrefs.GetString(ConstDefine.LogOn_AccountUserName));
                }
                else
                {
                    //保存一下帐号密码在本地
                    PlayerPrefs.SetInt(ConstDefine.LogOn_AccountID, retAccountEntity.Id);
                    PlayerPrefs.SetString(ConstDefine.LogOn_AccountUserName, logOnView.txt_AccountInpField.text);
                    PlayerPrefs.SetString(ConstDefine.LogOn_AccountPwd, logOnView.txt_PwdInpField.text);
                    Stat.LogOn(retAccountEntity.Id, logOnView.txt_AccountInpField.text);
                }

                GameServerCtrl.Instance.OpenView(WindowUIType.GameServerEnter);
                GameServerCtrl.Instance.GameServerEnterView.SetUI(GlobalInit.Instance.m_currentSelectGameServer);
            }
        }
    }
Example #10
0
        // POST: api/Account
        public RetValue Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳
            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }

            ////  2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }


            int    type     = Convert.ToInt32(jsonData["Type"].ToString());
            string userName = jsonData["UserName"].ToString();
            string pwd      = jsonData["Pwd"].ToString();

            if (type == 0)
            {
                string channelId = jsonData["ChannelId"].ToString();
                ret.Type = "0";
                //注册
                MFReturnValue <int> retValue = AccountCacheModel.Instance.Register(userName, pwd, channelId, deviceIdentifier, deviceModel);
                ret.HasError = retValue.HasError;
                ret.ErrorMsg = retValue.Message;

                int userID = retValue.Value;

                AccountEntity entity = AccountCacheModel.Instance.GetEntity(userID);

                RetAccountEntity retAccountEntity = new RetAccountEntity(entity);
                ret.Value = JsonMapper.ToJson(retAccountEntity);
            }
            else
            {
                ret.Type = "1";
                //登录
                AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel);
                if (entity != null)
                {
                    RetAccountEntity rect = new RetAccountEntity(entity);
                    ret.objValue = rect;
                }
                else
                {
                    // 登录失败
                    ret.HasError = true;
                    ret.ErrorMsg = "帐户取出来为空";
                }
            }

            return(ret);
        }