Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <sqlx>
- new c_SqlHost, c_SqlUser, c_SqlPass, c_SqlDB, c_SqlType, g_Error[512], Handle:g_SqlTuple;
- public plugin_init()
- {
- register_plugin("Player On", "1.0", "*Or!g!naL*")
- c_SqlHost = register_cvar( "zp_ammo_bank_host", "linuxclub.ro" )
- c_SqlUser = register_cvar( "zp_ammo_bank_user", "darkcs_zm" )
- c_SqlPass = register_cvar( "zp_ammo_bank_pass", "1234567890" )
- c_SqlDB = register_cvar( "zp_ammo_bank_db", "darkcs_zm" )
- c_SqlType = register_cvar( "zp_ammo_bank_type", "mysql" )
- if( !_PrepareSQL() )
- {
- set_fail_state( "[ZP Ammo Bank] Fail to prepare SQL" )
- return;
- }
- }
- public client_putinserver(id)
- {
- _LoadSQL(id)
- }
- public client_disconnect(id)
- {
- _SaveSQL(id)
- }
- _PrepareSQL() {
- new host[32], user[32], pass[32], db[32], type[12]
- get_pcvar_string( c_SqlHost, host, charsmax(host) )
- get_pcvar_string( c_SqlUser, user, charsmax(user) )
- get_pcvar_string( c_SqlPass, pass, charsmax(pass) )
- get_pcvar_string( c_SqlDB, db, charsmax(db) )
- get_pcvar_string( c_SqlType, type, charsmax(type) )
- new get_type[12]
- SQL_GetAffinity( get_type, charsmax(get_type) )
- log_amx( "[ZP Ammo Bank] SQL affinity type is %s", get_type )
- if( !equali(get_type, type) )
- {
- if( !SQL_SetAffinity(type) )
- {
- log_amx( "[ZP Ammo Bank] Failed to set affinity from %s to %s", get_type, type )
- }
- }
- g_SqlTuple = SQL_MakeDbTuple( host, user, pass, db )
- if( g_SqlTuple == Empty_Handle )
- {
- log_amx( "[ZP Ammo Bank] Failed to create SQL tuple." )
- return 0;
- }
- new const queryString[] = "CREATE TABLE IF NOT EXISTS `salutare` (\
- `auth` VARCHAR(64) NOT NULL,\
- `ZHunter` INT UNSIGNED NOT NULL,\
- PRIMARY KEY (`auth`) );"
- new errcode, error[128];
- new Handle:link = SQL_Connect( g_SqlTuple, errcode, error, charsmax(error) )
- if( link == Empty_Handle )
- {
- log_amx( "[ZP Ammo Bank] Failed to connect to database (%d): %s", errcode, error )
- return 0;
- }
- new Handle:query = SQL_PrepareQuery( link, "%s", queryString )
- if( !SQL_Execute(query) )
- {
- SQL_QueryError( query, error, charsmax(error) )
- log_amx( "[ZP Ammo Bank] Error creating table: %s", error )
- return 0;
- }
- else
- {
- server_print( "[ZP Ammo Bank] SQL table successful create!" )
- }
- SQL_FreeHandle(query)
- SQL_FreeHandle(link)
- return 1;
- }
- _MakeStringSQLSafe( output[], len ) {
- replace_all( output, len, "'", "*" )
- replace_all( output, len, "^"", "*" ) //" - fix Sublime Text syntax highlight
- replace_all( output, len, "`", "*" )
- }
- _LoadSQL(id) {
- new Name[64], onnli[64] = 1;
- get_user_name( id, Name, charsmax(Name) )
- _MakeStringSQLSafe( Name, charsmax(Name) )
- new queryString[512]
- new data[2]
- data[0] = id
- new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
- if(SqlConnection == Empty_Handle)
- set_fail_state(g_Error)
- formatex( queryString, charsmax(queryString),
- "INSERT INTO salutare(auth, ZHunter) VALUES ('%s',1) ON DUPLICATE KEY UPDATE auth = VALUES(auth), ZHunter = VALUES(ZHunter)",
- Name, onnli);
- new Handle:Query = SQL_PrepareQuery(SqlConnection,queryString)
- if(!SQL_Execute(Query))
- {
- SQL_QueryError(Query,g_Error,511)
- }
- while(SQL_MoreResults(Query))
- {
- SQL_NextRow(Query)
- }
- SQL_FreeHandle(Query)
- SQL_FreeHandle(SqlConnection)
- }
- _SaveSQL(id) {
- new data[2]
- data[0] = id
- new Name[64], online[64] = 0;
- get_user_name( id, Name, charsmax(Name) )
- _MakeStringSQLSafe( Name, charsmax(Name) )
- new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
- if(SqlConnection == Empty_Handle)
- set_fail_state(g_Error)
- new queryString[ 1024 ];
- formatex( queryString, charsmax(queryString),
- "INSERT INTO salutare(auth, ZHunter) VALUES ('%s',0) ON DUPLICATE KEY UPDATE auth = VALUES(auth), ZHunter = VALUES(ZHunter)",
- Name, online);
- new Handle:Query = SQL_PrepareQuery(SqlConnection,queryString)
- if(!SQL_Execute(Query))
- {
- SQL_QueryError(Query,g_Error,511)
- set_fail_state(g_Error)
- }
- SQL_FreeHandle(Query)
- SQL_FreeHandle(SqlConnection)
- }
- public QuerySaveData( failstate, Handle:query, error[], errcode, data[], size, Float:queueTime )
- {
- if( failstate == TQUERY_CONNECT_FAILED )
- {
- log_amx( "[ZP Achievement] Failed connecting to save data (%d): %s", errcode, error )
- }
- else if( failstate == TQUERY_QUERY_FAILED )
- {
- log_amx( "[ZP Achievement] Failed query on save data (%d): %s", errcode, error )
- }
- else
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement