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