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.