Raised This Month: $32 Target: $400
 8% 

Solved is_user_admin(id) , does not check after map change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJBosma
Member
Join Date: Dec 2009
Old 03-14-2020 , 18:51   is_user_admin(id) , does not check after map change
Reply With Quote #1

EDIT: I've removed my code and attached Bugsy's plugin so you don't have to browse between the irrelevant comments.
Make sure you put this plugin under admin.amxx (does not work with amxbans, will update soon on other ban systems because I will have to find an alternative my self as well)


v0.4 - now checks if user already has flags and does not add them to vault. I’m using it with GM-x , and placing it user the user access control plugins. Works fine.

PHP Code:

#include <amxmodx>
#include <nvault>

new const Version[] = "0.4";

const 
DaySeconds 86400;

enum VeteranLevels
{
    
Player,
    
Veteran,
    
Pro
}
enum VeteranLevelData
{
    
SecondsNeeded,
    
VeteranFlags26 ],
    
VeteranBits
}
new 
VeteranInfoVeteranLevels ][ VeteranLevelData ] = 
{
    { 
"" },
    { 
1800 "fghji" },
    { 
3600 "fghjijklmnopqrstu" }
};

enum VeteranData
{
    
SteamID34 ],
    
bool:IsAdmin,
    
SecondsPlayed,
    
VeteranLevels:VeteranLevel
}
new 
PlayerDataMAX_PLAYERS ][ VeteranData ];

new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Veterans" Version "bugsy" );

    
register_event"HLTV" "NewRound" "a" "1=0" "2=0" );
    
    
register_clcmd"say !veteran" "VeteranSay" );
    
register_clcmd"say_team !veteran" "VeteranSay" );
    
    
register_clcmd"say !pro" "ProSay" );
    
register_clcmd"say_team !pro" "ProSay" );

    
register_clcmd"say !skill" "SkillSay" );
    
register_clcmd"say_team !skill" "SkillSay" );
}

public 
plugin_cfg()
{
    
nvault_prune( ( g_Vault nvault_open"veteran_data" ) ) , get_systime() - ( DaySeconds ) );
    
    for ( new 
VeteranLevels:Veteran VeteranLevels i++ )
    {
        
VeteranInfo][ VeteranBits ] = read_flagsVeteranInfo][ VeteranFlags ] );
    }
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szData11 ] , iTS;
    
    if ( !( 
PlayerDataid ][ IsAdmin ] = bool:( !( get_user_flagsid ) & ADMIN_USER ) ) ) )
    { 
        
get_user_authidid PlayerDataid ][ SteamID ] , charsmaxPlayerData[][ SteamID ] ) );
        
        if ( 
nvault_lookupg_Vault PlayerDataid ][ SteamID ] , szData charsmaxszData ) , iTS ) )
        {
            
PlayerDataid ][ SecondsPlayed ] = str_to_numszData );
            
SetVeteranLevelid );
        }
    }
}

public 
client_disconnectedid )
{
    new 
szSeconds11 ];
    
    if ( !
PlayerDataid ][ IsAdmin ] )
    {
        
num_to_strPlayerDataid ][ SecondsPlayed ] + get_user_timeid ) , szSeconds charsmaxszSeconds ) )
        
nvault_setg_Vault PlayerDataid ][ SteamID ] , szSeconds );
        
        
PlayerDataid ][ SecondsPlayed ] = 0;
        
PlayerDataid ][ VeteranLevel ] = Player;
    }
}

public 
VeteranSayid )
{
    
show_motdid "veteran_motd.txt" );
}

public 
ProSayid )
{
    
show_motdid "pro_motd.txt" );
}

public 
SkillSayid )
{
    if ( 
PlayerDataid ][ IsAdmin ] )
    {
        
client_printid  print_chat "* You are an admin" );
    }
    else
    {
        if ( 
PlayerDataid  ][ VeteranLevel ] < Pro )
        {
            
set_dhudmessage255 , -1.0 , -1.0 0.0 5.0 0.0 0.0 );
            
            switch ( 
PlayerDataid  ][ VeteranLevel ] )
            {
                case 
Player:
                {
                    
show_dhudmessageid  "To become veteran play %d minutes. Type !veteran" VeteranInfoVeteran ][ SecondsNeeded ] / 60 );
                }
                case 
