Advertisement
CRP_Seven

[SourceMod] VoiceBan Plugin SQL Part (보이스밴 SQL 파트)

Jun 27th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.86 KB | None | 0 0
  1. // SQL Part
  2. SQL_ConnectToDB()
  3. {
  4.     decl String:DB_Names[64];
  5.     GetConVarString(DB_CFG_Name, DB_Names, sizeof(DB_Names));
  6.    
  7.     SQL_TConnect(SQL_Connection, DB_Names);
  8. }
  9.  
  10. SQL_DisconnectFromDB()
  11. {
  12.     if(DB != INVALID_HANDLE)
  13.     {
  14.         CloseHandle(DB);
  15.         DB = INVALID_HANDLE;
  16.     }
  17. }
  18.  
  19. SQL_CheckClientData(Handle:Database, client) // String:Steamid[]
  20. {
  21.     if(Database != INVALID_HANDLE)
  22.     {
  23.         decl String:Query[128], String:Steamid[32];
  24.         GetClientAuthString(client, Steamid, sizeof(Steamid));
  25.        
  26.         Format(Query, sizeof(Query), "SELECT * FROM %s WHERE Steamid = '%s';", DB_Name, Steamid);
  27.        
  28.         SQL_TQuery(Database, SQL_CheckClient, Query, client, DBPrio_High);
  29.     }
  30. }
  31.  
  32. SQL_CreateClientData(Handle:Database, client)
  33. {
  34.     if(Database != INVALID_HANDLE)
  35.     {
  36.         decl String:Query[512], String:Steamid[32];
  37.         GetClientAuthString(client, Steamid, sizeof(Steamid));
  38.        
  39.         Format(Query, sizeof(Query), "INSERT INTO %s(Steamid, Ban) VALUES('%s', '%N', 0, 0, 0, 0, 0);", DB_Name, Steamid, Steamid);
  40.        
  41.         SQL_TQuery(Database, SQL_CheckError, Query, client, DBPrio_High);
  42.     }
  43. }
  44.  
  45. SQL_LoadClientData(Handle:Database, client)
  46. {
  47.     if(Database != INVALID_HANDLE)
  48.     {
  49.         decl String:Query[256], String:Steamid[32];
  50.         GetClientAuthString(client, Steamid, sizeof(Steamid));
  51.        
  52.         Format(Query, sizeof(Query), "SELECT * FROM %s WHERE Steamid = '%s';", DB_Name, Steamid);
  53.        
  54.         SQL_TQuery(Database, SQL_LoadData, Query, client, DBPrio_High);
  55.     }
  56. }
  57.  
  58. SQL_SaveClientData(Handle:Database, client)
  59. {
  60.     if(Database != INVALID_HANDLE)
  61.     {
  62.         decl String:Query[512], String:Steamid[32];
  63.         GetClientAuthString(client, Steamid, sizeof(Steamid));
  64.        
  65.         Format(Query, sizeof(Query), "UPDATE %s SET Ban = %i WHERE Steamid = '%s';", DB_Name, Ban[client], Steamid);
  66.        
  67.         SQL_TQuery(Database, SQL_CheckError, Query, client, DBPrio_High);
  68.     }
  69. }
  70.  
  71. public SQL_CheckTable(Handle:owner, Handle:handle, const String:error[], any:data)
  72. {
  73.     if(handle == INVALID_HANDLE)
  74.     {
  75.         PrintToServer("[CRP Lab] Error : %s", error);
  76.     }
  77.     // if there is no table
  78.     if(SQL_GetRowCount(handle) == 0)
  79.     {
  80.         SQL_CreateTable(DB);
  81.     }
  82. }
  83.  
  84. public SQL_CheckClient(Handle:owner, Handle:handle, const String:error[], any:client)
  85. {
  86.     if(handle == INVALID_HANDLE)
  87.     {
  88.         PrintToServer("[CRP Lab] Error : %s", error);
  89.     }
  90.     // if there is data
  91.     else if(SQL_GetRowCount(handle))
  92.     {
  93.         SQL_LoadClientData(DB, client);
  94.     }
  95.     // if there is no data
  96.     else if(SQL_GetRowCount(handle) == 0)
  97.     {
  98.         SQL_CreateClientData(DB, client);
  99.     }
  100. }
  101.  
  102. public SQL_LoadData(Handle:owner, Handle:handle, const String:error[], any:client)
  103. {
  104.     if(handle == INVALID_HANDLE)
  105.     {
  106.         PrintToChat(client, "\x05[CRP Lab]\x03 당신의 VoiceBan 정보를 불러올 수 없습니다.");
  107.     }
  108.     else
  109.     {
  110.         if(SQL_GetRowCount(handle))
  111.         {
  112.             if(SQL_HasResultSet(handle))
  113.             {
  114.                 decl String:Steamid[32], String:Check[32];
  115.                 GetClientAuthString(client, Steamid, sizeof(Steamid));
  116.                
  117.                 while(SQL_FetchRow(handle))
  118.                 {
  119.                     SQL_FetchString(handle, 0, Check, sizeof(Check));
  120.                
  121.                     if(StrEqual(Steamid, Check))
  122.                     {
  123.                         Ban[client]  = SQL_FetchInt(handle, 2);
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.     }
  129. }
  130.  
  131. public SQL_Connection(Handle:owner, Handle:handle, const String:error[], any:data)
  132. {
  133.     if(handle == INVALID_HANDLE)
  134.     {
  135.         PrintToServer("[CRP Lab] Error : %s", error);
  136.     }
  137.     else
  138.     {
  139.         decl String:Query[128];
  140.        
  141.         DB = handle;
  142.        
  143.         SQL_TQuery(DB, SQL_CheckError, "SET NAMES UTF8;", 0, DBPrio_High);     
  144.        
  145.         Format(Query, sizeof(Query), "SHOW TABLES LIKE '%s';", DB_Name);
  146.         SQL_TQuery(DB, SQL_CheckError, Query, 0, DBPrio_High);
  147.     }
  148. }
  149.  
  150. SQL_CreateTable(Handle:Database)
  151. {
  152.     if(Database != INVALID_HANDLE)
  153.     {
  154.         decl String:Query[128];
  155.        
  156.         Format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS %s(Steamid VARCHAR(32) NOT NULL, Ban INT, PRIMARY KEY (Steamid)) ENGINE=MyISAM DEFAULT CHARSET=UTF8;", DB_Name);
  157.         SQL_TQuery(Database, SQL_CheckError, Query, 0, DBPrio_High);
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement