Hi, I was about 50% finished making this !unban command when I notice someone released one. However, I notice that the current one doesn't unban macs and ip addresses, and mine does, so I decided I'd finish mine and release it.
Here's the code for CommandProcessor.java:
Code:else if(splitted[0].equals("!unban")) { String playerName = splitted[1]; Connection con = DatabaseConnection.getConnection(); PreparedStatement ps; int accountid = 0; try { //get points according to town ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?"); ps.setString(1, playerName); ResultSet rs = ps.executeQuery(); if (!rs.next()) { ps.close(); } accountid = rs.getInt("accountid"); ps.close(); } catch (SQLException e) {System.out.println("SQL Exception: " + e);} String banString = ""; String macsOrig = ""; try { ps = con.prepareStatement("SELECT banreason, macs FROM accounts WHERE id = " + accountid); ResultSet rs = ps.executeQuery(); if (!rs.next()) { ps.close(); } banString = rs.getString("banreason"); macsOrig = rs.getString("macs"); ps.close(); } catch (SQLException e) {System.out.println("SQL Exception: " + e);} if(macsOrig != null) { int occurs = 0; for(int i = 0; i < macsOrig.length(); i++) { char next = macsOrig.charAt(i); if(next == ',') { occurs++; } } String macs[] = new String[occurs + 1]; System.out.println("Creating macs array..."); for(int i = 0; i <= occurs; i++) { int offset = 0; if(i > 0) offset = 2; macs[i] = macsOrig.substring((i * 17) + offset, (i * 17) + 17); System.out.println(macs[i]); } for(int i = 0; i < macs.length; i++) { try { ps = con.prepareStatement("DELETE FROM macbans WHERE mac = ?"); ps.setString(1, macs[i]); ps.executeUpdate(); ps.close(); } catch (SQLException e) {System.out.println("SQL Exception: " + e);} } mc.dropMessage("Macs Unbanned"); } if(banString.indexOf("IP: /") != -1) { String ip = banString.substring(banString.indexOf("IP: /") + 5, banString.length() - 1); try { ps = con.prepareStatement("DELETE FROM ipbans WHERE ip = ?"); ps.setString(1, ip); ps.executeUpdate(); ps.close(); mc.dropMessage("IP Address Unbanned"); } catch (SQLException e) {System.out.println("SQL Exception: " + e);} } try { ps = con.prepareStatement("UPDATE accounts SET banned = -1, banreason = null WHERE id = " + accountid); ps.executeUpdate(); ps.close(); mc.dropMessage("Account Unbanned"); } catch (SQLException e) {System.out.println("SQL Exception: " + e);} }
And you'll need to execute this query in your database.
REMEMBER: Always make backups of your database before making any changes
Code:ALTER TABLE `accounts` MODIFY COLUMN `banreason` VARCHAR(500) CHARACTER SET latin1 COLLATE latin1_swedish_ci;



Reply With Quote


