Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <sqlx>
- #pragma semicolon 1
- // File nale .sq3
- #define SQL_FILE_NAME "sql_ban"
- // Table name
- #define SQL_TABLE "lite_ban_list"
- // Create query
- #define SQL_CREATE_TABLE "CREATE TABLE IF NOT EXISTS lite_ban_list (id INTEGER, auth TEXT, name TEXT, now TEXT, expire TEXT, reason TEXT, admin_auth TEXT, admin TEXT, enabled INTEGER DEFAULT 1, PRIMARY KEY(id AUTOINCREMENT));"
- // INSERT BAN QUERY
- #define SQL_
- // Column nammes and position
- #define SQL_COL_0 "id"
- #define SQL_COL_1 "auth"
- #define SQL_COL_2 "name"
- #define SQL_COL_3 "now"
- #define SQL_COL_4 "expire"
- #define SQL_COL_5 "reason"
- #define SQL_COL_6 "admin_auth"
- #define SQL_COL_7 "admin"
- #define SQL_COL_8 "enabled"
- // Global handler
- new Handle:g_hTuple;
- // Query Types
- enum _:SQL_QUERY_TYPES
- {
- QUERY_BAN_CHECK,
- QUERY_BAN_ACTION
- };
- enum _:ePlayerData
- {
- szUserName[MAX_NAME_LENGTH],
- szUserAuth[MAX_AUTHID_LENGTH]
- };
- new g_iPlayerData[MAX_PLAYERS+1][ePlayerData];
- public plugin_init()
- {
- // Init Plugin
- register_plugin("SQL Lite Ban System",AMXX_VERSION_STR,"SmileY");
- // Set it to sqlite affinity
- SQL_SetAffinity("sqlite");
- // Try to create tuple using file name
- g_hTuple = SQL_MakeDbTuple("","","",SQL_FILE_NAME);
- // Execute query to create table if not exists
- SQL_ThreadQuery(g_hTuple,"SQL_HandleGeneric",SQL_CREATE_TABLE);
- }
- public plugin_end()
- {
- // If has tuple
- if(g_hTuple)
- {
- // Freed it!
- SQL_FreeHandle(g_hTuple);
- }
- }
- public SQL_HandleGeneric()
- {
- /* I DO NOT CARE */
- }
- public SQL_HandleGlobal(iState,Handle:hResult,szError[],iError,szData[],iSize)
- {
- if(iState == TQUERY_SUCCESS)
- {
- switch(szData[0])
- {
- case QUERY_BAN_CHECK:
- {
- if(SQL_NumRows(hResult))
- {
- new szName[2][MAX_NAME_LENGTH],szAuth[2][MAX_AUTHID_LENGTH];
- new szBannedTime[32],szExpireTime[32];
- new szReason[128];
- new iBanIndex = SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_0));
- if(iBanIndex)
- {
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_1),szAuth[0],sizeof(szAuth[]));
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_2),szName[0],sizeof(szName[]));
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_3),szBannedTime,charsmax(szBannedTime));
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_4),szExpireTime,charsmax(szExpireTime));
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_5),szReason,charsmax(szReason));
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_6),szAuth[1],sizeof(szAuth[]));
- SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_7),szName[1],sizeof(szName[]));
- ACTION_PrintBan(szData[1],iBanIndex,szName[0],szAuth[0],szBannedTime,szExpireTime,szReason,szName[1],szAuth[1]);
- server_cmd("kick #%i ^"YOU HAVE BEEN BANNED! CHECK YOUR CONSOLE!!^"",get_user_userid(szData[1]));
- }
- }
- }
- case QUERY_BAN_ACTION:
- {
- if(SQL_GetInsertId(hResult))
- {
- //ACTION_Disconnect(szData[1],"YOU HAVE BEEN BANNED!^nCHECK YOUR CONSOLE!!");
- }
- }
- }
- }
- }
- public client_putinserver(id)
- {
- get_user_authid(id,g_iPlayerData[id][szUserAuth],MAX_AUTHID_LENGTH-1);
- get_user_name(id,g_iPlayerData[id][szUserName],MAX_NAME_LENGTH-1);
- set_task(2.0,"ACTION_CheckBan",id);
- }
- ACTION_BanPlayer(id,iPlayer,iMinutes,szReason[],bool:bShowAction = false,bool:bKick = false)
- {
- new szQuery[512];
- formatex
- (
- szQuery,
- charsmax(szQuery),
- "INSERT INTO %s VALUES(NULL, '%s', '%s', CURRENT_TIMESTAMP, DATETIME(CURRENT_TIMESTAMP, '+%i MINUTES'), '%s', '%s', '%s', 1)",
- SQL_TABLE,
- g_iPlayerData[iPlayer][szUserAuth],
- g_iPlayerData[iPlayer][szUserName],
- iMinutes,
- szReason,
- g_iPlayerData[id][szUserAuth],
- g_iPlayerData[id][szUserName]
- );
- new szData[2];
- szData[0] = QUERY_BAN_ACTION;
- szData[1] = iPlayer;
- SQL_ThreadQuery(g_hTuple,"SQL_HandleGlobal",szQuery,szData,sizeof(szData));
- }
- public ACTION_CheckBan(id)
- {
- new szQuery[256];
- formatex
- (
- szQuery,
- charsmax(szQuery),
- "SELECT *, (expire > CURRENT_TIMESTAMP) AS banned FROM %s WHERE banned = 1 AND %s = 1 AND %s = '%s' ORDER BY %s DESC LIMIT 1;",
- SQL_TABLE,
- SQL_COL_8,
- SQL_COL_1,
- g_iPlayerData[id][szUserAuth],
- SQL_COL_0
- );
- new szData[2];
- szData[0] = QUERY_BAN_CHECK;
- szData[1] = id;
- SQL_ThreadQuery(g_hTuple,"SQL_HandleGlobal",szQuery,szData,sizeof(szData));
- }
- ACTION_PrintBan(id,iBanIndex,szName[],szAuth[],szBannedTime[],szExpireTime[],szReason[],szAdmin[],szAdminAuth[])
- {
- console_print(id,"--------- YOU HAVE BEEN BANNED ---------");
- console_print(id,"ADMIN: %s (%s)",szAdmin,szAdminAuth);
- console_print(id,"PLAYER: %s (%s)",szName,szAuth);
- console_print(id,"AT: %s",szBannedTime);
- console_print(id,"UNTIL: %s",szExpireTime);
- console_print(id,"REASON: %s",szReason);
- console_print(id,"TICKET: #%i",iBanIndex);
- console_print(id,"--------- YOU HAVE BEEN BANNED ---------",iBanIndex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement