Advertisement
Kwarde

BugReport v0.4.34-RC

May 23rd, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.31 KB | None | 0 0
  1. /*
  2.     Filterscript made by Kwarde:
  3.         * SA-MP Forums: forum.sa-mp.com/member.php?u=70717
  4.         * E-Mail:       kwarde@mail.com
  5.  
  6.     For information about this filterscript and its defines, check out the 'BugReport_README.txt' file!
  7.  
  8.     YOU MAY:
  9.         - Use this script ;-)
  10.         - Edit this script (but don't re-release it!)
  11.         - 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)
  12.         - Put this into your gamemode
  13.         - Remove this annoying text (the one from start 'till '#define FILTERSCRIPT')
  14.     YOU MAY NOT:
  15.         - Re-release this script
  16.         - Re-release this script and claim it for your own (That is just very pathethic and dumb)
  17.         - Claim the script for your own without re-releasing it
  18.         - Kill other people or steal from other people (re-releasing / claiming as your own is stealing!)
  19.  
  20.     Enjoy the filterscript :)
  21. */
  22. #define FILTERSCRIPT
  23. #include <a_samp>
  24. #include <djson>
  25. #include <sscanf2>
  26. #include <zcmd>
  27.  
  28. #define COLOR_WHITE             0xFFFFFFAA
  29. #define COLOR_RED               0xFF0000AA
  30. #define COLOR_GREEN             0x00FF00AA
  31. #define COLOR_LIGHTBLUE         0x00FFFFAA
  32. #define COLOR_GRAY              0xAFAFAFAA
  33.  
  34. #define FS_VERS_MAJOR           0
  35. #define FS_VERS_MINOR           4
  36. #define FS_VERS_BUILD           34
  37. #define FS_VERS_TAG             "RC"
  38.  
  39. #define BUG_REPORT_FILE         "ServerBugReports.txt"
  40. #define CONF_FILE               "BugReport.conf"
  41. #define TMP_FILE                "BugReport.tmp"
  42. #define USE_INGAME_ADVERTISE    true
  43. #define REPORT_INTERVAL         30
  44.  
  45. #define DIALOG_BREPORT          666
  46. #define DIALOG_BREPORT_CONFIRM  667
  47.  
  48. #define CB:%0(%1)               forward %0(%1); public %0(%1)
  49. #define ploop(%0)               for (new %0 = 0; %0 < MAX_PLAYERS; %0++) if (IsPlayerConnected(%0) && !IsPlayerNPC(%0))
  50.  
  51. enum sConf
  52. {
  53.     bool:useAds,
  54.     cmdInterval,
  55.     bool:fileUpdated,
  56.     nextBugId,
  57. };
  58. new ServerConf[sConf];
  59.  
  60. enum pInf
  61. {
  62.     bool:pFirstSpawn,
  63.     bool:pCanReport,
  64.     pReportTimer,
  65.     pReportStr[100]
  66. };
  67. new PlayerInfo[MAX_PLAYERS][pInf];
  68.  
  69. public OnFilterScriptInit()
  70. {
  71.     djson_GameModeInit();
  72.     if (!fexist(CONF_FILE))
  73.     {
  74.         djCreateFile(CONF_FILE);
  75.         djSetInt(CONF_FILE, "useAds", USE_INGAME_ADVERTISE);
  76.         djSetInt(CONF_FILE, "cmdInterval", REPORT_INTERVAL * 1000);
  77.  
  78.         if (!fexist(BUG_REPORT_FILE))
  79.         {
  80.             djSetInt(CONF_FILE, "bugReportFileUpdated", 1);
  81.             djSetInt(CONF_FILE, "nextBugID", -1);
  82.         }
  83.         else djSetInt(CONF_FILE, "bugReportFileUpdated", 0);
  84.         ServerConf[useAds] = USE_INGAME_ADVERTISE;
  85.         ServerConf[cmdInterval] = REPORT_INTERVAL;
  86.         ServerConf[nextBugId] = 0;
  87.     }
  88.     else
  89.     {
  90.         ServerConf[useAds]      = djInt(CONF_FILE, "useAds") ? true : false;
  91.         ServerConf[cmdInterval] = djInt(CONF_FILE, "cmdInterval") ? true : false;
  92.         ServerConf[nextBugId]   = djInt(CONF_FILE, "nextBugID");
  93.     }
  94.     ServerConf[fileUpdated] = djInt(CONF_FILE, "bugReportFileUpdated") ? true : false;
  95.  
  96.     if (fexist(BUG_REPORT_FILE) && !ServerConf[fileUpdated])
  97.     {
  98.         print("[BugReport] Checking the server bug report file...");
  99.         new File:bugReportFile,
  100.             File:tmpFile,
  101.             readData[135],
  102.             storeData_Name[24],
  103.             storeData_Report[100],
  104.             storeData_ID = (-1),
  105.             bool:mustUpdate;
  106.  
  107.         bugReportFile = fopen(BUG_REPORT_FILE, io_read);
  108.         while (fread(bugReportFile, readData))
  109.         {
  110.             if (sscanf(readData, "{p<|>ds[24]s[100]}"))
  111.             {
  112.                 mustUpdate = true;
  113.                 break;
  114.             }
  115.         }
  116.         fclose(bugReportFile);
  117.         if (!mustUpdate)
  118.         {
  119.             print("[BugReport] Server bug report file is already compatible with your current script version.");
  120.         }
  121.         else
  122.         {
  123.             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")");
  124.             print("[BugReport] Updating '"#BUG_REPORT_FILE"'...");
  125.  
  126.             bugReportFile = fopen(BUG_REPORT_FILE, io_read);
  127.             tmpFile = fopen(TMP_FILE, io_append);
  128.             while (fread(bugReportFile, readData))
  129.             {
  130.                 new tmpWrite[135];
  131.                 storeData_ID++;
  132.                 sscanf(readData, "p<|>s[24]s[100]", storeData_Name, storeData_Report);
  133.                 format(tmpWrite, 135, "%d|%s|%s", storeData_ID, storeData_Name, storeData_Report);
  134.                 fwrite(tmpFile, tmpWrite);
  135.             }
  136.             fclose(bugReportFile);
  137.             fclose(tmpFile);
  138.             fremove(BUG_REPORT_FILE);
  139.             bugReportFile = fopen(BUG_REPORT_FILE, io_append);
  140.             tmpFile = fopen(TMP_FILE, io_read);
  141.             while (fread(tmpFile, readData))
  142.                 fwrite(bugReportFile, readData);
  143.             fclose(bugReportFile);
  144.             fclose(tmpFile);
  145.             fremove(TMP_FILE);
  146.             ServerConf[nextBugId] = storeData_ID + 1;
  147.             ServerConf[fileUpdated] = true;
  148.  
  149.             print("[BugReport] Server bug report file has been updated and is now compatible with the BugReport FS!");
  150.         }
  151.     }
  152.     else ServerConf[fileUpdated] = true;
  153.     ploop(i) ResetPlayer(i);
  154.  
  155.     print(">> BugReport v"#FS_VERS_MAJOR"."#FS_VERS_MINOR"."#FS_VERS_BUILD"-"#FS_VERS_TAG" loaded <<");
  156.     print(">> BugReport created by Kwarde (contact: kwarde@mail.com) <<");
  157.     return 1;
  158. }
  159.  
  160. public OnFilterScriptExit()
  161. {
  162.     djSetInt(CONF_FILE, "useAds", ServerConf[useAds]);
  163.     djSetInt(CONF_FILE, "cmdInterval", ServerConf[cmdInterval]);
  164.     djSetInt(CONF_FILE, "nextBugID", ServerConf[nextBugId]);
  165.     djSetInt(CONF_FILE, "bugReportFileUpdated", ServerConf[fileUpdated]);
  166.     djson_GameModeExit();
  167.     ploop (i) ResetPlayer(i);
  168.  
  169.     print(">> WARNING: BugReport filterscript unloaded! <<");
  170.     return 1;
  171. }
  172.  
  173. public OnPlayerConnect(playerid)
  174. {
  175.     if (ServerConf[useAds] && !PlayerInfo[playerid][pFirstSpawn])
  176.     {
  177.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}We are using BugReport so that you can report bugs! ({FFFF00}/reportbug{FFFFFF})");
  178.         SendClientMessage(playerid, COLOR_GREEN, "BugReport is created by kwarde ({FFFFFF}kwarde@mail.com{00FF00})");
  179.         PlayerInfo[playerid][pFirstSpawn] = true;
  180.     }
  181.     return 1;
  182. }
  183.  
  184. public OnPlayerDisconnect(playerid)
  185. {
  186.     ResetPlayer(playerid);
  187.     return 1;
  188. }
  189.  
  190. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  191. {
  192.     switch (dialogid)
  193.     {
  194.         case DIALOG_BREPORT:
  195.         {
  196.             if (!response)
  197.                 return SendClientMessage(playerid, COLOR_GRAY, "You cancelled the bug report");
  198.  
  199.             if (strlen(inputtext) < 10 || strlen(inputtext) > 100)
  200.             {
  201.                 SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}The bug report must contain 10-100 characters!");
  202.                 ShowDialog(playerid, DIALOG_BREPORT);
  203.                 return 1;
  204.             }
  205.             strset(PlayerInfo[playerid][pReportStr], inputtext);
  206.             ShowDialog(playerid, DIALOG_BREPORT_CONFIRM);
  207.             return 1;
  208.         }
  209.         case DIALOG_BREPORT_CONFIRM:
  210.         {
  211.             if (!response)
  212.                 return ShowDialog(playerid, DIALOG_BREPORT);
  213.  
  214.             new str[128], pName[MAX_PLAYER_NAME];
  215.             GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  216.             BugReport(playerid, PlayerInfo[playerid][pReportStr]);
  217.             SendClientMessage(playerid, COLOR_GREEN, "Thank you very much for reporting this bug!");
  218.             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);
  219.             ploop(i)
  220.             {
  221.                 if (!IsAdmin(i)) continue;
  222.                 SendClientMessage(i, COLOR_LIGHTBLUE, str);
  223.             }
  224.             PlayerInfo[playerid][pCanReport] = false;
  225.             SetTimerEx("PReportOn", ServerConf[cmdInterval] * 1000, false, "i", playerid);
  226.         }
  227.     }
  228.     return 1;
  229. }
  230.  
  231. CB:PReportOn(playerid)
  232. {
  233.     PlayerInfo[playerid][pReportTimer] = (-1);
  234.     PlayerInfo[playerid][pCanReport] = true;
  235.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}You can use /reportbug again to report bugs!");
  236.     return 1;
  237. }
  238.  
  239. stock strset(string[], substr[])
  240. {
  241.     strdel(string, 0, strlen(string) + 1);
  242.     strins(string, substr, 0, strlen(substr) + 1);
  243.     return 1;
  244. }
  245.  
  246. stock RemoveBugId(id)
  247. {
  248.     new File:bugReportFile,
  249.         File:tmpFile,
  250.         readStr[135];
  251.  
  252.     bugReportFile = fopen(BUG_REPORT_FILE, io_read);
  253.     tmpFile = fopen(TMP_FILE, io_append);
  254.     while (fread(bugReportFile, readStr))
  255.         fwrite(tmpFile, readStr);
  256.     fclose(bugReportFile);
  257.     fclose(tmpFile);
  258.     fremove(BUG_REPORT_FILE);
  259.     bugReportFile = fopen(BUG_REPORT_FILE, io_append);
  260.     tmpFile = fopen(TMP_FILE, io_read);
  261.     while (fread(tmpFile, readStr))
  262.     {
  263.         new storeData_ID;
  264.         sscanf(readStr, "p<|>d{s[24]s[100]}", storeData_ID);
  265.         if (storeData_ID == id) continue;
  266.         fwrite(bugReportFile, readStr);
  267.     }
  268.     fclose(bugReportFile);
  269.     fclose(tmpFile);
  270.     fremove(TMP_FILE);
  271.     return 1;
  272. }
  273.  
  274. stock ResetPlayer(playerid)
  275. {
  276.     if (PlayerInfo[playerid][pReportTimer] != -1)
  277.         KillTimer(PlayerInfo[playerid][pReportTimer]);
  278.  
  279.     PlayerInfo[playerid][pFirstSpawn]   =   false;
  280.     PlayerInfo[playerid][pCanReport]    =   true;
  281.     PlayerInfo[playerid][pReportTimer]  =   (-1);
  282.     PlayerInfo[playerid][pReportStr]    =   EOS;
  283.     return 1;
  284. }
  285.  
  286. stock GetFileLines(file[])
  287. {
  288.     if (!fexist(file)) return 0;
  289.     new File:readFile = fopen(file, io_read),
  290.         readStr[135],
  291.         lines = 0;
  292.  
  293.     while (fread(readFile, readStr))
  294.         lines++;
  295.     fclose(readFile);
  296.     return lines;
  297. }
  298.  
  299. stock BugReport(playerid, bug[])
  300. {
  301.     new pName[MAX_PLAYER_NAME],
  302.         File:bugReportFile = fopen(BUG_REPORT_FILE, io_append),
  303.         writeStr[135];
  304.  
  305.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  306.     format(writeStr, 135, "%d|%s|%s\n", ServerConf[nextBugId], pName, bug);
  307.     fwrite(bugReportFile, writeStr);
  308.     fclose(bugReportFile);
  309.     ServerConf[nextBugId]++;
  310.     djSetInt(CONF_FILE, "nextBugID", ServerConf[nextBugId]);
  311.     return 1;
  312. }
  313.  
  314. stock IsAdmin(playerid)
  315. {
  316.     if (IsPlayerAdmin(playerid))
  317.         return true;
  318.     return false;
  319. }
  320.  
  321. stock ShowDialog(playerid, dialogid)
  322. {
  323.     switch (dialogid)
  324.     {
  325.         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");
  326.         case DIALOG_BREPORT_CONFIRM:
  327.         {
  328.             new str[210];
  329.             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]);
  330.             ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Bug report: CONF_FILEirm", str, "Yes", "No");
  331.         }
  332.     }
  333.     return 1;
  334. }
  335.  
  336. CMD:reportbug(playerid, params[])
  337. {
  338.     if (PlayerInfo[playerid][pCanReport])
  339.         ShowDialog(playerid, DIALOG_BREPORT);
  340.     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");
  341.     return 1;
  342. }
  343.  
  344. CMD:checkbugs(playerid, params[])
  345. {
  346.     if (!IsAdmin(playerid)) return 0;
  347.     if (!fexist(BUG_REPORT_FILE)) return SendClientMessage(playerid, COLOR_RED, "[NOTICE] {FFFFFF}There are no bugs reported!");
  348.     for (new i = 0; i < 10; i++) SendClientMessage(playerid, -1, " ");
  349.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "|---------- {FFFF00}Bug reports {00FFFF}----------|");
  350.  
  351.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
  352.         readStr[135],
  353.         str[128],
  354.         curLine = 0,
  355.         start;
  356.     if (GetFileLines(BUG_REPORT_FILE) <= 9) start = 0;
  357.     else start = GetFileLines(BUG_REPORT_FILE) - 8;
  358.     while (fread(bugReportFile, readStr))
  359.     {
  360.         curLine++;
  361.         if (curLine < start) continue;
  362.         new infoId,
  363.             infoName[MAX_PLAYER_NAME],
  364.             infoBug[100];
  365.         sscanf(readStr, "p<|>ds[24]s[100]", infoId, infoName, infoBug);
  366.         format(str, 128, "#%d %s: {AFAFAF}%s", infoId, infoName, infoBug);
  367.         SendClientMessage(playerid, COLOR_WHITE, str);
  368.     }
  369.     fclose(bugReportFile);
  370.     return 1;
  371. }
  372.  
  373. CMD:editconf(playerid, params[])
  374. {
  375.     if (!IsAdmin(playerid)) return 0;
  376.     new opt[9], conf;
  377.     if (sscanf(params, "s[9]D(-1)", opt, conf)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf ['interval' or 'useads'] [value]");
  378.     if (!strcmp(opt, "interval"))
  379.     {
  380.         if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf interval [interval time in seconds]");
  381.         if (conf < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}CMD interval time bust be 1 or higher!");
  382.         if (conf == ServerConf[cmdInterval]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}cmdInterval already has that value!");
  383.         ServerConf[cmdInterval] = conf * 1000;
  384.         djSetInt(CONF_FILE, "cmdInterval", conf);
  385.         new str[70];
  386.         format(str, 70, "SERVER: /reportbug usage interval changed to %d seconds", conf);
  387.         SendClientMessage(playerid, COLOR_WHITE, str);
  388.     }
  389.     else if (!strcmp(opt, "useads"))
  390.     {
  391.         if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf useads [0/1]");
  392.         if (conf != 0 && conf != 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf useads {FF0000}[0/1]");
  393.         if ((conf ? true : false) == ServerConf[useAds]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}useAds already has that value!");
  394.         ServerConf[useAds] = (conf ? true : false);
  395.         djSetInt(CONF_FILE, "useAds", conf);
  396.         ploop(i) PlayerInfo[i][pFirstSpawn] = false;
  397.  
  398.         if (ServerConf[useAds])
  399.             SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now enabled");
  400.         else SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now disabled");
  401.     }
  402.     else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf {FF0000}['interval' or 'useads']{00FFFF} [value]");
  403.     return 1;
  404. }
  405.  
  406. CMD:removebugreport(playerid, params[])
  407. {
  408.     if (!IsAdmin(playerid)) return 0;
  409.     if (!fexist(BUG_REPORT_FILE) || 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)");
  410.     if (isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /removebugreport [bug id]");
  411.     new bugId = (-1),
  412.         File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
  413.         readStr[135];
  414.     while (fread(bugReportFile, readStr))
  415.     {
  416.         new storeData_ID;
  417.         sscanf(readStr, "p<|>d{s[24]s[100]}", storeData_ID);
  418.         if (storeData_ID == strval(params))
  419.         {
  420.             bugId = storeData_ID;
  421.             break;
  422.         }
  423.         else continue;
  424.     }
  425.     fclose(bugReportFile);
  426.     if (bugId != -1)
  427.     {
  428.         RemoveBugId(bugId);
  429.         new str[40];
  430.         format(str, 40, "Bug report #%d has been removed!", bugId);
  431.         SendClientMessage(playerid, COLOR_GREEN, str);
  432.     }
  433.     else return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}That bug report ID doesn't exist!");
  434.     return 1;
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement