public bool TryLogin(int account, int password) { if (!CheckTable(userTableName)) { return(false); } string[] items = { "Account", "Password", }; string[] selectKeys = { "UserId", }; string[] selectValues = { $"'{account}'", }; var dr = SelectWhereEqual(userTableName, items, selectKeys, selectValues); while (dr.Read()) { string drAccount = dr.GetString(dr.GetOrdinal("Account")); string drPassword = dr.GetString(dr.GetOrdinal("Password")); if (account.ToString() == drAccount && password.ToString() == drPassword) { if (!m_UserTable.HasDBRow(account)) { DBUser dbUser = new DBUser(account, password); dbUser.Load(); m_UserTable.AddDBRow(account, dbUser); } m_DBTableManager.Init(account); m_UserData = GetDBRow <DBUser>(account); //CloseSqlConnection(); return(true); } } return(false); }
private bool OnLoginClick(string accountInput, string passwordInput) { int account; int password; if (!int.TryParse(accountInput, out account)) { //Log.Error("Account must be number!"); return(false); } if (!int.TryParse(passwordInput, out password)) { //Log.Error("Password must be number!"); return(false); } if (GameEntry.Database.TryLogin(account, password)) { m_ProcedureOwner.SetData <VarInt>(Constant.ProcedureData.UserId, account); m_LoginSuccess = true; IDBTable <DBUser> dtUser = GameEntry.Database.GetDBTable <DBUser>(); DBUser drUser = dtUser.GetDBRow(account); if (drUser == null || drUser.Player == 0) { m_GetPlayerSuccess = false; } else { m_ProcedureOwner.SetData <VarInt>(Constant.ProcedureData.PlayerId, drUser.Player); m_GetPlayerSuccess = true; } return(true); } else { //Log.Error("账号密码不存在!"); return(false); } }
public bool TryRegister(int account, int password) { string[] items = { "Account", "Password", }; string[] selectKeys = { "UserId", }; string[] selectValues = { $"'{account}'", }; var dr = SelectWhereEqual(userTableName, items, selectKeys, selectValues); //账号已存在 if (dr.Read()) { return(false); } DBUser dbUser = new DBUser(account, password); dbUser.Account = account; dbUser.Password = password; dbUser.Player = 0; dbUser.Insert(); m_UserTable.AddDBRow(account, dbUser); return(true); }
private void OnClickCreateRole(string roleName) { Log.Info("create role ,name : " + roleName); if (m_ProcedureOwner != null) { //创建角色数据 string userId = m_ProcedureOwner.GetData <VarString>(Constant.ProcedureData.UserId); int playerId = GameEntry.Entity.GenerateSerialId(); DBPlayer dbPlayer = new DBPlayer(playerId, userId); dbPlayer.EntityTypeId = m_SelectRoleTypeId; dbPlayer.Name = roleName; dbPlayer.Level = 1; dbPlayer.Insert(); GameEntry.Database.AddDBRow <DBPlayer>(dbPlayer.Id, dbPlayer); DBUser dbUser = GameEntry.Database.GetDBRow <DBUser>(int.Parse(userId)); dbUser.Player = dbPlayer.Id; m_ProcedureOwner.SetData <VarInt>(Constant.ProcedureData.PlayerId, dbUser.Player); m_ProcedureOwner.SetData <VarInt>(Constant.ProcedureData.NextSceneId, (int)SceneId.MainCity); ChangeState <ProcedureChangeScene>(m_ProcedureOwner); } }
private void OnLoginClick(string account, string password) { if (GameEntry.Database.TryLogin(account, password)) { m_ProcedureOwner.SetData <VarString>(Constant.ProcedureData.UserId, account); m_LoginSuccess = true; IDBTable <DBUser> dtUser = GameEntry.Database.GetDBTable <DBUser>(); DBUser drUser = dtUser.GetDBRow(int.Parse(account)); if (drUser == null || drUser.Player == 0) { m_GetPlayerSuccess = false; } else { m_ProcedureOwner.SetData <VarInt>(Constant.ProcedureData.PlayerId, drUser.Player); m_GetPlayerSuccess = true; } } else { Log.Error("账号密码不存在!"); } }