Veteran:
                {
                    
show_dhudmessageid  "You are a Veteran. To become Pro play for %d minutes. Type !pro" VeteranInfoPro ][ SecondsNeeded ] / 60 );
                }
            }
        }
        else
        {
            
client_printid  print_chat "* You are a Pro player" );
        }
    }
}

public 
NewRound()
{
    new 
iPlayers32 ] , iNum iPlayer;
    
    
get_playersiPlayers iNum "ch" );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( !
PlayerDataiPlayer ][ IsAdmin ] )
        {
            
SetVeteranLeveliPlayer );
            
SkillSayiPlayer );
        }
    }
}

SetVeteranLevelid )
{
    new 
VeteranLevels:vlLevel Player;
    
    if ( 
PlayerDataid ][ VeteranLevel ] < Pro )
    {
        for ( new 
VeteranLevels:Pro >= Veteran i-- )
        {
            if ( 
PlayerDataid ][ SecondsPlayed ] >= VeteranInfo][ SecondsNeeded ] )
            {
                
vlLevel i;
                
remove_user_flagsid ADMIN_USER );
                
set_user_flagsid , ( get_user_flagsid ) | VeteranInfo][ VeteranBits ] ) );
                break;
            }
        }
        
        
PlayerDataid ][ VeteranLevel ] = vlLevel;
    }


Last edited by DJBosma; 03-30-2020 at 08:24. Reason: Bugsy plugin attached v0.4
DJBosma is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-14-2020 , 19:37   Re: is_user_admin(id) , does not check after map change
Reply With Quote #2

Explain your issue in your post. is_user_admin() will be accurate after client_authorized() since that is when AMX Mod X is able to verify who is who. Also, there is no guarantee that client_authorized() will be called at a certain time. It could be before or after client_putinserver().
__________________

Last edited by fysiks; 03-14-2020 at 19:38.
fysiks is offline
DJBosma
Member
Join Date: Dec 2009
Old 03-15-2020 , 04:11   Re: is_user_admin(id) , does not check after map change
Reply With Quote #3

When an user reaches X kills and X time played in the server a extra menu item pop’s up called ‘Receive extras’ and the user get’s certain flags. The menu does not open when the user has these flags loaded. They reload after next round even after user disconnects and connects again. The issue is that the user has to go thru the menu and select ‘receive flags’ after every change of map(when user stays connected).

Last edited by DJBosma; 03-15-2020 at 04:13.
DJBosma is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-15-2020 , 13:26   Re: is_user_admin(id) , does not check after map change
Reply With Quote #4

Did you take someone else's plugin and change things? I see a bunch of things commented out.. you can't expect it to magically continue to work when doing this unless you know what you're doing. Key item being client_authorized(), I would use this over client_putinserver().
__________________

Last edited by Bugsy; 03-15-2020 at 13:27.
Bugsy is offline
DJBosma
Member
Join Date: Dec 2009
Old 03-15-2020 , 15:01   Re: is_user_admin(id) , does not check after map change
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Did you take someone else's plugin and change things? I see a bunch of things commented out.. you can't expect it to magically continue to work when doing this unless you know what you're doing. Key item being client_authorized(), I would use this over client_putinserver().
The main reason I've changed things is because the clean version of the plugin does not work as well. It saved data on name but it had the same issue.

Quote:
Originally Posted by DJBosma
The issue is that the user has to go thru the menu and select ‘receive flags’ after every change of map(when user stays connected).
So here is the clean version..
Code:
#include <amxmodx>
#include <amxmisc>
#include <fvault>
#include <colorchat>

#define PLUGIN     "Become Admin"
#define VERSION    "1.0"
#define AUTHOR     "hackera457"

//#define CHECK_USER_BANNED

#define ADMIN_EXPIRED 2592000 /*30 days*/ /*Time in seconds*/



enum _:Settings
{
	BADMIN_REQUIRE_TIME,
	BADMIN_REQUIRE_KILLS,
	BADMIN_ADMIN_FLAGS
};

new const g_szDataVault[] = "BecomeAdmin_USER_Data";
new const g_szAdminsVault[] = "BecomeAdmin_ADMIN_DB";

new g_szCommands[][]={
	
	"say /ba","say_team /ba",
	"say ba", "say_team ba"
};

new g_iKills[33], g_iPlayedTime[33];
new g_szFlags[32];
new g_pSettings[Settings];

#if defined CHECK_USER_BANNED
new Trie:g_tUserBansDB;

new bool:g_bIsUserNotBanned[33];
#endif

new bool:g_bHasUserReqTime[33];
new bool:g_bHasUserReqKills[33];

public plugin_init()
{
	register_plugin(PLUGIN,VERSION,AUTHOR);
	
	register_cvar("hackera457_becomeadmin",VERSION,FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED);
	
	g_pSettings[BADMIN_REQUIRE_TIME] = register_cvar("becomeadmin_req_playtime","1500");
	g_pSettings[BADMIN_REQUIRE_KILLS] = register_cvar("becomeadmin_req_kills","50");
	g_pSettings[BADMIN_ADMIN_FLAGS] = register_cvar("becomeadmin_admin_flags","abcdeijo");
	
	for(new i=0; i < 4; i++)
		register_clcmd(g_szCommands[i],"ShowMenu");
	
	get_pcvar_string(g_pSettings[BADMIN_ADMIN_FLAGS],g_szFlags, sizeof g_szFlags -1);
	
	#if defined CHECK_USER_BANNED
	g_tUserBansDB = TrieCreate();
	LoadBansFromFile();
	#endif
	
	register_event("DeathMsg", "eDeath", "a");
	register_event("HLTV", "event_new_round", "a", "1=0", "2=0");
	
}


public client_connect(id)
{	
	LoadUserData(id);
	CheckUser(id);
}

public client_disconnect(id)
{
	SaveUserData(id);
}

public client_putinserver(id)
{
	LoadAdminInfo(id);
}

public event_new_round()
{
	static iPlayers[32],iNum, iPlayer;
	
	get_players(iPlayers,iNum,"ch");
	
	for(new i=0; i < iNum; i++)
	{
		iPlayer = iPlayers[i];
		
		if(!is_user_connected(iPlayer))
			continue;
		
		g_iPlayedTime[iPlayer] = g_iPlayedTime[iPlayer]+ (get_user_time(iPlayer) / 60);
	}
		
}

public plugin_end()
{
	#if defined CHECK_USER_BANNED
	TrieDestroy(g_tUserBansDB);
	#endif

}

public ShowMenu(id)
{
	if(is_user_admin(id))
	{
		ColorChat(id,TEAM_COLOR,"^1[^4Become^3Admin^1] You have been already became an Admin!");
		return PLUGIN_HANDLED;
	}
	
	CheckUser(id);
	
	static szMenuItem[64], iMenu;
	
	iMenu = menu_create("\rBecome an Admin:","handlerMenuAdmin");
	
	#if defined CHECK_USER_BANNED
		formatex(szMenuItem, sizeof szMenuItem -1,"\yYou were not banned. %s",(g_bIsUserNotBanned[id] ? "\r[CHECKED]" : ""));
	#else
		formatex(szMenuItem, sizeof szMenuItem -1,"\dYou were not banned.");
	#endif
	
	menu_additem(iMenu, szMenuItem,"1",_,menu_makecallback("DisableBanOption"));
	
	formatex(szMenuItem, sizeof szMenuItem -1, "\yYou were played \d%i \yminutes. %s",get_pcvar_num(g_pSettings[BADMIN_REQUIRE_TIME]),(g_bHasUserReqTime[id] ? "\r[CHECKED]" : ""));
	menu_additem(iMenu, szMenuItem,"2",_,menu_makecallback("DisableTimeOption"));
	
	formatex(szMenuItem, sizeof szMenuItem -1,"\yYou were have \d%i \ykills. %s",get_pcvar_num(g_pSettings[BADMIN_REQUIRE_KILLS]),(g_bHasUserReqKills[id] ? "\r[CHECKED]" : ""));
	menu_additem(iMenu, szMenuItem,"3",_,menu_makecallback("DisableKillOption"));
	
	if(is_user_become_admin(id))
	{
		menu_additem(iMenu, "\rBecome Admin","4");
	}
	
	menu_setprop(iMenu, MPROP_EXITNAME, "\rExit");
	menu_display(id,iMenu,0);
	
	return PLUGIN_HANDLED;	
}

public DisableBanOption(id,iMenu, iItem)
{
	return ITEM_DISABLED;
}

public DisableTimeOption(id,iMenu, iItem)
{
	return ITEM_DISABLED;
}

public DisableKillOption(id,iMenu, iItem)
{
	return ITEM_DISABLED;
}

public handlerMenuAdmin(id,iMenu, iItem)
{
	if(iItem == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return PLUGIN_HANDLED;
	}
	
	static szData[6],szName[64],iAccess, iCallback, iKey;
	
	menu_item_getinfo(iMenu, iItem, iAccess, szData, sizeof szData -1, szName, sizeof szName -1, iCallback);
	
	iKey = str_to_num(szData);
	
	switch(iKey)
	{
		case 4:
		{
			#if defined CHECK_USER_BANNED
			if(g_bIsUserNotBanned[id] && g_bHasUserReqTime[id] && g_bHasUserReqKills[id])
			#else
			if(g_bHasUserReqTime[id] && g_bHasUserReqKills[id])
			#endif
			{
				BecomeAdmin(id,g_szFlags);
				SaveAdminInfo(id,g_szFlags);
			}
		}
	}
	
	return PLUGIN_HANDLED;
}

public eDeath()
{
	static iKiller, iVictim;
	
	iKiller = read_data(1);
	iVictim = read_data(2);
	
	if(!is_user_connected(iKiller) || !is_user_connected(iVictim) || iKiller == iVictim)
		return;
	
	g_iKills[iKiller]++;
	
}

#if defined CHECK_USER_BANNED
LoadBansFromFile()
{
	static iFilePointer, szData[512], szAddIp[32], szBanTime[40], szUserIp[32], iTotalBans, iStart;
	
	iTotalBans = 0;
	
	iFilePointer = fopen("listip.cfg","r");
	
	if(!iFilePointer)
		return;
		
	while(!feof(iFilePointer))
	{
		fgets(iFilePointer,szData, sizeof szData -1);
		
		trim(szData);
		
		if(!szData[0] || szData[0] == ';' || (szData[0] == '/' && szData[1] == '/'))
			continue;
			
		iStart = containi(szData, "addip");
		
		if(iStart < 0)
			continue;
			
		parse(szData[iStart], szAddIp, sizeof szAddIp -1, szBanTime, sizeof szBanTime -1, szUserIp, sizeof szUserIp -1);
		
		TrieSetCell(g_tUserBansDB, szUserIp, iTotalBans);
		
		iTotalBans++;
	}
	
	fclose(iFilePointer);
}
#endif

CheckUser(id)
{
	if(!is_user_connected(id) || is_user_hltv(id) || is_user_bot(id))
		return;
		
	static iRequireTime, iRequireKills;
	
	iRequireTime = get_pcvar_num(g_pSettings[BADMIN_REQUIRE_TIME]);
	iRequireKills = get_pcvar_num(g_pSettings[BADMIN_REQUIRE_KILLS]);
	
	#if defined CHECK_USER_BANNED
	static szUserIp[30], iUserTotalBans;
		
	get_user_ip(id,szUserIp, sizeof szUserIp -1,1);
		
	TrieGetCell(g_tUserBansDB, szUserIp, iUserTotalBans);
		
	if(iUserTotalBans <=0)
		g_bIsUserNotBanned[id] = true;
	#endif

	
	if(g_iPlayedTime[id] >= iRequireTime)
		g_bHasUserReqTime[id] = true;
		
	if(g_iKills[id] >=iRequireKills)
		g_bHasUserReqKills[id] = true;
}

BecomeAdmin(id, const szFlags[])
{
	if(is_user_admin(id))
		return;
		
	if(is_user_become_admin(id))
	{
		remove_user_flags(id,read_flags("z"));
		set_user_flags(id,read_flags(szFlags));
	}
	
	ColorChat(id,TEAM_COLOR,"^1[^4Become^3Admin^1] You became an ^4ADMIN^1! Your flags: ^4%s^1!",szFlags);
	
}

LoadUserData(id)
{
	static szName[32], szData[512], szPlayedTime[60], szKills[32];
	
	get_user_name(id,szName, sizeof szName -1);
	
	if(fvault_get_data(g_szDataVault,szName, szData, sizeof szData -1))
	{
		replace_all(szData, sizeof szData -1,"#"," ");
		parse(szData, szPlayedTime, sizeof szPlayedTime -1, szKills, sizeof szKills -1);
		
		g_iKills[id] = str_to_num(szKills);
		g_iPlayedTime[id] = str_to_num(szPlayedTime);
	}
	else
	{
		g_iKills[id] = 0;
		g_iPlayedTime[id] = 0;
	}
		
}

SaveUserData(id)
{
	static szName[32],  szVaultData[512];
	
	get_user_name(id,szName, sizeof szName -1);
	
	formatex(szVaultData, sizeof szVaultData -1, "%i#%i",g_iPlayedTime[id], g_iKills[id]);
		
	fvault_set_data(g_szDataVault,szName,szVaultData);
	
	g_iKills[id] = 0;
	g_iPlayedTime[id] = 0;
}

LoadAdminInfo(id)
{
	static szName[32], szData[512], szFlags[32], szExpire[60], iExpireTime;
	
	get_user_name(id,szName, sizeof szName -1);
	
	if(fvault_get_data(g_szAdminsVault,szName,szData, sizeof szData -1))
	{
		replace_all(szData, sizeof szData -1,"|", " ");
		parse(szData,szFlags, sizeof szFlags -1,szExpire, sizeof szExpire -1);
		
		iExpireTime = str_to_num(szExpire);
		
		if(iExpireTime < time())
			fvault_remove_key(g_szAdminsVault, szName);
		else
			BecomeAdmin(id,szFlags);
		
		
	}
		
}

SaveAdminInfo(id, const sFlags[])
{
	if(!is_user_become_admin(id))
		return;
	
	static szName[32], szData[512], szVaultData[512], iExpired;
	
	get_user_name(id,szName, sizeof szName -1);
	
	iExpired = time()+ ADMIN_EXPIRED;
	
	if(!fvault_get_data(g_szAdminsVault,szName,szData, sizeof szData -1))
	{
		formatex(szVaultData, sizeof szVaultData -1, "%s|%i", sFlags,iExpired);
		fvault_set_data(g_szAdminsVault,szName,szVaultData);
	}
	
}

bool:is_user_become_admin(id)
{
	#if defined CHECK_USER_BANNED
	return (g_bIsUserNotBanned[id] && g_bHasUserReqTime[id] && g_bHasUserReqKills[id]) ? true : false;
	#else
	return (g_bHasUserReqTime[id] && g_bHasUserReqKills[id]) ? true: false;
	#endif
	
}

Last edited by DJBosma; 03-15-2020 at 15:04.
DJBosma is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-15-2020 , 15:21   Re: is_user_admin(id) , does not check after map change
Reply With Quote #6

Ok, so what specifically is the problem with the clean version?
__________________
Bugsy is offline
DJBosma
Member
Join Date: Dec 2009
Old 03-15-2020 , 15:27   Re: is_user_admin(id) , does not check after map change
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
Ok, so what specifically is the problem with the clean version?
Same issue, it’s stated above the code of the clean version.

After a certain time played && kills made , the user goes to the menu to “get the flags”. They stay if the user reconnects and are valid every round till the map change.. when the map is changed and the user is still connected.. he has to go thru the menu again in order to receive the flags.

PS: Keep in mind that the clean version has get_user_name and my edit has get_user_authid.

Last edited by DJBosma; 03-15-2020 at 15:29.
DJBosma is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-15-2020 , 15:29   Re: is_user_admin(id) , does not check after map change
Reply With Quote #8

So you want the flags to stick after a map change? The more specific information you can give the better/easier I can help you.
__________________
Bugsy is offline
DJBosma
Member
Join Date: Dec 2009
Old 03-15-2020 , 15:40   Re: is_user_admin(id) , does not check after map change
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
So you want the flags to stick after a map change? The more specific information you can give the better/easier I can help you.
I would want them to stick after the map change. If it’s possible, please remove the ‘receive flags’ from the menu and add them automatically. If you are making any edits, please do so on the code of the first post.

Thanks in advance.

PS: applying this for client_infochanged would be appreciated. Where it senses that “name” has changed.

Last edited by DJBosma; 03-15-2020 at 15:43.
DJBosma is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-15-2020 , 15:46   Re: is_user_admin(id) , does not check after map change
Reply With Quote #10

1. I am not using the original code because you may have modified code which will make it not work. I am not going to look every line of the code to reverse engineer it to make sure it works.
2. You should use steam id not name, so client_infochanged() does not matter.
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

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 12:11.


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