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

Regexing/Extracting info from ServerCommandEx


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nano2e
SourceMod Donor
Join Date: Apr 2012
Location: Australia
Old 06-07-2013 , 09:05   Regexing/Extracting info from ServerCommandEx
Reply With Quote #1

Hey, I'm working on a plugin that extracts info from certain console commands server side that I can store them in variables and send them to a db.

Here is some of my code and an example of a servercommand string I want to regex info from:

PHP Code:

#include <sourcemod>

new Handle:logtimer INVALID_HANDLE;

public 
CreatimerFunction()
{
    
//Create the timer when I need it
    
logtimer CreateTimer(5.0loginfo0TIMER_REPEAT);
}

public 
OnMapEnd()
{
    
KillTimer(logtimer);
    
logtimer INVALID_HANDLE;
}

public 
Action:loginfo(Handle:timer)
{
    
decl String:buffer[4096];
    
decl Float:tickrate

    ServerCommandEx
(buffersizeof(buffer), "stats"); //Get the stats console input
    
    
tickrate 1.00 GetTickInterval( ); //Get server tickrate
    
    //Have a function to regex certain info from the stats command (String buffer).
    
    //String Buffer
    //CPU    In (KB/s)  Out (KB/s)  Uptime  Map changes  FPS      Players  Connects
    //0.00   0.00       0.00        650     1            67.24    0        9   
    
    //How to regex say the FPS or/and uptime (or multiple info) from the buffer string and store it in a String/Float.
    
    //Have function that sends that info and the tickrate + date/time to a DB.

I'm not that great with regex and have no clue to getting around to do this, any help or solutions would be much appreciated!
__________________
Veni Vidi Vici

Last edited by Nano2e; 06-07-2013 at 09:07.
Nano2e is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 06-07-2013 , 21:55   Re: Regexing/Extracting info from ServerCommandEx
Reply With Quote #2

PHP Code:
#include <regex>
stock GetStatsInfo()
{
    
decl String:buffer[256];
    
ServerCommandEx(buffersizeof(buffer), "stats");

    new 
Handle:re CompileRegex("(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+)\\s+(?:(\\d+)\\s+)?");
    new 
subCount MatchRegex(rebuffer);

    if (
subCount != || subCount != 9)
    {
        
// not match
        
CloseHandle(re);
        return;
    }

    
decl String:cpu[12];
    
decl String:in[12];
    
decl String:out[12];
    
decl String:uptime[12];
    
decl String:mapchanges[12];
    
decl String:users[12];
    
decl String:fps[12];
    
decl String:players[12];
    
decl String:connects[12];

    
GetRegexSubString(re1cpusizeof(cpu));
    
GetRegexSubString(re2insizeof(in));
    
GetRegexSubString(re3outsizeof(out));
    
GetRegexSubString(re4uptimesizeof(uptime));
    
GetRegexSubString(re6fpssizeof(fps));
    
GetRegexSubString(re7playerssizeof(players));

    if (
subCount == 8)
    {
        
// L4D2, CSGO
        // CPU   In    Out   Uptime  Users   FPS    Players
        
GetRegexSubString(re5userssizeof(users));
    }
    else
    {
        
// CPU    In (KB/s)  Out (KB/s)  Uptime  Map changes  FPS      Players  Connects
        
GetRegexSubString(re5mapchangessizeof(mapchanges));
        
GetRegexSubString(re8connectssizeof(connects));
    }

    
CloseHandle(re);
    
LogMessage("cpu=%s, fps=%s, uptime=%s"cpufpsuptime);

__________________
sorry, for my poor english.

Last edited by mcpan313; 06-07-2013 at 22:15.
mcpan313 is offline
Send a message via MSN to mcpan313
Nano2e
SourceMod Donor
Join Date: Apr 2012
Location: Australia
Old 06-07-2013 , 22:11   Re: Regexing/Extracting info from ServerCommandEx
Reply With Quote #3

Wow you are a legend, I'll give it a crack and learn off it!
__________________
Veni Vidi Vici
Nano2e is offline
API
Veteran Member
Join Date: May 2006
Old 06-07-2013 , 23:13   Re: Regexing/Extracting info from ServerCommandEx
Reply With Quote #4

Don't forget about these functions: http://img.iaconosoftware.com/51b2a1464ef16.png
__________________
API is offline
Send a message via AIM to API
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 01:11.


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