From 373aebdc16ecd193a716a7afdea17b1dc094fed4 Mon Sep 17 00:00:00 2001 From: Petr Ilin Date: Sun, 25 Dec 2022 21:03:40 +0300 Subject: Save IP and date on every login --- .../java/net/elytrium/limboauth/LimboAuth.java | 19 ++++++++++++- .../limboauth/handler/AuthSessionHandler.java | 10 ++++++- .../elytrium/limboauth/model/RegisteredPlayer.java | 32 ++++++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java index b9f6453..9eaef13 100644 --- a/src/main/java/net/elytrium/limboauth/LimboAuth.java +++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java @@ -27,6 +27,7 @@ import com.j256.ormlite.dao.GenericRawResults; import com.j256.ormlite.db.DatabaseType; import com.j256.ormlite.field.FieldType; import com.j256.ormlite.stmt.QueryBuilder; +import com.j256.ormlite.stmt.UpdateBuilder; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableInfo; import com.j256.ormlite.table.TableUtils; @@ -515,7 +516,9 @@ public class LimboAuth { "", System.currentTimeMillis(), player.getUniqueId().toString(), - player.getUniqueId().toString() + player.getUniqueId().toString(), + player.getRemoteAddress().getAddress().getHostAddress(), + System.currentTimeMillis() ); try { @@ -572,6 +575,12 @@ public class LimboAuth { switch (event.getResult()) { case BYPASS: { this.factory.passLoginLimbo(player); + this.cacheAuthUser(player); + try { + this.updateLoginData(player); + } catch (SQLException e) { + e.printStackTrace(); + } break; } case CANCEL: { @@ -594,6 +603,14 @@ public class LimboAuth { } } + public void updateLoginData(Player player) throws SQLException { + UpdateBuilder updateBuilder = this.playerDao.updateBuilder(); + updateBuilder.where().eq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, player.getUsername().toLowerCase(Locale.ROOT)); + updateBuilder.updateColumnValue(RegisteredPlayer.LOGIN_IP_FIELD, player.getRemoteAddress().getAddress().getHostAddress()); + updateBuilder.updateColumnValue(RegisteredPlayer.LOGIN_DATE_FIELD, System.currentTimeMillis()); + updateBuilder.update(); + } + private boolean validateScheme(JsonElement jsonElement, List scheme) { if (!scheme.isEmpty()) { if (!(jsonElement instanceof JsonObject)) { diff --git a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java index 6ce39e6..2ea17e0 100644 --- a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java +++ b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java @@ -199,7 +199,9 @@ public class AuthSessionHandler implements LimboSessionHandler { "", System.currentTimeMillis(), this.proxyPlayer.getUniqueId().toString(), - "" + "", + this.proxyPlayer.getRemoteAddress().getAddress().getHostAddress(), + System.currentTimeMillis() ); try { @@ -348,6 +350,12 @@ public class AuthSessionHandler implements LimboSessionHandler { return; } + try { + this.plugin.updateLoginData(this.proxyPlayer); + } catch (SQLException e) { + e.printStackTrace(); + } + this.plugin.cacheAuthUser(this.proxyPlayer); this.player.disconnect(); } diff --git a/src/main/java/net/elytrium/limboauth/model/RegisteredPlayer.java b/src/main/java/net/elytrium/limboauth/model/RegisteredPlayer.java index 4827d92..d5f37de 100644 --- a/src/main/java/net/elytrium/limboauth/model/RegisteredPlayer.java +++ b/src/main/java/net/elytrium/limboauth/model/RegisteredPlayer.java @@ -27,8 +27,10 @@ public class RegisteredPlayer { public static final String LOWERCASE_NICKNAME_FIELD = "LOWERCASENICKNAME"; public static final String HASH_FIELD = "HASH"; public static final String IP_FIELD = "IP"; + public static final String LOGIN_IP_FIELD = "LOGINIP"; public static final String TOTP_TOKEN_FIELD = "TOTPTOKEN"; public static final String REG_DATE_FIELD = "REGDATE"; + public static final String LOGIN_DATE_FIELD = "LOGINDATE"; public static final String UUID_FIELD = "UUID"; public static final String PREMIUM_UUID_FIELD = "PREMIUMUUID"; @@ -56,8 +58,14 @@ public class RegisteredPlayer { @DatabaseField(columnName = RegisteredPlayer.PREMIUM_UUID_FIELD) private String premiumUuid; + @DatabaseField(columnName = LOGIN_IP_FIELD) + private String loginIp; + + @DatabaseField(columnName = LOGIN_DATE_FIELD) + private Long loginDate; + public RegisteredPlayer(String nickname, String lowercaseNickname, - String hash, String ip, String totpToken, Long regDate, String uuid, String premiumUuid) { + String hash, String ip, String totpToken, Long regDate, String uuid, String premiumUuid, String loginIp, Long loginDate) { this.nickname = nickname; this.lowercaseNickname = lowercaseNickname; this.hash = hash; @@ -66,6 +74,8 @@ public class RegisteredPlayer { this.regDate = regDate; this.uuid = uuid; this.premiumUuid = premiumUuid; + this.loginIp = loginIp; + this.loginDate = loginDate; } public RegisteredPlayer() { @@ -116,8 +126,8 @@ public class RegisteredPlayer { this.regDate = regDate; } - public Long getRegDate() { - return this.regDate == null ? (Long) Long.MIN_VALUE : this.regDate; + public long getRegDate() { + return this.regDate == null ? Long.MIN_VALUE : this.regDate; } public void setUuid(String uuid) { @@ -135,4 +145,20 @@ public class RegisteredPlayer { public String getPremiumUuid() { return this.premiumUuid == null ? "" : this.premiumUuid; } + + public String getLoginIp() { + return this.loginIp == null ? "" : this.uuid; + } + + public void setLoginIp(String loginIp) { + this.loginIp = loginIp; + } + + public long getLoginDate() { + return this.loginDate == null ? Long.MIN_VALUE : this.loginDate; + } + + public void setLoginDate(Long loginDate) { + this.loginDate = loginDate; + } } -- cgit