/// <summary> /// 注册 /// </summary> /// <param name="conn"></param> /// <param name="args"></param> public void db_register_account(MySqlConnection conn, CustomArgs args) { HttpListenerResponse response = args.GetParam("response") as HttpListenerResponse; string account = args.GetParam("account") as string; string password = args.GetParam("password") as string; DBStoredProcedCmd cmd = new DBStoredProcedCmd("PRO_REGISTER_ACCOUNT", conn); cmd.AddParamVChar("account", account, account.Length); cmd.AddParamVChar("password", password, password.Length); string md5 = LibServer.Utility.Security.MD5(account + password + DateTime.Now.ToString()); cmd.AddParamVChar("token", md5, md5.Length); cmd.AddOutParamInt("errcode"); cmd.AddOutParamText("errmsg", LOGIN_DEFINE.VAR_CHAR_LENGHT_255); int bsuc = cmd.Execute(); if (bsuc == 0) { RES_Common res = new RES_Common(); res.errcode = (int)cmd.GetParam("errcode").Value; res.errmsg = cmd.GetParam("errmsg").Value as string; send(JsonConvert.SerializeObject(res), response); return; // 注册成功; } else { throw new Exception("执行存储过程 PRO_REGISTER_ACCOUNT 失败!"); } }
/// <summary> /// /// </summary> /// <param name="conn"></param> /// <param name="args"></param> public void db_login_account(MySqlConnection conn, CustomArgs args) { HttpListenerResponse response = args.GetParam("response") as HttpListenerResponse; string account = args.GetParam("account") as string; string password = args.GetParam("password") as string; if (response == null) { return; } DBStoredProcedCmd cmd = new DBStoredProcedCmd("PRO_LOGIN_ACCOUNT", conn); cmd.AddParamVChar("account", account, account.Length); cmd.AddParamVChar("password", password, password.Length); string md5 = LibServer.Utility.Security.MD5(account + password + DateTime.Now.ToString()); cmd.AddParamVChar("token", md5, md5.Length); cmd.AddOutParamInt("errcode"); cmd.AddOutParamText("errmsg", LOGIN_DEFINE.VAR_CHAR_LENGHT_255); int bsuc = cmd.Execute(); if (bsuc == 0) { int nErrCode = (int)cmd.GetParam("errcode").Value; string err_string = cmd.GetParam("errmsg").Value as string; if (nErrCode != 0) { RES_Common res = new RES_Common(); res.errcode = nErrCode; res.errmsg = err_string; send(JsonConvert.SerializeObject(res), response); } else { // 账号密码校验成功, 返回登录token RES_LoginSuc res = new RES_LoginSuc(); res.errcode = 0; res.errmsg = ""; res.token = cmd.GetValue(0, "token") as string;; res.tokenstamp = (System.DateTime)cmd.GetValue(0, "tokenstamp"); send(JsonConvert.SerializeObject(res), response); } } else { throw new Exception("执行存储过程 PRO_LOGIN_ACCOUNT 失败!"); } }
public void OnDBTask(MySqlConnection conn, CustomArgs args) { string token = args.GetParam("token") as string; ClientSession session = args.GetParam("session") as ClientSession; DBBase.DBStoredProcedCmd cmd = new DBBase.DBStoredProcedCmd("PRO_CHECK_LOGIN", conn); cmd.AddParamVChar("token", token, token.Length); int bSuc = cmd.Execute(); if (bSuc == 0) { string account = cmd.GetValue(0, "account") as string; int nGold = (int)cmd.GetValue(0, "gold"); ByteBuffer buffer = new ByteBuffer(); buffer.WriteString(account); buffer.WriteInt(nGold); UserUtil.Add(session.uid, session); SocketUtil.SendMessage(session, Protocal.Login, buffer); return; } }