From dccbd5262f5490d601ddf1be7fe3847c35bf2df4 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Tue, 12 Jul 2016 21:43:07 +0200 Subject: [PATCH] Don't update IP twice - IP is updated in datasource#updateSession after successful login - Remove no longer used DataSource#updateIp --- .../xephi/authme/datasource/CacheDataSource.java | 9 --------- .../fr/xephi/authme/datasource/DataSource.java | 9 --------- .../fr/xephi/authme/datasource/FlatFile.java | 5 ----- .../java/fr/xephi/authme/datasource/MySQL.java | 14 -------------- .../java/fr/xephi/authme/datasource/SQLite.java | 14 -------------- .../authme/process/login/AsynchronousLogin.java | 5 ----- .../AbstractDataSourceIntegrationTest.java | 16 ---------------- 7 files changed, 72 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 79cc6ae6e..cb916378f 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -229,15 +229,6 @@ public class CacheDataSource implements DataSource { return result; } - @Override - public boolean updateIp(String user, String ip) { - boolean result = source.updateIp(user, ip); - if (result) { - cachedAuths.refresh(user); - } - return result; - } - @Override public List getAllAuths() { return source.getAllAuths(); diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index f1bb991a5..12ee8060a 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -186,15 +186,6 @@ public interface DataSource extends Reloadable { */ boolean updateRealName(String user, String realName); - /** - * Update a player's IP address. - * - * @param user The name of the user (lowercase) - * @param ip The IP address to save - * @return True upon success, false upon failure - */ - boolean updateIp(String user, String ip); - /** * Return all players of the database. * diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 7ae6026e1..592309b0d 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -486,11 +486,6 @@ public class FlatFile implements DataSource { throw new UnsupportedOperationException("Flat file no longer supported"); } - @Override - public boolean updateIp(String user, String ip) { - throw new UnsupportedOperationException("Flat file no longer supported"); - } - @Override public List getAllAuths() { BufferedReader br = null; diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index e1720f959..0bb9a3d0f 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -790,20 +790,6 @@ public class MySQL implements DataSource { return false; } - @Override - public boolean updateIp(String user, String ip) { - String sql = "UPDATE " + tableName + " SET " + col.IP + "=? WHERE " + col.NAME + "=?;"; - try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { - pst.setString(1, ip); - pst.setString(2, user); - pst.executeUpdate(); - return true; - } catch (SQLException ex) { - logSqlException(ex); - } - return false; - } - @Override public List getAllAuths() { List auths = new ArrayList<>(); diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index a60dfd0dc..0edbdf751 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -555,20 +555,6 @@ public class SQLite implements DataSource { return false; } - @Override - public boolean updateIp(String user, String ip) { - String sql = "UPDATE " + tableName + " SET " + col.IP + "=? WHERE " + col.NAME + "=?;"; - try (PreparedStatement pst = con.prepareStatement(sql)) { - pst.setString(1, ip); - pst.setString(2, user); - pst.executeUpdate(); - return true; - } catch (SQLException ex) { - logSqlException(ex); - } - return false; - } - @Override public List getAllAuths() { List auths = new ArrayList<>(); diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 6fb7a189f..2c2d7e11c 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -139,11 +139,6 @@ public class AsynchronousLogin implements AsynchronousProcess { captchaManager.increaseCount(name); tempbanManager.increaseCount(ip); - if (!pAuth.getIp().equals(ip)) { - pAuth.setIp(ip); - database.updateIp(pAuth.getNickname(), ip); - } - String email = pAuth.getEmail(); boolean passwordVerified = forceLogin || passwordSecurity.comparePassword( password, pAuth.getPassword(), player.getName()); diff --git a/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java index 0c0d217bb..b94748166 100644 --- a/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java @@ -271,22 +271,6 @@ public abstract class AbstractDataSourceIntegrationTest { assertThat(dataSource.getAllAuths(), hasItem(hasAuthBasicData("user", "user", email, "34.56.78.90"))); } - @Test - public void shouldUpdateIp() { - // given - DataSource dataSource = getDataSource(); - String ip = "250.230.67.73"; - - // when - boolean response1 = dataSource.updateIp("bobby", ip); - boolean response2 = dataSource.updateIp("bogus", "123.123.123.123"); - - - // then - assertThat(response1 && response2, equalTo(true)); - assertThat(dataSource.getAllAuths(), hasItem(hasAuthBasicData("bobby", "Bobby", "your@email.com", ip))); - } - @Test public void shouldCountAuths() { // given