upstream to 1.7.7-alpha-10

This commit is contained in:
Sachin 2025-10-03 17:18:24 +05:30
commit 2de2924cef
106 changed files with 5897 additions and 3306 deletions

View file

@ -9,21 +9,31 @@ public class ServerManager
{
private int _getIpTryCount;
/// <summary>
/// Checks whether the server setting <c>sv_hibernate_when_empty</c> is enabled.
/// Logs an error if this setting is true, since it prevents the plugin from working properly.
/// </summary>
public static void CheckHibernationStatus()
{
var convar = ConVar.Find("sv_hibernate_when_empty");
if (convar == null || !convar.GetPrimitiveValue<bool>())
return;
CS2_SimpleAdmin._logger?.LogError("Detected setting \"sv_hibernate_when_empty true\", set false to make plugin work properly");
}
/// <summary>
/// Initiates the asynchronous process to load server data such as IP address, port, hostname, and RCON password.
/// Handles retry attempts if IP address is not immediately available.
/// Updates or inserts the server record in the database accordingly.
/// After loading, triggers admin reload and cache initialization.
/// Also optionally sends plugin usage metrics if enabled in configuration.
/// </summary>
public void LoadServerData()
{
CS2_SimpleAdmin.Instance.AddTimer(1.2f, () =>
CS2_SimpleAdmin.Instance.AddTimer(2.0f, () =>
{
if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.ServerId != null || CS2_SimpleAdmin.Database == null) return;
if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.DatabaseProvider == null) return;
if (_getIpTryCount > 32 && Helper.GetServerIp().StartsWith("0.0.0.0") || string.IsNullOrEmpty(Helper.GetServerIp()))
{
@ -32,7 +42,6 @@ public class ServerManager
}
var ipAddress = ConVar.Find("ip")?.StringValue;
if (string.IsNullOrEmpty(ipAddress) || ipAddress.StartsWith("0.0.0"))
{
ipAddress = Helper.GetServerIp();
@ -58,7 +67,7 @@ public class ServerManager
{
try
{
await using var connection = await CS2_SimpleAdmin.Database.GetConnectionAsync();
await using var connection = await CS2_SimpleAdmin.DatabaseProvider.CreateConnectionAsync();
var addressExists = await connection.ExecuteScalarAsync<bool>(
"SELECT COUNT(*) FROM sa_servers WHERE address = @address",
new { address });
@ -67,11 +76,11 @@ public class ServerManager
{
string query = "INSERT INTO sa_servers (address, hostname) VALUES (@address, @hostname)";
if(CS2_SimpleAdmin.Instance.Config.IsCSSPanel)
if (CS2_SimpleAdmin.Instance.Config.IsCSSPanel)
{
query = "INSERT INTO sa_servers (address, hostname, rcon) VALUES (@address, @hostname, @rcon)";
}
await connection.ExecuteAsync(
query,
new { address, hostname, rcon });
@ -80,11 +89,11 @@ public class ServerManager
{
string query = "UPDATE `sa_servers` SET `hostname` = @hostname, `id` = `id` WHERE `address` = @address";
if(CS2_SimpleAdmin.Instance.Config.IsCSSPanel)
if (CS2_SimpleAdmin.Instance.Config.IsCSSPanel)
{
query = "UPDATE `sa_servers` SET `hostname` = @hostname, rcon = @rcon, `id` = `id` WHERE `address` = @address";
}
await connection.ExecuteAsync(
query,
new { address, rcon, hostname });
@ -95,7 +104,6 @@ public class ServerManager
new { address });
CS2_SimpleAdmin.ServerId = serverId;
CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress);
if (CS2_SimpleAdmin.ServerId != null)