Redo hwid bans - reduce amount of db queries on login

Works by loading all hwid bans on startup and querying the collection in memory
rather than making calls on every login.
This commit is contained in:
P0nk
2024-10-01 07:04:25 +02:00
parent 7661cd0f75
commit af02f8b744
20 changed files with 235 additions and 55 deletions

View File

@@ -315,32 +315,6 @@ public class Client extends ChannelInboundHandlerAdapter {
return inServerTransition;
}
// TODO: load hwidbans on server start and query it on demand. This query should not be run on every login!
@Deprecated
public boolean hasBannedHWID() {
if (hwid == null) {
return false;
}
boolean ret = false;
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?")) {
ps.setString(1, hwid.hwid());
try (ResultSet rs = ps.executeQuery()) {
if (rs != null && rs.next()) {
if (rs.getInt(1) > 0) {
ret = true;
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return ret;
}
// TODO: load macbans on server start and query it on demand. This query should not be run on every login!
@Deprecated
public boolean hasBannedMac() {
@@ -490,8 +464,6 @@ public class Client extends ChannelInboundHandlerAdapter {
}
public void updateHwid(Hwid hwid) {
this.hwid = hwid;
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?")) {
ps.setString(1, hwid.hwid());