Raised This Month: $ Target: $400
 0% 

get_players always not find players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DPAKOH
Member
Join Date: Oct 2005
Location: Russia, Moscow
Old 11-18-2006 , 18:49   get_players always not find players
Reply With Quote #1

I write admin base script... See function accessUser_

Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#define ADMIN_LOOKUP	(1<<0)
#define ADMIN_NORMAL	(1<<1)
#define ADMIN_STEAM	(1<<2)
#define ADMIN_IPADDR	(1<<3)
#define ADMIN_NAME	(1<<4)

new g_cmdLoopback[16]

new szSqlTemplateAcess[] = "SELECT user_id, `access`, IF(((flag_disconnect = 1 AND flag_password = 1 ) OR (flag_ip = 0 AND auth = '%s')) AND `password` != '%s', 1, 0) AS `kick` FROM `%s` WHERE  server_id = '%d' AND (flag_ip = 1 AND auth = '%s') OR (flag_ip = 0 AND auth = '%s')"
new Handle:g_MysqlTurple = Empty_Handle

#include "sql_server.inl"
/*

UPDATE cssite_amx_admins SET flag_disconnect = 1, flag_password = 1 WHERE flags LIKE "%a%";
UPDATE cssite_amx_admins SET flag_ip = 1 WHERE flags LIKE "%d%";
UPDATE cssite_amx_admins SET flag_password = 0 WHERE flags LIKE "%e%";


SELECT user_id, `access`, 
	IF(
		((flag_disconnect = 1 AND flag_password = 1 )
		OR
		(flag_ip = 0 AND auth = '%name'))
		AND
	
		`password` != '%pass', 1, 0) AS `kick`
FROM
`%admins`
WHERE 
	server_id = '%d'
	AND
	(flag_ip = 1 AND auth = '%ip') OR (flag_ip = 0 AND auth = '%name')
*/

new g_ResPtr
new g_HidePtr

public plugin_init()
{
	register_plugin("Dubki admin base", "1.0", "Drakon")
	
	register_dictionary("admin.txt")
	register_dictionary("common.txt")
	register_cvar("amx_mode", "1")
	register_cvar("amx_password_field", "_pw")
	register_cvar("amx_default_access", "")

	register_cvar("amx_vote_ratio", "0.02")
	register_cvar("amx_vote_time", "10")
	register_cvar("amx_vote_answers", "1")
	register_cvar("amx_vote_delay", "60")
	register_cvar("amx_last_voting", "0")
	register_cvar("amx_show_activity", "2")
	register_cvar("amx_votekick_ratio", "0.40")
	register_cvar("amx_voteban_ratio", "0.40")
	register_cvar("amx_votemap_ratio", "0.40")

	set_cvar_float("amx_last_voting", 0.0)

	register_cvar("amx_sql_host", "127.0.0.1")
	register_cvar("amx_sql_user", "root")
	register_cvar("amx_sql_pass", "")
	register_cvar("amx_sql_db", "amx")
	register_cvar("amx_sql_type", "mysql")
	
	register_cvar("amx_server_host", "127.0.0.1:27015")
	register_cvar("amx_admins_list", "admins")
	register_cvar("amx_servers_list", "servers")

	register_dictionary("adminslots.txt")
	register_dictionary("common.txt")
	g_ResPtr = register_cvar("amx_reservation", "0")
	g_HidePtr = register_cvar("amx_hideslots", "0")

	format(g_cmdLoopback, 15, "amxauth%c%c%c%c", random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'))
	register_clcmd(g_cmdLoopback, "ackSignal")

	remove_user_flags(0, read_flags("z")) // Remove 'user' flag from server rights

	new configsDir[64]
	get_configsdir(configsDir, 63)
	
	server_cmd("exec %s/amxx.cfg", configsDir)	// Execute main configuration file
	server_cmd("exec %s/sql.cfg", configsDir)
	server_exec()
	g_MysqlTurple = SQL_MakeStdTuple()
	get_server_id_sql()
}

public plugin_cfg()
{
	new configFile[64], curMap[32]

	get_configsdir(configFile, 31)
	get_mapname(curMap, 31)

	new len = format(configFile, 63, "%s/maps/%s.cfg", configFile, curMap)

	if (file_exists(configFile))
		set_task(6.1, "delayed_load", 0, configFile, len + 1)

	set_task(3.0, "MapLoaded")
}

public MapLoaded()
{
	if (!get_pcvar_num(g_HidePtr))
		return

	new maxplayers = get_maxplayers()
	new players = get_playersnum(1)
	new limit = maxplayers - get_pcvar_num(g_ResPtr)
	setVisibleSlots(players, maxplayers, limit)
}

public delayed_load(configFile[])
{
	server_cmd("exec %s", configFile)
}
/******************************************************************************************************/
accessUser(id, name[] = "")
{
	remove_user_flags(id)
	
	new userip[32], password[32], passfield[32], username[32], admintable[32]
	
	get_user_ip(id, userip, 31, 1)
	
	if (name[0])
		copy(username, 31, name)
	else
		get_user_name(id, username, 31)
	
	get_cvar_string("amx_password_field", passfield, 31)
	get_user_info(id, passfield, password, 31)
	get_cvar_string("amx_admins_list", admintable, 31)

	new query[2048]
	format(query, 2047, szSqlTemplateAcess, username, password, admintable, g_ServerID, userip, username)
//	log_amx(query)
	new data[2]
	data[0] = get_user_userid(id)

//	log_amx("Send id: %d", data[0])
	setDefFlags(id)
	SQL_ThreadQuery(g_MysqlTurple, "accessUser_", query, data, 1)	

	return PLUGIN_CONTINUE
}

public setDefFlags(id)
{
	new defaccess[32]
	get_cvar_string("amx_default_access", defaccess, 31)
	if (!strlen(defaccess)) copy(defaccess, 32, "z")
	new idefaccess = read_flags(defaccess)
	if (idefaccess) set_user_flags(id, idefaccess)
	return PLUGIN_HANDLED
}

public GetPlayerByID(userid)
{
    new players[32], plCount, i
    get_players(players, plCount)
    log_amx("Pl count: %d", plCount)
    for (i = 0; i < plCount; i++)
    {
	log_amx("This uid: %d", players[i])
	if (get_user_userid(players[i]) == userid)
	    return players[i]
    }
    return 0
}

getAccess(id, name[], a[], b[], c[])
{
    return 8
}

public accessUser_(failstate, Handle:query, error[], errnum, data[], size)
{
	if (failstate)
	{
		log_amx("[MySQL error text] %s", error)
		return PLUGIN_HANDLED
	}

	new userid = data[0]
//	new id = find_player("khj", userid)
	new id
	id = GetPlayerByID(userid)
	log_amx("Getted ID: %d, userid: %d", id, data[0])
	if (!id) return PLUGIN_HANDLED

	if (!SQL_NumResults(query))
	{
		log_amx("Default access")
		setDefFlags(id)
		checkReserv(id)
		return PLUGIN_HANDLED
	}

//	new qColUID = SQL_FieldNameToNum(query, "user_id")
	new qColAccess = SQL_FieldNameToNum(query, "access")
	new qColKick = SQL_FieldNameToNum(query, "kick")

	new skick[2], saccess[32],  nkick, naccess
//	new nuid, suid[32]

//	SQL_ReadResult(query, qColUID, suid, 31)
	SQL_ReadResult(query, qColAccess, saccess, 31)
	SQL_ReadResult(query, qColKick, skick, 31)

	log_amx("Fetch admin result: %s, %s", saccess, skick)

	naccess = read_flags(saccess)
	nkick = str_to_num(skick)
//	nuid = str_to_num(suid)

	if (nkick)
	{
		ackSignal(id)
		return PLUGIN_HANDLED
	}

	set_user_flags(id, naccess)

	checkReserv(id)
	return PLUGIN_HANDLED
}
/******************************************************************************************************/
public client_infochanged(id)
{
	if (!is_user_connected(id) || !get_cvar_num("amx_mode"))
		return PLUGIN_CONTINUE

	new newname[32], oldname[32]
	
	get_user_name(id, oldname, 31)
	get_user_info(id, "name", newname, 31)

	if (!equal(newname, oldname))
		accessUser(id, newname)

	return PLUGIN_CONTINUE
}

public ackSignal(id)
{
	server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY")
}

public client_authorized(id)
{
	return get_cvar_num("amx_mode") ? accessUser(id) : PLUGIN_CONTINUE
}

public checkReserv(id)
{
	new maxplayers = get_maxplayers()
	new players = get_playersnum(1)
	new limit = maxplayers - get_pcvar_num(g_ResPtr)

	if (access(id, ADMIN_RESERVATION) || (players <= limit))
	{
		if (get_pcvar_num(g_HidePtr) == 1)
			setVisibleSlots(players, maxplayers, limit)
		return PLUGIN_CONTINUE
	}
	
	client_cmd(id, "%s", g_cmdLoopback)

	return PLUGIN_HANDLED
}

public setVisibleSlots(players, maxplayers, limit)
{
	new num = players + 1

	if (players == maxplayers)
		num = maxplayers
	else if (players < limit)
		num = limit
	
	set_cvar_num("sv_visiblemaxplayers", num)
}


public client_putinserver(id)
{
	if (!is_dedicated_server() && id == 1)
		return get_cvar_num("amx_mode") ? accessUser(id) : PLUGIN_CONTINUE
	
	return PLUGIN_CONTINUE
}

public client_disconnect(id)
{
	if (!get_pcvar_num(g_HidePtr))
		return PLUGIN_CONTINUE

	new maxplayers = get_maxplayers()
	
	setVisibleSlots(get_playersnum(1) - 1, maxplayers, maxplayers - get_pcvar_num(g_ResPtr))
	return PLUGIN_CONTINUE
}
__________________
Sorry for bad english

Dubki CS 1.6 Servers: http://www.cs.dubki.ru/
Server: 2 x AMD Opteron 275 = 4 cores x 2.2 Ghz, 2x1Gb ECC DDR400 Mem.

Last edited by DPAKOH; 11-19-2006 at 07:30.
DPAKOH is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 11-18-2006 , 18:55   Re: get_players always return 0
Reply With Quote #2

I don't see you using get_players' return value anywhere.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
DPAKOH
Member
Join Date: Oct 2005
Location: Russia, Moscow
Old 11-19-2006 , 07:30   Re: get_players always return 0
Reply With Quote #3

get_players(players, plCount)

plCount = 0
__________________
Sorry for bad english

Dubki CS 1.6 Servers: http://www.cs.dubki.ru/
Server: 2 x AMD Opteron 275 = 4 cores x 2.2 Ghz, 2x1Gb ECC DDR400 Mem.
DPAKOH is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-19-2006 , 12:11   Re: get_players always not find players
Reply With Quote #4

I don't know why, but I had been having problems with get_players as well. So I made my own function.
Code:
 /* Sets indexes of players.
 * Flags:
 * "a" - don't collect dead players.
 * "b" - don't collect alive players.
 * "c" - skip bots.
 * "d" - skip real players.
 * "e" - match with team number.
 * "f" - match with part of name.   //not used - leaving blank to match AMXX's get_players
 * "g" - ignore case sensitivity.   //not used - leaving blank to match AMXX's get_players
 * "h" - skip HLTV.
 * Example: Get all alive on team 2: poke_get_players(players,num,"ae",2) */
 stock poke_get_players(players[MAX_PLAYERS], &pnum, const flags[]="", team=-1)
 {
	new total = 0
	for(new i=1; i<=MAX_PLAYERS; i++){
		if(!is_user_connected(i))
			continue
		if(containi(flags,"a")!=-1 && !is_user_alive(i))
			continue
		if(containi(flags,"b")!=-1 && is_user_alive(i))
			continue
		if(containi(flags,"c")!=-1 && is_user_bot(i))
			continue
		if(containi(flags,"d")!=-1 && !is_user_bot(i))
			continue
		if(containi(flags,"e")!=-1 && team!=-1 && get_user_team(i)!=team)
			continue
		if(containi(flags,"h")!=-1 && is_user_hltv(i))
			continue
		players[total] = i
		total++
	}
	pnum = total

	return true
 }
*Note - that the last parameter is no longer a string, but a number
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
DPAKOH
Member
Join Date: Oct 2005
Location: Russia, Moscow
Old 11-19-2006 , 20:18   Re: get_players always not find players
Reply With Quote #5

I see in sqlbans script... To SQL_ThreadQuery script send id... Not userid.
I use same method. But we have chance to have other user in this id. Therefore I send userid and check get_user_userid(received id) and received userid.

All works.
__________________
Sorry for bad english

Dubki CS 1.6 Servers: http://www.cs.dubki.ru/
Server: 2 x AMD Opteron 275 = 4 cores x 2.2 Ghz, 2x1Gb ECC DDR400 Mem.
DPAKOH 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 06:58.


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