Raised This Month: $51 Target: $400
 12% 

[REQUEST] Plug-in to log player latency


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Weasel
AlliedModders Donor
Join Date: Apr 2004
Location: Undisclosed / Secure
Old 01-07-2024 , 22:54   [REQUEST] Plug-in to log player latency
Reply With Quote #1

Anybody have or care to throw-together an plug-in such as this?
It is a pretty simple idea, for monitoring/diagnostic purposes.
  • Start a new log file every map load.
  • Once a minute, log every players latency to a log file.
  • Each log entry/line should be time-stamped of course.
Maybe a tab-separated format somewhat like this in the log file:

Code:
yyyy-mm-dd-hh:mm:ss <tab> Player-SteamID <tab> Latency <tab> Player-Name
__________________
Pwease pardon by bad Engrish.
Steam Profile, Steam Group, Stats, Twitter
Weasel is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-12-2024 , 13:44   Re: [REQUEST] Plug-in to log player latency
Reply With Quote #2

This log files into
Code:
...logs/YYYY-MM-DD-MMSS_mapname.log
Code:
2024-01-12-20:35:39	[U:1:28327177]	30	'Bacardi
This now create new empty line, after checking all human players in game.
You can remove that line if you don't like it.

Latency is ms, and this ping follows like "status" or "ping" command.
- Scoreboard ping again work differently

PHP Code:





File logfile
;

public 
void OnMapStart()
{
    if(
logfile != null)
    {
        
logfile.Flush();
        
delete logfile;
    }

    if(!
DirExists("logs") && !CreateDirectory("logs"0x1ED))    //0x1C0 = 700, 0x1E8 = 750, 0x1ED = 755
    
{
        
SetFailState("Plugin failed to create directory /logs");
    }



    
char map[PLATFORM_MAX_PATH];
    
char path[PLATFORM_MAX_PATH];

    
GetCurrentMap(mapsizeof(map));
    
FormatTime(pathsizeof(path), "%F-%H%M_");
    
Format(pathsizeof(path), "logs/%s%s.log"pathmap);

    
logfile OpenFile(path"a");
    
    if(
logfile == null)
        
SetFailState("Plugin failed to create or open file %s"path);

    
CreateTimer(60.0checkPinglogfileTIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}

public 
Action checkPing(Handle timerFile log)
{
    if(
log == null)
        return 
Plugin_Stop;

    if(
log != logfile)
    {
        
log.Flush();
        
delete log;
        return 
Plugin_Stop;
    }



    
char buffer[MAX_NAME_LENGTH];
    
//FormatTime(buffer, sizeof(buffer), "%FT%T%z"); // ISO 8601
    
FormatTime(buffersizeof(buffer), "%F-%T");

    
char auth[PLATFORM_MAX_PATH];
    
bool DoFlush false;

    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsFakeClient(i)) continue;

        
auth[0] = '\0';

        
GetClientAuthId(iAuthId_Engineauthsizeof(auth));
        
//PrintToServer("%s    %s    %0.0f    %N",buffer, auth, GetClientAvgLatency(i, NetFlow_Outgoing) * 1000.0, i);
        
Format(authsizeof(auth), "%s    %s    %0.0f    %N",bufferauthGetClientAvgLatency(iNetFlow_Outgoing) * 1000.0i);
        
        if(!
log.WriteLine(auth))
            
LogError("Plugin WriteLine failed");

        
DoFlush true;
    }

    if(
DoFlush)
    {
        
log.WriteLine("\n"); // extra new line
        
log.Flush();
    }

    return 
Plugin_Continue;

__________________
Do not Private Message @me

Last edited by Bacardi; 01-12-2024 at 13:55. Reason: add check DoFlush
Bacardi is offline
Weasel
AlliedModders Donor
Join Date: Apr 2004
Location: Undisclosed / Secure
Old 01-21-2024 , 14:25   Re: [REQUEST] Plug-in to log player latency
Reply With Quote #3

Thanks! Will check it out!
__________________
Pwease pardon by bad Engrish.
Steam Profile, Steam Group, Stats, Twitter
Weasel is offline
Weasel
AlliedModders Donor
Join Date: Apr 2004
Location: Undisclosed / Secure
Old 01-21-2024 , 14:45   Re: [REQUEST] Plug-in to log player latency
Reply With Quote #4

Thanks. Made a plugin based on that. Compiled it. Tested it. Working as expected. Exactly what I needed for troubleshooting / monitoring.

I have a compiled version available for anyone who wants ...

Compiled Plugin:
logpings.smx

Source Code:
logpings.sp

Spoiler
__________________
Pwease pardon by bad Engrish.
Steam Profile, Steam Group, Stats, Twitter

Last edited by Weasel; 01-21-2024 at 22:10. Reason: Changes in the relative positions of the Sun, the Moon and the stars.
Weasel is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode