· 6 years ago · Oct 03, 2019, 07:22 PM
1Muted <- array( GetMaxPlayers(), null );
2
3Punishment <- {
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 MSG("true");
73 if ( GetSQLColumnData( q , 1) == 2)
74 {
75 if (GetSQLColumnData( q , 0).tolower() == player.Name.tolower())
76 {
77 Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s was kicked. Reason: Nick banned.", player.Name) );
78 player.Kick();
79 }
80 }
81 else
82 {
83 Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s was kicked. Reason: Banned with the account: %s", player.Name, GetSQLColumnData( q , 0)) );
84 player.Kick();
85 }
86
87 }
88
89 //This will save data that will be useful when giving offline users ban
90 local q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ player.Name +"'" )
91 if( !q ) QuerySQL( db, "INSERT INTO UsersDatas ( Name, UID, UID2, IP ) VALUES ( '" + player + "', '" + player.UniqueID + "', '" + player.UniqueID2 + "', '" + player.IP + "' )" );
92 }
93
94 function DecreaseBanTime()
95 {
96 QuerySQL( db, "UPDATE Tempbans SET Time= (Time - 1) WHERE Time > 0" );
97 local q = QuerySQL( db, "SELECT Name FROM TempBans WHERE Time='0'" );
98
99 local name = GetSQLColumnData( q , 0);
100 if( name )
101 {
102 Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s's ban time is over", name));
103 Punishment.Unban(name, "SERVER");
104 }
105 }
106
107 //------------------- Mute functions --------------------//
108
109 function AddMute(player, admin, reason, Time)
110 {
111 QuerySQL( db, "INSERT INTO Mute ( Name, Time) VALUES ( '" + player.Name + "', '" + Time + "' )" );
112 Message( "[#EAEAEA][[#F0FFF0]MUTE[#EAEAEA]][#EEDD82] "+ player.Name +"'s was muted by "+ admin +". Reason: "+ reason);
113 Punishment.CheckMute(player, 1);
114 }
115
116 function UnMute(player, admin)
117 {
118 QuerySQL( db, "DELETE FROM Mute WHERE Name='" + player + "'" );
119 _Timer.Destroy(Muted[ player.ID ].Timer);
120 Muted[ player.ID ] = null;
121 Message( format("[#EAEAEA][[#F0FFF0]MUTE[#EAEAEA]][#EEDD82] %s's was unmuted by %s.", player.Name, admin));
122 }
123
124 function CheckMute(player, type)
125 {
126 switch (type)
127 {
128 //Type 1: When a user join in the server or is silenced.
129 //Type 2: When a user leaves the server
130
131 case 1:
132 local q = QuerySQL( db, "SELECT Time FROM Mute WHERE Name='" + player + "'" );
133 if ( GetSQLColumnData( q , 0) )
134 {
135 try{
136 Muted[ player.ID ] =
137 {
138 Time = GetSQLColumnData( q , 0).tointeger(),
139 Timer = _Timer.Create(this, Punishment.DecreaseMuteTime, 1000, 0, player)
140 };
141 } catch (e)
142 {
143 print(e);
144 }
145 }
146 break;
147
148 case 2:
149 QuerySQL( db, format("UPDATE Mute SET Time='"+ Muted[ player.ID ].Time +"' WHERE Name='"+ player.Name +"'" ) );
150 _Timer.Destroy(Muted[ player.ID ].Timer);
151 Muted[ player.ID ] = null;
152 break;
153 }
154 }
155
156 function DecreaseMuteTime(player)
157 {
158 if (Muted[ player.ID ].Time == 0)
159 {
160 UnMute(player, "SERVER");
161 }
162 else
163 {
164 Muted[ player.ID ].Time--;;
165 }
166 }
167
168 //------------------- Other functions --------------------//
169 function GetDate()
170 {
171 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);
172 }
173
174 function CountBans()
175 {
176 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" );
177 print(" "+ GetSQLColumnData( TempBans , 0) + " Accounts with temporary ban.");
178 print(" "+ GetSQLColumnData( Bans , 0) + " Accounts with permanent ban.");
179 print(" "+ GetSQLColumnData( BanNicks , 0) + " Nicks banneds.");
180 print(" "+ GetSQLColumnData( IPBans , 0) + " IPs with ban.");
181 }
182
183 function Command(cmd, text, player)
184 {
185 switch ( cmd.tolower() )
186 {
187 case "ban":
188 if (!text) MessagePlayer("Sintax: /ban <nick> <reason>", player)
189 else
190 {
191 local plr = GetTok(text, " ", 1), reason = "Not specified.";
192 local q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'");
193 if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
194 else
195 {
196 plr = {
197 Name = GetSQLColumnData( q, 0 ),
198 UniqueID = GetSQLColumnData( q, 1 ),
199 UniqueID2 = GetSQLColumnData( q, 2 ),
200 IP = GetSQLColumnData( q, 3 )
201 };
202
203 if (GetTok(text, " ", 2)) reason = GetTok(text, " ", 2);
204 Punishment.AddBan(plr, player.Name, reason, 0);
205 }
206 }
207 break;
208
209 case "banick":
210 case "bannick":
211 if (!text) MessagePlayer("Sintax: /ban <nick> <reason>", player)
212 else
213 {
214 local plr = GetTok(text, " ", 1), reason = "Not specified.", q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'");
215 if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
216 else
217 {
218 plr = {
219 Name = GetSQLColumnData( q, 0 ),
220 UniqueID = GetSQLColumnData( q, 1 ),
221 UniqueID2 = GetSQLColumnData( q, 2 ),
222 IP = GetSQLColumnData( q, 3 )
223 }
224
225 if (GetTok(text, " ", 2)) reason = GetTok(text, " ", 2);
226 Punishment.AddBan(plr, player.Name, reason, 2);
227 }
228 }
229 break;
230
231 case "tempban":
232 if(!text) MessagePlayer("Sintax: /banick <nick> <days:minutes:seconds> <reason>", player);
233 else
234 {
235 local plr = GetTok(text, " ", 1),
236 time = GetTok(text, " ", 2),
237 reason = GetTok(text, " ", 3),
238 q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'"),
239 q1 = QuerySQL( db, "SELECT * FROM TempBans WHERE Name='"+ plr +"'");
240
241 if (!time) MessagePlayer("Sintax: /tempban <nick> <days:minutes:seconds> <reason>", player);
242 else if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
243 else if (q1) MessagePlayer("Already banned.", player);
244 else
245 {
246
247 local days = (GetTok(time, ":", 1).tointeger() * 86400); //Days to seg
248 local hours = (GetTok(time, ":", 2).tointeger() * 3600); //Hours to seg
249 local mins = (GetTok(time, ":", 3).tointeger() * 60); //Minutes to seg
250 local total = (days + hours + mins);
251 plr = {
252 Name = GetSQLColumnData( q, 0 ),
253 UniqueID = GetSQLColumnData( q, 1 ),
254 UniqueID2 = GetSQLColumnData( q, 2 ),
255 IP = GetSQLColumnData( q, 3 )
256 }
257 if (!reason) reason = "Not specified.";
258 Punishment.AddTempBan(plr, player.Name, reason, total);
259 }
260
261 }
262 break;
263
264 case "banip":
265 if (!text) MessagePlayer("/banip IP", player);
266 else
267 {
268 local ip = GetTok(text, " ", 1);
269 Punishment.AddBanIP(ip, player.Name);
270 }
271 break;
272
273 case "mute":
274 if (!text) MessagePlayer("/mute <nick> <minutes> <reason>", player);
275 else
276 {
277 local plr = GetPlayer(GetTok(text, " ", 1)), minutes = GetTok(text, " ", 2), reason = GetTok(text, " ", 3);
278
279 if (!minutes || !reason) MessagePlayer("/mute <nick> <minutes> <reason>",player);
280 else if ( Muted[ plr.ID ] ) MessagePlayer("Player already silenced", player);
281 else Punishment.AddMute(plr, player.Name, reason, (minutes.tointeger() * 60) );
282 }
283 break;
284
285 case "unbanip":
286 if (!text) MessagePlayer("/unbanip IP", player);
287 else
288 {
289 Punishment.UnBanIP(ip, player.Name);
290 }
291 break;
292
293 case "unban":
294 if (!text) MessagePlayer("/unban nick", player);
295 else
296 {
297 local plr = GetTok(text, " ", 1);
298 local q = QuerySQL( db, "SELECT * FROM Bans WHERE Name='"+plr+"'");
299 if (!q) MessagePlayer("Player isn't banned", player);
300 else Punishment.Unban(plr, player.Name);
301 }
302 break;
303
304 case "unmute":
305
306 if (!text) MessagePlayer("/unmute nick", player);
307 else
308 {
309 local plr = GetPlayer(GetTok(text, " ", 1));
310 if ( !plr ) MessagePlayer("Player not found", player);
311 else if ( !Muted[ plr.ID ] ) MessagePlayer("Player isn't muted", player);
312 else Punishment.UnMute(plr, player.Name);
313 }
314 break;
315
316
317 }
318 }
319};