Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <sqlx>
  3.  
  4. #pragma semicolon 1
  5.  
  6. // File nale .sq3
  7. #define SQL_FILE_NAME "sql_ban"
  8.  
  9. // Table name
  10. #define SQL_TABLE "lite_ban_list"
  11.  
  12. // Create query
  13. #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));"
  14.  
  15. // INSERT BAN QUERY
  16. #define SQL_
  17.  
  18. // Column nammes and position
  19. #define SQL_COL_0 "id"
  20. #define SQL_COL_1 "auth"
  21. #define SQL_COL_2 "name"
  22. #define SQL_COL_3 "now"
  23. #define SQL_COL_4 "expire"
  24. #define SQL_COL_5 "reason"
  25. #define SQL_COL_6 "admin_auth"
  26. #define SQL_COL_7 "admin"
  27. #define SQL_COL_8 "enabled"
  28.  
  29. // Global handler
  30. new Handle:g_hTuple;
  31.  
  32. // Query Types
  33. enum _:SQL_QUERY_TYPES
  34. {
  35. QUERY_BAN_CHECK,
  36. QUERY_BAN_ACTION
  37. };
  38.  
  39. enum _:ePlayerData
  40. {
  41. szUserName[MAX_NAME_LENGTH],
  42. szUserAuth[MAX_AUTHID_LENGTH]
  43. };
  44.  
  45. new g_iPlayerData[MAX_PLAYERS+1][ePlayerData];
  46.  
  47. public plugin_init()
  48. {
  49. // Init Plugin
  50. register_plugin("SQL Lite Ban System",AMXX_VERSION_STR,"SmileY");
  51.  
  52. // Set it to sqlite affinity
  53. SQL_SetAffinity("sqlite");
  54.  
  55. // Try to create tuple using file name
  56. g_hTuple = SQL_MakeDbTuple("","","",SQL_FILE_NAME);
  57.  
  58. // Execute query to create table if not exists
  59. SQL_ThreadQuery(g_hTuple,"SQL_HandleGeneric",SQL_CREATE_TABLE);
  60. }
  61.  
  62. public plugin_end()
  63. {
  64. // If has tuple
  65. if(g_hTuple)
  66. {
  67. // Freed it!
  68. SQL_FreeHandle(g_hTuple);
  69. }
  70. }
  71.  
  72. public SQL_HandleGeneric()
  73. {
  74. /* I DO NOT CARE */
  75. }
  76.  
  77. public SQL_HandleGlobal(iState,Handle:hResult,szError[],iError,szData[],iSize)
  78. {
  79. if(iState == TQUERY_SUCCESS)
  80. {
  81. switch(szData[0])
  82. {
  83. case QUERY_BAN_CHECK:
  84. {
  85. if(SQL_NumRows(hResult))
  86. {
  87. new szName[2][MAX_NAME_LENGTH],szAuth[2][MAX_AUTHID_LENGTH];
  88. new szBannedTime[32],szExpireTime[32];
  89. new szReason[128];
  90.  
  91. new iBanIndex = SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_0));
  92.  
  93. if(iBanIndex)
  94. {
  95. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_1),szAuth[0],sizeof(szAuth[]));
  96. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_2),szName[0],sizeof(szName[]));
  97.  
  98. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_3),szBannedTime,charsmax(szBannedTime));
  99. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_4),szExpireTime,charsmax(szExpireTime));
  100.  
  101. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_5),szReason,charsmax(szReason));
  102.  
  103. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_6),szAuth[1],sizeof(szAuth[]));
  104. SQL_ReadResult(hResult,SQL_FieldNameToNum(hResult,SQL_COL_7),szName[1],sizeof(szName[]));
  105.  
  106. ACTION_PrintBan(szData[1],iBanIndex,szName[0],szAuth[0],szBannedTime,szExpireTime,szReason,szName[1],szAuth[1]);
  107.  
  108. server_cmd("kick #%i ^"YOU HAVE BEEN BANNED! CHECK YOUR CONSOLE!!^"",get_user_userid(szData[1]));
  109. }
  110. }
  111. }
  112. case QUERY_BAN_ACTION:
  113. {
  114. if(SQL_GetInsertId(hResult))
  115. {
  116.  
  117. //ACTION_Disconnect(szData[1],"YOU HAVE BEEN BANNED!^nCHECK YOUR CONSOLE!!");
  118. }
  119. }
  120. }
  121. }
  122. }
  123.  
  124. public client_putinserver(id)
  125. {
  126. get_user_authid(id,g_iPlayerData[id][szUserAuth],MAX_AUTHID_LENGTH-1);
  127. get_user_name(id,g_iPlayerData[id][szUserName],MAX_NAME_LENGTH-1);
  128.  
  129. set_task(2.0,"ACTION_CheckBan",id);
  130. }
  131.  
  132. ACTION_BanPlayer(id,iPlayer,iMinutes,szReason[],bool:bShowAction = false,bool:bKick = false)
  133. {
  134. new szQuery[512];
  135.  
  136. formatex
  137. (
  138. szQuery,
  139. charsmax(szQuery),
  140. "INSERT INTO %s VALUES(NULL, '%s', '%s', CURRENT_TIMESTAMP, DATETIME(CURRENT_TIMESTAMP, '+%i MINUTES'), '%s', '%s', '%s', 1)",
  141. SQL_TABLE,
  142. g_iPlayerData[iPlayer][szUserAuth],
  143. g_iPlayerData[iPlayer][szUserName],
  144. iMinutes,
  145. szReason,
  146. g_iPlayerData[id][szUserAuth],
  147. g_iPlayerData[id][szUserName]
  148. );
  149.  
  150. new szData[2];
  151. szData[0] = QUERY_BAN_ACTION;
  152. szData[1] = iPlayer;
  153.  
  154. SQL_ThreadQuery(g_hTuple,"SQL_HandleGlobal",szQuery,szData,sizeof(szData));
  155. }
  156.  
  157. public ACTION_CheckBan(id)
  158. {
  159. new szQuery[256];
  160. formatex
  161. (
  162. szQuery,
  163. charsmax(szQuery),
  164. "SELECT *, (expire > CURRENT_TIMESTAMP) AS banned FROM %s WHERE banned = 1 AND %s = 1 AND %s = '%s' ORDER BY %s DESC LIMIT 1;",
  165. SQL_TABLE,
  166. SQL_COL_8,
  167. SQL_COL_1,
  168. g_iPlayerData[id][szUserAuth],
  169. SQL_COL_0
  170. );
  171.  
  172. new szData[2];
  173. szData[0] = QUERY_BAN_CHECK;
  174. szData[1] = id;
  175.  
  176. SQL_ThreadQuery(g_hTuple,"SQL_HandleGlobal",szQuery,szData,sizeof(szData));
  177. }
  178.  
  179. ACTION_PrintBan(id,iBanIndex,szName[],szAuth[],szBannedTime[],szExpireTime[],szReason[],szAdmin[],szAdminAuth[])
  180. {
  181. console_print(id,"--------- YOU HAVE BEEN BANNED ---------");
  182. console_print(id,"ADMIN: %s (%s)",szAdmin,szAdminAuth);
  183. console_print(id,"PLAYER: %s (%s)",szName,szAuth);
  184. console_print(id,"AT: %s",szBannedTime);
  185. console_print(id,"UNTIL: %s",szExpireTime);
  186. console_print(id,"REASON: %s",szReason);
  187. console_print(id,"TICKET: #%i",iBanIndex);
  188. console_print(id,"--------- YOU HAVE BEEN BANNED ---------",iBanIndex);
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement