Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined _sys_log_included
- #endinput
- #endif
- #define _sys_log_included
- #include <a_samp>
- #include <a_mysql>
- #include <CTime>
- /*
- native InsertLog(const text[]);
- native DisplayLogs(playerid, limit);
- */
- #if !defined mysql_included
- #error "a_mysql must be included"
- #endif
- #if !defined _CTime_Included
- #error "CTime must be included"
- #endif
- new
- connectionHandle,
- scriptString[256];
- #if defined FILTERSCRIPT
- public OnFilterScriptInit() {
- connectionHandle = mysql_connect("localhost", "root", "sa-mp", "");
- if(mysql_ping(connectionHandle) == -1)
- return SendRconCommand("unloadfs sys_log");
- mysql_function_query(connectionHandle,
- "CREATE TABLE IF NOT EXISTS `sys_log` (`log_date` INT(11) NOT NULL, `log_text` VARCHAR(128) NOT NULL)", false, #, #);
- if(funcidx("log_OnFilterScriptInit") != -1)
- return CallLocalFunction("log_OnFilterScriptInit", #);
- return true;
- }
- public OnFilterScriptExit() {
- mysql_close(connectionHandle);
- if(funcidx("log_OnFilterScriptExit") != -1)
- return CallLocalFunction("log_OnFilterScriptExit", #);
- return true;
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit log_OnFilterScriptInit
- #if defined _ALS_OnFilterScriptExit
- #undef OnFilterScriptExit
- #else
- #define _ALS_OnFilterScriptExit
- #endif
- #define OnFilterScriptExit log_OnFilterScriptExit
- forward log_OnFilterScriptInit();
- forward log_OnFilterScriptExit();
- #else
- public OnGameModeInit() {
- connectionHandle = mysql_connect("localhost", "root", "sa-mp", "");
- if(mysql_ping(connectionHandle) == -1)
- return SendRconCommand("unloadfs sys_log");
- mysql_function_query(connectionHandle,
- "CREATE TABLE IF NOT EXISTS `sys_log` (`log_date` INT(11) NOT NULL, `log_text` VARCHAR(128) NOT NULL)", false, #, #);
- if(funcidx("log_OnGameModeInit") != -1)
- return CallLocalFunction("log_OnGameModeInit", #);
- return true;
- }
- public OnGameModeExit() {
- mysql_close(connectionHandle);
- if(funcidx("log_OnGameModeExit") != -1)
- return CallLocalFunction("log_OnGameModeExit", #);
- return true;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit log_OnGameModeInit
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit log_OnGameModeExit
- forward log_OnGameModeInit();
- forward log_OnGameModeExit();
- #endif
- stock InsertLog(const text[]) {
- mysql_format(connectionHandle, scriptString, sizeof scriptString,
- "INSERT INTO `sys_log` (`log_date`, `log_text`) VALUES (UNIX_TIMESTAMP(), '%s')", text);
- mysql_function_query(connectionHandle, scriptString, false, #, #);
- return true;
- }
- stock DisplayLogs(playerid, limit) {
- mysql_format(connectionHandle, scriptString, sizeof scriptString,
- "SELECT * FROM `sys_log` ORDER BY `log_date` ASC LIMIT %d", limit);
- mysql_function_query(connectionHandle, scriptString, true, "r@DisplayLogs", "ii", playerid, limit);
- return true;
- }
- r@DisplayLogs(playerid, limit); public r@DisplayLogs(playerid, limit) {
- new num_rows, num_fields;
- cache_get_data(num_rows, num_fields, connectionHandle);
- if(!num_rows)
- return SendClientMessage(playerid, 0xff0000ff, "(!) Não há nenhum log no banco de dados.");
- new
- index = -1,
- timestamp,
- content[128],
- tm<tmTime>;
- format(content, sizeof content, "Últimos %02d logs", limit);
- SendClientMessage(playerid, 0xffffffff, content);
- while(++index < num_rows) {
- timestamp = cache_get_field_content_int(index, "log_date", connectionHandle);
- localtime(Time:timestamp, tmTime);
- strftime(scriptString, sizeof scriptString, "%d/%m/%Y às %X", tmTime);
- cache_get_field_content(index, "log_text", content, connectionHandle);
- format(scriptString, sizeof scriptString,
- " %s, %s: %s", GetWeekDay(timestamp), scriptString, content);
- SendClientMessage(playerid, 0xffffffff, scriptString);
- }
- return true;
- }
- stock GetWeekDay(timestamp) {
- new
- tm<tmTime>,
- buffer[32];
- localtime(Time:timestamp, tmTime);
- switch(tmTime[tm_wday]) {
- case 1: buffer = "Segunda-feira";
- case 2: buffer = "Terça-feira";
- case 3: buffer = "Quarta-feira";
- case 4: buffer = "Quinta-feira";
- case 5: buffer = "Sexta-feira";
- case 6: buffer = "Sábado";
- case 7: buffer = "Domingo";
- }
- return buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement