Advertisement
Kwarde

BugReport v1.0.1-S

May 26th, 2013
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.46 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           1
  35. #define FS_VERS_MINOR           0
  36. #define FS_VERS_BUILD           1
  37. #define FS_VERS_TAG             "S"
  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.             return 1;
  227.         }
  228.     }
  229.     return 0;
  230. }
  231.  
  232. CB:PReportOn(playerid)
  233. {
  234.     PlayerInfo[playerid][pReportTimer] = (-1);
  235.     PlayerInfo[playerid][pCanReport] = true;
  236.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}You can use /reportbug again to report bugs!");
  237.     return 1;
  238. }
  239.  
  240. stock strset(string[], substr[])
  241. {
  242.     strdel(string, 0, strlen(string) + 1);
  243.     strins(string, substr, 0, strlen(substr) + 1);
  244.     return 1;
  245. }
  246.  
  247. stock RemoveBugId(id)
  248. {
  249.     new File:bugReportFile,
  250.         File:tmpFile,
  251.         readStr[135];
  252.  
  253.     bugReportFile = fopen(BUG_REPORT_FILE, io_read);
  254.     tmpFile = fopen(TMP_FILE, io_append);
  255.     while (fread(bugReportFile, readStr))
  256.         fwrite(tmpFile, readStr);
  257.     fclose(bugReportFile);
  258.     fclose(tmpFile);
  259.     fremove(BUG_REPORT_FILE);
  260.     bugReportFile = fopen(BUG_REPORT_FILE, io_append);
  261.     tmpFile = fopen(TMP_FILE, io_read);
  262.     while (fread(tmpFile, readStr))
  263.     {
  264.         new storeData_ID;
  265.         sscanf(readStr, "p<|>d{s[24]s[100]}", storeData_ID);
  266.         if (storeData_ID == id) continue;
  267.         fwrite(bugReportFile, readStr);
  268.     }
  269.     fclose(bugReportFile);
  270.     fclose(tmpFile);
  271.     fremove(TMP_FILE);
  272.     return 1;
  273. }
  274.  
  275. stock ResetPlayer(playerid)
  276. {
  277.     if (PlayerInfo[playerid][pReportTimer] != -1)
  278.         KillTimer(PlayerInfo[playerid][pReportTimer]);
  279.  
  280.     PlayerInfo[playerid][pFirstSpawn]   =   false;
  281.     PlayerInfo[playerid][pCanReport]    =   true;
  282.     PlayerInfo[playerid][pReportTimer]  =   (-1);
  283.     PlayerInfo[playerid][pReportStr]    =   EOS;
  284.     return 1;
  285. }
  286.  
  287. stock GetFileLines(file[])
  288. {
  289.     if (!fexist(file)) return 0;
  290.     new File:readFile = fopen(file, io_read),
  291.         readStr[135],
  292.         lines = 0;
  293.  
  294.     while (fread(readFile, readStr))
  295.         lines++;
  296.     fclose(readFile);
  297.     return lines;
  298. }
  299.  
  300. stock BugReport(playerid, bug[])
  301. {
  302.     new pName[MAX_PLAYER_NAME],
  303.         File:bugReportFile = fopen(BUG_REPORT_FILE, io_append),
  304.         writeStr[135];
  305.  
  306.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  307.     format(writeStr, 135, "%d|%s|%s\n", ServerConf[nextBugId], pName, bug);
  308.     fwrite(bugReportFile, writeStr);
  309.     fclose(bugReportFile);
  310.     ServerConf[nextBugId]++;
  311.     djSetInt(CONF_FILE, "nextBugID", ServerConf[nextBugId]);
  312.     return 1;
  313. }
  314.  
  315. stock IsAdmin(playerid)
  316. {
  317.     if (IsPlayerAdmin(playerid))
  318.         return true;
  319.     return false;
  320. }
  321.  
  322. stock ShowDialog(playerid, dialogid)
  323. {
  324.     switch (dialogid)
  325.     {
  326.         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");
  327.         case DIALOG_BREPORT_CONFIRM:
  328.         {
  329.             new str[210];
  330.             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]);
  331.             ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Bug report: CONF_FILEirm", str, "Yes", "No");
  332.         }
  333.     }
  334.     return 1;
  335. }
  336.  
  337. CMD:reportbug(playerid, params[])
  338. {
  339.     if (PlayerInfo[playerid][pCanReport])
  340.         ShowDialog(playerid, DIALOG_BREPORT);
  341.     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");
  342.     return 1;
  343. }
  344.  
  345. CMD:checkbugs(playerid, params[])
  346. {
  347.     if (!IsAdmin(playerid)) return 0;
  348.     if (GetFileLines(BUG_REPORT_FILE) == 0) return SendClientMessage(playerid, COLOR_RED, "[NOTICE] {FFFFFF}There are no bugs reported!");
  349.     for (new i = 0; i < 10; i++) SendClientMessage(playerid, -1, " ");
  350.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "|---------- {FFFF00}Bug reports {00FFFF}----------|");
  351.  
  352.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
  353.         readStr[135],
  354.         str[128],
  355.         curLine = 0,
  356.         start;
  357.     if (GetFileLines(BUG_REPORT_FILE) <= 9) start = 0;
  358.     else start = GetFileLines(BUG_REPORT_FILE) - 8;
  359.     while (fread(bugReportFile, readStr))
  360.     {
  361.         curLine++;
  362.         if (curLine < start) continue;
  363.         new infoId,
  364.             infoName[MAX_PLAYER_NAME],
  365.             infoBug[100];
  366.         sscanf(readStr, "p<|>ds[24]s[100]", infoId, infoName, infoBug);
  367.         format(str, 128, "#%d %s: {AFAFAF}%s", infoId, infoName, infoBug);
  368.         SendClientMessage(playerid, COLOR_WHITE, str);
  369.     }
  370.     fclose(bugReportFile);
  371.     return 1;
  372. }
  373.  
  374. CMD:editconf(playerid, params[])
  375. {
  376.     if (!IsAdmin(playerid)) return 0;
  377.     new opt[9], conf;
  378.     if (sscanf(params, "s[9]D(-1)", opt, conf)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf ['interval' or 'useads'] [value]");
  379.     if (!strcmp(opt, "interval"))
  380.     {
  381.         if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf interval [interval time in seconds]");
  382.         if (conf < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}CMD interval time bust be 1 or higher!");
  383.         if (conf == ServerConf[cmdInterval]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}cmdInterval already has that value!");
  384.         ServerConf[cmdInterval] = conf;
  385.         djSetInt(CONF_FILE, "cmdInterval", conf);
  386.         new str[70];
  387.         format(str, 70, "SERVER: /reportbug usage interval changed to %d seconds", conf);
  388.         SendClientMessage(playerid, COLOR_WHITE, str);
  389.        
  390.         ploop(i)
  391.         {
  392.             if (!PlayerInfo[i][pCanReport])
  393.             {
  394.                 KillTimer(PlayerInfo[i][pReportTimer]);
  395.                 PReportOn(i);
  396.             }
  397.         }
  398.     }
  399.     else if (!strcmp(opt, "useads"))
  400.     {
  401.         if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf useads [0/1]");
  402.         if (conf != 0 && conf != 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf useads {FF0000}[0/1]");
  403.         if ((conf ? true : false) == ServerConf[useAds]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}useAds already has that value!");
  404.         ServerConf[useAds] = (conf ? true : false);
  405.         djSetInt(CONF_FILE, "useAds", conf);
  406.         ploop(i) PlayerInfo[i][pFirstSpawn] = false;
  407.  
  408.         if (ServerConf[useAds])
  409.             SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now enabled");
  410.         else SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now disabled");
  411.     }
  412.     else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf {FF0000}['interval' or 'useads']{00FFFF} [value]");
  413.     return 1;
  414. }
  415.  
  416. CMD:removebugreport(playerid, params[])
  417. {
  418.     if (!IsAdmin(playerid)) return 0;
  419.     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)");
  420.     if (isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /removebugreport [bug id]");
  421.     new bugId = (-1),
  422.         File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
  423.         readStr[135];
  424.     while (fread(bugReportFile, readStr))
  425.     {
  426.         new storeData_ID;
  427.         sscanf(readStr, "p<|>d{s[24]s[100]}", storeData_ID);
  428.         if (storeData_ID == strval(params))
  429.         {
  430.             bugId = storeData_ID;
  431.             break;
  432.         }
  433.         else continue;
  434.     }
  435.     fclose(bugReportFile);
  436.     if (bugId != -1)
  437.     {
  438.         RemoveBugId(bugId);
  439.         new str[40];
  440.         format(str, 40, "Bug report #%d has been removed!", bugId);
  441.         SendClientMessage(playerid, COLOR_GREEN, str);
  442.     }
  443.     else return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}That bug report ID doesn't exist!");
  444.     return 1;
  445. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement