Описание:
Плагин проверяет наличие Steam ID игрока в базе MySQL\SQLite при подключении к серверу.
Если данный идентификатор найден, происходит его активация\подтверждение. Возможно ограничение по времени в unix формате.
Возможно, пригодится кому либо для регистрации игроков в каких-нибудь ивентах или розыгрышах.
Требования:
SourceMod 1.4.0+
MySQL\SQLite БД
Список изменений:
28.07.12 - v0.0.1 - Первая версия
07.08.12 - v0.0.2 - Добавлен конфиг файл
25.08.12 - v0.0.3 - Мелкая корректировка кода
Настройка:
Настроить подключение БД (databases.cfg)
"RegSys" { "driver" "Тип" //sqlite или mysql "host" "Адрес" "database" "Имя БД" "user" "Логин" "pass" "Пароль" //"timeout" "0" //"port" "3306" }
sm_rs_tb - Имя таблицы
sm_rs_tb_steamid - Имя колонки со Steam ID
sm_rs_tb_active - Имя колонки с индикатором активации (1\0)
sm_rs_tb_te - Имя колонки с временем активации, до скольки
sm_rs_tb_ta - Имя колонки с временем активации, во сколько
Код плагина:
/* ------------------------------------------------------------------------------------- * _____ _____ * | __ \ / ____| * | |__) |___ __ _| (___ _ _ ___ * | _ // _ \/ _` |\___ \| | | / __| Система регистрации\подтверждения Steam ID * | | \ \ __/ (_| |____) | |_| \__ \ (Registration System \ Steam ID confirmation) * |_| \_\___|\__, |_____/ \__, |___/ * __/ | __/ | * |___/ |___/ * -------------------------------------------------------------------------------------- * --Change list------------------------------------------------------------------------- * - 28.07.12 - v0.0.1 - Первая версия * - 07.08.12 - v0.0.2 - Добавлен конфиг файл * - 25.08.12 - v0.0.3 - Мелкая корректировка кода * - 30.11.12 - v0.0.3 - Мелкая корректировка кода #2 * -------------------------------------------------------------------------------------- * --Requirements------------------------------------------------------------------------ * - SourceMod 1.4.0+ * - MySQL\SQLite database * -------------------------------------------------------------------------------------- */ #pragma semicolon 1 #include#define PLUGIN_VERSION "0.0.3" #define PHRASES "translations/RegSys.phrases.txt" #define TIME 3.0 #define DEBUG // --MySQL------------------------------------------------------------------------------- new String:MySQL_SelectTables[] = "SELECT %s, %s FROM %s WHERE %s REGEXP '^STEAM_[0-9]:%s$';"; new String:MySQL_UpdateTables[] = "UPDATE %s SET %s = '1', %s = '%d' WHERE %s REGEXP '^STEAM_[0-9]:%s$';"; // --SQLite------------------------------------------------------------------------------ new String:SQLite_SelectTables[] = "SELECT %s, %s FROM %s WHERE %s = '%s';"; new String:SQLite_UpdateTables[] = "UPDATE %s SET %s = '1', %s = '%d' WHERE %s = '%s';"; // -------------------------------------------------------------------------------------- new String:szDatabase[64], String:szTimeEnd[64], String:szActive[64], String:szSteamID[64], String:szTimeActive[64]; new Handle:ClientRecheck[MAXPLAYERS+1]; new Handle:db = INVALID_HANDLE; new Handle:sm_rs_tb = INVALID_HANDLE; new Handle:sm_rs_tb_steamid = INVALID_HANDLE; new Handle:sm_rs_tb_active = INVALID_HANDLE; new Handle:sm_rs_tb_te = INVALID_HANDLE; new Handle:sm_rs_tb_ta = INVALID_HANDLE; public Plugin:myinfo = { name = "RegSys", author = "duxa", description = "Registration System", version = PLUGIN_VERSION, url = "" } public OnPluginStart() { decl String:szPath[PLATFORM_MAX_PATH]; BuildPath(Path_SM, szPath, sizeof(szPath), "%s", PHRASES); if(!FileExists(szPath)) { PrintToServer("[RegSys] Cannot find the translations for \"RegSys\""); LogError("[RegSys] Cannot find the translations for \"RegSys\""); return; } LoadTranslations("RegSys.phrases"); CreateConVar("sm_rs_version", PLUGIN_VERSION, _, FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_DONTRECORD|FCVAR_NOTIFY); sm_rs_tb = CreateConVar("sm_rs_tb", "reg_data", "The name table"); sm_rs_tb_steamid = CreateConVar("sm_rs_tb_steamid", "STEAM_ID", "The name table with STEAM_ID"); sm_rs_tb_active = CreateConVar("sm_rs_tb_active", "active", "The name table with the state of activation"); sm_rs_tb_te = CreateConVar("sm_rs_tb_te", "time_end", "The name table with end time"); sm_rs_tb_ta = CreateConVar("sm_rs_tb_ta", "time_active", "The name table for activation time"); HookConVarChange(sm_rs_tb, OnSettingChanged); HookConVarChange(sm_rs_tb_steamid, OnSettingChanged); HookConVarChange(sm_rs_tb_active, OnSettingChanged); HookConVarChange(sm_rs_tb_te, OnSettingChanged); HookConVarChange(sm_rs_tb_ta, OnSettingChanged); AutoExecConfig(true, "RegSys"); } public OnConfigsExecuted() { if(!SQL_CheckConfig("RegSys")) { PrintToServer("[RegSys] Database failure: Could not find Database conf \"RegSys\""); LogError("[RegSys] Database failure: Could not find Database conf \"RegSys\""); return; } GetConVarString(sm_rs_tb, szDatabase, sizeof(szDatabase)); GetConVarString(sm_rs_tb_te, szTimeEnd, sizeof(szTimeEnd)); GetConVarString(sm_rs_tb_active, szActive, sizeof(szActive)); GetConVarString(sm_rs_tb_steamid, szSteamID, sizeof(szSteamID)); GetConVarString(sm_rs_tb_ta, szTimeActive, sizeof(szTimeActive)); #if defined DEBUG PrintToServer("OnConfigsExecuted: TB = %s, TE = %s, A = %s, S = %s, TA = %s", szDatabase, szTimeEnd, szActive, szSteamID, szTimeActive); #endif SQL_TConnect(GotDatabase, "RegSys"); } public OnSettingChanged(Handle:convar, const String:oldValue[], const String:newValue[]) { if(convar == sm_rs_tb) { if(!StrEqual(oldValue, newValue)) { GetConVarString(convar, szDatabase, sizeof(szDatabase)); } } else if(convar == sm_rs_tb_te) { if(!StrEqual(oldValue, newValue)) { GetConVarString(convar, szTimeEnd, sizeof(szTimeEnd)); } } else if(convar == sm_rs_tb_active) { if(!StrEqual(oldValue, newValue)) { GetConVarString(convar, szActive, sizeof(szActive)); } } else if(convar == sm_rs_tb_steamid) { if(!StrEqual(oldValue, newValue)) { GetConVarString(convar, szSteamID, sizeof(szSteamID)); } } else if(convar == sm_rs_tb_ta) { if(!StrEqual(oldValue, newValue)) { GetConVarString(convar, szTimeActive, sizeof(szTimeActive)); } } #if defined DEBUG PrintToServer("OnSettingChanged: TB = %s, TE = %s, A = %s, S = %s, TA = %s", szDatabase, szTimeEnd, szActive, szSteamID, szTimeActive); #endif } public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data) { if(hndl == INVALID_HANDLE) { PrintToServer("[RegSys] Unable to connect to database"); LogError("[RegSys] Unable to connect to database (%s)", error); return; } db = hndl; } public OnClientAuthorized(client, const String:auth[]) { if(auth[0] == 'B' || auth[9] == 'L' || IsFakeClient(client) || db == INVALID_HANDLE) return; decl String:szQuery[256]; new String:szIdent[16]; SQL_ReadDriver(db, szIdent, sizeof(szIdent)); if(strcmp(szIdent, "mysql") == 0) { Format(szQuery, sizeof(szQuery), MySQL_SelectTables, szTimeEnd, szActive, szDatabase, szSteamID, auth[8]); } else if(strcmp(szIdent, "sqlite") == 0) { Format(szQuery, sizeof(szQuery), SQLite_SelectTables, szTimeEnd, szActive, szDatabase, szSteamID, auth); } else { PrintToServer("[RegSys] Unknown driver type."); LogError("[RegSys] Unknown driver type."); return; } #if defined DEBUG PrintToServer("OnClientAuthorized(%d): %s", client, szQuery); #endif SQL_TQuery(db, T_Check, szQuery, client); } public OnClientDisconnect_Post(client) { if(ClientRecheck[client] != INVALID_HANDLE) { CloseHandle(ClientRecheck[client]); ClientRecheck[client] = INVALID_HANDLE; } } public Action:Recheck(Handle:timer, any:client) { decl String:szClientSteamID[21]; GetClientAuthString(client, szClientSteamID, sizeof(szClientSteamID)); OnClientAuthorized(client, szClientSteamID); } public T_Check(Handle:owner, Handle:hndl, const String:error[], any:client) { if(hndl == INVALID_HANDLE) { #if defined DEBUG PrintToServer("T_Check(%d): %s", client, error); #endif KickClient(client, "%t", "Error Miss"); return; } if(SQL_FetchRow(hndl)) { new time_end, active; time_end = SQL_FetchInt(hndl, 0); active = SQL_FetchInt(hndl, 1); if(active == 1) { KickClient(client, "%t", "Already Confirmed"); return; } if(time_end > GetTime()) { decl String:szQuery[256]; decl String:szClientSteamID[21]; new String:szIdent[16]; GetClientAuthString(client, szClientSteamID, sizeof(szClientSteamID)); SQL_ReadDriver(db, szIdent, sizeof(szIdent)); if(strcmp(szIdent, "mysql") == 0) { Format(szQuery, 255, MySQL_UpdateTables, szDatabase, szActive, szTimeActive, GetTime(), szSteamID, szClientSteamID[8]); } else if(strcmp(szIdent, "sqlite") == 0) { Format(szQuery, 255, SQLite_UpdateTables, szDatabase, szActive, szTimeActive, GetTime(), szSteamID, szClientSteamID); } else { PrintToServer("[RegSys] Unknown driver type."); LogError("[RegSys] Unknown driver type."); return; } #if defined DEBUG PrintToServer("T_Check(%d): %s", client, szQuery); #endif SQL_TQuery(db, SQL_CheckCallback, szQuery, client); } else { KickClient(client, "%t", "Error Time"); return; } } else { KickClient(client, "%t", "Error Miss"); return; } } public SQL_CheckCallback(Handle:owner, Handle:hndl, const String:error[], any:client) { if(hndl == INVALID_HANDLE) { ClientRecheck[client] = CreateTimer(TIME, Recheck, client); return; } #if defined DEBUG decl String:szClientSteamID[21]; GetClientAuthString(client, szClientSteamID, sizeof(szClientSteamID)); PrintToServer("SQL_CheckCallback(%d): '%s' was confirmed", client, szClientSteamID); #endif KickClient(client, "%t", "Confirm"); } /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Copyright © 2012 duxa | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
Содержание RegSys.phrases.txt
"Phrases" { "Already Confirmed" { "en" "Your STEAM_ID been confirmed" "ru" "Ваш STEAM_ID уже подтвержден" } "Error Time" { "en" "Time to confirm STEAM_ID expired" "ru" "Время для подтверждения STEAM_ID истекло" } "Error Miss" { "en" "This STEAM_ID in the database can not be found" "ru" "Данный STEAM_ID в базе не найден" } "Confirm" { "en" "Your STEAM_ID successfully confirmed" "ru" "Ваш STEAM_ID успешно подтвержден" } }