Senior Member
|
09-07-2020
, 13:10
Re: small edit please.
|
#24
|
Quote:
Originally Posted by Foxa
The plugin doesn't count frames correctly anyways, something like this would be better, although it can still result in false positives
.....
|
Eh, it looks a bit messy..
Lag spikes can cause players to get slayed for no reason since you don't even have warning count, and also because of this fps limit should be somewhere in 110.
I never understood this 'TASKID_DO' thing. Why not just pass the client index as the taskid? There's nothing wrong with that.
Perhaps you should check in x second intervals if client's fps is illegal and have at least 3 warnings.
This will reduce false positives drastically, if not get rid of them completely.
I've written at least a little better version of this feel free to use it..
It has all the features were requested and it logs client warnings into your logs directory.
If you're still getting false positives try increasing amx_max_fps.
You can modify how often (seconds) a client is being checked via amx_fps_check.
Spoiler
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <colorchat>
#pragma semicolon 1
#define CS_CT 2
#define MAXWARNINGS 4
#define DELAY_COUNT 1.0
#define MAX_PATH 256
new g_cvMaxFPS;
new g_cvInterval;
new g_iFPS[33];
new g_iWarnings[33];
public plugin_init()
{
register_plugin("fps thing", "0.0.1", "alliedmods");
g_cvMaxFPS = register_cvar("amx_max_fps", "107");
g_cvInterval = register_cvar("amx_fps_check", "5.0");
register_forward(FM_PlayerPreThink, "fwPlayerPreThink");
}
public plugin_cfg()
{
new sLogsDirectory[MAX_PATH];
get_localinfo( "amx_logdir", sLogsDirectory, charsmax(sLogsDirectory) );
add( sLogsDirectory, charsmax(sLogsDirectory), "/fps" );
if( !dir_exists( sLogsDirectory ) ) mkdir( sLogsDirectory );
}
public client_connect(iPlayer)
{
g_iFPS[iPlayer] = 0;
g_iWarnings[iPlayer] = 0;
}
public client_disconnect(iPlayer)
{
g_iFPS[iPlayer] = 0;
g_iWarnings[iPlayer] = 0;
if( task_exists(iPlayer) ) remove_task(iPlayer);
}
public client_authorized(iPlayer)
{
set_task( get_pcvar_float(g_cvInterval), "fwCheck", iPlayer, _, _, "b" );
}
public fwCheck(iPlayer)
{
if( !is_user_connected(iPlayer)
|| !is_user_alive(iPlayer)
|| !( get_user_team(iPlayer) == CS_CT ) )
{
g_iWarnings[iPlayer] = 0;
return;
}
static sName[33];
static sMsg[191];
static sAuth[33];
new iMax = get_pcvar_num(g_cvMaxFPS);
if( g_iFPS[iPlayer] >= iMax )
{
g_iWarnings[iPlayer]++;
get_user_name( iPlayer, sName, charsmax(sName) );
get_user_authid( iPlayer, sAuth, charsmax(sAuth) );
//formatex( sMsg, charsmax(sMsg), "^3[^4ADMINS^3] ^3Client ^4<%s> ^3fps warning! ^4(%i/%i)", sName, g_iWarnings[iPlayer], MAXWARNINGS );
//print_admins(sMsg);
log( "Warning client <%s> <%s> (%i/%i) <%i fps> (Can be lag)", sName, sAuth, g_iWarnings[iPlayer], MAXWARNINGS, g_iFPS[iPlayer] );
}
else g_iWarnings[iPlayer] = 0;
if( g_iWarnings[iPlayer] >= MAXWARNINGS )
{
g_iWarnings[iPlayer] = 0;
get_user_name( iPlayer, sName, charsmax(sName) );
get_user_authid( iPlayer, sAuth, charsmax(sAuth) );
formatex( sMsg, charsmax(sMsg), "^3[^4ADMINS^3] ^3Client ^4<%s> ^3is being slayed for ^4%i ^3FPS!", sName, g_iFPS[iPlayer] );
print_admins(sMsg);
set_task(5.0, "fwKillClient", iPlayer);
log( "Client <%s> <%s> was slayed for <%i> FPS!", sName, sAuth, g_iFPS[iPlayer] );
}
}
public fwPlayerPreThink(iPlayer)
{
static Float:fGameTime, Float:fCountNext[33], iCountFrames[33];
if ( fCountNext[iPlayer] >= ( fGameTime = get_gametime() ) )
{
iCountFrames[iPlayer]++;
return FMRES_IGNORED;
}
g_iFPS[iPlayer] = iCountFrames[iPlayer];
iCountFrames[iPlayer] = 0;
fCountNext[iPlayer] = fGameTime + DELAY_COUNT;
return FMRES_IGNORED;
}
public fwKillClient(iPlayer)
{
if( !is_user_connected(iPlayer) || !is_user_alive(iPlayer) ) return;
user_kill(iPlayer);
ColorChat(iPlayer, RED, "^3[AMXX] You were slayed for too high FPS! Write ^4fps_max 100 ^3in your console!");
}
stock print_admins( sMsg[] )
{
for(new i; i < 33; i++)
if( is_user_connected(i) )
if( get_user_flags(i) & ADMIN_RCON && i != 0 )
ColorChat(i, RED, sMsg);
}
stock log( const message_fmt[], any:... )
{
static sMessage[256];
vformat( sMessage, charsmax(sMessage), message_fmt, 2 );
static sDir[64];
static sFile[96];
if( !sDir[0] )
{
get_basedir( sDir, charsmax(sDir) );
add( sDir, charsmax(sDir), "/logs/fps" );
}
format_time( sFile, charsmax(sFile), "%Y.%m.%d" );
format( sFile, charsmax(sFile), "%s/fps_%s.log", sDir, sFile );
log_to_file(sFile, "%s", sMessage);
}
__________________
Last edited by Rohanlogs; 09-08-2020 at 02:32.
|
|