terrorstyles

Rocky's Ban System

Jul 18th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. Rocky's Ban System
  2.  
  3. BannedIPs <- []; //Banned IPs will be stored here
  4. BannedNicks <- []; //Banned Nicks will be stored here
  5.  
  6. //Load up ban data into array.
  7. function onScriptLoad( )
  8. {
  9. database <- ConnectSQL("Banlist.db");
  10. LoadBansInMemory(); //Load ban files into array.
  11. print( "Banlist loaded!" );
  12. }
  13.  
  14. //Disconnect database.
  15. function onScriptUnload( )
  16. {
  17. DisconnectSQL( database );
  18. }
  19.  
  20. function LoadBansInMemory()
  21. {
  22. local query = QuerySQL(database, "CREATE TABLE IF NOT EXISTS Banlist ( Nick TEXT, Reason TEXT, Date TEXT, IP TEXT)" );
  23. FreeSQLQuery( query );
  24.  
  25. //Store data into array.
  26. local q = QuerySQL( database, "SELECT Nick, Reason, Date, IP FROM Banlist" );
  27. while ( GetSQLColumnData ( q, 0 ) )
  28. {
  29. BannedIPs.push( GetSQLColumnData( q, 3 ).tostring() );
  30. BannedNicks.push( GetSQLColumnData( q, 0 ).tostring() );
  31.  
  32. GetSQLNextRow( q );
  33. }
  34. FreeSQLQuery( q );
  35. }
  36.  
  37. //Function to ban a player.
  38. function BanPlayer( admin, player, reason )
  39. {
  40. if( BannedIPs.find( player.IP.tostring() ) == null )
  41. {
  42. BannedIPs.push( player.IP.tostring() );
  43. BannedNicks.push( player.Name.tolower() );
  44. local q = QuerySQL( database,"INSERT INTO Banlist ( Nick, Reason, Date, IP) VALUES ( '"+player.Name+"', '"+reason+"', '"+GetFullTime()+"', '"+player.IP+"')" );
  45. FreeSQLQuery( q );
  46. Message( "[BAN] Banned: " + player + " by: " + admin + " for: " + reason);
  47. player.Kick();
  48.  
  49. }
  50. }
  51.  
  52.  
  53. //Function to unban a player using IP.
  54. function UnbanFromIP( ip )
  55. {
  56. if( BannedIPs.find( ip.tostring() ) != null )
  57. {
  58. local query = QuerySQL( database, "SELECT Nick FROM Banlist WHERE IP='" + ip + "' COLLATE NOCASE" );
  59. local nickname = GetSQLColumnData( query, 0 );
  60. FreeSQLQuery( query );
  61. query = QuerySQL( database,"DELETE FROM Banlist WHERE Nick='" +nickname+ "' COLLATE NOCASE" );
  62. FreeSQLQuery( query );
  63. BannedNicks.remove( BannedNicks.find( nickname.tostring() ) );
  64. BannedIPs.remove( BannedIPs.find( ip.tostring() ) );
  65. }
  66. }
  67.  
  68. //Function to unban a player from their nickname.
  69. function UnbanFromNick( nickname )
  70. {
  71. if( BannedNicks.find( nickname.tostring() ) != null )
  72. {
  73. local query = QuerySQL( database, "SELECT IP FROM Banlist WHERE Nick='" + nickname + "' COLLATE NOCASE" );
  74. local ip = GetSQLColumnData( query, 0 );
  75. FreeSQLQuery( query );
  76. query = QuerySQL( database,"DELETE FROM Banlist WHERE Nick='" +nickname+ "' COLLATE NOCASE" );
  77. FreeSQLQuery( query );
  78. BannedNicks.remove( BannedNicks.find( nickname ) );
  79. BannedIPs.remove( BannedIPs.find( ip.tostring() ) );
  80. }
  81. }
  82.  
  83.  
  84. function onPlayerJoin( player )
  85. {
  86. // Check if the name is banned
  87. if( ( BannedNicks.find( player.Name.tolower() ) != null ) || ( BannedIPs.find( player.IP.tostring() ) != null ) )
  88. {
  89. Message("[BAN] Auto-Kicking: " + player.Name + " for Ban Evading.");
  90. player.Kick();
  91. return;
  92. }
  93. }
  94.  
  95. function IsStringIP( string )
  96. {
  97. local Format = split(string, ".");
  98. if( Format != 4 ) return false;
  99. return true;
  100. }
Add Comment
Please, Sign In to add comment