Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package custom;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8.  
  9. import net.sf.l2j.L2DatabaseFactory;
  10.  
  11. /**
  12. * @author RnP PC
  13. *
  14. */
  15. public class BanManager
  16. {
  17. public static ArrayList<String> ips = new ArrayList<>();
  18.  
  19. public static void BanIp(String ip)
  20. {
  21. ips.add(ip);
  22. Connection con = null;
  23. try
  24. {
  25. con = L2DatabaseFactory.getInstance().getConnection();
  26. final PreparedStatement statement = con.prepareStatement("INSERT INTO banned (ip) VALUES ('"+ip+"')");
  27. statement.execute();
  28. statement.close();
  29. }
  30. catch (final SQLException e)
  31. {
  32. e.printStackTrace();
  33. }
  34. finally
  35. {
  36. try{con.close();}catch(Exception e){}
  37. }
  38. }
  39.  
  40. public static boolean UnbanIp(String ip)
  41. {
  42. if(!ips.contains(ip))
  43. return false;
  44. ips.remove(ip);
  45. Connection con = null;
  46. try
  47. {
  48. con = L2DatabaseFactory.getInstance().getConnection();
  49. final PreparedStatement statement = con.prepareStatement("DELETE FROM banned where ip='"+ip+"'");
  50. statement.execute();
  51. statement.close();
  52. }
  53. catch (final SQLException e)
  54. {
  55. e.printStackTrace();
  56. }
  57. finally
  58. {
  59. try{con.close();}catch(Exception e){}
  60. }
  61. return true;
  62. }
  63.  
  64. public static void Load()
  65. {
  66. Connection con = null;
  67. try
  68. {
  69. con = L2DatabaseFactory.getInstance().getConnection();
  70. final PreparedStatement statement = con.prepareStatement("SELECT * FROM banned");
  71. final ResultSet rset = statement.executeQuery();
  72. if (rset.next())
  73. {
  74. String ip = rset.getString("ip");
  75. ips.add(ip);
  76. }
  77. rset.close();
  78. statement.close();
  79. }
  80. catch (final SQLException e)
  81. {
  82. e.printStackTrace();
  83. }
  84. finally
  85. {
  86. try{con.close();}catch(Exception e){}
  87. }
  88. System.out.println("BAN MANAGER: Loaded " + ips.size() + " banned ips");
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement