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

Connections Counter


Post New Thread Reply   
 
Thread Tools Display Modes
Lolz0r
Veteran Member
Join Date: Nov 2010
Location: Balgaria
Old 02-19-2012 , 12:05   Re: Connections Counter
Reply With Quote #161

Hey Bugsy, your system has bugs, here's photos:


Then it restarts(Connections)



After as added "debug" nothing shows in console, but it bothers me.

And the last thing I noticed - chat not shows in the console. If you can fix problems.

EDIT: I use nVault version.

Last edited by Lolz0r; 02-19-2012 at 12:36.
Lolz0r is offline
naSTR
Veteran Member
Join Date: Dec 2011
Location: Asia, Mongolia
Old 03-02-2012 , 10:17   Re: Connections Counter
Reply With Quote #162

Quote:
Originally Posted by lazarev View Post
[EDIT] This version Saves leave message:
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < nvault >

new const VERSION[] = "0.0.8";
new const 
PREFIX[] = "[CC] ";

new 
Connects33 ];
new 
szConnectStatus33 ][ ];

new 
g_iMsgSayText;
new 
g_vSaveFile;

new 
iPlayers33 ][ 32 ];
new 
iNum33 ];

new 
g_szLeaveMessage33 ][ 64 ];

new 
bool:g_bVeteran33 ];

public 
plugin_init()
{
    
register_plugin"Advanced Connections Counter"VERSION"Juice" );
    
    
register_cvar"connects_count"VERSIONFCVAR_SERVER FCVAR_SPONLY ); 
    
    
register_clcmd"say""HookSay" );
    
register_clcmd"say_team""HookSay_Team" );
    
    
g_iMsgSayText get_user_msgid"SayText" );
    
    
g_vSaveFile nvault_open"ConnectCount" );
}

public 
client_putinserverid )
{
    if( !
is_user_botid ) )
    {
        if( 
task_existsid ) )
        {
            
remove_taskid );
        }
        
        
LoadDataid );
        ++
Connectsid ];
        
        if ( 
is_user_adminid ) )
        {
            
szConnectStatusid ] = "Admin";
            
g_bVeteranid ] = true;
        }
        else 
        {
            if( 
Connectsid ] <= 100 
            {
                
szConnectStatusid ] = "Newbie";
            }
            else if( 
100 Connectsid ] <= 500 )
            {
                
szConnectStatusid ] = "Semi-Pro";
            }
            else if( 
500 Connectsid ] <= 750 )
            {
                
szConnectStatusid ] = "Pro";
            }
            else if( 
Connectsid ] > 750 
            {
                
szConnectStatusid ] = "Veteran";
                
g_bVeteranid ] = true;
            }
        }
        
set_task2.0"PrintZ0r"id ); 
    }
}

public 
PrintZ0rid )
{
    new 
szName33 ], szMessage128 ];
    
get_user_nameidszName32 );
    
formatszMessage127"^x04%s^x03%s have joined with^x04 %i^x03 Connections. [^x04Status: %s^x03]"PREFIXszNameConnectsid ], szConnectStatusid ] );
    Print( 
01szMessage )
}

public 
client_disconnectid 
{  
    if( !
is_user_botid ) )
    {
        new 
szName33 ], szMessage128 ];
        
get_user_nameidszName32 );
        
SaveDataid );
        
        if( 
g_bVeteranid ] )
        {
            
formatszMessage127"^x04%s^x03Veteran: %s has left the server. [^x04Message: %s^x03]"PREFIXszNameg_szLeaveMessageid ] );
            Print( 
01szMessage )
            
g_bVeteranid ] = false;
        }
        else 
        {
            
g_szLeaveMessageid ] = " ";
        }
        if( 
task_existsid ) )
        {
            
remove_taskid );
        }
    }
}  

public 
SaveDataid 

    new 
szAuthID20 ];
    new 
vaultkey20 ], vaultdata128 ]; 
    
    
get_user_authididszAuthID19 );
    
    
formatvaultkey19"%s"szAuthID );
    
formatvaultdata127" %i %s "Connectsid ], g_szLeaveMessageid ] ); 

    
nvault_setg_vSaveFilevaultkeyvaultdata ); 
    
    return 
PLUGIN_CONTINUE
}  

public 
LoadDataid 

    new 
szAuthID20 ]; 
    new 
vaultkey20 ], vaultdata128 ];
    new 
ConnectCount33 ];
    new 
LeaveMsg64 ];
    
    
get_user_authididszAuthID19 ); 
    
    
formatvaultkey19"%s"szAuthID ); 
    
formatvaultdata127" %i %s "Connectsid ], g_szLeaveMessageid ] ); 
    
    
nvault_getg_vSaveFilevaultkeyvaultdata127 ); 
    
    
parsevaultdataConnectCount32LeaveMsg63 ); 
    
    
Connectsid ] = str_to_numConnectCount ); 
    
g_szLeaveMessageid ] = LeaveMsg;
    
    return 
PLUGIN_CONTINUE
}  

public 
HookSayid )
{
    new 
szMessage257 ];
    
read_argsszMessage256 );
    
remove_quotesszMessage );
    
    new 
szName33 ];
    
get_user_nameidszName32 );
    
    if( 
g_bVeteranid ] )
    {
        if( 
szMessage] == '/' && szMessage] == 'e' && szMessage] == 'v' && szMessage] == 'm' )
        {
            new 
Arg64 ];
            
strbreakszMessageszMessage95Arg63 );
            
remove_quotesArg );
        
            if( !
Arg] )
            {
                if( 
g_szLeaveMessageid ][ ] )
                {
                    
client_printidprint_chat"%sYour current leave message is ^"%s^""PREFIXg_szLeaveMessageid ] );
                }
                else
                {
                    
client_printidprint_chat"%sYou haven't set a leave message yet. To do so, type /leavemsg ^"message^"."PREFIX );
                }
            }
        
            else if( 
equaliArg"remove" ) )
            {
                
g_szLeaveMessageid ] = "No Message Set";
                
client_printidprint_chat"%sYour leave message was removed."PREFIX )
            }
            else
            {
                
copyg_szLeaveMessageid ], 63Arg )
                
client_printidprint_chat"%sYour leave message has been set to ^"%s^""PREFIXArg );
            }
            return 
PLUGIN_CONTINUE;
        }
    }
    
    if ( 
szMessage[0] == '@' || szMessage[0] == '/' || szMessage[0] == '!' || equal (szMessage"") )
    {
        return 
PLUGIN_CONTINUE;
    }
    
    if ( 
is_user_aliveid ) )
    {
        
formatszMessage255"^x04[%s]^x03 %s^x01 :  %s"szConnectStatusid ], szNameszMessage );
        Print(
0idszMessage)
    }
    else if ( 
cs_get_user_teamid ) != CS_TEAM_SPECTATOR )
    {
        
formatszMessage255"^x04[%s]^x01 *DEAD*^x03 %s^x01 :  %s"szConnectStatusid ], szNameszMessage );
        Print(
0idszMessage)
    }
    else 
    {
        
formatszMessage255"^x04[%s]^x01 *SPEC*^x03 %s^x01 :  %s"szConnectStatusid ], szNameszMessage );
        Print(
0idszMessage)
    }
    return 
PLUGIN_HANDLED;
}

public 
HookSay_Teamid )
{
    new 
szMessage257 ];
    
read_argsszMessage256 );
    
remove_quotesszMessage );
    
    new 
szName33 ], szTeam33 ];
    
get_user_nameidszName32 );
        
    new 
CsTeams:userteam cs_get_user_teamid );

    if ( 
szMessage[0] == '@' || szMessage[0] == '/' || szMessage[0] == '!' || equalszMessage"" ) )
    {
        return 
PLUGIN_CONTINUE;
    }
    
    if ( 
userteam == CS_TEAM_T )
    {
        
get_playersiPlayersid ], iNumid ], _"TERRORIST" );
        
szTeam "(Terrorist)";
    }
    else if ( 
userteam == CS_TEAM_CT )
    {
        
get_playersiPlayersid ], iNumid ], _"CT" );
        
szTeam "(Counter-Terrorists)";
    }
    else
    {
        
get_playersiPlayersid ], iNumid ], _"SPECTATOR" );
        
szTeam "(Spectator)";
    }
    for ( new 
0iNumid ]; ++)
    {
        new 
iPlayersid ][ ];
        if( 
cs_get_user_team) != userteam )
        {
            return 
PLUGIN_HANDLED;
        }
        
        if ( 
is_user_aliveid ) )
        {
            
formatszMessage255"^x04[%s]^x01 %s^x03 %s^x01 :  %s"szConnectStatusid ], szTeamszNameszMessage );
            Print( 
iidszMessage )
        }
        else if (!
is_user_alive(id) && userteam != CS_TEAM_SPECTATOR)
        {
            
formatszMessage255"^x04[%s]^x01 *DEAD* %s^x03 %s^x01 :  %s"szConnectStatusid ], szTeamszNameszMessage );
            Print( 
iidszMessage )
        }
        else
        {
            
formatszMessage255"^x04[%s]^x01 %s^x03 %s^x01 :  %s"szConnectStatusid ], szTeamszNameszMessage );
            Print( 
iidszMessage )
        }
    }
    return 
PLUGIN_HANDLED;
}

Print( 
idcoloridszMessage[], any:... )
{
    
message_beginid MSG_ONE_UNRELIABLE MSG_BROADCASTg_iMsgSayText_id );
    
write_bytecolorid );
    
write_stringszMessage );
    
message_end( );

Someone fix this. Have retry bug. Save connect count by name will be much better for me. Exolent's version not working
__________________
naSTR is offline
Lolz0r
Veteran Member
Join Date: Nov 2010
Location: Balgaria
Old 04-08-2012 , 12:15   Re: Connections Counter
Reply With Quote #163

Quote:
Originally Posted by Lolz0r View Post
Hey Bugsy, your system has bugs, here's photos:


Then it restarts(Connections)



After as added "debug" nothing shows in console, but it bothers me.

And the last thing I noticed - chat not shows in the console. If you can fix problems.

EDIT: I use nVault version.
Bugsy, bump!
Lolz0r is offline
xakintosh
I run no-steam servers!
Join Date: Feb 2010
Location: Edge of nowhere
Old 10-22-2012 , 16:32   Re: Connections Counter
Reply With Quote #164

Hello again guys. I have edited the @Bugsy version a just little bit ( i hope not to get in any troubles.). I make the code more friendly. And only SQL and STEAM.
Let's get to the point. I have a few new ideas fit perfectly in the plugin.

• This was some nice request. http://forums.alliedmods.net/showthread.php?t=191050
• I trying to implent this protection K.K.Lv

I know the plugin updates the MySQL on every disconnect from server, so some players maybe wanna to crash it or etc. also i don't like to have much mysql request ( don't ask me ).

• My Attemps Bellow:
I have trying with automatic MySQL system update on every 5 mins after player join the server but i don't like to make one Huge MySQL request in just one sec.
I also try to make loading system, when player connect to the server to have just one query that print his status, and with the Auto MySQL System to sync him late in MySQL.
And couple of days i have been thinking for best solution and i think i got it. To count the connections and if player have 3 successfull retry with the server to get more CC to get him banned for (1min or 30sec)

After this is done will continue to make small lite request and soon we will get some Advanced Plugin for Connections be sure, i got some crazy ideas that are quite funny and easy.
If is possible to optimize the plugin to the maximum. ( To Clear the code a little bit from errors and make it friendly
Right now i have problems with detection from
@K.K.Lv
Also sometimes have problems when _putinserver sometimes shows 1587432days and 0 0 0. - maybe set_task will fix it. ( cannot catch it yet )

Changelog:
I give it same extra RAM [#pragma dynamic 16384]
3. Added Cvar to determine the time between messages to prevent spam messages. Fixed bug with e blank message.
2. Fixed problem with the first connection of the player, it shows that there are two connectors instead of one.
1. Concise code and Sqlx repaired query system is also modified by the cvars for sql host.


Code:
// *************************************************************************************************
//	####    #### ###### ####      ##   ## ###### ##   ## ######
//	## ##  ## ## ##  ## ##  #	###   ##  ##  ## ##  ##	
//	##  ###   ## ###### ##  #       ###   ######   ###   ##
//	##        ## ##  ## ####      ##   ## ##  ##   ##    ######
// *************************************************************************************************
// THIS PLUGIN IS EDITED BY MAD.XayC • SKYPE: X3NOMORPF • MAIL: [email protected]
// *************************************************************************************************
// 	• MYSQL ONLY • STEAM ONLY
// Thnx: 
// 	@Bugsy ==> He is  the Author!
//      @K.K.Lv ==> For his awesome plugin here >> https://forums.alliedmods.net/showpost.php?p=1763040&postcount=5
//
// Date: 2012.22.10
// *************************************************************************************************

#include <amxmodx> 
#include <cstrike> 
#include <fakemeta>
#include <sqlx> 
#pragma dynamic 16384

#define fClearTrieTime      12.4
#define iConnectionBanCount  3

#define NAMEOF_DB    "cs_db"
#define CREATE_DB    "CREATE TABLE IF NOT EXISTS `playtime_cc` (`key` VARCHAR(128) NOT NULL, `data` VARCHAR(255) NOT NULL, `timestamp` INT(11) NOT NULL, PRIMARY KEY (`key`))"
#define SEARCH_DB    "SELECT `data` , `timestamp` FROM `playtime_cc` WHERE `key`='%s' LIMIT 1" 
#define INSERT_DB    "REPLACE INTO `playtime_cc` (`key`,`data`,`timestamp`) VALUES ('%s','%s','%d')" 

// *************************************************************************************************
// Bellow you can add your own Status (I open i door for you just look in too the code)
// *************************************************************************************************
enum ConnectionStatus { 
	Newbie, 
	SemiPro, 
	Pro, 
	/*	UltraPro,	*/
	Veteran 
} 
new const StatusDescription[ConnectionStatus][] = { 
	"Newbie", 
	"Semi-Pro", 
	"Pro", 
	/*	"UltraPro",	*/
	"Veteran" 
}
enum StatusLevelRange { 
	Floor, 
	Ceiling 
} 
new const StatusLevels[ConnectionStatus][StatusLevelRange] = { 
	{ 0 , 100 },     
	{ 101 , 500 }, 
	{ 501 , 750 },
	{ 751 , 99999 } 
	/*	{ 751 , 1000 }, 	// UltraPro*/
	/*	{ 1000 , 99999 }	// Veteran*/
} 
// =================================================================================================
new const Teams[ CsTeams ][] = { 
	"(Unassigned)", 
	"(Terrorist)",  
	"(Counter-Terrorist)", 
	"(Spectator)" 
} 
enum PlayerData { 
	Name[33], 
	AuthID[35], 
	Connections, 
	Status, 
	PlayTime, 
	LeaveMsg[33] 
} 
// =================================================================================================
const MAX_PLAYERS = 32
new Float:lastmsg[33]
new Handle:g_iSQLTuple
new g_szDBQueryCache[1024]
new g_PData[MAX_PLAYERS + 1][PlayerData]
new g_iConnectTime[MAX_PLAYERS + 1]
new bool:g_bIsBot[MAX_PLAYERS + 1]
new g_iMsgSayText
new g_iMaxPlayers
new g_pAllChat
new g_pAllChatS
new connection_host
new connection_user
new connection_pass
new Trie:ghTrie;
// =================================================================================================
public plugin_init() { 
	register_plugin("Connections and Time", "0.6", "bugsy")
	// ======================================================
	register_clcmd("say", "HookSay")
	register_clcmd("say_team", "HookSay_Team")
	// ==================================================
	connection_host = register_cvar("connection_sql_host", "localhost")
	connection_user = register_cvar("connection_sql_user", "root")
	connection_pass = register_cvar("connection_sql_pass", "toosecretforyou", FCVAR_PROTECTED)
	g_pAllChat = register_cvar("cat_allchat" , "0")
	g_pAllChatS = register_cvar("cat_spam", "1.0")
	g_iMsgSayText = get_user_msgid("SayText")
	g_iMaxPlayers = get_maxplayers()
	// ==================================================
	register_forward(FM_ClientPutInServer, "onPost", true);
	ghTrie = TrieCreate()
} 
// =================================================================================================
bool:CheckSpam(const id) {
	new Float:gametime = get_gametime()   
	if(is_user_connected(id)) {
		if(lastmsg[id]  < gametime) {
			lastmsg[id] = gametime + get_pcvar_float(g_pAllChatS)
			return false
		}
	}
	return true
}
// =================================================================================================
public HookSay(id) { 
	if(CheckSpam(id)) { return PLUGIN_HANDLED; }
	// ========================================
	static szMessage[256], szMsgSaid[256]
	new bool:bIsAlive , bool:bAllChat
	read_args(szMsgSaid, charsmax(szMsgSaid))
	remove_quotes(szMsgSaid)
	if(equal(szMsgSaid, "")) { return PLUGIN_HANDLED; }
	//	leavemsg 
	if(ConnectionStatus:g_PData[id][Status] == Veteran) { 
		if(szMsgSaid[0] == '/' && szMsgSaid[2] == 'e' && szMsgSaid[4] == 'v' && szMsgSaid[6] == 'm') { 
			new Arg[64]
			strbreak(szMsgSaid, szMsgSaid, 95, Arg, 63)
			remove_quotes(Arg)
			if(!Arg[0]) { 
				if(g_PData[id][LeaveMsg][0]) { 
					client_print(id, print_chat, "* Your current leave message is ^"%s^"", g_PData[id][LeaveMsg]) 
					} else { 
					client_print(id ,print_chat, "* You haven't set a leave message yet. To do so, type /leavemsg ^"message^".")
				} 
			} 
			else if(equali(Arg , "remove")) { 
				g_PData[id][LeaveMsg][0] = EOS 
				client_print(id, print_chat , "* Your leave message was removed.") 
				} else { 
				copy(g_PData[id][LeaveMsg], charsmax(g_PData[][LeaveMsg]), Arg)
				client_print(id, print_chat, "* Your leave message has been set to ^"%s^"", Arg) 
			} 
			return PLUGIN_HANDLED 
		} 
	} 
	//	playtime 
	if(szMsgSaid[0] == '/' && szMsgSaid[1] == 'p' && szMsgSaid[4] == 'y' && szMsgSaid[7] == 'm') { 
		new iHours, iDays, iMinutes, iCurTime
		static szPlayTime[128], iPos
		formatex(szMessage, charsmax(szMessage), "^x04*^x03 You currently have^x04 %d^x03 connections. [^x04Status: %s^x03]" , g_PData[id][Connections], StatusDescription[ConnectionStatus:g_PData[id][Status]]) 
		Print(id, id, szMessage)
		iCurTime = g_PData[id][PlayTime] + (get_systime() - g_iConnectTime[id]) 
		iPos = 0
		if(iCurTime >= 86400) { 
			iDays = iCurTime / 86400
			iCurTime -= iDays * 86400
			iPos = formatex(szPlayTime, charsmax(szPlayTime), "%d days, ", iDays) 
		} 
		if(iCurTime >= 3600) { 
			iHours = iCurTime / 3600
			iCurTime -= iHours * 3600
			iPos += formatex(szPlayTime[iPos], charsmax(szPlayTime) - iPos, "%d hour%s, ", iHours, iHours > 1 ? "s" : "")
		} 
		if(iCurTime >= 60) { 
			iMinutes = iCurTime / 60
			iCurTime -= iMinutes * 60
			iPos += formatex(szPlayTime[iPos], charsmax(szPlayTime) - iPos, "%d minute%s, ", iMinutes, iMinutes > 1 ? "s" : "")
		} 
		if(iCurTime) { 
			iPos += formatex(szPlayTime[iPos], charsmax(szPlayTime) - iPos, "%d second%s, ", iCurTime, iCurTime > 1 ? "s" : "")
		} 
		szPlayTime[ iPos - 2 ] = EOS
		formatex(szMessage, charsmax(szMessage), "^x04*^x03 You have played on this server for:^x04 %s", szPlayTime) 
		Print(id, id, szMessage) 
		return PLUGIN_HANDLED
	} 
	bIsAlive = bool:!!is_user_alive(id)
	bAllChat = bool:!!get_pcvar_num(g_pAllChat)
	if(bIsAlive) 
		formatex(szMessage, charsmax(szMessage), "^x04[%s]^x03 %s^x01 :  %s", StatusDescription[ConnectionStatus:g_PData[id][Status]] , g_PData[id][Name] , szMsgSaid)
	else  
		formatex(szMessage, charsmax(szMessage), "^x04[%s]^x01 %s^x03 %s^x01 :  %s", StatusDescription[ConnectionStatus:g_PData[id][Status]], (cs_get_user_team(id) != CS_TEAM_SPECTATOR) ? "*DEAD*" : "*SPEC*" , g_PData[id][Name], szMsgSaid)
	for(new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++) 
		if(is_user_connected(iPlayer) && (bAllChat || (bIsAlive || (!bIsAlive && !is_user_alive(iPlayer))))) 
		Print(iPlayer, id, szMessage)
	return PLUGIN_HANDLED
} 
// =================================================================================================
public HookSay_Team(id) { 
	if(CheckSpam(id)) { return PLUGIN_HANDLED; }
	// ========================================
	static szMessage[256], szMsgSaid[256]
	new CsTeams:iTeam, bool:bIsAlive, bool:bAllChat
	read_args(szMsgSaid, charsmax(szMsgSaid))
	remove_quotes(szMsgSaid)
	if(equal(szMsgSaid, "")) { return PLUGIN_HANDLED; }
	iTeam = cs_get_user_team(id)
	bIsAlive = bool:!!is_user_alive(id)
	bAllChat = bool:!!get_pcvar_num(g_pAllChat)
	if(bIsAlive || (iTeam == CS_TEAM_SPECTATOR)) 
		formatex(szMessage, charsmax(szMessage), "^x04[%s]^x01 %s^x03 %s^x01 :  %s", StatusDescription[ConnectionStatus:g_PData[id][Status]], Teams[iTeam], g_PData[id][Name], szMsgSaid)
	else  
		formatex(szMessage, charsmax(szMessage), "^x04[%s]^x01 *DEAD* %s^x03 %s^x01 :  %s", StatusDescription[ConnectionStatus:g_PData[id][Status]], Teams[iTeam], g_PData[id][Name], szMsgSaid) 
	for(new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) 
		if((is_user_connected(iPlayer) && (cs_get_user_team(iPlayer) == iTeam)) && (bAllChat || (bIsAlive || (!bIsAlive && !is_user_alive(iPlayer))))) 
		Print(iPlayer, id, szMessage)
	return PLUGIN_HANDLED
} 
// =================================================================================================
Print(id, colorid, szMessage[]) { 
	message_begin(id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, g_iMsgSayText, {0,0,0}, id)
	write_byte(colorid)
	write_string(szMessage)
	message_end()
} 
public ShowJoinMsg(id) { 
	static szMessage[128] 
	formatex(szMessage, charsmax(szMessage), "^x04* ^x03%s has joined with^x04 %d^x03 connections. [^x04Status: %s^x03]", g_PData[id][Name], g_PData[id][Connections], StatusDescription[ConnectionStatus:g_PData[id][Status]])
	Print(0, 1, szMessage)
} 
// *************************************************************************************************
// This is the part ot the plugin that working the information with sql
// *************************************************************************************************
public plugin_cfg() { 
	new szHost[64], szUser[64], szPass[64]
	get_pcvar_string(connection_host, szHost, charsmax(szHost))
	get_pcvar_string(connection_user, szUser, charsmax(szUser))
	get_pcvar_string(connection_pass, szPass, charsmax(szPass))
	g_iSQLTuple = SQL_MakeDbTuple(szHost, szUser, szPass, NAMEOF_DB)
	formatex(g_szDBQueryCache, 1023, CREATE_DB) 
	SQL_ThreadQuery(g_iSQLTuple, "DefaultHandle", g_szDBQueryCache) 
} 
public ClearValueFromTrie(params[]) {
	static szAddress[32];
	copy(szAddress, 31, params);
	TrieDeleteKey(ghTrie , szAddress);
	return PLUGIN_CONTINUE;
}
// =================================================================================================
public plugin_end() { SQL_FreeHandle(g_iSQLTuple); TrieClear(ghTrie); } 
// =================================================================================================
public SearchHandle(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) { 
	if(FailState == TQUERY_CONNECT_FAILED) 
		return set_fail_state("Could not connect to SQL database.")
	else if(FailState == TQUERY_QUERY_FAILED) 
		return set_fail_state("SQL Query failed.") 
	if(Errcode) 
		return log_amx("SQL Error on query: %s", Error)
	static szData[128], szConnections[5], szStatus[2], szPlayTime[8]
	new id = Data[0]
	if(SQL_MoreResults(Query)) { 
		SQL_ReadResult(Query, 0, szData, charsmax(szData))
		parse(szData, g_PData[id][Name], charsmax(g_PData[][Name]), g_PData[id][AuthID], charsmax(g_PData[][AuthID]), szConnections, charsmax(szConnections), szStatus , charsmax(szStatus), szPlayTime, charsmax(szPlayTime), g_PData[id][LeaveMsg], charsmax(g_PData[][LeaveMsg]))
		g_PData[id][Connections] = str_to_num(szConnections)
		g_PData[id][PlayTime] = str_to_num(szPlayTime)
	} 
	g_PData[id][Connections]++ 
	g_iConnectTime[id] = get_systime()
	for(new ConnectionStatus:i = Newbie; i < Veteran; i++) { 
		if(StatusLevels[i][Floor] <= g_PData[id][Connections] <= StatusLevels[i][Ceiling]) { 
			g_PData[id][Status] = _:i
			break
		} 
	} 
	get_user_name(id, g_PData[id][Name], charsmax(g_PData[][Name]))
	set_task(6.0, "ShowJoinMsg", id)
	return PLUGIN_CONTINUE
} 
// =================================================================================================
public DefaultHandle(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) { 
	if(FailState == TQUERY_CONNECT_FAILED) 
		return set_fail_state("Could not connect to SQL database.")
	else if(FailState == TQUERY_QUERY_FAILED) 
		return set_fail_state("SQL Query failed.")
	if(Errcode) 
		return log_amx("SQL Error on query: %s", Error)
	return PLUGIN_CONTINUE
}
// =================================================================================================
public onPost(id, const szName[] , const szAddress[], const szRejectReason[128]) { 
	if (pev(id, pev_flags) & FL_FAKECLIENT) { return FMRES_IGNORED; }
	if (szAddress[0] == 0) { return FMRES_IGNORED; }
	static iConnectionCount;
	static params[32];
	if (!TrieGetCell(ghTrie, szAddress, iConnectionCount)) {
		g_bIsBot[id] = bool:!!is_user_bot(id) 
		if(g_bIsBot[id]) return PLUGIN_CONTINUE
		copy(params, 31, szAddress);
		set_task(fClearTrieTime, "ClearValueFromTrie", 0, params, 32);
		TrieSetCell( ghTrie , szAddress, 0 );
		get_user_authid(id, g_PData[id][AuthID], charsmax(g_PData[][AuthID]))
		new iData[1]
		iData[0] = id
		formatex(g_szDBQueryCache, 255, SEARCH_DB , g_PData[id][AuthID])
		SQL_ThreadQuery(g_iSQLTuple, "SearchHandle", g_szDBQueryCache, iData, sizeof(iData))
		return PLUGIN_CONTINUE
	}
	if (iConnectionCount == iConnectionBanCount) {	
		set_task(3.0,"fight_him", id)
		return FMRES_HANDLED
		
	}
	TrieSetCell(ghTrie, szAddress, (iConnectionCount+1));
	return FMRES_IGNORED;
} 
public fight_him(id) {
	new szName[32]
	get_user_name(id, szName, charsmax(szName))
	server_cmd("amx_ban %s 1 SPAM", szName);
}
// =================================================================================================
public client_infochanged(id) {     
	static szNewName[33]
	get_user_info(id, "name", szNewName, 32)
	if(!equal(g_PData[id][Name], szNewName)) 
		copy(g_PData[id][Name], charsmax(g_PData[][Name]), szNewName) 
} 
// =================================================================================================
public client_disconnect(id) { 
	static szMessage[128] 
	if(g_bIsBot[id]) return PLUGIN_CONTINUE
	remove_task(id)
	g_PData[id][PlayTime] += (get_systime() - g_iConnectTime[id])
	formatex(szMessage, charsmax(szMessage), "^"%s^" ^"%s^" ^"%d^" ^"%d^" ^"%d^" ^"%s^"", g_PData[id][Name], g_PData[id][AuthID], g_PData[id][Connections], g_PData[id][Status], g_PData[id][PlayTime], g_PData[id][LeaveMsg]) 
	formatex(g_szDBQueryCache, 511, INSERT_DB, g_PData[id][AuthID], szMessage, get_systime())
	SQL_ThreadQuery(g_iSQLTuple, "DefaultHandle" ,g_szDBQueryCache)
	if(ConnectionStatus:g_PData[id][Status] == Veteran) { 
		formatex(szMessage, charsmax(szMessage), "^x04* ^x03Veteran: %s has left the server. [^x04Message: %s^x03]", g_PData[id][Name], g_PData[id][LeaveMsg])
		Print(0, 1, szMessage)
	} 
	g_PData[id][Name][0] = EOS
	g_PData[id][AuthID][0] = EOS
	g_PData[id][Connections] = 0
	g_PData[id][Status] = 0
	g_PData[id][PlayTime] = 0
	g_PData[id][LeaveMsg][0] = EOS
	g_iConnectTime[id] = 0
	return PLUGIN_CONTINUE 
} 
// *************************************************************************************************
//	####    #### ###### ####      ##   ## ###### ##   ## ######
//	## ##  ## ## ##  ## ##  #	###   ##  ##  ## ##  ##	
//	##  ###   ## ###### ##  #       ###   ######   ###   ##
//	##        ## ##  ## ####      ##   ## ##  ##   ##    ######
// *************************************************************************************************
Please do not using in public servers, this version is not working, it's in alpha stage for new update.
__________________
As soon as possible.

Last edited by xakintosh; 10-22-2012 at 17:03.
xakintosh is offline
Send a message via Yahoo to xakintosh Send a message via Skype™ to xakintosh
redkobra
New Member
Join Date: Dec 2010
Old 03-17-2013 , 10:38   Re: Connections Counter
Reply With Quote #165

Can anyone make a living can not see what they write dead... dont give me another code ,just make this code with out allchat please =]


Quote:
Originally Posted by lazarev View Post
[EDIT] This version Saves leave message:
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < nvault >

new const VERSION[] = "0.0.8";
new const 
PREFIX[] = "[CC] ";

new 
Connects33 ];
new 
szConnectStatus33 ][ ];

new 
g_iMsgSayText;
new 
g_vSaveFile;

new 
iPlayers33 ][ 32 ];
new 
iNum33 ];

new 
g_szLeaveMessage33 ][ 64 ];

new 
bool:g_bVeteran33 ];

public 
plugin_init()
{
    
register_plugin"Advanced Connections Counter"VERSION"Juice" );
    
    
register_cvar"connects_count"VERSIONFCVAR_SERVER FCVAR_SPONLY ); 
    
    
register_clcmd"say""HookSay" );
    
register_clcmd"say_team""HookSay_Team" );
    
    
g_iMsgSayText get_user_msgid"SayText" );
    
    
g_vSaveFile nvault_open"ConnectCount" );
}

public 
client_putinserverid )
{
    if( !
is_user_botid ) )
    {
        if( 
task_existsid ) )
        {
            
remove_taskid );
        }
        
        
LoadDataid );
        ++
Connectsid ];
        
        if ( 
is_user_adminid ) )
        {
            
szConnectStatusid ] = "Admin";
            
g_bVeteranid ] = true;
        }
        else 
        {
            if( 
Connectsid ] <= 100 
            {
                
szConnectStatusid ] = "Newbie";
            }
            else if( 
100 Connectsid ] <= 500 )
            {
                
szConnectStatusid ] = "Semi-Pro";
            }
            else if( 
500 Connectsid ] <= 750 )
            {
                
szConnectStatusid ] = "Pro";
            }
            else if( 
Connectsid ] > 750 
            {
                
szConnectStatusid ] = "Veteran";
                
g_bVeteranid ] = true;
            }
        }
        
set_task2.0"PrintZ0r"id ); 
    }
}

public 
PrintZ0rid )
{
    new 
szName33 ], szMessage128 ];
    
get_user_nameidszName32 );
    
formatszMessage127"^x04%s^x03%s have joined with^x04 %i^x03 Connections. [^x04Status: %s^x03]"PREFIXszNameConnectsid ], szConnectStatusid ] );
    Print( 
01szMessage )
}

public 
client_disconnectid 
{  
    if( !
is_user_botid ) )
    {
        new 
szName33 ], szMessage128 ];
        
get_user_nameidszName32 );
        
SaveDataid );
        
        if( 
g_bVeteranid ] )
        {
            
formatszMessage127"^x04%s^x03Veteran: %s has left the server. [^x04Message: %s^x03]"PREFIXszNameg_szLeaveMessageid ] );
            Print( 
01szMessage )
            
g_bVeteranid ] = false;
        }
        else 
        {
            
g_szLeaveMessageid ] = " ";
        }
        if( 
task_existsid ) )
        {
            
remove_taskid );
        }
    }
}  

public 
SaveDataid 

    new 
szAuthID20 ];
    new 
vaultkey20 ], vaultdata128 ]; 
    
    
get_user_authididszAuthID19 );
    
    
formatvaultkey19"%s"szAuthID );
    
formatvaultdata127" %i %s "Connectsid ], g_szLeaveMessageid ] ); 

    
nvault_setg_vSaveFilevaultkeyvaultdata ); 
    
    return 
PLUGIN_CONTINUE
}  

public 
LoadDataid 

    new 
szAuthID20 ]; 
    new 
vaultkey20 ], vaultdata128 ];
    new 
ConnectCount33 ];
    new 
LeaveMsg64 ];
    
    
get_user_authididszAuthID19 ); 
    
    
formatvaultkey19"%s"szAuthID ); 
    
formatvaultdata127" %i %s "Connectsid ], g_szLeaveMessageid ] ); 
    
    
nvault_getg_vSaveFilevaultkeyvaultdata127 ); 
    
    
parsevaultdataConnectCount32LeaveMsg63 ); 
    
    
Connectsid ] = str_to_numConnectCount ); 
    
g_szLeaveMessageid ] = LeaveMsg;
    
    return 
PLUGIN_CONTINUE
}  

public 
HookSayid )
{
    new 
szMessage257 ];
    
read_argsszMessage256 );
    
remove_quotesszMessage );
    
    new 
szName33 ];
    
get_user_nameidszName32 );
    
    if( 
g_bVeteranid ] )
    {
        if( 
szMessage] == '/' && szMessage] == 'e' && szMessage] == 'v' && szMessage] == 'm' )
        {
            new 
Arg64 ];
            
strbreakszMessageszMessage95Arg63 );
            
remove_quotesArg );
        
            if( !
Arg] )
            {
                if( 
g_szLeaveMessageid ][ ] )
                {
                    
client_printidprint_chat"%sYour current leave message is ^"%s^""PREFIXg_szLeaveMessageid ] );
                }
                else
                {
                    
client_printidprint_chat"%sYou haven't set a leave message yet. To do so, type /leavemsg ^"message^"."PREFIX );
                }
            }
        
            else if( 
equaliArg"remove" ) )
            {
                
g_szLeaveMessageid ] = "No Message Set";
                
client_printidprint_chat"%sYour leave message was removed."PREFIX )
            }
            else
            {
                
copyg_szLeaveMessageid ], 63Arg )
                
client_printidprint_chat"%sYour leave message has been set to ^"%s^""PREFIXArg );
            }
            return 
PLUGIN_CONTINUE;
        }
    }
    
    if ( 
szMessage[0] == '@' || szMessage[0] == '/' || szMessage[0] == '!' || equal (szMessage"") )
    {
        return 
PLUGIN_CONTINUE;
    }
    
    if ( 
is_user_aliveid ) )
    {
        
formatszMessage255"^x04[%s]^x03 %s^x01 :  %s"szConnectStatusid ], szNameszMessage );
        Print(
0idszMessage)
    }
    else if ( 
cs_get_user_teamid ) != CS_TEAM_SPECTATOR )
    {
        
formatszMessage255"^x04[%s]^x01 *DEAD*^x03 %s^x01 :  %s"szConnectStatusid ], szNameszMessage );
        Print(
0idszMessage)
    }
    else 
    {
        
formatszMessage255"^x04[%s]^x01 *SPEC*^x03 %s^x01 :  %s"szConnectStatusid ], szNameszMessage );
        Print(
0idszMessage)
    }
    return 
PLUGIN_HANDLED;
}

public 
HookSay_Teamid )
{
    new 
szMessage257 ];
    
read_argsszMessage256 );
    
remove_quotesszMessage );
    
    new 
szName33 ], szTeam33 ];
    
get_user_nameidszName32 );
        
    new 
CsTeams:userteam cs_get_user_teamid );

    if ( 
szMessage[0] == '@' || szMessage[0] == '/' || szMessage[0] == '!' || equalszMessage"" ) )
    {
        return 
PLUGIN_CONTINUE;
    }
    
    if ( 
userteam == CS_TEAM_T )
    {
        
get_playersiPlayersid ], iNumid ], _"TERRORIST" );
        
szTeam "(Terrorist)";
    }
    else if ( 
userteam == CS_TEAM_CT )
    {
        
get_playersiPlayersid ], iNumid ], _"CT" );
        
szTeam "(Counter-Terrorists)";
    }
    else
    {
        
get_playersiPlayersid ], iNumid ], _"SPECTATOR" );
        
szTeam "(Spectator)";
    }
    for ( new 
0iNumid ]; ++)
    {
        new 
iPlayersid ][ ];
        if( 
cs_get_user_team) != userteam )
        {
            return 
PLUGIN_HANDLED;
        }
        
        if ( 
is_user_aliveid ) )
        {
            
formatszMessage255"^x04[%s]^x01 %s^x03 %s^x01 :  %s"szConnectStatusid ], szTeamszNameszMessage );
            Print( 
iidszMessage )
        }
        else if (!
is_user_alive(id) && userteam != CS_TEAM_SPECTATOR)
        {
            
formatszMessage255"^x04[%s]^x01 *DEAD* %s^x03 %s^x01 :  %s"szConnectStatusid ], szTeamszNameszMessage );
            Print( 
iidszMessage )
        }
        else
        {
            
formatszMessage255"^x04[%s]^x01 %s^x03 %s^x01 :  %s"szConnectStatusid ], szTeamszNameszMessage );
            Print( 
iidszMessage )
        }
    }
    return 
PLUGIN_HANDLED;
}

Print( 
idcoloridszMessage[], any:... )
{
    
message_beginid MSG_ONE_UNRELIABLE MSG_BROADCASTg_iMsgSayText_id );
    
write_bytecolorid );
    
write_stringszMessage );
    
message_end( );

redkobra 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:02.


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