Advertisement
-ARG-Maximiliano

Punishment System - VCMP - By (ARG)Maximiliano

Oct 3rd, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.04 KB | None | 0 0
  1. Muted <- array( GetMaxPlayers(), null );
  2.  
  3. Punishment <- {
  4.  
  5. function LoadSystem()
  6. {
  7. Punishment.CreateTable();
  8. print("===========================================");
  9. print(" ");
  10. print(" Punishment System by (ARG)Maximiliano");
  11. print(" ");
  12. Punishment.CountBans();
  13. print(" ");
  14. print("===========================================");
  15. DecreaseBanTime <- _Timer.Create(this, Punishment.DecreaseBanTime, 1000, 0);
  16. }
  17.  
  18. function CreateTable()
  19. {
  20. QuerySQL( db, "CREATE TABLE IF NOT EXISTS Bans ( Name TEXT, Admin TEXT, Reason TEXT, Date TEXT, Type NUMERIC, UID VARCHAR(255), UID2 VARCHAR(255), IP VARCHAR(32) )" );
  21. //Types of Bans: Type 0 = Permanent - Type 1 = Temporary - Type 2 = Nick
  22. QuerySQL( db, "CREATE TABLE IF NOT EXISTS TempBans ( Name TEXT, Time NUMERIC )" ); // This db is where you will store the time, which will decrease every second (It can be modified to minutes or hours)
  23. QuerySQL( db, "CREATE TABLE IF NOT EXISTS BanIPs ( IP TEXT, Admin TEXT )" );
  24. QuerySQL( db, "CREATE TABLE IF NOT EXISTS Mute ( Name TEXT, Time NUMERIC )" );
  25. QuerySQL( db, "CREATE TABLE IF NOT EXISTS UsersDatas ( Name TEXT, UID VARCHAR(255), UID2 VARCHAR(255), IP VARCHAR(32) )" );
  26. }
  27.  
  28. //------------------------------------------------- Bans functions --------------------------------------------------//
  29.  
  30.  
  31. function AddBan(player, Admin, Reason, BanType)
  32. {
  33. QuerySQL( db, "INSERT INTO Bans ( Name, Admin, Reason, Date, Type, UID, UID2, IP ) VALUES ( '" + player.Name + "', '" + Admin + "', '" + Reason + "', '" +Punishment.GetDate()+ "', '" + BanType + "', '" + e(player.UniqueID) + "', '" + e(player.UniqueID2) + "', '" + player.IP + "' )" );
  34. Message("[#FF4500][ADMIN][#EEDD82] " + player.Name +" was banned by " + Admin + ". Reason: " + Reason + "." );
  35. }
  36.  
  37. function AddBanIP(IP, Admin)
  38. {
  39. //It will store the ips and the admin that banned them as log
  40. QuerySQL( db, "INSERT INTO BanIPs VALUES ( '" + IP + "', '" + Admin + "' )" );
  41. Message("[#FF4500][ADMIN][#EEDD82] " + IP +" banned by " + Admin );
  42. BanIP(IP);
  43. }
  44.  
  45. function AddTempBan(player, Admin, Reason, Time)
  46. {
  47. Punishment.AddBan(player, Admin, Reason, 1);
  48. QuerySQL( db, "INSERT INTO TempBans ( Name, Time) VALUES ( '" + player.Name + "', '" + Time + "' )" );
  49. }
  50.  
  51. function Unban(player, Admin)
  52. {
  53. QuerySQL( db, "DELETE FROM TempBans WHERE Name='" + player + "'" );
  54. QuerySQL( db, "DELETE FROM Bans WHERE Name='" + player + "'" );
  55. Message( "[#FF4500][ADMIN][#EEDD82] "+ player +" was unbanned by "+Admin+"." );
  56.  
  57. }
  58.  
  59. function UnbanIP(IP, Admin)
  60. {
  61. QuerySQL( db, "DELETE FROM BanIPs WHERE IP='" + IP + "'" );
  62. Message( "[#FF4500][ADMIN][#EEDD82] "+ IP +" unbanned by "+Admin+"." );
  63. UnbanIP(IP);
  64. }
  65.  
  66. function CheckBan(player)
  67. {
  68. local q = QuerySQL( db, "SELECT Name,Type FROM Bans WHERE UID='" + e(player.UniqueID) + "' " );
  69.  
  70. if ( q )
  71. {
  72. if ( GetSQLColumnData( q , 1) == 2)
  73. {
  74. if (GetSQLColumnData( q , 0).tolower() == player.Name.tolower())
  75. {
  76. Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s was kicked. Reason: Nick banned.", player.Name) );
  77. player.Kick();
  78. }
  79. }
  80. else
  81. {
  82. Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s was kicked. Reason: Banned with the account: %s", player.Name, GetSQLColumnData( q , 0)) );
  83. player.Kick();
  84. }
  85.  
  86. }
  87.  
  88. //This will save data that will be useful when giving offline users ban
  89. local q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ player.Name +"'" )
  90. if( !q ) QuerySQL( db, "INSERT INTO UsersDatas ( Name, UID, UID2, IP ) VALUES ( '" + player + "', '" + player.UniqueID + "', '" + player.UniqueID2 + "', '" + player.IP + "' )" );
  91. }
  92.  
  93. function DecreaseBanTime()
  94. {
  95. QuerySQL( db, "UPDATE Tempbans SET Time= (Time - 1) WHERE Time > 0" );
  96. local q = QuerySQL( db, "SELECT Name FROM TempBans WHERE Time='0'" );
  97.  
  98. local name = GetSQLColumnData( q , 0);
  99. if( name )
  100. {
  101. Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s's ban time is over", name));
  102. Punishment.Unban(name, "SERVER");
  103. }
  104. }
  105.  
  106. //------------------- Mute functions --------------------//
  107.  
  108. function AddMute(player, admin, reason, Time)
  109. {
  110. QuerySQL( db, "INSERT INTO Mute ( Name, Time) VALUES ( '" + player.Name + "', '" + Time + "' )" );
  111. Message( "[#EAEAEA][[#F0FFF0]MUTE[#EAEAEA]][#EEDD82] "+ player.Name +"'s was muted by "+ admin +". Reason: "+ reason);
  112. Punishment.CheckMute(player, 1);
  113. }
  114.  
  115. function UnMute(player, admin)
  116. {
  117. QuerySQL( db, "DELETE FROM Mute WHERE Name='" + player + "'" );
  118. _Timer.Destroy(Muted[ player.ID ].Timer);
  119. Muted[ player.ID ] = null;
  120. Message( format("[#EAEAEA][[#F0FFF0]MUTE[#EAEAEA]][#EEDD82] %s's was unmuted by %s.", player.Name, admin));
  121. }
  122.  
  123. function CheckMute(player, type)
  124. {
  125. switch (type)
  126. {
  127. //Type 1: When a user join in the server or is silenced.
  128. //Type 2: When a user leaves the server
  129.  
  130. case 1:
  131. local q = QuerySQL( db, "SELECT Time FROM Mute WHERE Name='" + player + "'" );
  132. if ( GetSQLColumnData( q , 0) )
  133. {
  134. try{
  135. Muted[ player.ID ] =
  136. {
  137. Time = GetSQLColumnData( q , 0).tointeger(),
  138. Timer = _Timer.Create(this, Punishment.DecreaseMuteTime, 1000, 0, player)
  139. };
  140. } catch (e)
  141. {
  142. print(e);
  143. }
  144. }
  145. break;
  146.  
  147. case 2:
  148. QuerySQL( db, format("UPDATE Mute SET Time='"+ Muted[ player.ID ].Time +"' WHERE Name='"+ player.Name +"'" ) );
  149. _Timer.Destroy(Muted[ player.ID ].Timer);
  150. Muted[ player.ID ] = null;
  151. break;
  152. }
  153. }
  154.  
  155. function DecreaseMuteTime(player)
  156. {
  157. if (Muted[ player.ID ].Time == 0)
  158. {
  159. UnMute(player, "SERVER");
  160. }
  161. else
  162. {
  163. Muted[ player.ID ].Time--;;
  164. }
  165. }
  166.  
  167. //------------------- Other functions --------------------//
  168. function GetDate()
  169. {
  170. return format("%.2d/%.2d/%.2d - %.2d hour/s, %.2d minute/s, %.2d second/s", date().day, (date().month +1), date().year, date().hour, date().min, date().sec);
  171. }
  172.  
  173. function CountBans()
  174. {
  175. local TempBans = QuerySQL( db, "SELECT count(*) from TempBans" ), Bans = QuerySQL( db, "SELECT count(*) from Bans WHERE Type='0'" ), BanNicks = QuerySQL( db, "SELECT count(*) from Bans WHERE Type='2'" ), IPBans = QuerySQL( db, "SELECT count(*) from BanIPs" );
  176. print(" "+ GetSQLColumnData( TempBans , 0) + " Accounts with temporary ban.");
  177. print(" "+ GetSQLColumnData( Bans , 0) + " Accounts with permanent ban.");
  178. print(" "+ GetSQLColumnData( BanNicks , 0) + " Nicks banneds.");
  179. print(" "+ GetSQLColumnData( IPBans , 0) + " IPs with ban.");
  180. }
  181.  
  182. function Command(cmd, text, player)
  183. {
  184. switch ( cmd.tolower() )
  185. {
  186. case "ban":
  187. if (!text) MessagePlayer("Sintax: /ban <nick> <reason>", player)
  188. else
  189. {
  190. local plr = GetTok(text, " ", 1), reason = "Not specified.";
  191. local q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'");
  192. if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
  193. else
  194. {
  195. plr = {
  196. Name = GetSQLColumnData( q, 0 ),
  197. UniqueID = GetSQLColumnData( q, 1 ),
  198. UniqueID2 = GetSQLColumnData( q, 2 ),
  199. IP = GetSQLColumnData( q, 3 )
  200. };
  201.  
  202. if (GetTok(text, " ", 2)) reason = GetTok(text, " ", 2);
  203. Punishment.AddBan(plr, player.Name, reason, 0);
  204. }
  205. }
  206. break;
  207.  
  208. case "banick":
  209. case "bannick":
  210. if (!text) MessagePlayer("Sintax: /ban <nick> <reason>", player)
  211. else
  212. {
  213. local plr = GetTok(text, " ", 1), reason = "Not specified.", q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'");
  214. if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
  215. else
  216. {
  217. plr = {
  218. Name = GetSQLColumnData( q, 0 ),
  219. UniqueID = GetSQLColumnData( q, 1 ),
  220. UniqueID2 = GetSQLColumnData( q, 2 ),
  221. IP = GetSQLColumnData( q, 3 )
  222. }
  223.  
  224. if (GetTok(text, " ", 2)) reason = GetTok(text, " ", 2);
  225. Punishment.AddBan(plr, player.Name, reason, 2);
  226. }
  227. }
  228. break;
  229.  
  230. case "tempban":
  231. if(!text) MessagePlayer("Sintax: /banick <nick> <days:hours:minutes> <reason>", player);
  232. else
  233. {
  234. local plr = GetTok(text, " ", 1),
  235. time = GetTok(text, " ", 2),
  236. reason = GetTok(text, " ", 3),
  237. q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'"),
  238. q1 = QuerySQL( db, "SELECT * FROM TempBans WHERE Name='"+ plr +"'");
  239.  
  240. if (!time) MessagePlayer("Sintax: /tempban <nick> <days:hours:minutes> <reason>", player);
  241. else if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
  242. else if (q1) MessagePlayer("Already banned.", player);
  243. else
  244. {
  245.  
  246. local days = (GetTok(time, ":", 1).tointeger() * 86400); //Days to seg
  247. local hours = (GetTok(time, ":", 2).tointeger() * 3600); //Hours to seg
  248. local mins = (GetTok(time, ":", 3).tointeger() * 60); //Minutes to seg
  249. local total = (days + hours + mins);
  250. plr = {
  251. Name = GetSQLColumnData( q, 0 ),
  252. UniqueID = GetSQLColumnData( q, 1 ),
  253. UniqueID2 = GetSQLColumnData( q, 2 ),
  254. IP = GetSQLColumnData( q, 3 )
  255. }
  256. if (!reason) reason = "Not specified.";
  257. Punishment.AddTempBan(plr, player.Name, reason, total);
  258. }
  259.  
  260. }
  261. break;
  262.  
  263. case "banip":
  264. if (!text) MessagePlayer("/banip IP", player);
  265. else
  266. {
  267. local ip = GetTok(text, " ", 1);
  268. Punishment.AddBanIP(ip, player.Name);
  269. }
  270. break;
  271.  
  272. case "mute":
  273. if (!text) MessagePlayer("/mute <nick> <minutes> <reason>", player);
  274. else
  275. {
  276. local plr = GetPlayer(GetTok(text, " ", 1)), minutes = GetTok(text, " ", 2), reason = GetTok(text, " ", 3);
  277.  
  278. if (!minutes || !reason) MessagePlayer("/mute <nick> <minutes> <reason>",player);
  279. else if ( Muted[ plr.ID ] ) MessagePlayer("Player already silenced", player);
  280. else Punishment.AddMute(plr, player.Name, reason, (minutes.tointeger() * 60) );
  281. }
  282. break;
  283.  
  284. case "unbanip":
  285. if (!text) MessagePlayer("/unbanip IP", player);
  286. else
  287. {
  288. Punishment.UnBanIP(ip, player.Name);
  289. }
  290. break;
  291.  
  292. case "unban":
  293. if (!text) MessagePlayer("/unban nick", player);
  294. else
  295. {
  296. local plr = GetTok(text, " ", 1);
  297. local q = QuerySQL( db, "SELECT * FROM Bans WHERE Name='"+plr+"'");
  298. if (!q) MessagePlayer("Player isn't banned", player);
  299. else Punishment.Unban(plr, player.Name);
  300. }
  301. break;
  302.  
  303. case "unmute":
  304.  
  305. if (!text) MessagePlayer("/unmute nick", player);
  306. else
  307. {
  308. local plr = GetPlayer(GetTok(text, " ", 1));
  309. if ( !plr ) MessagePlayer("Player not found", player);
  310. else if ( !Muted[ plr.ID ] ) MessagePlayer("Player isn't muted", player);
  311. else Punishment.UnMute(plr, player.Name);
  312. }
  313. break;
  314.  
  315.  
  316. }
  317. }
  318. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement