Skip to content

Commit

Permalink
Fix GetBanData
Browse files Browse the repository at this point in the history
  • Loading branch information
zeng-github01 authored Aug 16, 2022
1 parent 60d5467 commit 369dac7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions Database/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ private BanPlayerData BuildBanPlayerData(MySqlDataReader reader)
public BanPlayerData GetBanPlayerData(CSteamID cSteamID,EQueryType searchMode)
{
BanPlayerData playerData = null;
MySqlConnection connection = databaseConnection.CreateConnection();
try
{
MySqlConnection connection =databaseConnection.CreateConnection();

MySqlCommand command = connection.CreateCommand();
switch(searchMode)
{
Expand All @@ -103,29 +104,31 @@ public BanPlayerData GetBanPlayerData(CSteamID cSteamID,EQueryType searchMode)
command.CommandText = $"SELECT * from `{GlobalBan.Instance.Configuration.Instance.DatabaseTableName}` where `HWID` = '{PlayerInfoLib.Database.QueryById(cSteamID).HWID}'";
break;
case EQueryType.SearchByHWIDAndIP:
command.CommandText = $"SELECT * from `{GlobalBan.Instance.Configuration.Instance.DatabaseTableName}` where `IP` = '{PlayerInfoLib.Database.QueryById(cSteamID).IP}' AND `HWID` = '{PlayerInfoLib.Database.QueryById(cSteamID).HWID}'";
command.CommandText = $"SELECT * from `{GlobalBan.Instance.Configuration.Instance.DatabaseTableName}` where `IP` = '{PlayerInfoLib.Database.QueryById(cSteamID).IP}' OR `HWID` = '{PlayerInfoLib.Database.QueryById(cSteamID).HWID}'";
break;
}

connection.Open();
MySqlDataReader reader = command.ExecuteReader();
if(reader.Read())
{
playerData = BuildBanPlayerData(reader);
}
connection.Close();
}
catch (Exception ex)
{
Logger.LogException(ex);
}
finally
{
connection.Close();
}
return playerData;
}

internal void SaveToDB(BanPlayerData banPlayerData)
{
databaseConnection.ExecuteQuery(true,
$"INSERT INTO `{GlobalBan.Instance.Configuration.Instance.DatabaseTableName}` (SteamID,HWID,IP,BanOfTime,Duration,Reason,IsUnbanned,Admin,ServerID) values('{banPlayerData.CSteamID}','{banPlayerData.HWID}','{Parser.getUInt32FromIP(banPlayerData.IP)}','{DateTime.Now}','{banPlayerData.Duration}','{banPlayerData.Reason}',{banPlayerData.IsUnbanned},'{banPlayerData.AdminID}','{banPlayerData.ServerID}') ON DUPLICATE KEY UPDATE `SteamID` = VALUES(`SteamID`), `HWID` = VALUES(`HWID`), `IP` = VALUES(`IP`), `BanOfTime` = VALUES(`BanOfTime`), `Duration` = VALUES(`Duration`), `Reason` = VALUES(`Reason`), `IsUnbanned` = VALUES(`IsUnbanned`), `Admin` = VALUES(`Admin`), `ServerID` = VALUES(`ServerID`)");
$"INSERT INTO `{GlobalBan.Instance.Configuration.Instance.DatabaseTableName}` (SteamID,HWID,IP,BanOfTime,Duration,Reason,IsUnbanned,Admin,ServerID) values('{banPlayerData.CSteamID}','{banPlayerData.HWID}','{Parser.getUInt32FromIP(banPlayerData.IP)}','{banPlayerData.BanOfTime}','{banPlayerData.Duration}','{banPlayerData.Reason}',{banPlayerData.IsUnbanned},'{banPlayerData.AdminID}','{banPlayerData.ServerID}') ON DUPLICATE KEY UPDATE `SteamID` = VALUES(`SteamID`), `HWID` = VALUES(`HWID`), `IP` = VALUES(`IP`), `BanOfTime` = VALUES(`BanOfTime`), `Duration` = VALUES(`Duration`), `Reason` = VALUES(`Reason`), `IsUnbanned` = VALUES(`IsUnbanned`), `Admin` = VALUES(`Admin`), `ServerID` = VALUES(`ServerID`)");
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.1")]
[assembly: AssemblyFileVersion("1.2.0.1")]

0 comments on commit 369dac7

Please sign in to comment.