Advertisement
Kwarde

BugReport v0.3.0-RC

May 15th, 2013
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.15 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           3
  36. #define FS_VERS_BUILD           0
  37. #define FS_VERS_TAG             "RC"
  38. #define FS_LAST_UPDATE          0 //Do NOT change or remove this!
  39.  
  40. #define BUG_REPORT_FILE         "ServerBugReports.txt"
  41. #define CONF_FILE               "BugReport.conf"
  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. };
  56. new ServerConf[sConf];
  57.  
  58. enum pInf
  59. {
  60.     bool:pFirstSpawn,
  61.     bool:pCanReport,
  62.     pReportTimer,
  63.     pReportStr[100]
  64. };
  65. new PlayerInfo[MAX_PLAYERS][pInf];
  66.    
  67. public OnFilterScriptInit()
  68. {
  69.     djson_GameModeInit();
  70.     if (!fexist(CONF_FILE))
  71.     {
  72.         djCreateFile(CONF_FILE);
  73.         djSetInt(CONF_FILE, "useAds", USE_INGAME_ADVERTISE);
  74.         djSetInt(CONF_FILE, "cmdInterval", REPORT_INTERVAL);
  75.         djSetInt(CONF_FILE, "lastUpdate", FS_LAST_UPDATE);
  76.     }
  77.     else
  78.     {
  79.         if (!djIsSet(CONF_FILE, "lastUpdate"))
  80.             djSetInt(CONF_FILE, "lastUpdate", FS_LAST_UPDATE);
  81.     }
  82.     ServerConf[useAds]      = djInt(CONF_FILE, "useAds") ? true : false;
  83.     ServerConf[cmdInterval] = djInt(CONF_FILE, "cmdInterval");
  84.    
  85.     ploop(i) ResetPlayer(i);
  86.    
  87.     print(" ");
  88.     print(">> BugReport v"#FS_VERS_MAJOR"."#FS_VERS_MINOR"."#FS_VERS_BUILD"-"#FS_VERS_TAG" loaded <<");
  89.     print(">> BugReport created by Kwarde (contact: kwarde@mail.com) <<");
  90.     print(" ");
  91.     return 1;
  92. }
  93.  
  94. public OnFilterScriptExit()
  95. {
  96.     djSetInt(CONF_FILE, "useAds", ServerConf[useAds]);
  97.     djSetInt(CONF_FILE, "cmdInterval", ServerConf[cmdInterval]);
  98.     djson_GameModeExit();
  99.     ploop (i) ResetPlayer(i);
  100.    
  101.     print(">> WARNING: BugReport filterscript unloaded! <<");
  102.     return 1;
  103. }
  104.  
  105. public OnPlayerConnect(playerid)
  106. {
  107.     if (ServerConf[useAds] && !PlayerInfo[playerid][pFirstSpawn])
  108.     {
  109.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}We are using BugReport so that you can report bugs! ({FFFF00}/reportbug{FFFFFF})");
  110.         SendClientMessage(playerid, COLOR_GREEN, "BugReport is created by kwarde ({FFFFFF}kwarde@mail.com{00FF00})");
  111.         PlayerInfo[playerid][pFirstSpawn] = true;
  112.     }
  113.     return 1;
  114. }
  115.  
  116. public OnPlayerDisconnect(playerid)
  117. {
  118.     ResetPlayer(playerid);
  119.     return 1;
  120. }
  121.  
  122. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  123. {
  124.     switch (dialogid)
  125.     {
  126.         case DIALOG_BREPORT:
  127.         {
  128.             if (!response)
  129.                 return SendClientMessage(playerid, COLOR_GRAY, "You cancelled the bug report");
  130.                
  131.             if (strlen(inputtext) < 10 || strlen(inputtext) > 100)
  132.             {
  133.                 SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}The bug report must contain 10-100 characters!");
  134.                 ShowDialog(playerid, DIALOG_BREPORT);
  135.                 return 1;
  136.             }
  137.             strset(PlayerInfo[playerid][pReportStr], inputtext);
  138.             ShowDialog(playerid, DIALOG_BREPORT_CONFIRM);
  139.             return 1;
  140.         }
  141.         case DIALOG_BREPORT_CONFIRM:
  142.         {
  143.             if (!response)
  144.                 return ShowDialog(playerid, DIALOG_BREPORT);
  145.                
  146.             new str[128], pName[MAX_PLAYER_NAME];
  147.             GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  148.             BugReport(playerid, PlayerInfo[playerid][pReportStr]);
  149.             SendClientMessage(playerid, COLOR_GREEN, "Thank you very much for reporting this bug!");
  150.             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);
  151.             ploop(i)
  152.             {
  153.                 if (!IsAdmin(i)) continue;
  154.                 SendClientMessage(i, COLOR_LIGHTBLUE, str);
  155.             }
  156.             PlayerInfo[playerid][pCanReport] = false;
  157.             SetTimerEx("PReportOn", ServerConf[cmdInterval] * 1000, false, "i", playerid);
  158.         }
  159.     }
  160.     return 1;
  161. }
  162.  
  163. CB:PReportOn(playerid)
  164. {
  165.     PlayerInfo[playerid][pReportTimer] = (-1);
  166.     PlayerInfo[playerid][pCanReport] = true;
  167.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "[NOTICE] {FFFFFF}You can use /reportbug again to report bugs!");
  168.     return 1;
  169. }
  170.  
  171. stock strset(string[], substr[])
  172. {
  173.     strdel(string, 0, strlen(string) + 1);
  174.     strins(string, substr, 0, strlen(substr) + 1);
  175.     return 1;
  176. }
  177.  
  178. stock ResetPlayer(playerid)
  179. {
  180.     if (PlayerInfo[playerid][pReportTimer] != -1)
  181.         KillTimer(PlayerInfo[playerid][pReportTimer]);
  182.        
  183.     PlayerInfo[playerid][pFirstSpawn]   =   false;
  184.     PlayerInfo[playerid][pCanReport]    =   true;
  185.     PlayerInfo[playerid][pReportTimer]  =   (-1);
  186.     PlayerInfo[playerid][pReportStr]    =   EOS;
  187.     return 1;
  188. }
  189.  
  190. stock GetFileLines(file[])
  191. {
  192.     if (!fexist(file)) return 0;
  193.     new File:readFile = fopen(file, io_read),
  194.         readStr[200],
  195.         lines = 0;
  196.        
  197.     while (fread(readFile, readStr))
  198.         lines++;
  199.     fclose(readFile);
  200.     return lines;
  201. }
  202.  
  203. stock BugReport(playerid, bug[])
  204. {
  205.     new pName[MAX_PLAYER_NAME],
  206.         File:bugReportFile = fopen(BUG_REPORT_FILE, io_append),
  207.         writeStr[200];
  208.        
  209.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  210.     format(writeStr, 200, "%s|%s\n", pName, bug);
  211.     fwrite(bugReportFile, writeStr);
  212.     fclose(bugReportFile);
  213.     return 1;
  214. }
  215.  
  216. stock IsAdmin(playerid)
  217. {
  218.     if (IsPlayerAdmin(playerid))
  219.         return true;
  220.     return false;
  221. }
  222.  
  223. stock ShowDialog(playerid, dialogid)
  224. {
  225.     switch (dialogid)
  226.     {
  227.         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");
  228.         case DIALOG_BREPORT_CONFIRM:
  229.         {
  230.             new str[210];
  231.             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]);
  232.             ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Bug report: CONF_FILEirm", str, "Yes", "No");
  233.         }
  234.     }
  235.     return 1;
  236. }
  237.  
  238. CMD:reportbug(playerid, params[])
  239. {
  240.     if (PlayerInfo[playerid][pCanReport])
  241.         ShowDialog(playerid, DIALOG_BREPORT);
  242.     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");
  243.     return 1;
  244. }
  245.  
  246. CMD:checkbugs(playerid, params[])
  247. {
  248.     if (!IsAdmin(playerid)) return 0;
  249.     if (!fexist(BUG_REPORT_FILE)) return SendClientMessage(playerid, COLOR_RED, "[NOTICE] {FFFFFF}There are no bugs reported!");
  250.     for (new i = 0; i < 10; i++) SendClientMessage(playerid, -1, " ");
  251.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "|---------- {FFFF00}Bug reports {00FFFF}----------|");
  252.    
  253.     new File:bugReportFile = fopen(BUG_REPORT_FILE, io_read),
  254.         readStr[200],
  255.         str[128],
  256.         curLine = 0,
  257.         start;
  258.     if (GetFileLines(BUG_REPORT_FILE) <= 9) start = 0;
  259.     else start = GetFileLines(BUG_REPORT_FILE) - 8;
  260.     while (fread(bugReportFile, readStr))
  261.     {
  262.         curLine++;
  263.         if (curLine < start) continue;
  264.         new infoName[MAX_PLAYER_NAME],
  265.             infoBug[100];
  266.         sscanf(readStr, "p<|>s[24]s[100]", infoName, infoBug);
  267.         format(str, 128, "%s: {AFAFAF}%s", infoName, infoBug);
  268.         SendClientMessage(playerid, COLOR_WHITE, str);
  269.     }
  270.     fclose(bugReportFile);
  271.     return 1;
  272. }
  273.  
  274. CMD:editconf(playerid, params[])
  275. {
  276.     if (!IsAdmin(playerid)) return 0;
  277.     new opt[9], conf;
  278.     if (sscanf(params, "s[9]D(-1)", opt, conf)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf ['interval' or 'useads'] [value]");
  279.     if (!strcmp(opt, "interval"))
  280.     {
  281.         if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf interval [interval time in seconds]");
  282.         if (conf < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}CMD interval time bust be 1 or higher!");
  283.         if (conf == ServerConf[cmdInterval]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}cmdInterval already has that value!");
  284.         ServerConf[cmdInterval] = conf;
  285.         djSetInt(CONF_FILE, "cmdInterval", conf);
  286.         new str[70];
  287.         format(str, 70, "SERVER: /reportbug usage interval changed to %d seconds", conf);
  288.         SendClientMessage(playerid, COLOR_WHITE, str);
  289.     }
  290.     else if (!strcmp(opt, "useads"))
  291.     {
  292.         if (conf == -1) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /editconf useads [0/1]");
  293.         if (conf != 0 && conf != 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf useads {FF0000}[0/1]");
  294.         if ((conf ? true : false) == ServerConf[useAds]) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}useAds already has that value!");
  295.         ServerConf[useAds] = (conf ? true : false);
  296.         djSetInt(CONF_FILE, "useAds", conf);
  297.         ploop(i) PlayerInfo[i][pFirstSpawn] = false;
  298.        
  299.         if (ServerConf[useAds])
  300.             SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now enabled");
  301.         else SendClientMessage(playerid, COLOR_WHITE, "SERVER: BugReport ads are now disabled");
  302.     }
  303.     else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /editconf {FF0000}['interval' or 'useads']{00FFFF} [value]");
  304.     return 1;
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement