/// <summary> /// DB返回查询登陆结果 /// </summary> private static void OnSmartQueryLoginRet(NetSessionBase session, Google.Protobuf.IMessage message, object[] args) { Protos.LS2GC_AskLoginRet gcLoginRet = (Protos.LS2GC_AskLoginRet)args[0]; uint sid = ( uint )args[1]; LoginContext context = ( LoginContext )args[2]; Protos.DB2LS_QueryLoginRet queryLoginRet = (Protos.DB2LS_QueryLoginRet)message; //如果查询成功 if (queryLoginRet.Result == Protos.Global.Types.ECommon.Success) { gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.Success; //写入redis缓存 if (LS.instance.redisWrapper.IsConnected) { LS.instance.redisWrapper.HashSet("unames", context.id, string.Empty); } context.ukey = queryLoginRet.Ukey; context.channel = queryLoginRet.Channel; context.browser = queryLoginRet.Browser; context.platform = queryLoginRet.Platform; context.unionID = queryLoginRet.UnionID; context.nickname = queryLoginRet.Nickname; context.avatar = queryLoginRet.Avatar; context.gender = ( byte )queryLoginRet.Gender; context.money = queryLoginRet.Money; context.diamoned = queryLoginRet.Diamoned; context.rank = queryLoginRet.Rank; context.exp = queryLoginRet.Exp; context.champions = queryLoginRet.Champions; context.actorID = queryLoginRet.ActorID; HandleLoginSuccess(gcLoginRet, sid, context); } else { Logger.Error($"smart register occurs an error:{queryLoginRet.Result}"); gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.Failed; //通知客户端登陆失败 LS.instance.netSessionMgr.Send(sid, gcLoginRet); LS.instance.netSessionMgr.CloseSession(sid, "login failed"); } }
public ErrorCode OnLs2DbQueryLogin(NetSessionBase session, Google.Protobuf.IMessage message) { Protos.LS2DB_QueryLogin queryLogin = (Protos.LS2DB_QueryLogin)message; Protos.DB2LS_QueryLoginRet queryLoginRet = ProtoCreator.R_LS2DB_QueryLogin(queryLogin.Opts.Pid); ErrorCode errorCode = DB.instance.accountDB.SqlExecQuery( $"select * from account_user where uname=\'{queryLogin.Name}\'", dataReader => { if (!dataReader.HasRows) { return(ErrorCode.InvalidUname); } dataReader.Read(); queryLoginRet.Ukey = dataReader.GetUInt32("id"); queryLoginRet.Channel = (Protos.Global.Types.Channel)dataReader.GetByte("channel"); queryLoginRet.Browser = (Protos.Global.Types.Browser)dataReader.GetByte("browser"); queryLoginRet.Platform = (Protos.Global.Types.Platform)dataReader.GetByte("platform"); queryLoginRet.UnionID = dataReader.GetString("unionID"); queryLoginRet.Nickname = dataReader.GetString("nickname"); queryLoginRet.Avatar = dataReader.GetString("avatar"); queryLoginRet.Gender = dataReader.GetByte("gender"); queryLoginRet.Money = dataReader.GetInt32("money"); queryLoginRet.Diamoned = dataReader.GetInt32("diamoned"); queryLoginRet.Rank = dataReader.GetInt32("ranking"); queryLoginRet.Exp = dataReader.GetUInt32("exp"); queryLoginRet.Champions = dataReader.GetString("champions"); queryLoginRet.ActorID = dataReader.GetInt32("actorID"); ErrorCode QueryError = ErrorCode.Success; if (queryLogin.VertPwd) { if (dataReader.GetString("pwd") != queryLogin.Pwd) { QueryError = ErrorCode.InvalidPwd; } } return(QueryError); }); if (errorCode == ErrorCode.Success) { //成功则更新记录 errorCode = DB.instance.accountDB.SqlExecNonQuery( $"update account_user SET channel={( byte )queryLogin.Channel},browser={( byte )queryLogin.Browser},platform={( byte )queryLogin.Platform}," + $"unionID=\'{queryLogin.UnionID}\',nickname=\'{queryLogin.Nickname}\',avatar=\'{queryLogin.Avatar}\',gender={( byte )queryLogin.Gender}," + $"last_login_time={queryLogin.Time},last_login_ip=\'{queryLogin.Ip}\'" + $" where uname=\'{queryLogin.Name}\'", out _, out uint _); } else { //自动注册 errorCode = DB.instance.accountDB.SqlExecNonQuery( $"insert account_user( uname,channel,browser,platform,unionID,nickname,avatar,gender,money,diamoned,ranking,last_login_time,last_login_ip ) values" + $"(\'{queryLogin.Name}\',{( byte )queryLogin.Channel},{( byte )queryLogin.Browser},{( byte )queryLogin.Platform}," + $"\'{queryLogin.UnionID}\',\'{queryLogin.Nickname}\',\'{queryLogin.Avatar}\',\'{( byte )queryLogin.Gender}\'," + $"{queryLogin.Money},{queryLogin.Diamoned},{queryLogin.Rank}," + $"{queryLogin.Time},\'{queryLogin.Ip}\');", out _, out uint id); queryLoginRet.Ukey = id; queryLoginRet.Channel = queryLogin.Channel; queryLoginRet.Browser = queryLogin.Browser; queryLoginRet.Platform = queryLogin.Platform; queryLoginRet.UnionID = queryLogin.UnionID; queryLoginRet.Nickname = queryLogin.Nickname; queryLoginRet.Avatar = queryLogin.Avatar; queryLoginRet.Gender = queryLogin.Gender; queryLoginRet.Money = queryLogin.Money; queryLoginRet.Diamoned = queryLogin.Diamoned; queryLoginRet.Rank = queryLogin.Rank; queryLoginRet.Exp = queryLogin.Exp; queryLoginRet.Champions = queryLogin.Champions; } switch (errorCode) { case ErrorCode.Success: queryLoginRet.Result = Protos.Global.Types.ECommon.Success; break; default: queryLoginRet.Result = Protos.Global.Types.ECommon.Failed; break; } session.Send(queryLoginRet); return(ErrorCode.Success); }