mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-03-03 06:31:00 +00:00
Database connection exception fix, additional ip check (problem with steam auth)
This commit is contained in:
@@ -23,6 +23,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
public static IStringLocalizer? _localizer;
|
public static IStringLocalizer? _localizer;
|
||||||
public static ConcurrentBag<int> gaggedPlayers = new ConcurrentBag<int>();
|
public static ConcurrentBag<int> gaggedPlayers = new ConcurrentBag<int>();
|
||||||
public static ConcurrentBag<int> mutedPlayers = new ConcurrentBag<int>();
|
public static ConcurrentBag<int> mutedPlayers = new ConcurrentBag<int>();
|
||||||
|
public static List<int> loadedPlayers = new List<int>();
|
||||||
public static Dictionary<string, int> voteAnswers = new Dictionary<string, int>();
|
public static Dictionary<string, int> voteAnswers = new Dictionary<string, int>();
|
||||||
public static List<int> GodPlayers = new List<int>();
|
public static List<int> GodPlayers = new List<int>();
|
||||||
public static bool TagsDetected = false;
|
public static bool TagsDetected = false;
|
||||||
@@ -33,7 +34,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
public override string ModuleName => "CS2-SimpleAdmin";
|
public override string ModuleName => "CS2-SimpleAdmin";
|
||||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||||
public override string ModuleAuthor => "daffyy";
|
public override string ModuleAuthor => "daffyy";
|
||||||
public override string ModuleVersion => "1.2.6b";
|
public override string ModuleVersion => "1.2.6c";
|
||||||
|
|
||||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
command = new MySqlCommand(sql, connection);
|
command = new MySqlCommand(sql, connection);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
sql = @"CREATE TABLE `sa_servers` (
|
sql = @"CREATE TABLE IF NOT EXISTS `sa_servers` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`address` varchar(64) NOT NULL,
|
`address` varchar(64) NOT NULL,
|
||||||
`hostname` varchar(64) NOT NULL,
|
`hostname` varchar(64) NOT NULL,
|
||||||
|
|||||||
41
Events.cs
41
Events.cs
@@ -16,6 +16,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
private void registerEvents()
|
private void registerEvents()
|
||||||
{
|
{
|
||||||
RegisterListener<OnClientAuthorized>(OnClientAuthorized);
|
RegisterListener<OnClientAuthorized>(OnClientAuthorized);
|
||||||
|
RegisterListener<OnClientConnected>(OnClientConnected);
|
||||||
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerFullConnect);
|
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerFullConnect);
|
||||||
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
||||||
RegisterListener<OnMapStart>(OnMapStart);
|
RegisterListener<OnMapStart>(OnMapStart);
|
||||||
@@ -124,6 +125,38 @@ public partial class CS2_SimpleAdmin
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnClientConnected(int playerSlot)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.IpAddress == null || loadedPlayers.Contains((int)player.Index) || player.IsBot || player.IsHLTV)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
BanManager _banManager = new(dbConnectionString);
|
||||||
|
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid) return;
|
||||||
|
if (isBanned)
|
||||||
|
{
|
||||||
|
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
@@ -142,7 +175,6 @@ public partial class CS2_SimpleAdmin
|
|||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
BanManager _banManager = new(dbConnectionString);
|
BanManager _banManager = new(dbConnectionString);
|
||||||
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
||||||
|
|
||||||
@@ -158,6 +190,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
if (isBanned)
|
if (isBanned)
|
||||||
{
|
{
|
||||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||||
|
Console.WriteLine("Authorized banned");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,6 +310,9 @@ public partial class CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!loadedPlayers.Contains((int)player.Index))
|
||||||
|
loadedPlayers.Add((int)player.Index);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -308,6 +344,9 @@ public partial class CS2_SimpleAdmin
|
|||||||
GodPlayers.Remove((int)player.Index);
|
GodPlayers.Remove((int)player.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loadedPlayers.Contains((int)player.Index))
|
||||||
|
loadedPlayers.Remove((int)player.Index);
|
||||||
|
|
||||||
if (player.AuthorizedSteamID != null)
|
if (player.AuthorizedSteamID != null)
|
||||||
{
|
{
|
||||||
//string steamIdString = player.AuthorizedSteamID.SteamId64.ToString();
|
//string steamIdString = player.AuthorizedSteamID.SteamId64.ToString();
|
||||||
|
|||||||
Reference in New Issue
Block a user