Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------
- // ReportSystem v1.0.0 by paul988
- //--------------------------------------------------
- #include <a_samp>
- #undef MAX_PLAYERS
- #define MAX_PLAYERS (50) // == MAX_PLAYERS (change to the amount of player slots you have on your server)
- #include <a_mysql>
- #include <sscanf2>
- #include <zcmd>
- //-------------(DO NOT CHANGE)------------------------------------
- #define AUTHOR "paul988" // == AUTHOR (Do not change)
- #define VERSION "v1.0.0" // == VERSION (Do not change)
- //----------------------------------------------------------------
- #define MAX_REPORTS (100)
- // Define when to split the text into another line!
- #define EX_SPLITLENGTH (118)
- #define SQL_HOST "" // == MySQL Host
- #define SQL_USER "" // == MySQL Username
- #define SQL_DB "" // == MYSQL Database
- #define SQL_PASS "" // == MYSQL Password
- #define SQL_PORT (3306) // == MySQL Port
- #define SQL_AUTOCONNECT true // == MySQL AutoConnect
- #define SQL_POOL-SIZE (4) // == MySQL Pool_Size
- #define DEBUG false // == DEBUG Mode
- enum ReportInfo
- {
- ID,
- Reporter[MAX_PLAYER_NAME],
- Reported[MAX_PLAYER_NAME],
- Reason[128]
- }
- new rInfo[MAX_REPORTS][ReportInfo];
- new ReportCount;
- new ReportTimer[MAX_PLAYERS];
- static PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME];
- static dbHandle = -1;
- forward OnCreateTableIfNotExists();
- public OnCreateTableIfNotExists()
- {
- LoadReports();
- return 1;
- }
- forward OnLoadReports();
- public OnLoadReports()
- {
- new rows, fields;
- cache_get_data(rows, fields);
- if(rows)
- {
- new idx;
- while(idx < rows)
- {
- rInfo[idx][ID] = cache_get_field_content_int(idx, "id");
- cache_get_field_content(idx, "reporter", rInfo[idx][Reporter], dbHandle, MAX_PLAYER_NAME);
- cache_get_field_content(idx, "reported", rInfo[idx][Reported], dbHandle, MAX_PLAYER_NAME);
- cache_get_field_content(idx, "reason", rInfo[idx][Reason], dbHandle, 128);
- ReportCount++;
- idx++;
- }
- }
- #if DEBUG == true
- printf("[ReportSystem]: Loaded %d reports.", ReportCount);
- #endif
- return 1;
- }
- forward OnDeleteReport(playerid, reportid);
- public OnDeleteReport(playerid, reportid)
- {
- for(new ReportInfo:r; r < ReportInfo; ++r)
- {
- if(IsNumeric(rInfo[reportid][r])) rInfo[reportid][r] = -1;
- else format(rInfo[reportid][r], 128, "");
- }
- ReportCount--;
- SendClientMessage(playerid, 0xD3D3D3AA, "Report successfully deleted!");
- return 1;
- }
- forward OnCreateReport(playerid, target, reason[128], reportid);
- public OnCreateReport(playerid, target, reason[128], reportid)
- {
- rInfo[reportid][ID] = reportid;
- format(rInfo[reportid][Reporter], MAX_PLAYER_NAME, "%s", PlayerName[playerid]);
- format(rInfo[reportid][Reported], MAX_PLAYER_NAME, "%s", PlayerName[target]);
- format(rInfo[reportid][Reason], 128, "%s", reason);
- ReportTimer[playerid] = (GetTickCount() + 180000);
- ReportCount++;
- SendClientMessage(playerid, 0xD3D3D3AA, "Report successfully created!");
- return 1;
- }
- public OnFilterScriptInit()
- {
- for(new idx = 0; idx < MAX_REPORTS; idx++) rInfo[idx][ID] = -1;
- for(new i = 0; i < MAX_PLAYERS; i++)
- if( (IsPlayerConnected(i)) && (i != INVALID_PLAYER_ID) )
- GetPlayerName(i, PlayerName[i], MAX_PLAYER_NAME);
- mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
- dbHandle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS, SQL_PORT, SQL_AUTOCONNECT, SQL_POOL-SIZE);
- #if DEBUG == true
- if(mysql_errno() != 0) printf("[ReportSystem]: Could not connect to %s!", SQL_DB);
- else printf("[ReportSystem]: Successfully connected to %s!", SQL_DB);
- #endif
- CreateTableIfNotExists();
- printf("[ReportSystem]: Version %s by %s successfully loaded.", VERSION, AUTHOR);
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close(dbHandle);
- printf("[ReportSystem]: Version %s by %s successfully unloaded.", VERSION, AUTHOR);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- GetPlayerName(playerid, PlayerName[playerid], MAX_PLAYER_NAME);
- ReportTimer[playerid] = (GetTickCount() - 1);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- format(PlayerName[playerid], MAX_PLAYER_NAME, "");
- ReportTimer[playerid] = (GetTickCount() - 1);
- }
- CMD:report(playerid, params[])
- {
- if(ReportTimer[playerid] > GetTickCount()) return SendClientMessage(playerid, 0xD3D3D3AA, "Command on cooldown! Please try again later!");
- new target;
- static reason[128];
- if(sscanf(params, "ds[128]", target, reason)) return SendClientMessage(playerid, 0xD3D3D3AA, "Usage: /report [PlayerID/PartOfName] [Reason]");
- if( (!IsPlayerConnected(target)) && (target == INVALID_PLAYER_ID) ) return SendClientMessage(playerid, 0xD3D3D3AA, "Target not connected!");
- if(playerid == target) return SendClientMessage(playerid, 0xD3D3D3AA, "You are unable to report yourself!");
- if(IsPlayerAdmin(target)) return SendClientMessage(playerid, 0xD3D3D3AA, "You are unable to report adminstrators!");
- CreateReport(playerid, target, reason);
- return 1;
- }
- CMD:reports(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xD3D3D3AA, "You are not allowed to use this command!");
- ShowReports(playerid);
- return 1;
- }
- CMD:reloadreports(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xD3D3D3AA, "You are not allowed to use this command!");
- ReloadReports();
- SendClientMessage(playerid, 0xD3D3D3AA, "Reports successfully reloaded!");
- return 1;
- }
- CMD:deletereport(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xD3D3D3AA, "You are not allowed to use this command!");
- new reportid;
- if(sscanf(params, "d", reportid)) return SendClientMessage(playerid, 0xD3D3D3AA, "Usage: /deletereport [ReportID]");
- DeleteReport(playerid, reportid);
- return 1;
- }
- CMD:checkreports(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xD3D3D3AA, "You are not allowed to use this command!");
- new type, select[MAX_PLAYER_NAME];
- if(sscanf(params, "ds[24]", type, select)) return SendClientMessage(playerid, 0xD3D3D3AA, "Usage: /checkreports [1/2/3] [ReportID/Reporter/Reported]");
- CheckReport(playerid, type, select);
- return 1;
- }
- CreateTableIfNotExists()
- {
- static query[256];
- mysql_format(dbHandle, query, sizeof(query), "CREATE TABLE IF NOT EXISTS `reports` ( \
- `id` INT(11) NOT NULL, \
- `reporter` VARCHAR(24) NOT NULL, \
- `reported` VARCHAR(24) NOT NULL, \
- `reason` VARCHAR(128) NOT NULL, \
- PRIMARY KEY (`id`) \
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- mysql_pquery(dbHandle, query, "OnCreateTableIfNotExists");
- return 1;
- }
- LoadReports()
- {
- static query[128];
- mysql_format(dbHandle, query, sizeof(query), "SELECT * FROM `reports` ORDER BY `id` LIMIT %d", MAX_REPORTS);
- mysql_pquery(dbHandle, query, "OnLoadReports");
- return 1;
- }
- ReloadReports()
- {
- for(new idx = 0; idx < MAX_REPORTS; idx++)
- {
- for(new ReportInfo:r; r < ReportInfo; ++r)
- {
- if(IsNumeric(rInfo[idx][r])) rInfo[idx][r] = -1;
- else format(rInfo[idx][r], 128, "");
- }
- }
- LoadReports();
- }
- CreateReport(playerid, target, reason[128])
- {
- new reportid = GetUnusedID();
- if(reportid == -1) return 0;
- if(ReportCount > MAX_REPORTS) return SendClientMessage(playerid, 0xD3D3D3AA, "Too many reports! Please try again later.");
- static query[187];
- mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `reports` (`id`, `reporter`, `reported`, `reason`) VALUES (%d, '%e', '%e', '%e')",
- reportid, PlayerName[playerid], PlayerName[target], reason);
- mysql_pquery(dbHandle, query, "OnCreateReport", "ddsd", playerid, target, reason, reportid);
- return 1;
- }
- DeleteReport(playerid, reportid)
- {
- if( (rInfo[reportid][ID] == -1) || (reportid > MAX_REPORTS) ) return SendClientMessage(playerid, 0xD3D3D3AA, "Invalid report id!");
- static query[128];
- mysql_format(dbHandle, query, sizeof(query), "DELETE FROM `reports` WHERE `id` = %d LIMIT 1", reportid);
- mysql_pquery(dbHandle, query, "OnDeleteReport", "dd", playerid, reportid);
- return 1;
- }
- ShowReports(playerid)
- {
- SendClientMessage(playerid, 0xD3D3D3AA, "______________________________{BEBEBE} Reports{D3D3D3} ______________________________");
- SendClientMessage(playerid, 0xD3D3D3AA, "");
- static str[237];
- for(new idx = 0; idx < 7; idx++)
- {
- if(rInfo[idx][ID] != -1)
- {
- format(str, sizeof(str), "> ReportID: %d - Reporter: %s - Reported: %s - Reason: %s", rInfo[idx][ID], rInfo[idx][Reporter], rInfo[idx][Reported], rInfo[idx][Reason]);
- SendSplitMessage(playerid, 0xD3D3D3AA, str);
- }
- }
- SendClientMessage(playerid, 0xD3D3D3AA, "");
- SendClientMessage(playerid, 0xD3D3D3AA, "____________________________________________________________________");
- return 1;
- }
- CheckReport(playerid, type, select[MAX_PLAYER_NAME])
- {
- switch(type)
- {
- case 1:
- {
- if(!IsNumeric(select)) return SendClientMessage(playerid, 0xD3D3D3AA, "Usage: /checkreports [1/2/3] [ReportID/Reporter/Reported]");
- new val = strval(select);
- for(new idx = 0; idx < MAX_REPORTS; idx++)
- {
- if(rInfo[idx][ID] == val)
- {
- static str[237];
- format(str, sizeof(str), "> ReportID: %d - Reporter: %s - Reported: %s - Reason: %s", rInfo[idx][ID], rInfo[idx][Reporter], rInfo[idx][Reported], rInfo[idx][Reason]);
- return SendSplitMessage(playerid, 0xD3D3D3AA, str);
- }
- }
- return SendClientMessage(playerid, 0xD3D3D3AA, "Report not found in database!");
- }
- case 2:
- {
- new count = 0;
- for(new idx = 0; idx < MAX_REPORTS; idx++)
- {
- if( (!strcmp(rInfo[idx][Reported], select, true)) && (rInfo[idx][ID] != -1) )
- {
- static str[237];
- format(str, sizeof(str), "> ReportID: %d - Reporter: %s - Reported: %s - Reason: %s", rInfo[idx][ID], rInfo[idx][Reporter], rInfo[idx][Reported], rInfo[idx][Reason]);
- SendSplitMessage(playerid, 0xD3D3D3AA, str);
- count++;
- }
- }
- if(count > 0) return 1;
- else SendClientMessage(playerid, 0xD3D3D3AA, "Report not found in database!");
- }
- case 3:
- {
- new count = 0;
- for(new idx = 0; idx < MAX_REPORTS; idx++)
- {
- if( (!strcmp(rInfo[idx][Reported], select, true)) && (rInfo[idx][ID] != -1) )
- {
- static str[237];
- format(str, sizeof(str), "> ReportID: %d - Reporter: %s - Reported: %s - Reason: %s", rInfo[idx][ID], rInfo[idx][Reporter], rInfo[idx][Reported], rInfo[idx][Reason]);
- SendSplitMessage(playerid, 0xD3D3D3AA, str);
- count++;
- }
- }
- if(count > 0) return 1;
- else SendClientMessage(playerid, 0xD3D3D3AA, "Report not found in database!");
- }
- default: SendClientMessage(playerid, 0xD3D3D3AA, "Usage: /checkreports [1/2/3] [ReportID/Reporter/Reported]");
- }
- return 1;
- }
- stock GetUnusedID()
- {
- new found = -1;
- for(new idx = 0; idx < MAX_REPORTS; idx++)
- {
- if(rInfo[idx][ID] == -1)
- {
- return idx;
- }
- }
- return found;
- }
- // Credits to Mike (http://wiki.sa-mp.com/wiki/Useful_Functions#IsNumeric)
- stock IsNumeric(const string[])
- {
- for (new i = 0, j = strlen(string); i < j; i++)
- {
- if (string[i] > '9' || string[i] < '0') return 0;
- }
- return 1;
- }
- // Credits to Extremo (http://forum.sa-mp.com/showpost.php?p=1916941&postcount=4)
- stock SendSplitMessage(playerid, color, final[])
- {
- new buffer[EX_SPLITLENGTH+5];
- new len = strlen(final);
- if(len>EX_SPLITLENGTH)
- {
- new times = (len/EX_SPLITLENGTH);
- for(new i = 0; i < times+1; i++)
- {
- strdel(buffer, 0, EX_SPLITLENGTH+5);
- if(len-(i*EX_SPLITLENGTH)>EX_SPLITLENGTH)
- {
- strmid(buffer, final, EX_SPLITLENGTH*i, EX_SPLITLENGTH*(i+1));
- format(buffer, sizeof(buffer), "%s ...", buffer);
- }
- else
- {
- strmid(buffer, final, EX_SPLITLENGTH*i, len);
- format(buffer, sizeof(buffer), "... %s", buffer);
- }
- SendClientMessage(playerid, color, buffer);
- }
- }
- else
- {
- SendClientMessage(playerid, color, final);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement