Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SQL Part
- SQL_ConnectToDB()
- {
- decl String:DB_Names[64];
- GetConVarString(DB_CFG_Name, DB_Names, sizeof(DB_Names));
- SQL_TConnect(SQL_Connection, DB_Names);
- }
- SQL_DisconnectFromDB()
- {
- if(DB != INVALID_HANDLE)
- {
- CloseHandle(DB);
- DB = INVALID_HANDLE;
- }
- }
- SQL_CheckClientData(Handle:Database, client) // String:Steamid[]
- {
- if(Database != INVALID_HANDLE)
- {
- decl String:Query[128], String:Steamid[32];
- GetClientAuthString(client, Steamid, sizeof(Steamid));
- Format(Query, sizeof(Query), "SELECT * FROM %s WHERE Steamid = '%s';", DB_Name, Steamid);
- SQL_TQuery(Database, SQL_CheckClient, Query, client, DBPrio_High);
- }
- }
- SQL_CreateClientData(Handle:Database, client)
- {
- if(Database != INVALID_HANDLE)
- {
- decl String:Query[512], String:Steamid[32];
- GetClientAuthString(client, Steamid, sizeof(Steamid));
- Format(Query, sizeof(Query), "INSERT INTO %s(Steamid, Ban) VALUES('%s', '%N', 0, 0, 0, 0, 0);", DB_Name, Steamid, Steamid);
- SQL_TQuery(Database, SQL_CheckError, Query, client, DBPrio_High);
- }
- }
- SQL_LoadClientData(Handle:Database, client)
- {
- if(Database != INVALID_HANDLE)
- {
- decl String:Query[256], String:Steamid[32];
- GetClientAuthString(client, Steamid, sizeof(Steamid));
- Format(Query, sizeof(Query), "SELECT * FROM %s WHERE Steamid = '%s';", DB_Name, Steamid);
- SQL_TQuery(Database, SQL_LoadData, Query, client, DBPrio_High);
- }
- }
- SQL_SaveClientData(Handle:Database, client)
- {
- if(Database != INVALID_HANDLE)
- {
- decl String:Query[512], String:Steamid[32];
- GetClientAuthString(client, Steamid, sizeof(Steamid));
- Format(Query, sizeof(Query), "UPDATE %s SET Ban = %i WHERE Steamid = '%s';", DB_Name, Ban[client], Steamid);
- SQL_TQuery(Database, SQL_CheckError, Query, client, DBPrio_High);
- }
- }
- public SQL_CheckTable(Handle:owner, Handle:handle, const String:error[], any:data)
- {
- if(handle == INVALID_HANDLE)
- {
- PrintToServer("[CRP Lab] Error : %s", error);
- }
- // if there is no table
- if(SQL_GetRowCount(handle) == 0)
- {
- SQL_CreateTable(DB);
- }
- }
- public SQL_CheckClient(Handle:owner, Handle:handle, const String:error[], any:client)
- {
- if(handle == INVALID_HANDLE)
- {
- PrintToServer("[CRP Lab] Error : %s", error);
- }
- // if there is data
- else if(SQL_GetRowCount(handle))
- {
- SQL_LoadClientData(DB, client);
- }
- // if there is no data
- else if(SQL_GetRowCount(handle) == 0)
- {
- SQL_CreateClientData(DB, client);
- }
- }
- public SQL_LoadData(Handle:owner, Handle:handle, const String:error[], any:client)
- {
- if(handle == INVALID_HANDLE)
- {
- PrintToChat(client, "\x05[CRP Lab]\x03 당신의 VoiceBan 정보를 불러올 수 없습니다.");
- }
- else
- {
- if(SQL_GetRowCount(handle))
- {
- if(SQL_HasResultSet(handle))
- {
- decl String:Steamid[32], String:Check[32];
- GetClientAuthString(client, Steamid, sizeof(Steamid));
- while(SQL_FetchRow(handle))
- {
- SQL_FetchString(handle, 0, Check, sizeof(Check));
- if(StrEqual(Steamid, Check))
- {
- Ban[client] = SQL_FetchInt(handle, 2);
- }
- }
- }
- }
- }
- }
- public SQL_Connection(Handle:owner, Handle:handle, const String:error[], any:data)
- {
- if(handle == INVALID_HANDLE)
- {
- PrintToServer("[CRP Lab] Error : %s", error);
- }
- else
- {
- decl String:Query[128];
- DB = handle;
- SQL_TQuery(DB, SQL_CheckError, "SET NAMES UTF8;", 0, DBPrio_High);
- Format(Query, sizeof(Query), "SHOW TABLES LIKE '%s';", DB_Name);
- SQL_TQuery(DB, SQL_CheckError, Query, 0, DBPrio_High);
- }
- }
- SQL_CreateTable(Handle:Database)
- {
- if(Database != INVALID_HANDLE)
- {
- decl String:Query[128];
- 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);
- SQL_TQuery(Database, SQL_CheckError, Query, 0, DBPrio_High);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement