entWatch4: fix includes, add EW_ClientHasItem

ReservedSlot: kick people with 0 idle time too, add back rule 4: alive non-donator, idle > 30, no item
This commit is contained in:
BotoX 2019-11-16 19:46:51 +01:00
parent 9256bbbf3e
commit a4bf8d8d0e
6 changed files with 58 additions and 10 deletions

View File

@ -5,6 +5,7 @@
#undef REQUIRE_PLUGIN #undef REQUIRE_PLUGIN
#include <AFKManager> #include <AFKManager>
#include <unloze> #include <unloze>
#tryinclude <entWatch_core>
#define REQUIRE_PLUGIN #define REQUIRE_PLUGIN
#pragma semicolon 1 #pragma semicolon 1
@ -12,6 +13,7 @@
bool g_Plugin_AFKManager; bool g_Plugin_AFKManager;
bool g_Plugin_UNLOZE; bool g_Plugin_UNLOZE;
bool g_Plugin_entWatch;
int g_Client_Reservation[MAXPLAYERS + 1] = {0, ...}; int g_Client_Reservation[MAXPLAYERS + 1] = {0, ...};
@ -38,6 +40,7 @@ public void OnAllPluginsLoaded()
{ {
g_Plugin_AFKManager = LibraryExists("AFKManager"); g_Plugin_AFKManager = LibraryExists("AFKManager");
g_Plugin_UNLOZE = LibraryExists("UNLOZE_ForumIntegration"); g_Plugin_UNLOZE = LibraryExists("UNLOZE_ForumIntegration");
g_Plugin_entWatch = LibraryExists("entWatch-core");
LogMessage("ReservedSlots capabilities:\nAFKManager: %s\nUNLOZE: %s\n", LogMessage("ReservedSlots capabilities:\nAFKManager: %s\nUNLOZE: %s\n",
(g_Plugin_AFKManager ? "loaded" : "not loaded"), (g_Plugin_AFKManager ? "loaded" : "not loaded"),
@ -50,6 +53,8 @@ public void OnLibraryAdded(const char[] name)
g_Plugin_AFKManager = true; g_Plugin_AFKManager = true;
else if(StrEqual(name, "UNLOZE_ForumIntegration")) else if(StrEqual(name, "UNLOZE_ForumIntegration"))
g_Plugin_UNLOZE = true; g_Plugin_UNLOZE = true;
else if(StrEqual(name, "entWatch-core"))
g_Plugin_entWatch = true;
} }
public void OnLibraryRemoved(const char[] name) public void OnLibraryRemoved(const char[] name)
@ -58,6 +63,8 @@ public void OnLibraryRemoved(const char[] name)
g_Plugin_AFKManager = false; g_Plugin_AFKManager = false;
else if(StrEqual(name, "UNLOZE_ForumIntegration")) else if(StrEqual(name, "UNLOZE_ForumIntegration"))
g_Plugin_UNLOZE = false; g_Plugin_UNLOZE = false;
else if(StrEqual(name, "entWatch-core"))
g_Plugin_entWatch = false;
} }
public void OnClientPostAdminCheck(int client) public void OnClientPostAdminCheck(int client)
@ -149,15 +156,15 @@ public void AsyncHasSteamIDReservedSlotCallback(const char[] sSteam32ID, int Res
stock bool KickValidClient(const char[] sName, const char[] sSteam32ID, AdminId admin, int Immunity) stock bool KickValidClient(const char[] sName, const char[] sSteam32ID, AdminId admin, int Immunity)
{ {
int HighestValue[4] = {0, ...}; int HighestValue[3] = {-1, ...};
int HighestValueClient[4] = {0, ...}; int HighestValueClient[3] = {0, ...};
for(int client = 1; client <= MaxClients; client++) for(int client = 1; client <= MaxClients; client++)
{ {
if(!IsClientInGame(client) || IsFakeClient(client)) if(!IsClientInGame(client) || IsFakeClient(client))
continue; continue;
int Donator = g_Client_Reservation[client]; bool Donator = view_as<bool>(g_Client_Reservation[client]);
int ConnectionTime = RoundToNearest(GetClientTime(client)); int ConnectionTime = RoundToNearest(GetClientTime(client));
int IdleTime; int IdleTime;
@ -166,6 +173,12 @@ stock bool KickValidClient(const char[] sName, const char[] sSteam32ID, AdminId
else // Fall back to highest connection time. else // Fall back to highest connection time.
IdleTime = ConnectionTime; IdleTime = ConnectionTime;
int HasItem;
#if defined entWatch_core_included
if(g_Plugin_entWatch)
HasItem = EW_ClientHasItem(client);
#endif
/* Spectators /* Spectators
* Sort by idle time and also kick donators if IdleTime > 30 * Sort by idle time and also kick donators if IdleTime > 30
*/ */
@ -197,7 +210,7 @@ stock bool KickValidClient(const char[] sName, const char[] sSteam32ID, AdminId
/* Alive non-donator with IdleTime > 30 /* Alive non-donator with IdleTime > 30
* Sort by idle time and don't kick donators and item owners. * Sort by idle time and don't kick donators and item owners.
* */
if(!Donator && IsPlayerAlive(client) && !HasItem) if(!Donator && IsPlayerAlive(client) && !HasItem)
{ {
if(IdleTime > 30 && IdleTime > HighestValue[2]) if(IdleTime > 30 && IdleTime > HighestValue[2])
@ -206,13 +219,13 @@ stock bool KickValidClient(const char[] sName, const char[] sSteam32ID, AdminId
HighestValueClient[2] = client; HighestValueClient[2] = client;
} }
} }
* Alive non-donator with IdleTime > 30 */ /* Alive non-donator with IdleTime > 30 */
} }
// Check if any condition was met in the correct order and perform kick // Check if any condition was met in the correct order and perform kick
for(int i = 0; i < sizeof(HighestValue); i++) for(int i = 0; i < sizeof(HighestValue); i++)
{ {
if(HighestValue[i]) if(HighestValue[i] != -1)
{ {
ExecuteKickValidClient(HighestValueClient[i], sName, sSteam32ID, admin, Immunity); ExecuteKickValidClient(HighestValueClient[i], sName, sSteam32ID, admin, Immunity);
return true; return true;

View File

@ -56,6 +56,7 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int erro
CreateNative("EW_GetItemCount", Native_GetItemCount); CreateNative("EW_GetItemCount", Native_GetItemCount);
CreateNative("EW_GetItemData", Native_GetItemData); CreateNative("EW_GetItemData", Native_GetItemData);
CreateNative("EW_ClientHasItem", Native_ClientHasItem);
RegPluginLibrary("entWatch-core"); RegPluginLibrary("entWatch-core");
return APLRes_Success; return APLRes_Success;
@ -752,4 +753,34 @@ public int Native_GetItemData(Handle hPlugin, int numParams)
} }
return view_as<int>(g_hArray_Items.Get(index)); return view_as<int>(g_hArray_Items.Get(index));
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_ClientHasItem(Handle hPlugin, int numParams)
{
int client = GetNativeCell(1);
if(client > MaxClients || client <= 0)
{
return ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid.");
}
if(!IsClientInGame(client))
{
ThrowNativeError(SP_ERROR_NATIVE, "Client is not in game.");
}
for (int index; index < g_hArray_Items.Length; index++)
{
CItem item = g_hArray_Items.Get(index);
if (item.bClient && item.iClient == client)
{
return 1;
}
}
return 0;
}

View File

@ -24,8 +24,8 @@
/* CLASSES */ /* CLASSES */
#include <basic> #include <basic>
#include "../classes/CConfig.inc" #include "entWatch/CConfig.inc"
#include "../classes/CItem.inc" #include "entWatch/CItem.inc"
public SharedPlugin __pl_entWatch_core = public SharedPlugin __pl_entWatch_core =
{ {
@ -44,6 +44,7 @@ public SharedPlugin __pl_entWatch_core =
{ {
MarkNativeAsOptional("EW_GetItemCount"); MarkNativeAsOptional("EW_GetItemCount");
MarkNativeAsOptional("EW_GetItemData"); MarkNativeAsOptional("EW_GetItemData");
MarkNativeAsOptional("EW_ClientHasItem");
} }
#endif #endif
@ -51,6 +52,8 @@ native int EW_GetItemCount();
native CItem EW_GetItemData(int index); native CItem EW_GetItemData(int index);
native bool EW_ClientHasItem(int client);
forward void EW_OnClientItemDrop(int client, int index); forward void EW_OnClientItemDrop(int client, int index);
forward void EW_OnClientItemDeath(int client, int index); forward void EW_OnClientItemDeath(int client, int index);
forward void EW_OnClientItemPickup(int client, int index); forward void EW_OnClientItemPickup(int client, int index);
@ -58,4 +61,4 @@ forward void EW_OnClientItemActivate(int client, int index);
forward void EW_OnClientItemDisconnect(int client, int index); forward void EW_OnClientItemDisconnect(int client, int index);
forward Action EW_OnClientItemCanPickup(int client, int index); forward Action EW_OnClientItemCanPickup(int client, int index);
forward Action EW_OnClientItemCanActivate(int client, int index); forward Action EW_OnClientItemCanActivate(int client, int index);

1
includes/entWatch Symbolic link
View File

@ -0,0 +1 @@
../entWatch4/scripting/include/entWatch