generated from K4ryuu/Project_Template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
201 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Text.Json; | ||
|
||
namespace KitsuneSteamRestrict | ||
{ | ||
public class BypassConfig | ||
{ | ||
public ulong SteamID { get; set; } | ||
public bool BypassMinimumCS2Level { get; set; } = false; | ||
public bool BypassMinimumHours { get; set; } = false; | ||
public bool BypassMinimumLevel { get; set; } = false; | ||
public bool BypassMinimumSteamAccountAge { get; set; } = false; | ||
public bool BypassPrivateProfile { get; set; } = false; | ||
public bool BypassTradeBanned { get; set; } = false; | ||
public bool BypassVACBanned { get; set; } = false; | ||
public bool BypassSteamGroupCheck { get; set; } = false; | ||
public bool BypassGameBanned { get; set; } = false; | ||
} | ||
|
||
public class BypassConfigService | ||
{ | ||
private readonly string _configFilePath; | ||
|
||
public BypassConfigService(string configFilePath) | ||
{ | ||
_configFilePath = configFilePath; | ||
} | ||
|
||
public BypassConfig LoadConfig() | ||
{ | ||
if (File.Exists(_configFilePath)) | ||
{ | ||
string json = File.ReadAllText(_configFilePath); | ||
return JsonSerializer.Deserialize<BypassConfig>(json)!; | ||
} | ||
else | ||
{ | ||
BypassConfig defaultConfig = new BypassConfig | ||
{ | ||
SteamID = 76561198345583467, | ||
BypassMinimumCS2Level = true, | ||
BypassMinimumHours = false, | ||
BypassMinimumLevel = true, | ||
BypassMinimumSteamAccountAge = false, | ||
BypassPrivateProfile = true, | ||
BypassTradeBanned = false, | ||
BypassVACBanned = true, | ||
BypassSteamGroupCheck = false, | ||
BypassGameBanned = true | ||
}; | ||
|
||
string json = JsonSerializer.Serialize(defaultConfig, new JsonSerializerOptions { WriteIndented = true }); | ||
File.WriteAllText(_configFilePath, json); | ||
|
||
return defaultConfig; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Dapper; | ||
using KitsuneSteamRestrict; | ||
using MySqlConnector; | ||
|
||
public class DatabaseService | ||
{ | ||
private readonly string _tablePrefix; | ||
private readonly string _connectionString; | ||
|
||
public DatabaseService(DatabaseSettings settings) | ||
{ | ||
_tablePrefix = settings.TablePrefix; | ||
_connectionString = $"Server={settings.Host};Port={settings.Port};Database={settings.Database};Uid={settings.Username};Pwd={settings.Password};SslMode={Enum.Parse<MySqlSslMode>(settings.Sslmode, true)};"; | ||
} | ||
|
||
public async Task<bool> IsSteamIdAllowedAsync(ulong steamId) | ||
{ | ||
using var connection = new MySqlConnection(_connectionString); | ||
var result = await connection.QueryFirstOrDefaultAsync<DateTime?>( | ||
$"SELECT `expiration_date` FROM `{_tablePrefix}allowed_users` WHERE `steam_id` = @steamId AND `expiration_date` > NOW()", | ||
new { steamId }); | ||
|
||
return result.HasValue; | ||
} | ||
|
||
public async Task AddAllowedUserAsync(ulong steamId, int daysValid) | ||
{ | ||
using var connection = new MySqlConnection(_connectionString); | ||
await connection.ExecuteAsync( | ||
$"INSERT INTO `{_tablePrefix}allowed_users` (`steam_id`, `expiration_date`) VALUES (@steamId, DATE_ADD(NOW(), INTERVAL @daysValid DAY))", | ||
new { steamId, daysValid }); | ||
} | ||
|
||
public async Task EnsureTablesExistAsync() | ||
{ | ||
using var connection = new MySqlConnection(_connectionString); | ||
await connection.ExecuteAsync($@" | ||
CREATE TABLE IF NOT EXISTS `{_tablePrefix}allowed_users` ( | ||
`steam_id` BIGINT UNSIGNED PRIMARY KEY, | ||
`expiration_date` DATETIME | ||
)"); | ||
} | ||
|
||
public async Task PurgeExpiredSavesAsync() | ||
{ | ||
using var connection = new MySqlConnection(_connectionString); | ||
await connection.ExecuteAsync($"DELETE FROM `{_tablePrefix}allowed_users` WHERE `expiration_date` < NOW()"); | ||
} | ||
} |