public void ChangeUserAndPwd(String user, String pwd, Action <LoginResult> completeCall) { WXProtocol.Log("修改用户名和密码"); curAction = OPERATEION.EDIT_USER_PWD; CheckUser(user, null, (b, d) => { if (b) { List <object> list = d["data"] as List <object>; if (list.Count > 0) { var dict = list[0] as Dictionary <string, object>; if (dict["uid"].ToString() == WXProtocol.uid) { b = false; } } } if (!b) { this.doneCallback = completeCall; string sql = "http://api.waixing.com:8090/client/getMb.action?sql=update games_users set name='" + user + "', pwd='" + pwd + "', newtime = GETDATE() where uid='" + WXProtocol.uid + "'&id=31"; WXProtocol.instance.GetJson(sql, (json) => { WXProtocol.userName = user; WXProtocol.userPwd = pwd; if (doneCallback != null) { doneCallback(new LoginResult() { success = true }); } }, (faileStr) => { if (doneCallback != null) { doneCallback(new LoginResult() { reason = "您当前没有网络无法连接服务器" }); } }); } else { if (doneCallback != null) { doneCallback(new LoginResult() { reason = "用户名已存在,请更换用户名重试" }); } } }); }
/// <summary> /// 登你妹的陆啊 /// </summary> /// <param name="doneCall"></param> public void Login(Action <LoginResult> doneCall, bool checkUserBefore = true) { curAction = OPERATEION.LOGIN; doneCallback = doneCall; //用本机的UID注册一个 WXProtocol.instance.GetJson("http://api.waixing.com:8090/client/getMb.action?sql=select * from games_users where uid = '" + WXProtocol.uid + "' &id=30", (json) => { if (WXProtocol.CheckSuccess(json)) { SetLoginID(json); WXProtocol.Log("UID" + WXProtocol.uid + "已注册,刷新上线时间为现在"); RefreshLogin(); } else { WXProtocol.Log("UID" + WXProtocol.uid + "未注册,新注册用户"); CreateUser(); //需要拿上次登陆的UID来登陆,除非用户切换了账号 } }, (failedReason) => { LoginResult data = new LoginResult() { success = false, reason = failedReason }; doneCall(data); }); }
/// <summary> /// 切换用户 /// </summary> /// <param name="username"></param> /// <param name="pwd"></param> /// <param name="doneCall"></param> public void SwitchUser(String username, String pwd, Action <LoginResult> doneCall, Action failedCall = null) { if (username == WXProtocol.userName) { doneCall(new LoginResult() { reason = "不能切换您当前的用户名" }); return; } this.doneCallback = doneCall; curAction = OPERATEION.SWITCH_USER; //检查用户是否存在 CheckUser(username, pwd, (b, jsonData) => { if (b) { //用户存在的话,更新UID为新的用户ID var list = jsonData["data"] as List <object>; var dic = list[0] as Dictionary <string, object>; String backUID = dic["uid"].ToString(); String uid = GetNewUID(); UpdateUserNameAndPWD(uid, backUID, (bb) => { if (bb) { SetLoginID(jsonData); //保存UID WXProtocol.uid = uid; SaveUID(uid); needSaveUID = true; //游戏逻辑,需要读取当前某条表数据再返回 GetGameData(); } else { if (doneCall != null) { doneCall(new LoginResult() { reason = "更新用户名密码失败" }); } } }); } else { if (failedCall != null) { failedCall(); } else { if (doneCall != null) { doneCall(new LoginResult() { reason = "没有这个用户或者用户名密码错误" }); } } } }); }