aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Ilin <hevav@hevav.dev>2022-12-25 21:03:40 +0300
committerPetr Ilin <hevav@hevav.dev>2022-12-25 21:03:40 +0300
commit373aebdc16ecd193a716a7afdea17b1dc094fed4 (patch)
treecbc330fb7011858128e9e03818589ec865084a00
parentdbc5b3edc4d05fc7ea5820bb3c0c4daa736be177 (diff)
downloadLimboAuth-373aebdc16ecd193a716a7afdea17b1dc094fed4.tar.gz
LimboAuth-373aebdc16ecd193a716a7afdea17b1dc094fed4.tar.bz2
LimboAuth-373aebdc16ecd193a716a7afdea17b1dc094fed4.zip
Save IP and date on every login
-rw-r--r--src/main/java/net/elytrium/limboauth/LimboAuth.java19
-rw-r--r--src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java10
-rw-r--r--src/main/java/net/elytrium/limboauth/model/RegisteredPlayer.java32
3 files changed, 56 insertions, 5 deletions
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<RegisteredPlayer, String> 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<String> 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;
+ }
}