terrorstyles

Rocky TempBan System ( Modified ) 0.4

Jul 18th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. /*
  2. [RBG] Rocky's Temp-Ban system (v0.1)
  3. This is completly made by Rocky,
  4. You are free to use, modify it for your own use.
  5. Put my name on credits list only if you like my work.
  6. */
  7. Credits: TerrorStyles for Editing PM Messages ( Means Nothing :P )
  8. //Events ->
  9. function onScriptLoad()
  10. {
  11. database <- ConnectSQL( "Data.sqlite" );
  12. QuerySQL( database, "CREATE TABLE IF NOT EXISTS Banned( ban_nick TEXT, ban_ip TEXT, ban_time TEXT, ban_expire TEXT, ban_expireratio TEXT, ban_admin TEXT, ban_reason TEXT )" );
  13. print("[RBAN] Rocky's Ban system Loaded (v0.1)");
  14. }
  15.  
  16. function onPlayerCommand( player, cmd, text )
  17. {
  18. cmd = cmd.tolower();
  19. if( cmd == "untempban" )
  20. {
  21. if( status[ player.ID ].Registered == false ) MessagePlayer( "[#FFF000]>> You must be registered in to use this command", player );
  22. else if( status[ player.ID ].LoggedIn == false ) MessagePlayer( "[#FF0000]>> You must be logged in to use this command", player );
  23. else if ( status[ player.ID ].Level < 6 ) PrivMessage(player,"[#FF8000]You need to be admin of level 6 in order to use this command." );
  24. else if( !text ) PrivMessage(player, "[#FFFFFF][TempBan] / untempban <Fullname>");
  25. else if( !IsBanned( text ) ) PrivMessage(player, "[#FFFFFF}[TempBan]Player is not banned.");
  26. else
  27. {
  28. QuerySQL( database, "DELETE TABLE FROM Banned WHERE ban_nick='" + text + "' COLLATE NOCASE" );
  29. Message("[#FF8000]Unbanned: [ " + text + " ] by Admin: [ " + player.Name + " ]" );
  30. }
  31. }
  32. else if ( cmd == "commands" )
  33. {
  34. MessagePlayer( "[#FFFFFF]Available Commands /tempban /untempban", player );
  35. }
  36. else if ( cmd == "tempban" )
  37. {
  38. local txt_Split;
  39. if( status[ player.ID ].Registered == false ) MessagePlayer( "[#FFF000]>> You must be registered in to use this command", player );
  40. else if( status[ player.ID ].LoggedIn == false ) MessagePlayer( "[#FF0000]>> You must be logged in to use this command", player );
  41. else if ( status[ player.ID ].Level < 6 ) PrivMessage(player,"[#FF8000]You need to be admin of level 6 in order to use this command." );
  42. else if( !text ) PrivMessage(player, "[#FFFFFF]/ tempban <player> <day:hour:min> <reason>" );
  43. else
  44. {
  45. if( NumTok( text, " " ) == 2 )
  46. {
  47. txt_Split = split( text, " " );
  48. local plr = FindPlayer( txt_Split[ 0 ] ), expire = txt_Split[ 1 ];
  49. if( plr ) AddBan( player, plr, expire );
  50. else PrivMessage(player,"[Tempban] No such player." );
  51. }
  52. else if( NumTok( text, " " ) >= 3 )
  53. {
  54. txt_Split = split( text, " " );
  55. local plr = FindPlayer( txt_Split[ 0 ] ), expire = txt_Split[ 1 ], reason = txt_Split[ 2 ];
  56. if( plr ) AddBan( player, plr, expire, reason );
  57. else PrivMessage(player,"[Tempban] No such player." );
  58. }
  59. else PrivMessage(player, "[TempBan] / tempban <player> <day:hour:min> <reason>" );
  60. }
  61. }
  62. else PrivMessage( player, "[#FF8000]Unknown Command Type /commands to see available commands" );
  63. }
  64.  
  65. function onPlayerJoin( player )
  66. {
  67. NewTimer( "Banned", 3000, 1, player ); //Check if player is banned.
  68. }
  69.  
  70. //Functions ->
  71. //Everyone is familiar with this function. :P
  72. function NumTok(string, separator)
  73. {
  74. local tokenized = split(string, separator);
  75. return tokenized.len();
  76. }
  77. //This basically stores the ban info into database reason for ban is optional.
  78. function AddBan( admin, player, expire, reason = "Not Specified" )
  79. {
  80. //Equation = (DAYS*24*60*60) + (HOUR*60*60) + (MIN*60)
  81. local ban_Expire = split( expire, ":" ); //days:hours:minutes
  82. if( NumTok( expire, ":" ) == 3 )
  83. {
  84. if( IsNum( ban_Expire[ 0 ] ) && IsNum( ban_Expire[ 1 ] ) && IsNum( ban_Expire[ 2 ] ) )
  85. {
  86. if( ban_Expire[ 0 ].tointeger() <= 31 && ban_Expire[ 1 ].tointeger() <= 24 && ban_Expire[ 2 ].tointeger() <= 60 )
  87. {
  88. local ban_Expires = ( (ban_Expire[ 0 ].tointeger()*24*60*60) + (ban_Expire[ 1 ].tointeger()*60*60) + (ban_Expire[ 2 ].tointeger()*60) ),
  89. Calc = ban_Expire[ 0 ] + " Day(s), " + ban_Expire[ 1 ] + " Hour(s), " + ban_Expire[ 2 ] + " Minute(s).",
  90. query = QuerySQL( database, "INSERT INTO Banned( ban_nick, ban_ip, ban_time, ban_expire, ban_expireratio, ban_admin, ban_reason ) VALUES ( '"+ player.Name.tostring() +"','"+ player.IP.tostring() +"','"+ time().tostring() +"', '"+ ban_Expires.tostring() +"', '" + expire.tostring() + "', '"+ admin.Name.tostring() +"', '"+ reason.tostring() +"')");
  91. FreeSQLQuery( query );
  92. MessagePlayer("[#FF8000][TempBan]You have been temporarily banned by " + admin.Name, player);
  93. MessagePlayer("[#FF8000][TempBan]Your ban is set to expire in: " + Calc, player);
  94. player.Kick();
  95. }
  96. }
  97. else MessagePlayer("[#FF8000][TempBan]Time should be numeric (day:hour:min)", admin );
  98. }
  99. else MessagePlayer("[#FF8000][TempBan]Wrong format, day:hour:min (Numeric)", admin );
  100. }
  101. //Check if player is banned and Kick him/her.
  102. function Banned( player )
  103. {
  104. local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_nick='" + player.Name + "' COLLATE NOCASE" ), Ip = player.IP.tostring();
  105. if( GetSQLColumnData( query, 0 ) )
  106. {
  107. if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
  108. {
  109. local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_nick='" + player.Name.tostring() + "'" );
  110. FreeSQLQuery( query2 );
  111. MessagePlayer("[#FF8000][TempBan]Your ban has been expired.", player );
  112. MessagePlayer("[#FF8000][TempBan]Stick to the rules or you will get permanently banned.", player );
  113. }
  114. else
  115. {
  116. local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ) );
  117. //local splitban = split( GetSQLColumnData( query, 4 ), ":" ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
  118. MessagePlayer("[#FF8000][TempBan]Your ban has not expired.", player );
  119. MessagePlayer("[#FF8000][TempBan]Your ban is set to expire in. " + Time_Left, player );
  120. player.Kick();
  121. }
  122. }
  123. else if( GetSQLColumnData( QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" ), 0 ) )
  124. {
  125. local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" );
  126. if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
  127. {
  128. local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_ip='" + player.IP.tostring() + "'" );
  129. FreeSQLQuery( query2 );
  130. MessagePlayer("[#FF8000][TempBan]Your ban has been expired.", player );
  131. MessagePlayer("[#FF8000][TempBan]Stick to the rules or you will get permanently banned.", player );
  132. }
  133. else
  134. {
  135. local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ).tostring() );
  136. //local splitban = split( GetSQLColumnData( query, 4 ), ":" ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
  137. MessagePlayer("[#FF8000][TempBan] Your ban has not expired.", player );
  138. MessagePlayer("[#FF8000][TempBan] Your ban is set to expire in. " + Time_Left , player );
  139. player.Kick();
  140. }
  141. }
  142. FreeSQLQuery( query );
  143. }
  144.  
  145. //This returns the time left for ban in Day:hour:minute format.
  146.  
  147. //GeTok function
  148. function GetTok(string, separator, n, ...)
  149. {
  150. local m = vargv.len() > 0 ? vargv[0] : n,
  151. tokenized = split(string, separator),
  152. text = "";
  153.  
  154. if (n > tokenized.len() || n < 1) return null;
  155. for (; n <= m; n++)
  156. {
  157. text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
  158. }
  159. return text;
  160. }
  161.  
  162. //Check is player is banned.
  163. function IsBanned( fullname )
  164. {
  165. local query = QuerySQL( database, "SELECT ban_ip FROM Banned WHERE ban_nick='" + fullname + "' COLLATE NOCASE" );
  166. if( GetSQLColumnData( query, 0 ) ) return true;
  167. return false;
  168. }
  169.  
  170. //This returns the time left for ban in Day:hour:minute format.
  171. function TimeRem( bantime, banratio )
  172. {
  173. local ban_current = time()-bantime, sp = split(banratio,":"), ban_Days, ban_Hours, ban_Minutes,
  174. ban_Day = sp[ 0 ].tointeger(),
  175. ban_Hour = sp[ 1 ].tointeger(),
  176. ban_Minute = sp[ 2 ].tointeger();
  177. ban_Days = ban_current/86400;
  178. ban_current = ban_current%86400;
  179. ban_Hours = ban_current/3600;
  180. ban_current = ban_current%3600;
  181. ban_Minutes = ban_current/60;
  182. ban_current = ban_current%60;
  183. ban_Day -= ban_Days;
  184. ban_Hour -= ban_Hours;
  185. ban_Minute -= ban_Minutes;
  186. return ban_Day + " Day(s), " + ban_Hour + " Hour(s), " + ban_Minute + " Minutes.";
  187. }
  188.  
  189. /*
  190. ~End of the code~
  191. */
Add Comment
Please, Sign In to add comment