Raised This Month: $ Target: $400
 0% 

[SOLVED] Is it set_task problem?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kclteam
Junior Member
Join Date: Feb 2006
Old 03-23-2006 , 19:10   [SOLVED] Is it set_task problem?
Reply With Quote #1

Hi!
My concept of set_task was quite immature...finally got them straight...thanx to all the people who helped me

I am using set_task to call a function which gets the data from a field in my MySQL database and acts accordingly. This is done to all users who connect to our server. However, set_task seems to miss out on some players. I dont seem to get the logical/coding flaw that i might have.

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

#define PLUGINNAME "MyDBPlugin"
#define VERSION "1.0"
#define AUTHOR "KCLTeam"

new Sql:sql
public plugin_init() {
	register_plugin(PLUGINNAME, VERSION, AUTHOR)
	new sqlcfgpath[128]
	get_configsdir(sqlcfgpath, 127)
	format(sqlcfgpath, 127, "%s/sql.cfg", sqlcfgpath)
	server_cmd("exec %s", sqlcfgpath)
	server_exec()
	
	if (!connect(sql)) {
		log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
		pause("a")
		return
	}
	else
		server_print("[%s] Connected successfully to SQL database.", PLUGINNAME)
	dbi_close(sql)
}

public plugin_modules() {
	require_module("dbi")
}

public client_putinserver(id) {
	if (is_user_bot(id))
		return PLUGIN_HANDLED
	if (!connect(sql)) {
		log_amx("Error - Couldn't connect to SQL db")
		return PLUGIN_HANDLED
	}
	new idd[2]
	idd[0] = id
	new flags[3]
	flags = "b"
	set_task(60.0, "kac_exists", 0, idd, 1)
	return PLUGIN_CONTINUE
	
}

public kac_exists(idd[]) {
	new ip[32]
	get_user_ip(idd[0], ip, 32, 0)
	const LONGER = 128
	new query[LONGER + 1]
	format(query, LONGER, "SELECT `ip2` FROM `amxx_register` WHERE `ip` = ^"%s^" AND `kac_exists` = '0' LIMIT 1", ip)
	new Result:result = dbi_query(sql, query)
		if (result <= RESULT_FAILED) {
			new error[256]
			dbi_error(sql, error, 255)
			log_amx("Error while quering SQL server for %s, Error: %s", ip, error)
			dbi_close(sql)
			return PLUGIN_CONTINUE
		}
		else if (result == RESULT_NONE) {
			server_print("[%s] %s has valid token.", PLUGINNAME, ip)
			return PLUGIN_CONTINUE
		}

		if (!dbi_nextrow(result)) {
			server_print("[%s] %s has valid token.", PLUGINNAME, ip)
			return	PLUGIN_CONTINUE	
		}
		server_print("[%s] %s has invalid token.", PLUGINNAME, ip)
		server_cmd("kick #%d You must have valid token to play on this server", get_user_userid(idd[0]))
	}
        dbi_close(sql)
	return PLUGIN_CONTINUE	
}


bool:connect(&Sql:sql) {
	const LEN = 128
	new error_msg[LEN]

	get_cvar_string("amx_sql_host",mhost,64)
	get_cvar_string("amx_sql_user",muser,32)
	get_cvar_string("amx_sql_pass",mpass,32)
	get_cvar_string("amx_sql_db",mdb,32)

	sql = dbi_connect(mhost, muser, mpass, mdb, error_msg, LEN - 1)

	if (!sql) {
		log_amx("ERROR - Can't connect to SQL db: %s", error_msg)
		return false
	}

	return true
}
Some people get kicked for not having valid token, while some are not kicked. But people having valid token are never kicked.

Thanx in advance.
kclteam is offline
Jordan
Veteran Member
Join Date: Aug 2005
Old 03-23-2006 , 19:46  
Reply With Quote #2

Try setting it to:

Code:
set_task(60.0, "kac_exists", 0, id, 1)
Jordan is offline
kclteam
Junior Member
Join Date: Feb 2006
Old 03-24-2006 , 03:31   argument type mismatch..
Reply With Quote #3

Sorry but your suggestion doesn't seem to help...

I get the following error:
Code:
 argument type mismatch (argument 4)
Ne other idea?
kclteam is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-24-2006 , 04:23  
Reply With Quote #4

Well .. what's the line?
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
kclteam
Junior Member
Join Date: Feb 2006
Old 03-24-2006 , 04:56   Set_task
Reply With Quote #5

the line where error pops out is the line where I changed the argument for set_task on Satan's suggestion.

When I pass idd (an array) to kac_exists function thru set_task, I don't get any errors while compilation but only first person to connect is checked for valid token and rest are simply ignored.

I want my plugin to wait for 60 seconds after a client has connected and then check if the token is valid or not in DB. This task should be set for all people who connect but doesnt happen so.

Ne suggestions?
kclteam is offline
akysiev
Junior Member
Join Date: Mar 2006
Location: Earth
Old 03-24-2006 , 07:03  
Reply With Quote #6

I know I didn't change much but see if it works:

Code:
public client_putinserver(id) {     if (is_user_bot(id))         return PLUGIN_HANDLED     if (!connect(sql))     {         log_amx("Error - Couldn't connect to SQL db")         return PLUGIN_HANDLED     }     new idd[1]     idd[0] = id     set_task(60.0, "kac_exists", 0, idd, 1)     return PLUGIN_CONTINUE }

Don't know if the array length would have any effect on it but its worth a shot.
akysiev is offline
kclteam
Junior Member
Join Date: Feb 2006
Old 03-24-2006 , 08:34   thnx
Reply With Quote #7

thnx mate...

I got it working! I guess by just changing the array size it mattered. Why did it? Neway...now I hav one more doubt.

Whenever a client joins the server, this task is set for him. But assuming a client disconnects before the time for execution is reached for the task...wat happens then?

If i use remove_task in client_disconnect(id), will it remove the task set for all players or for the particualr player who disconnected?
kclteam is offline
akysiev
Junior Member
Join Date: Mar 2006
Location: Earth
Old 03-24-2006 , 08:39  
Reply With Quote #8

It would remove the task for all players since all of them are grouped under task id 0. To solve this, use a unique task id as follows:

Code:
public client_putinserver(id) {     if (is_user_bot(id))         return PLUGIN_HANDLED     if (!connect(sql))     {         log_amx("Error - Couldn't connect to SQL db")         return PLUGIN_HANDLED     }     new idd[1]     idd[0] = id     set_task(60.0, "kac_exists", 50 + id, idd, 1)     return PLUGIN_CONTINUE } public client_disconnect(id) {     remove_task(50 + id); }

Make sure that you don't set any other tasks with an id between 50, or whatever arbitrary number you want to start with, and 82, or 32 plus your number.
akysiev is offline
kclteam
Junior Member
Join Date: Feb 2006
Old 03-24-2006 , 09:25   yoohoo
Reply With Quote #9

thank you very much...

this idea rocked...now its working fine


thank you akysiev, v3x and satan for all the help.
kclteam 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 16:41.


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