Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Filterscript made by Kwarde:
- * SA-MP Forums: forum.sa-mp.com/member.php?u=70717
- * E-Mail: kwarde@mail.com
- For information about this filterscript and its defines, check out the 'BugReport_README.txt' file!
- YOU MAY:
- - Use this script ;-)
- - Edit this script (but don't re-release it!)
- - Remove ingame credits (either set USE_INGAME_ADVERTISE to false or change it ingame), but please keep the prints (so you see my name yay :3)
- - Put this into your gamemode
- - Remove this annoying text (the one from start 'till '#define FILTERSCRIPT')
- YOU MAY NOT:
- - Re-release this script
- - Re-release this script and claim it for your own (That is just very pathethic and dumb)
- - Claim the script for your own without re-releasing it
- - Kill other people or steal from other people (re-releasing / claiming as your own is stealing!)
- Enjoy the filterscript :)
- */
- #define FILTERSCRIPT
- #include <a_samp>
- #include <djson>
- #include <sscanf2>
- #include <zcmd>
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_RED 0xFF0000AA
- #define COLOR_GREEN 0x00FF00AA
- #define COLOR_LIGHTBLUE 0x00FFFFAA
- #define COLOR_GRAY 0xAFAFAFAA
- #define FS_VERS_MAJOR 1
- #define FS_VERS_MINOR 0
- #define FS_VERS_BUILD 0
- #define FS_VERS_TAG "S"
- #define BUG_REPORT_FILE "ServerBugReports.txt"
- #define CONF_FILE "BugReport.conf"
- #define TMP_FILE "BugReport.tmp"
- #define USE_INGAME_ADVERTISE true
- #define REPORT_INTERVAL 30
- #define DIALOG_BREPORT 666
- #define DIALOG_BREPORT_CONFIRM 667
- #define CB:%0(%1) forward %0(%1); public %0(%1)
- #define ploop(%0) for (new %0 = 0; %0 < MAX_PLAYERS; %0++) if (IsPlayerConnected(%0) && !IsPlayerNPC(%0))
- enum sConf
- {
- bool:useAds,
- cmdInterval,
- bool:fileUpdated,
- nextBugId,
- };
- new ServerConf[sConf];
- enum pInf
- {
- bool:pFirstSpawn,
- bool:pCanReport,
- pReportTimer,
- pReportStr[100]
- };
- new PlayerInfo[MAX_PLAYERS][pInf];
- public OnFilterScriptInit()
- {
- djson_GameModeInit();
- if (!fexist(CONF_FILE))
- {
- djCreateFile(CONF_FILE);
- djSetInt(CONF_FILE, "useAds", USE_INGAME_ADVERTISE);
- djSetInt(CONF_FILE, "cmdInterval", REPORT_INTERVAL * 1000);
- if (!fexist(BUG_REPORT_FILE))
- {
- djSetInt(CONF_FILE, "bugReportFileUpdated", 1);
- djSetInt(CONF_FILE, "nextBugID", -1);
- }
- else djSetInt(CONF_FILE, "bugReportFileUpdated", 0);
- ServerConf[useAds] = USE_INGAME_ADVERTISE;
- ServerConf[cmdInterval] = REPORT_INTERVAL;
- ServerConf[nextBugId] = 0;
- }
- else
- {
- ServerConf[useAds] = djInt(CONF_FILE, "useAds") ? true : false;
- ServerConf[cmdInterval] = djInt(CONF_FILE, "cmdInterval") ? true : false;
- ServerConf[nextBugId] = djInt(CONF_FILE, "nextBugID");
- }
- ServerConf[fileUpdated] = djInt(CONF_FILE, "bugReportFileUpdated") ? true : false;
- if (fexist(BUG_REPORT_FILE) && !ServerConf[fileUpdated])
- {
- print("[BugReport] Checking the server bug report file...");
- new File:bugReportFile,
- File:tmpFile,
- readData[135],
- storeData_Name[24],
- storeData_Report[100],
- storeData_ID = (-1),
- bool:mustUpdate;
- bugReportFile = fopen(BUG_REPORT_FILE, io_read);
- while (fread(bugReportFile, readData))
- {
- if (sscanf(readData, "{p<|>ds[24]s[100]}"))
- {
- mustUpdate = true;
- break;
- }
- }
- fclose(bugReportFile);
- if (!mustUpdate)
- {
- print("[BugReport] Server bug report file is already compatible with your current script version.");
- }
- else
- {
- print("[BugReport] Server bug report file is not compatible with the current version! (v"#FS_VERS_MAJOR"."#FS_VERS_MINOR"."#FS_VERS_BUILD"-"#FS_VERS_TAG")");
- print("[BugReport] Updating '"#BUG_REPORT_FILE"'...");
- bugReportFile = fopen(BUG_REPORT_FILE, io_read);
- tmpFile = fopen(TMP_FILE, io_append);
- while (fread(bugReportFile, readData))
- {
- new tmpWrite[135];
- storeData_ID++;
- sscanf(readData, "p<|>s[24]s[100]", storeData_Name, storeData_Report);
- format(tmpWrite, 135, "%d|%s|%s", storeData_ID, storeData_Name, storeData_Report);
- fwrite(tmpFile, tmpWrite);
- }
- fclose(bugReportFile);
- fclose(tmpFile);
- fremove(BUG_REPORT_FILE);
- bugReportFile = fopen(BUG_REPORT_FILE, io_append);
- tmpFile = fopen(TMP_FILE, io_read);
- while (fread(tmpFile, readData))
- fwrite(bugReportFile, readData);
- fclose(bugReportFile);
- fclose(tmpFile);
- fremove(TMP_FILE);
- ServerConf[nextBugId] = storeData_ID + 1;
- ServerConf[fileUpdated] = true;
- print("[BugReport] Server bug report file has been updated and is now compatible with the BugReport FS!");
- }
- }
- else ServerConf[fileUpdated] = true;
- ploop(i) ResetPlayer(i);
- print(">> BugReport v"#FS_VERS_MAJOR"."#FS_VERS_MINOR"."#FS_VERS_BUILD"-"#FS_VERS_TAG" loaded <<");
- print(">> BugReport created by Kwarde (contact: kwarde@mail.com) <<");
- return 1;
- }
- public OnFilterScriptExit()
- {
- djSetInt(CONF_FILE, "useAds", ServerConf[useAds]);
- djSetInt(CONF_FILE, "cmdInterval", ServerConf[cmdInterval]);
- djSetInt(CONF_FILE, "nextBugID", ServerConf[nextBugId]);
- djSetInt(CONF_FILE, "bugReportFileUpdated", ServerConf[fileUpdated]);
- djson_GameModeExit();
- ploop (i) ResetPlayer(i);
- print(">> WARNING: BugReport filterscript unloaded! <<");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if (ServerConf[useAds] && !PlayerInfo[playerid][pFirstSpawn])
- {
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}We are using BugReport so that you can report bugs! ({FFFF00}/reportbug{FFFFFF})");
- SendClientMessage(playerid, COLOR_GREEN, "BugReport is created by kwarde ({FFFFFF}kwarde@mail.com{00FF00})");
- PlayerInfo[playerid][pFirstSpawn] = true;
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- ResetPlayer(playerid);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch (dialogid)
- {
- case DIALOG_BREPORT:
- {
- if (!response)
- return SendClientMessage(playerid, COLOR_GRAY, "You cancelled the bug report");
- if (strlen(inputtext) < 10 || strlen(inputtext) > 100)
- {
- SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}The bug report must contain 10-100 characters!");
- ShowDialog(playerid, DIALOG_BREPORT);
- return 1;
- }
- strset(PlayerInfo[playerid][pReportStr], inputtext);
- ShowDialog(playerid, DIALOG_BREPORT_CONFIRM);
- return 1;
- }
- case DIALOG_BREPORT_CONFIRM:
- {
- if (!response)
- return ShowDialog(playerid, DIALOG_BREPORT);
- new str[128], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
- BugReport(playerid, PlayerInfo[playerid][pReportStr]);
- SendClientMessage(playerid, COLOR_GREEN, "Thank you very much for reporting this bug!");
- format(str, 128, "[NOTICE] %s (ID: %d) reported a bug! Use /checkbugs to see the report (You'll see the last 9 reports!)", pName, playerid);
- ploop(i)
- {
- if (!IsAdmin(i)) continue;
- SendClientMessage(i, COLOR_LIGHTBLUE, str);
- }
- PlayerInfo[playerid][pCanReport] = false;
- SetTimerEx("PReportOn", ServerConf[cmdInterval] * 1000, false, "i", playerid);
- }
- }
- return 1;
- }
- CB:PReportOn(playerid)
- {
- PlayerInfo[playerid][pReportTimer] = (-1);
- PlayerInfo[playerid][pCanReport] = true;
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}You can use /reportbug again to report bugs!");
- return 1;
- }
- stock strset(string[], substr[])
- {
- strdel(string, 0, strlen(string) + 1);
- strins(string, substr, 0, strlen(substr) + 1);
- return 1;
- }
- stock RemoveBugId(id)
- {
- new File:bugReportFile,
- File:tmpFile,
- readStr[135];
- bugReportFile = fopen(BUG_REPORT_FILE, io_read);
- tmpFile = fopen(TMP_FILE, io_append);
- while (fread(bugReportFile, readStr))
- fwrite(tmpFile, readStr);
- fclose(bugReportFile);
- fclose(tmpFile);
- fremove(BUG_REPORT_FILE);
- bugReportFile = fopen(BUG_REPORT_FILE, io_append);
- tmpFile = fopen(TMP_FILE, io_read);
- while (fread(tmpFile, readStr))
- {
- new storeData_ID;
- sscanf(readStr, "p<|>d{s[24]s[100]}", storeData_ID);
- if (storeData_ID == id) continue;
- fwrite(bugReportFile, readStr);
- }
- fclose(bugReportFile);
- fclose(tmpFile);
- fremove(TMP_FILE);
- return 1;
- }
- stock ResetPlayer(playerid)
- {
- if (PlayerInfo[playerid][pReportTimer] != -1)
- KillTimer(PlayerInfo[playerid][pReportTimer]);
- PlayerInfo[playerid][pFirstSpawn] = false;
- PlayerInfo[playerid][pCanReport] = true;
- PlayerInfo[playerid][pReportTimer] = (-1);
- PlayerInfo[playerid][pReportStr] = EOS;
- return 1;
- }
- stock GetFileLines(file[])
- {
- if (!fexist(file)) return 0;
- new File:readFile = fopen(file, io_read),
- readStr[135],
- lines = 0;
- while (fread(readFile, readStr))
- lines++;
- fclose(readFile);
- return lines;
- }
- stock BugReport(playerid, bug[])
- {
- new pName[MAX_PLAYER_NAME],
- File:bugReportFile = fopen(BUG_REPORT_FILE, io_append),
- writeStr[135];
- GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
- format(writeStr, 135, "%d|%s|%s\n", ServerConf[nextBugId], pName, bug);
- fwrite(bugReportFile, writeStr);
- fclose(bugReportFile);
- ServerConf[nextBugId]++;
- djSetInt(CONF_FILE, "nextBugID", ServerConf[nextBugId]);
- return 1;
- }
- stock IsAdmin(playerid)
- {
- if (IsPlayerAdmin(playerid))
- return true;
- return false;
- }
- stock ShowDialog(playerid, dialogid)
- {
- switch (dialogid)
- {
- case DIALOG_BREPORT: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Bug report", "Please fill in the bug you found as short as possible.\nDon't forget to say when this bug occured! (Eg. after using a function, after spawn? etc).\nA maximum of 100 characters is allowed", "Report", "Cancel");
- case DIALOG_BREPORT_CONFIRM:
- {
- new str[210];
- format(str, 210, "{FFFFFF}You are going to report the next bug:\n{FF0000}%s\n{FFFFFF}Are you sure you want to report that?", PlayerInfo[playerid][pReportStr]);
- ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Bug report: CONF_FILEirm", str, "Yes", "No");
- }
- }
- return 1;
- }
- CMD:reportbug(playerid, params[])
- {
- if (PlayerInfo[playerid][pCanReport])
- ShowDialog(playerid, DIALOG_BREPORT);
- else SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}You can't use this command yet! You'll get a message when you are allowed to use it again");
- return 1;
- }
- CMD:checkbugs(playerid, params[])
- {
- if (!IsAdmin(playerid)) return 0;
- if (GetFileLines(BUG_REPORT_FILE) == 0) return SendClientMessage(playerid, COLOR_RED, "[NOTICE] {FFFFFF}There are no bugs reported!");
- for (new i = 0; i < 10; i++) SendClientMessage(playerid, -1, " ");
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "|---------- {FFFF00}Bug reports {00FFFF}----------|");
- new File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
- readStr[135],
- str[128],
- curLine = 0,
- start;
- if (GetFileLines(BUG_REPORT_FILE) <= 9) start = 0;
- else start = GetFileLines(BUG_REPORT_FILE) - 8;
- while (fread(bugReportFile, readStr))
- {
- curLine++;
- if (curLine < start) continue;
- new infoId,
- infoName[MAX_PLAYER_NAME],
- infoBug[100];
- sscanf(readStr, "p<|>ds[24]s[100]", infoId, infoName, infoBug);
- format(str, 128, "#%d %s: {AFAFAF}%s", infoId, infoName, infoBug);
- SendClientMessage(playerid, COLOR_WHITE, str);
- }
- fclose(bugReportFile);
- return 1;
- }
- CMD:editconf(playerid, params[])
- {
- if (!IsAdmin(playerid)) return 0;
- new opt[9], conf;
- if (sscanf(params, "s[9]D(-1)", opt, conf)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf ['interval' or 'useads'] [value]");
- if (!strcmp(opt, "interval"))
- {
- if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf interval [interval time in seconds]");
- if (conf < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}CMD interval time bust be 1 or higher!");
- if (conf == ServerConf[cmdInterval]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}cmdInterval already has that value!");
- ServerConf[cmdInterval] = conf;
- djSetInt(CONF_FILE, "cmdInterval", conf);
- new str[70];
- format(str, 70, "SERVER: /reportbug usage interval changed to %d seconds", conf);
- SendClientMessage(playerid, COLOR_WHITE, str);
- ploop(i)
- {
- if (!PlayerInfo[i][pCanReport])
- {
- KillTimer(PlayerInfo[i][pReportTimer]);
- PReportOn(i);
- }
- }
- }
- else if (!strcmp(opt, "useads"))
- {
- if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf useads [0/1]");
- if (conf != 0 && conf != 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf useads {FF0000}[0/1]");
- if ((conf ? true : false) == ServerConf[useAds]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}useAds already has that value!");
- ServerConf[useAds] = (conf ? true : false);
- djSetInt(CONF_FILE, "useAds", conf);
- ploop(i) PlayerInfo[i][pFirstSpawn] = false;
- if (ServerConf[useAds])
- SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now enabled");
- else SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now disabled");
- }
- else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf {FF0000}['interval' or 'useads']{00FFFF} [value]");
- return 1;
- }
- CMD:removebugreport(playerid, params[])
- {
- if (!IsAdmin(playerid)) return 0;
- if (GetFileLines(BUG_REPORT_FILE) == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}No bugs were reported yet! (To be more specific, the report file doesn't exist or is empty)");
- if (isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /removebugreport [bug id]");
- new bugId = (-1),
- File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
- readStr[135];
- while (fread(bugReportFile, readStr))
- {
- new storeData_ID;
- sscanf(readStr, "p<|>d{s[24]s[100]}", storeData_ID);
- if (storeData_ID == strval(params))
- {
- bugId = storeData_ID;
- break;
- }
- else continue;
- }
- fclose(bugReportFile);
- if (bugId != -1)
- {
- RemoveBugId(bugId);
- new str[40];
- format(str, 40, "Bug report #%d has been removed!", bugId);
- SendClientMessage(playerid, COLOR_GREEN, str);
- }
- else return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}That bug report ID doesn't exist!");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement