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

qServerinfo count disconnected players bug


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jonatat
Senior Member
Join Date: Dec 2017
Old 06-05-2018 , 03:18   qServerinfo count disconnected players bug
Reply With Quote #1

Hello all. I'm using qserverinfo plugin. This plugin save server info to mysql like player numbers, map and etc. But, if i connect to server alone, and then disconnected i get -1 player in SQL... Can someone fix this? It should be not -1 but 0 players...

PHP Code:
/*
*      < Coded by grd aka  quark >
*
*  Description 
* This plugin will insert into a MYSQL Database server information as
* hostname, map and players for now.

*
*  Contacts
* Steam: grdPTFMAPS
* Mail: [email protected]
* Website: www.joserodrigues.tk

*
*  Changelog
* 0.1 - First release.
* 0.2 - Fixed bug when change map.
* 0.3 - Added server IP Saving.
*     - Removed Ignore HLTV/BOTS.
*     - Fixed Player Count. ( I guess. )
* 0.4 - Removed Server ID.
*     - Set Server IP as Primary key.
*     - Changed way to get Server IP.
*     - Added maxplayers.
*     - Fixed Player count. ( Testing. )
* 0.5 - Added log to amx.
*     - Fixed server IP.
* 0.6 - Fixed Player Couting
*
*
*  Original Thread
* https://forums.alliedmods.net/showthread.php?p=2025512
*
*/

/* Includes */
#include <amxmodx>
#include <sqlx>
/* --------- */

/* Table Configuration  */
new const QSINFO_TABLE[] = "qserverinfo";
/*  -----------------------------   */

/*  Connection Handle/Variables         */
new Handle:qSi_SqlTuple;
/*  -----------------------------   */

/* Variables        */
new g_pcvarHost;
new 
g_pcvaruUser;
new 
g_pcvarPass;
new 
g_pcvarDB;

new 
szMapName32 ];
new 
szAddress32 ];
new 
szHostName64 ];

new 
g_iPlayers;

new 
p_Address
new 
p_Maxplayers
/*  -----------------------------   */

public plugin_init() 
{
    
register_plugin("qServerinfo""0.6""quark");
    
    
/*     Register Cvars       */
    
g_pcvarHost register_cvar"qSi_host""localhost"FCVAR_PROTECTED );
    
g_pcvaruUser register_cvar"qSi_user""user"FCVAR_PROTECTED );
    
g_pcvarPass register_cvar"qSi_pass""pass"FCVAR_PROTECTED );
    
g_pcvarDB register_cvar"qSi_db""db"FCVAR_PROTECTED );
    
/*  ----------------------------------------------------------------------------------  */
    
    
p_Maxplayers get_maxplayers();
    
p_Address get_cvar_pointer("net_address");
    
g_iPlayers=0;
    
    
SqlInit();
}

public 
SqlInit()
{
    
/*     SQL Connection      */
    
new szHost32 ];
    new 
szUser32 ];
    new 
szPass32 ];
    new 
szDB32 ];
    
    
get_pcvar_stringg_pcvarHostszHostcharsmaxszHost ) );
    
get_pcvar_stringg_pcvaruUserszUsercharsmaxszUser ) );
    
get_pcvar_stringg_pcvarPassszPasscharsmaxszPass ) );
    
get_pcvar_stringg_pcvarDBszDBcharsmaxszDB ) );
    
    
qSi_SqlTuple SQL_MakeDbTupleszHostszUserszPassszDB );
    
    new 
g_Error512 ];
    new 
ErrorCode;
    new 
Handle:SqlConnection SQL_ConnectqSi_SqlTupleErrorCodeg_Errorcharsmaxg_Error ) );
    
/*  ----------------------------------------------------------------------------------  */
    
    
if( SqlConnection == Empty_Handle )
        
set_fail_stateg_Error );
    
    
/*    Create the SQL Table      */
    
new Handle:Queries;
    
Queries SQL_PrepareQuerySqlConnection,
    
"CREATE TABLE IF NOT EXISTS %s \
    ( ip VARCHAR( 32 ) PRIMARY KEY,\
    hostname VARCHAR( 64 ),\
    map VARCHAR( 32 ),\
    players INT( 11 ),\
    maxplayers int( 11 ) )"
,
    
QSINFO_TABLE );
    
/*  -----------------------------   */
    
    
if( !SQL_ExecuteQueries ) )
    {
        
SQL_QueryErrorQueriesg_Errorcharsmaxg_Error ) );
        
set_fail_stateg_Error );
    }
    
    
/*  Some delay so hostname won't be "Half Life" */
    
set_task(5.0"CheckqSi");
    
/* ----------------------------------------- */
    
    
    
SQL_FreeHandleQueries ); 
    
SQL_FreeHandleSqlConnection );
}

public 
CheckqSi()
{
    
get_pcvar_string(p_Address,szAddress,charsmax(szAddress)); 
    
    
/*  I only use this so when the results come, i can create     */
    /*  the row for the specific server ID    */
    /*  It will check if the server ID already exists in the database */
    
new szTemp512 ];
    
formatszTempcharsmaxszTemp ),
    
"SELECT `hostname` FROM %s WHERE `ip`='%s'",
    
