Veteran Member
Join Date: Jun 2009
Location: california
|
01-14-2018
, 23:58
Re: [CS:S/CS:GO] CT Bans
|
#394
|
Hi Byte,
Sorry it has taken so long for my reply. Unfortunately, there is no way to accommodate your use case entirely in SourcePawn with clientprefs extension because of the cached data that exists. There will still be a mismatch between the data unless I pull from SQL every time, which I would rather not do.
Instead there is another way to make your use case work. It is recommended that you do something similar to sourcebans and execute a server rcon command. There are several rcon commands already included with ctbans 2.0.0 such as the offline commands that will do exactly what you need.
As for the FakeClients, I agree. I allowed fake clients for testing purposes but it is a hassle if they are accidentally CTBanned.
Quote:
Originally Posted by Byte
Hey databomb,
Nice update to your CT Bans plugin!
Thank you for the release.
I have some small suggestions:
In DisplayCTBanPlayerMenu, add a fake client check:
PHP Code:
if (IsClientInGame(iIndex) && !IsFakeClient(iIndex))
You don't want FakeClients (i.e. Source TV demo bots) showing up in the menu.
Also, in OnClientPostAdminCheck, consider querying the database and updating the users cookie and ban time remaining. Replacing the functionality of OnClientAuthorized. Reason for this if a user is not on the server and a web script modifies the database but leaves it in a valid state, when they rejoin their cookie may be incorrect.
Use case: - User is perm CT banned
- User leaves server
- Database edited directly or via a web script (not plugin) while user is offline
- User joins back and is still CT banned
Here is my solution if you want to look into it but be wary of the query as it may not work on older MySQL engine versions:
PHP Code:
#define CTBAN_QUERY_BANTIME_BANTIMEREMAINING "SELECT COALESCE(sum(timeleft), 0), COALESCE(bantime, -1) FROM %s WHERE perp_steamid = '%s' AND timeleft >= 0"
public void OnClientPostAdminCheck(int iClient) { // check if we have a database connection if (gH_BanDatabase != INVALID_HANDLE) { char sAuthID[FIELD_AUTHID_MAXLENGTH]; GetClientAuthId(iClient, AuthId_Steam2, sAuthID, sizeof(sAuthID));
char sQuery[QUERY_MAXLENGTH]; Format(sQuery, sizeof(sQuery), CTBAN_QUERY_BANTIME_BANTIMEREMAINING, g_sLogTableName, sAuthID); SQL_TQuery(gH_BanDatabase, DB_Callback_RemoteUpdate, sQuery, view_as<int>(iClient)); } else { CreateTimer(AUTH_RESCAN_TIME, Timer_OnClientPostAdminCheck, iClient, TIMER_FLAG_NO_MAPCHANGE); } }
public Action Timer_OnClientPostAdminCheck(Handle hTimer, any iClient) { if (gH_BanDatabase != INVALID_HANDLE && IsClientInGame(iClient)) { char sAuthID[FIELD_AUTHID_MAXLENGTH]; GetClientAuthId(iClient, AuthId_Steam2, sAuthID, sizeof(sAuthID));
char sQuery[QUERY_MAXLENGTH]; Format(sQuery, sizeof(sQuery), CTBAN_QUERY_BANTIME_BANTIMEREMAINING, g_sLogTableName, sAuthID); SQL_TQuery(gH_BanDatabase, DB_Callback_RemoteUpdate, sQuery, view_as<int>(iClient)); } else if(IsClientInGame(iClient)) { CreateTimer(AUTH_RESCAN_TIME, Timer_OnClientPostAdminCheck, iClient, TIMER_FLAG_NO_MAPCHANGE); } }
public void DB_Callback_RemoteUpdate(Handle hOwner, Handle hCallback, const char[] sError, any iClient) { if (hCallback == INVALID_HANDLE) { LogError("Error in RemoteUpdate query: %s", sError); } else { int iRowCount = SQL_GetRowCount(hCallback); if (iRowCount) { SQL_FetchRow(hCallback); int iBanTimeRemaining = SQL_FetchInt(hCallback, 0); int iBanTime = SQL_FetchInt(hCallback, 1); //Update ban time remaining gA_LocalTimeRemaining[iClient] = iBanTimeRemaining; if (IsClientInGame(iClient) && !IsFakeClient(iClient)) { if (iBanTime == 0) { //Permanent ban int iBannedArrayIndex = FindValueInArray(gA_TimedBanLocalList, iClient); if (iBannedArrayIndex != -1) RemoveFromArray(gA_TimedBanLocalList, iBannedArrayIndex); //Ensure the ban cookie exists SetClientCookie(iClient, g_CT_Cookie, COOKIE_BANNED_STRING); } else if (iBanTimeRemaining > 0) { //Ban has time left still int iBannedArrayIndex = FindValueInArray(gA_TimedBanLocalList, iClient); //If entry does not exist (even though it should), add it in if (iBannedArrayIndex == -1) PushArrayCell(gA_TimedBanLocalList, iClient); //Ensure the ban cookie exists SetClientCookie(iClient, g_CT_Cookie, COOKIE_BANNED_STRING); } else { //iBanTimeRemaining <= 0 //Expired ban int iBannedArrayIndex = FindValueInArray(gA_TimedBanLocalList, iClient); if (iBannedArrayIndex != VALUE_NOT_FOUND_IN_ARRAY) { // remove them from the local array RemoveFromArray(gA_TimedBanLocalList, iBannedArrayIndex); } //Remove ban from cookie SetClientCookie(iClient, g_CT_Cookie, COOKIE_UNBANNED_STRING); } //Finally, handle team swapping if banned CreateTimer(COOKIE_INIT_CHECK_TIME, Timer_CheckBanCookies, iClient, TIMER_FLAG_NO_MAPCHANGE); } } } }
Again this probably isn't needed for everyone buts its nice for those who modify the database outside of the server using web scripts.
|
__________________
Last edited by databomb; 01-15-2018 at 00:01.
|
|