From 9b927f80937f9f7806f7c67e4e28c5cf55461ea6 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 18 Apr 2018 18:03:39 -0400 Subject: [PATCH] Core/Accounts: prevent existing account ban from being updated --- Source/Framework/Constants/Language.cs | 3 ++- Source/Framework/Constants/SharedConst.cs | 3 ++- Source/Game/Accounts/AccountManager.cs | 9 +++++++++ Source/Game/Chat/Commands/BanCommands.cs | 5 +++-- Source/Game/Server/WorldManager.cs | 12 ++++++++++-- sql/updates/world/master/2018_04_18_00_world.sql | 2 ++ 6 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 sql/updates/world/master/2018_04_18_00_world.sql diff --git a/Source/Framework/Constants/Language.cs b/Source/Framework/Constants/Language.cs index 8fd0d250f..12d779ec6 100644 --- a/Source/Framework/Constants/Language.cs +++ b/Source/Framework/Constants/Language.cs @@ -945,7 +945,8 @@ namespace Framework.Constants AccountBnetUnlinked = 1188, AccountBnetNotLinked = 1189, DisallowTicketsConfig = 1190, - // Room For More Level 3 1191-1198 Not Used + BanExists = 1191, + // Room For More Level 3 1192-1198 Not Used // Debug Commands DebugAreatriggerLeft = 1999, diff --git a/Source/Framework/Constants/SharedConst.cs b/Source/Framework/Constants/SharedConst.cs index fb45a79ab..4b144b3a8 100644 --- a/Source/Framework/Constants/SharedConst.cs +++ b/Source/Framework/Constants/SharedConst.cs @@ -957,7 +957,8 @@ namespace Framework.Constants { Success, SyntaxError, - Notfound + Notfound, + Exists } public enum WorldCfg diff --git a/Source/Game/Accounts/AccountManager.cs b/Source/Game/Accounts/AccountManager.cs index 8de476430..b0836e187 100644 --- a/Source/Game/Accounts/AccountManager.cs +++ b/Source/Game/Accounts/AccountManager.cs @@ -331,6 +331,15 @@ namespace Game return sha.ComputeHash(Encoding.UTF8.GetBytes(name + ":" + password)).ToHexString(); } + public bool IsBannedAccount(string name) + { + PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BANNED_BY_USERNAME); + stmt.AddValue(0, name); + SQLResult result = DB.Login.Query(stmt); + + return !result.IsEmpty(); + } + public bool IsPlayerAccount(AccountTypes gmlevel) { return gmlevel == AccountTypes.Player; diff --git a/Source/Game/Chat/Commands/BanCommands.cs b/Source/Game/Chat/Commands/BanCommands.cs index c717a96f3..dc3b98e2a 100644 --- a/Source/Game/Chat/Commands/BanCommands.cs +++ b/Source/Game/Chat/Commands/BanCommands.cs @@ -85,7 +85,6 @@ namespace Game.Chat.Commands case BanReturn.Notfound: { handler.SendSysMessage(CypherStrings.BanNotfound, "character", name); - return false; } default: @@ -174,8 +173,10 @@ namespace Game.Chat.Commands handler.SendSysMessage(CypherStrings.BanNotfound, "ip", nameOrIP); break; } - return false; + case BanReturn.Exists: + handler.SendSysMessage(CypherStrings.BanExists); + break; } return true; diff --git a/Source/Game/Server/WorldManager.cs b/Source/Game/Server/WorldManager.cs index 40a00512e..95d6ba0ae 100644 --- a/Source/Game/Server/WorldManager.cs +++ b/Source/Game/Server/WorldManager.cs @@ -1459,6 +1459,10 @@ namespace Game /// Ban an account or ban an IP address, duration is in seconds if positive, otherwise permban public BanReturn BanAccount(BanMode mode, string nameOrIP, uint duration_secs, string reason, string author) { + // Prevent banning an already banned account + if (mode == BanMode.Account && Global.AccountMgr.IsBannedAccount(nameOrIP)) + return BanReturn.Exists; + SQLResult resultAccounts; PreparedStatement stmt = null; @@ -1589,17 +1593,21 @@ namespace Game else guid = pBanned.GetGUID(); + //Use transaction in order to ensure the order of the queries + SQLTransaction trans = new SQLTransaction(); + // make sure there is only one active ban PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHARACTER_BAN); stmt.AddValue(0, guid.GetCounter()); - DB.Characters.Execute(stmt); + trans.Append(stmt); stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHARACTER_BAN); stmt.AddValue(0, guid.GetCounter()); stmt.AddValue(1, duration_secs); stmt.AddValue(2, author); stmt.AddValue(3, reason); - DB.Characters.Execute(stmt); + trans.Append(stmt); + DB.Characters.CommitTransaction(trans); if (pBanned) pBanned.GetSession().KickPlayer(); diff --git a/sql/updates/world/master/2018_04_18_00_world.sql b/sql/updates/world/master/2018_04_18_00_world.sql new file mode 100644 index 000000000..a2d5b686b --- /dev/null +++ b/sql/updates/world/master/2018_04_18_00_world.sql @@ -0,0 +1,2 @@ +DELETE FROM `trinity_string` WHERE `entry`=1191; +INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES (1191, 'Ban exists');