using the nide config approach but actually works i guess
This commit is contained in:
parent
6acdc80767
commit
0866d58b59
@ -10,7 +10,9 @@ ArrayList g_hClanNames;
|
|||||||
|
|
||||||
int g_iBaseLatency[MAXPLAYERS + 1];
|
int g_iBaseLatency[MAXPLAYERS + 1];
|
||||||
int g_iLatency[MAXPLAYERS + 1];
|
int g_iLatency[MAXPLAYERS + 1];
|
||||||
int g_iFakesCount;
|
int g_iPlayerCount;
|
||||||
|
|
||||||
|
bool g_bMapended;
|
||||||
|
|
||||||
Database g_hDatabase;
|
Database g_hDatabase;
|
||||||
Database g_hDatabase_hlstats;
|
Database g_hDatabase_hlstats;
|
||||||
@ -23,7 +25,7 @@ public Plugin myinfo =
|
|||||||
name = "fakes",
|
name = "fakes",
|
||||||
author = "Neon + Dogan + Botox",
|
author = "Neon + Dogan + Botox",
|
||||||
description = "Handle Hitboxes via Plugin",
|
description = "Handle Hitboxes via Plugin",
|
||||||
version = "5.3.1",
|
version = "5.4.1",
|
||||||
url = "https://steamcommunity.com/id/n3ontm"
|
url = "https://steamcommunity.com/id/n3ontm"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,9 +44,12 @@ public void OnPluginStart()
|
|||||||
CreateTimer(GetRandomFloat(20.0, 40.0), RunPopulationCheck, _, TIMER_REPEAT);
|
CreateTimer(GetRandomFloat(20.0, 40.0), RunPopulationCheck, _, TIMER_REPEAT);
|
||||||
CreateTimer(3.0, RandomizePing, _, TIMER_REPEAT);
|
CreateTimer(3.0, RandomizePing, _, TIMER_REPEAT);
|
||||||
CreateTimer(600.0, RandomizeNames, _, TIMER_REPEAT);
|
CreateTimer(600.0, RandomizeNames, _, TIMER_REPEAT);
|
||||||
|
CreateTimer(80.0, CheckPopulation_interval, _, TIMER_REPEAT);
|
||||||
|
|
||||||
HookUserMessage(GetUserMessageId("SayText2"), UserMessage_SayText2, true);
|
HookUserMessage(GetUserMessageId("SayText2"), UserMessage_SayText2, true);
|
||||||
|
|
||||||
|
g_bMapended = false;
|
||||||
|
|
||||||
if (!g_hDatabase)
|
if (!g_hDatabase)
|
||||||
{
|
{
|
||||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||||
@ -53,28 +58,7 @@ public void OnPluginStart()
|
|||||||
{
|
{
|
||||||
Database.Connect(SQL_OnDatabaseConnect_hlstats, "hlstatsx");
|
Database.Connect(SQL_OnDatabaseConnect_hlstats, "hlstatsx");
|
||||||
}
|
}
|
||||||
HookEvent("round_start", Event_roundStart, EventHookMode_Pre);
|
g_iPlayerCount = 0;
|
||||||
g_iFakesCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Event_roundStart(Handle event, const char[] name, bool dontBroadcast)
|
|
||||||
{
|
|
||||||
int TimeLeft;
|
|
||||||
if (GetMapTimeLeft(TimeLeft) && TimeLeft < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_iFakesCount = 0;
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
|
||||||
{
|
|
||||||
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
|
||||||
{
|
|
||||||
if (IsFakeClient(i) && !IsClientSourceTV(i))
|
|
||||||
{
|
|
||||||
g_iFakesCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SQL_OnDatabaseConnect_hlstats(Database db, const char[] error, any data)
|
public void SQL_OnDatabaseConnect_hlstats(Database db, const char[] error, any data)
|
||||||
@ -157,15 +141,21 @@ public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[]
|
|||||||
delete results;
|
delete results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnMapEnd()
|
||||||
|
{
|
||||||
|
g_bMapended = true;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnMapStart()
|
public void OnMapStart()
|
||||||
{
|
{
|
||||||
KeyValues kv = CreateKeyValues("ints_used_already");
|
KeyValues kv = CreateKeyValues("ints_used_already");
|
||||||
for (float i = 0.0; i < g_iFakesCount;)
|
int fakes_needed = getFakesNeeded();
|
||||||
|
for (float i = 0.0; i < fakes_needed;)
|
||||||
{
|
{
|
||||||
int num = GetRandomInt(5, 150);
|
int num = GetRandomInt(5, 45);
|
||||||
char strnum[16];
|
char strnum[16];
|
||||||
IntToString(num, strnum, sizeof(strnum));
|
IntToString(num, strnum, sizeof(strnum));
|
||||||
int found = kv.GetNum(strnum, -1);
|
int found = kv.GetNum(strnum, -1);
|
||||||
@ -181,11 +171,53 @@ public void OnMapStart()
|
|||||||
delete kv;
|
delete kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getFakesNeeded()
|
||||||
|
{
|
||||||
|
//copied from nide fakeclients plugin.
|
||||||
|
char sPath[PLATFORM_MAX_PATH];
|
||||||
|
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/fakeclients_tiers.cfg");
|
||||||
|
|
||||||
|
KeyValues kv = new KeyValues("FakeClientsTiers");
|
||||||
|
if (!kv.ImportFromFile(sPath))
|
||||||
|
{
|
||||||
|
LogError("configs/fakeclients_tiers.cfg not found — falling back to sm_fakeclients_players");
|
||||||
|
delete kv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!kv.GotoFirstSubKey(false))
|
||||||
|
{
|
||||||
|
LogError("configs/fakeclients_tiers.cfg is empty or malformed");
|
||||||
|
delete kv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int prev_bots = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
char sKey[16], sVal[16];
|
||||||
|
kv.GetSectionName(sKey, sizeof(sKey));
|
||||||
|
kv.GetString(NULL_STRING, sVal, sizeof(sVal), "-1");
|
||||||
|
|
||||||
|
int bots = StringToInt(sVal);
|
||||||
|
int players = StringToInt(sKey);
|
||||||
|
if (players > g_iPlayerCount)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev_bots = bots;
|
||||||
|
|
||||||
|
} while (kv.GotoNextKey(false));
|
||||||
|
|
||||||
|
delete kv;
|
||||||
|
//LogMessage("prev_bots: %i", prev_bots);
|
||||||
|
return prev_bots;
|
||||||
|
}
|
||||||
|
|
||||||
public Action addfakes(Handle timer)
|
public Action addfakes(Handle timer)
|
||||||
{
|
{
|
||||||
|
int limit = getFakesNeeded();
|
||||||
int fakes = 0;
|
int fakes = 0;
|
||||||
int spectators = 0;
|
|
||||||
int inTeam = 0;
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
{
|
{
|
||||||
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
||||||
@ -194,32 +226,48 @@ public Action addfakes(Handle timer)
|
|||||||
{
|
{
|
||||||
fakes++;
|
fakes++;
|
||||||
}
|
}
|
||||||
if (GetClientTeam(i) <= CS_TEAM_SPECTATOR)
|
|
||||||
{
|
|
||||||
spectators++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
inTeam++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int limit = 16;
|
|
||||||
if (nightTime())
|
if (nightTime())
|
||||||
{
|
{
|
||||||
limit /= 2;
|
limit /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fakes < limit)
|
if (fakes < limit)
|
||||||
{
|
{
|
||||||
CreateFake();
|
CreateFake();
|
||||||
if (spectators > limit || inTeam + 2 < spectators)
|
|
||||||
{
|
|
||||||
SetFakeToTeam();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action CheckPopulation_interval(Handle timer)
|
||||||
|
{
|
||||||
|
int TimeLeft;
|
||||||
|
if (GetMapTimeLeft(TimeLeft) && TimeLeft < 0)
|
||||||
|
{
|
||||||
|
return Plugin_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_bMapended)
|
||||||
|
{
|
||||||
|
g_bMapended = false;
|
||||||
|
return Plugin_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_iPlayerCount = 0;
|
||||||
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
||||||
|
{
|
||||||
|
if (!IsFakeClient(i) && !IsClientSourceTV(i))
|
||||||
|
{
|
||||||
|
g_iPlayerCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -333,7 +381,7 @@ public Action Command_DebugFakes(int client, int argc)
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (IsFakeClient(i) || IsClientSourceTV(i))
|
if (IsFakeClient(i) && !IsClientSourceTV(i))
|
||||||
{
|
{
|
||||||
iFakes++;
|
iFakes++;
|
||||||
iPlayers--;
|
iPlayers--;
|
||||||
@ -398,121 +446,33 @@ public void OnClientDisconnect(int client)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void CheckPopulation()
|
public void CheckPopulation()
|
||||||
{
|
{
|
||||||
int iPlayersSpectate = 0;
|
int fakes = 0;
|
||||||
int iPlayersInTeam = 0;
|
int last_fake = 0;
|
||||||
int iFakesSpectate = 0;
|
|
||||||
int iFakesInTeam = 0;
|
|
||||||
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
|
||||||
{
|
|
||||||
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
|
||||||
{
|
|
||||||
if (!IsFakeClient(i) && !IsClientSourceTV(i))
|
|
||||||
{
|
|
||||||
if (GetClientTeam(i) > CS_TEAM_SPECTATOR)
|
|
||||||
{
|
|
||||||
iPlayersInTeam++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iPlayersSpectate++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (GetClientTeam(i) > CS_TEAM_SPECTATOR)
|
|
||||||
{
|
|
||||||
iFakesInTeam++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iFakesSpectate++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int iPlayers = iPlayersInTeam + iPlayersSpectate + iFakesInTeam + iFakesSpectate;
|
|
||||||
if (iPlayers >= 55)
|
|
||||||
{
|
|
||||||
KickFakes();
|
|
||||||
}
|
|
||||||
else if (iPlayers < 48)
|
|
||||||
{
|
|
||||||
ManageFakes(iPlayersSpectate, iPlayersInTeam, iFakesInTeam, iFakesSpectate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void KickFakes()
|
|
||||||
{
|
|
||||||
int fake_in_spec = 0;
|
|
||||||
int fake_in_team = 0;
|
|
||||||
|
|
||||||
int last_in_team = 0;
|
|
||||||
int last_in_spec = 0;
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
{
|
{
|
||||||
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
if (IsClientConnected(i) && IsClientInGame(i) && IsClientAuthorized(i))
|
||||||
{
|
{
|
||||||
if (IsFakeClient(i) && !IsClientSourceTV(i))
|
if (IsFakeClient(i) && !IsClientSourceTV(i))
|
||||||
{
|
{
|
||||||
if (GetClientTeam(i) <= CS_TEAM_SPECTATOR)
|
fakes++;
|
||||||
{
|
last_fake = i;
|
||||||
fake_in_spec++;
|
|
||||||
last_in_spec = i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fake_in_team++;
|
|
||||||
last_in_team = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fake_in_spec > fake_in_team && last_in_spec != 0)
|
int fakes_needed = getFakesNeeded();
|
||||||
{
|
|
||||||
g_iLatency[last_in_spec] = 0;
|
|
||||||
KickClient(last_in_spec, "Disconnect by user.");
|
|
||||||
}
|
|
||||||
else if (last_in_team != 0)
|
|
||||||
{
|
|
||||||
g_iLatency[last_in_team] = 0;
|
|
||||||
KickClient(last_in_team, "Disconnect by user.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ManageFakes(int iPlayersSpectate, int iPlayersInTeam, int iFakesInTeam, int iFakesSpectate)
|
|
||||||
{
|
|
||||||
int limit = 16;
|
|
||||||
if (nightTime())
|
if (nightTime())
|
||||||
{
|
{
|
||||||
limit /= 2;
|
fakes_needed /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iPlayersSpectate + iPlayersInTeam + 4 < iFakesSpectate + iFakesInTeam || iFakesSpectate + iFakesInTeam > limit)
|
if (fakes > fakes_needed && last_fake != 0)
|
||||||
{
|
{
|
||||||
KickFakes();
|
g_iLatency[last_fake] = 0;
|
||||||
|
KickClient(last_fake, "Disconnect by user.");
|
||||||
}
|
}
|
||||||
else if (iPlayersSpectate + iPlayersInTeam > iFakesSpectate + iFakesInTeam && iFakesSpectate + iFakesInTeam < limit)
|
else if (fakes < fakes_needed)
|
||||||
{
|
{
|
||||||
CreateFake();
|
CreateFake();
|
||||||
if (iPlayersSpectate + iFakesSpectate > limit || iPlayersInTeam + iFakesInTeam + 2 < iPlayersSpectate + iFakesSpectate)
|
|
||||||
{
|
|
||||||
SetFakeToTeam();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFakeToTeam()
|
|
||||||
{
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
|
||||||
{
|
|
||||||
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR)
|
|
||||||
{
|
|
||||||
ChangeClientTeam(i, CS_TEAM_CT);
|
|
||||||
FakeClientCommandEx(i, "joinclass");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,8 +482,8 @@ public bool nightTime()
|
|||||||
FormatTime(sTime, sizeof(sTime), "%H%M");
|
FormatTime(sTime, sizeof(sTime), "%H%M");
|
||||||
|
|
||||||
int CurTime = StringToInt(sTime);
|
int CurTime = StringToInt(sTime);
|
||||||
int MinTime = 2000;
|
int MinTime = 100;
|
||||||
int MaxTime = 500;
|
int MaxTime = 400;
|
||||||
|
|
||||||
//Wrap around.
|
//Wrap around.
|
||||||
CurTime = (CurTime <= MinTime) ? CurTime + 2400 : CurTime;
|
CurTime = (CurTime <= MinTime) ? CurTime + 2400 : CurTime;
|
||||||
@ -537,6 +497,21 @@ public bool nightTime()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//not used anymore
|
||||||
|
public void SetFakeToTeam()
|
||||||
|
{
|
||||||
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if(IsClientConnected(i) && IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR)
|
||||||
|
{
|
||||||
|
ChangeClientTeam(i, CS_TEAM_CT);
|
||||||
|
FakeClientCommandEx(i, "joinclass");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateFake()
|
public void CreateFake()
|
||||||
{
|
{
|
||||||
if (g_hNames.Length == 0 || g_hClanNames.Length == 0)
|
if (g_hNames.Length == 0 || g_hClanNames.Length == 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user