QSINFO_TABLEszAddress );
    
    
SQL_ThreadQueryqSi_SqlTuple"LoadqSi_Results"szTemp );
    
/* ------------------------------------------------------------ */
}

public 
LoadqSi_ResultsFailStateHandle:QueryError[ ], Errcode )
{
    if( 
SQL_IsFailFailStateErrcodeError ) )
        return;
    
    
/*          Create row for the server ID if not found         */
    
if( SQL_NumResultsQuery ) < 
    {
        
get_mapnameszMapNamecharsmaxszMapName ) );
        
get_cvar_string"hostname"szHostNamecharsmaxszHostName ) );
        
get_pcvar_string(p_Address,szAddress,charsmax(szAddress)); 
        
        new 
szTemp512 ]
        
formatszTempcharsmaxszTemp ),
        
"INSERT INTO %s ( ip, hostname, map, players, maxplayers )\
        VALUES( '%s', '%s', '%s', '%d', '%d' )"
,
        
QSINFO_TABLEszAddressszHostNameszMapNameg_iPlayersp_Maxplayers);
        
        
SQL_ThreadQueryqSi_SqlTuple"IgnoreHandle"szTemp );
        
        
log_amx("IP: %s | Hostname: %s | Map: %s | Players: %d | Maxplayers: %d"szAddressszHostNameszMapNameg_iPlayersp_Maxplayers);
    }
    
/* ----------------------------------------- */
    
    /* If the server ID already has an row, it will update the info */
    
else 
        
set_task(5.0"UpdateqSi");
    
/* ----------------------------------------- */
    
}

public 
UpdateqSi()
{
    
/* Update Server Information */
    
get_mapnameszMapNamecharsmaxszMapName ) );
    
get_cvar_string"hostname"szHostNamecharsmaxszHostName ) );
    
get_pcvar_string(p_Address,szAddress,charsmax(szAddress)); 
    
    new 
szTemp512 ];
    
formatexszTempcharsmaxszTemp ),
    
"UPDATE `%s` SET `hostname`='%s', `map`='%s', `players`='%d', `maxplayers`='%d'  WHERE `ip`='%s'",
    
QSINFO_TABLEszHostNameszMapNameg_iPlayersp_Maxplayers,  szAddress);
    
    
SQL_ThreadQueryqSi_SqlTuple"IgnoreHandle"szTemp );
    
    
log_amx("IP: %s | Hostname: %s | Map: %s | Players: %d | Maxplayers: %d"szAddressszHostNameszMapNameg_iPlayersp_Maxplayers);
    
/* ----------------------------------------- */
}

public 
client_putinserver(player)
{
    
set_task(1.0"CheckUser"player);
}

public 
CheckUser(player)
{
    if(
is_user_connected(player))
    {
        
g_iPlayers++; 
        
UpdateqSiPlayers();
    }    
}

public 
client_disconnect(player)
{
    
g_iPlayers--;
    
UpdateqSiPlayers();
}

public 
UpdateqSiPlayers()
{
    
/* Update the Players num */
    
new szTemp512 ];
    
formatexszTempcharsmaxszTemp ),
    
"UPDATE `%s` SET `players`='%d' WHERE `ip`='%s'",
    
QSINFO_TABLEg_iPlayersszAddress );
    
    
SQL_ThreadQueryqSi_SqlTuple"IgnoreHandle"szTemp );
    
/* -------------------------------- */
}

public 
IgnoreHandleFailStateHandle:QueryError[ ], ErrcodeData[ ], DataSize )
{
    if(
FailState)
    {
        
log_amx(Error);
    }
    
    
SQL_FreeHandleQuery );
}

public 
plugin_end()
    
g_iPlayers=0;

stock SQL_IsFailFailStateErrcodeError[ ] )
{
    if( 
FailState == TQUERY_CONNECT_FAILED )
    {
        
log_amx"[qServerinfo] Could not connect to SQL database: %s"Error );
        return 
true;
    }
    
    if( 
FailState == TQUERY_QUERY_FAILED )
    {
        
log_amx"[qServerinfo] Query failed: %s"Error );
        return 
true;
    }
    
    if( 
Errcode )
    {
        
log_amx"[qServerinfo] Error on query: %s"Error );
        return 
true;
    }
    
    return 
false;
}  
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2070\\ f0\\ fs16 \n\\ par }
*/ 
jonatat is offline
jonatat
Senior Member
Join Date: Dec 2017
Old 06-05-2018 , 10:21   Re: qServerinfo count disconnected players bug
Reply With Quote #2

Any help?
jonatat is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 06-05-2018 , 11:31   Re: qServerinfo count disconnected players bug
Reply With Quote #3

Wait for bump a thread.
iceeedr is offline
Send a message via Skype™ to iceeedr
jonatat
Senior Member
Join Date: Dec 2017
Old 06-06-2018 , 11:15   Re: qServerinfo count disconnected players bug
Reply With Quote #4

bumo
jonatat is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 06-08-2018 , 09:10   Re: qServerinfo count disconnected players bug
Reply With Quote #5

Much easier to use a game monitor for this instead of saving to mySQL with a plugin.
4ever16 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 10:33.


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