Advertisement
willbedie

[MySQL R41-4] Report System

Oct 5th, 2018
1,798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5. #include <sscanf2>
  6. #include <zcmd>
  7. #include <easyDialog>
  8. #include <foreach>
  9. #include "colors2.inc"
  10.  
  11. #if defined FILTERSCRIPT
  12.  
  13. new MySQL: Database;
  14.  
  15. #define MYSQL_HOST "localhost"
  16. #define MYSQL_USER "root"
  17. #define MYSQL_PASS ""
  18. #define MYSQL_DATABASE "testwo"
  19.  
  20. public OnFilterScriptInit()
  21. {
  22. new MySQLOpt: option_id = mysql_init_options();
  23. mysql_set_option(option_id, AUTO_RECONNECT, true); // We will set that option to automatically reconnect on timeouts.
  24. Database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE, option_id);
  25. if(Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0) // Checking if the database connection is invalid to shutdown.
  26. {
  27. print("Connection to MySQL database has failed! Shutting down the server.");
  28. printf("[DEBUG] Host: %s, User: %s, Password: %s, Database: %s", MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE);
  29. SendRconCommand("exit");
  30. return 1;
  31. }
  32. else
  33. print("Connection to MySQL database was successful.");
  34. return 1;
  35. }
  36.  
  37. CMD:report(playerid, params[])
  38. {
  39. new targetid, reason[200], query[300];
  40. if(sscanf(params, "ds[200]", targetid, reason)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "[USAGE]: {FFFFFF}/report [targetid] [reason]");
  41. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: {FFFFFF}That player is not connected.");
  42.  
  43. mysql_format(Database, query, sizeof(query), "INSERT INTO `reports` (`Reporter`, `Reported`, `Reason`, `Date`) VALUES ('%e', '%e', '%e', '%e')", GetName(playerid), GetName(targetid), reason, ReturnDate());
  44. mysql_tquery(Database, query);
  45. new string[200];
  46.  
  47. format(string, sizeof(string), "REPORT: {FFFFFF}%s has reported %s for the reason: %s", GetName(playerid), GetName(targetid), reason);
  48. foreach(new i : Player)
  49. {
  50. if(IsPlayerConnected(i))
  51. {
  52. if(IsPlayerAdmin(i))
  53. {
  54. SendClientMessage(i, COLOR_LIGHTBLUE, string);
  55. }
  56. }
  57. }
  58. SendClientMessage(playerid, COLOR_LIGHTBLUE, "[SUCCESS]: {FFFFFF}Your report has been successfully sent to all administrators online.");
  59. return 1;
  60. }
  61.  
  62. CMD:reports(playerid, params[])
  63. {
  64. new query[300];
  65. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: {FFFFFF}You are not authorized to use that command.");
  66. mysql_format(Database, query, sizeof(query), "SELECT * FROM `reports` ORDER BY `Date` LIMIT 15;");
  67. new Cache:result = mysql_query(Database, query);
  68. if(cache_num_rows())
  69. {
  70. new string[2300], rinfo[1000], Reporter[24], Reported[24], Reason[200], Date[30], reportid, Accepted;
  71. strcat(string, "Displaying 15 latest reports:\n\n");
  72. for(new i = 0; i < cache_num_rows(); i++)
  73. {
  74. cache_get_value_name(i, "Reporter", Reporter, 24);
  75. cache_get_value_name(i, "Reported", Reported, 24);
  76. cache_get_value_name(i, "Reason", Reason, 200);
  77. cache_get_value_name(i, "Date", Date, 30);
  78. cache_get_value_name_int(i, "ID", reportid);
  79. cache_get_value_name_int(i, "Accepted", Accepted);
  80. switch(Accepted)
  81. {
  82. case 0: format(rinfo, sizeof(rinfo), "{AFAFAF}[ID: %d]: {FFFFFF}%s has reported %s for the reason {AFAFAF}'%s'{FFFFFF} on %s - {AFAFAF}Not Checked\n", reportid, Reporter, Reported, Reason, Date);
  83. case 1: format(rinfo, sizeof(rinfo), "{AFAFAF}[ID: %d]: {FFFFFF}%s has reported %s for the reason {AFAFAF}'%s'{FFFFFF} on %s - {00AA00}Accepted\n", reportid, Reporter, Reported, Reason, Date);
  84. case 2: format(rinfo, sizeof(rinfo), "{AFAFAF}[ID: %d]: {FFFFFF}%s has reported %s for the reason {AFAFAF}'%s'{FFFFFF} on %s - {FF0000}Denied\n", reportid, Reporter, Reported, Reason, Date);
  85. }
  86. strcat(string, rinfo);
  87. }
  88. Dialog_Show(playerid, DIALOG_REPORTS, DIALOG_STYLE_MSGBOX, "Latest 15 Reports", string, "Okay", "");
  89. }
  90. else
  91. {
  92. Dialog_Show(playerid, DIALOG_REPORTS, DIALOG_STYLE_MSGBOX, "No reports were found", "No reports were found on the MySQL database.", "Close", "");
  93. }
  94. cache_delete(result);
  95. return 1;
  96. }
  97.  
  98. CMD:clearreports(playerid, params[])
  99. {
  100. new query[200];
  101. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: {FFFFFF}You are not authorized to use that command.");
  102.  
  103. mysql_format(Database, query, sizeof(query), "DELETE FROM `reports` ORDER BY `Date` LIMIT 15;");
  104. mysql_tquery(Database, query);
  105.  
  106. SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have deleted 15 latest reports that existed on the MySQL database.");
  107. return 1;
  108. }
  109.  
  110. CMD:ar(playerid, params[])
  111. {
  112. new reportid, string[200], query[300];
  113. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: {FFFFFF}You are not authorized to use that command.");
  114. if(sscanf(params, "d", reportid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "[USAGE]: {FFFFFF}/ar [reportid]");
  115. mysql_format(Database, query, sizeof(query), "SELECT * FROM `reports` WHERE `ID` = '%i'", reportid);
  116. new Cache:result = mysql_query(Database, query);
  117. if(cache_num_rows())
  118. {
  119. new Accepted, Reported[MAX_PLAYER_NAME], Reason[200];
  120. for(new i = 0; i < cache_num_rows(); i++)
  121. {
  122. cache_get_value_name_int(i, "Accepted", Accepted);
  123. cache_get_value_name(i, "Reported", Reported, MAX_PLAYER_NAME);
  124. cache_get_value_name(i, "Reason", Reason, 200);
  125. }
  126. if(Accepted == 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: That report has been already accepted once.");
  127.  
  128. format(string, sizeof(string), "You have accepted report id %d", reportid);
  129. SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  130. mysql_format(Database, query, sizeof(query), "UPDATE `reports` SET `Accepted` = '1' WHERE `ID` = '%i'", reportid);
  131. mysql_query(Database, query);
  132. }
  133. else
  134. {
  135. format(string, sizeof(string), "Report ID [%d] couldn't be found in the MySQL Database.", reportid);
  136. SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  137. }
  138. cache_delete(result);
  139. return 1;
  140. }
  141.  
  142. CMD:dr(playerid, params[])
  143. {
  144. new reportid, string[200], query[300];
  145. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: {FFFFFF}You are not authorized to use that command.");
  146. if(sscanf(params, "d", reportid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "[USAGE]: {FFFFFF}/dr [reportid]");
  147. mysql_format(Database, query, sizeof(query), "SELECT * FROM `reports` WHERE `ID` = '%i'", reportid);
  148. new Cache:result = mysql_query(Database, query);
  149. if(cache_num_rows())
  150. {
  151. new Accepted, Reported[MAX_PLAYER_NAME], Reason[200];
  152. for(new i = 0; i < cache_num_rows(); i++)
  153. {
  154. cache_get_value_name_int(i, "Accepted", Accepted);
  155. cache_get_value_name(i, "Reported", Reported, MAX_PLAYER_NAME);
  156. cache_get_value_name(i, "Reason", Reason, 200);
  157. }
  158. if(Accepted == 2) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: That report has been already denied once.");
  159.  
  160. format(string, sizeof(string), "You have denied report id %d", reportid);
  161. SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  162. mysql_format(Database, query, sizeof(query), "UPDATE `reports` SET `Accepted` = '2' WHERE `ID` = '%i'", reportid);
  163. mysql_query(Database, query);
  164. }
  165. else
  166. {
  167. format(string, sizeof(string), "Report ID [%d] couldn't be found in the MySQL Database.", reportid);
  168. SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  169. }
  170. cache_delete(result);
  171. return 1;
  172. }
  173.  
  174. ReturnDate()
  175. {
  176. new sendString[90], MonthStr[40], month, day, year;
  177. new hour, minute, second;
  178.  
  179. gettime(hour, minute, second);
  180. getdate(year, month, day);
  181. switch(month)
  182. {
  183. case 1: MonthStr = "January";
  184. case 2: MonthStr = "February";
  185. case 3: MonthStr = "March";
  186. case 4: MonthStr = "April";
  187. case 5: MonthStr = "May";
  188. case 6: MonthStr = "June";
  189. case 7: MonthStr = "July";
  190. case 8: MonthStr = "August";
  191. case 9: MonthStr = "September";
  192. case 10: MonthStr = "October";
  193. case 11: MonthStr = "November";
  194. case 12: MonthStr = "December";
  195. }
  196.  
  197. format(sendString, 90, "%s %d, %d %02d:%02d:%02d", MonthStr, day, year, hour, minute, second);
  198. return sendString;
  199. }
  200.  
  201. GetName(playerid)
  202. {
  203. new name[MAX_PLAYER_NAME];
  204. GetPlayerName(playerid, name, sizeof(name));
  205. return name;
  206. }
  207.  
  208. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement