/* AMX Mod script.
*
* SQL ServerCfg
*  by JustinHoMi
*
*/

/* db schema
*
* CREATE TABLE amx_servercfg (
*   id int(4) unsigned NOT NULL auto_increment,
*   command varchar(255) NOT NULL default '',
*   time_modified timestamp(14) NOT NULL,
*   PRIMARY KEY  (id)
* ) TYPE=MyISAM;
*
*/

#include <amxmod>
#include <mysql>

public load_data(){

	new merror[32]
	new mhost[64]
	new muser[32]
	new mpass[32]
	new mdb[32]
	new mysql = 0

	get_cvar_string("amx_mysql_host",mhost,64)
	get_cvar_string("amx_mysql_user",muser,32)
	get_cvar_string("amx_mysql_pass",mpass,32)
	get_cvar_string("amx_mysql_db",mdb,32)

	mysql = mysql_connect(mhost,muser,mpass,mdb,merror,32)

	if(mysql < 1){
		mysql_error(mysql,merror,32)
		server_print("[AMX] MySQL error : could not connect : '%s'",merror)
		return PLUGIN_HANDLED
	}
	else{
		server_print("[AMX] SQL ServerCfg Loading....")

		new query[256]
		format(query,256,"SELECT command from amx_servercfg")
		mysql_query(mysql,query)

		new cmd[256]
		while(mysql_nextrow(mysql)){
			mysql_getfield(mysql,1,cmd,255)
			server_cmd(cmd)
		}
		mysql_close(mysql)
	}

	return PLUGIN_CONTINUE
}


public plugin_init(){
	register_plugin("SQL ServerCfg","0.1b","JustinHoMi")
	set_task(5.0,"load_data")
	return PLUGIN_CONTINUE
}

