コード例 #1
0
    /// <summary>
    /// 登录成功后返回消息
    /// </summary>
    /// <param name="data"></param>
    /// <param name="error"></param>
    private void OnLoginRet(RetLoginMsg data, RetErrorMsg error)
    {
        if (error != null || data == null)
        {
            string dec = string.Format("{0}\n(错误码:{1})", error.ErrorReason, error.RetCode);
            UIManager.Instance.ShowTips(dec);
            return;
        }

        bool res = HttpClient.SetSession(data.SessionKey, data.Id);

        if (res)
        {
            UIManager.Instance.ShowTips("登录成功");
            UIManager.Instance.CloseWindow("UILoginWindow");

            OnLoginSuccess(data);
        }
        else
        {
            UIManager.Instance.ShowTips("session结构不对");
        }
    }
コード例 #2
0
    private static IEnumerator Send(WWWForm form, EnumHTTPHead head)
    {
        string url = "http://" + ip + ":" + port + "/" + GetHeadString(head);
        WWW    www = new WWW(url, form.data, cookies);

        //Debug.Log("request http url " + url + " cmdID, " + _cmdFormDic[form]);
        yield return(www);

        int cmdID = _cmdFormDic[form];

        _cmdFormDic.Remove(form);
        if (www.error != null)
        {
            Debug.Log("serch fail...");
        }
        else if (www.isDone)
        {
            if (www.bytes.Length == 0)
            {
                HttpEvent evt = new HttpEvent(cmdID.ToString());
                _dispatcher.DispatchEventInstance(evt);
                yield break;
            }
            ByteArray receiveBytes = new ByteArray();
            receiveBytes.WriteBytes(www.bytes);

            ReceivePackage pack = CmdUtil.ParseCmd(receiveBytes);
            if (pack.CmdID == (int)MsgType.ErrorMsg)
            {
                RetErrorMsg errorMsg = ProtoBuf.Serializer.Deserialize <RetErrorMsg>(pack.BodyStream);
                if (errorMsg.RetCode == 0)
                {
                    Debug.Log("response http url success" + url);
                    HttpEvent evt = new HttpEvent(cmdID.ToString());
                    _dispatcher.DispatchEventInstance(evt);
                }
                else
                {
                    if (LoginServerErrorCode.ErrorCodeName == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("用户名最多为4个汉字或8个英文字符");
                    }
                    else if (LoginServerErrorCode.ErrorCodeAuthErr == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("验证码错误,还可以输入" + errorMsg.Params + "次");
                    }
                    else if (LoginServerErrorCode.ErrorCodeDb == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("设置密码错误");
                    }
                    else if (LoginServerErrorCode.ErrorCodePass == errorMsg.RetCode)
                    {
                        if (cmdID == (int)MsgType.CheckOldPassword)
                        {
                            PopManager.ShowSimpleItem("密码错误");
                        }
                        else
                        {
                            PopManager.ShowSimpleItem("账号或密码错误");
                        }
                    }
                    else if (LoginServerErrorCode.ErrorCodeParam == errorMsg.RetCode)
                    {
                        if (cmdID == (int)MsgType.ChangePasswd || cmdID == (int)MsgType.SetPasswd || cmdID == (int)MsgType.CheckOldPassword)
                        {
                            PopManager.ShowSimpleItem("密码复杂度不够");
                        }
                        else if (cmdID == (int)MsgType.AuthCode)
                        {
                            PopManager.ShowSimpleItem("获取验证码过于频繁");
                            HttpEvent evt = new HttpEvent(MsgType.ErrorMsg.ToString());
                            _dispatcher.DispatchEventInstance(evt);
                        }
                        else
                        {
                            PopManager.ShowSimpleItem("参数错误");
                        }
                    }
                    else if (LoginServerErrorCode.ErrorCodeIsBind == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("手机号已被绑定");
                    }
                    else if (LoginServerErrorCode.ErrorCodeMsgErr == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("短信服务器出错");
                    }
                    else if (LoginServerErrorCode.ErrorCodeTelErr == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("手机号错误");
                    }
                    else if (LoginServerErrorCode.ErrorCodeMaxMsg == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("今天短信次数已用完");
                    }
                    else if (LoginServerErrorCode.ErrorCodeMaxErr == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("密码错误已超过最大限制");
                    }
                    else if (LoginServerErrorCode.ErrorCodeExist == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("用户名已存在");
                    }
                    else if (LoginServerErrorCode.ErrorCodeUnBind == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("未绑定手机");
                    }
                    else if (LoginServerErrorCode.ErrorCodeSetAccountTm == errorMsg.RetCode)
                    {
                        ulong leftDays = errorMsg.Params / (24 * 60 * 60);
                        if (leftDays >= 1)
                        {
                            PopManager.ShowSimpleItem("还需 " + (uint)leftDays + "天才可以修改用户名");
                        }
                        else
                        {
                            ulong leftHours = errorMsg.Params / (60 * 60);
                            if (leftHours >= 1)
                            {
                                PopManager.ShowSimpleItem("还需 " + (uint)leftHours + "小时才可以修改用户名");
                            }
                            else
                            {
                                PopManager.ShowSimpleItem("还需 " + (uint)(errorMsg.Params / 60) + "分钟才可以修改用户名");
                            }
                        }
                    }
                    else if (LoginServerErrorCode.ErrorCodeSignReward == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("签到奖励领取失败");
                    }
                    else if (LoginServerErrorCode.ErrorCodeSignIned == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("已签到");
                    }
                    else if (LoginServerErrorCode.ErrorCodeRoom == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("未找到房间");
                    }
                    else if (LoginServerErrorCode.ErrorCodeIsFull == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("目标房间已满");
                    }
                    else if (LoginServerErrorCode.ErrorCodeDb == errorMsg.RetCode)
                    {
                        PopManager.ShowSimpleItem("数据库错误");
                    }

                    Log("http cmd error code:" + errorMsg.RetCode + " para:" + errorMsg.Params);
                }
            }
            else
            {
                Log("response http url success " + url + " CmdID:" + (MsgType)pack.CmdID);
                HttpEvent evt = new HttpEvent(pack.CmdID.ToString(), pack.BodyStream);
                _dispatcher.DispatchEventInstance(evt);
            }
        }
    }