diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java index 0cdae071..1d681228 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java @@ -3,6 +3,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.UserHWID; import pro.gravit.utils.helper.LogHelper; public class GetUserCommand extends Command { @@ -30,5 +31,9 @@ public void invoke(String... args) throws Exception { return; } LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString()); + for(UserHWID hwid : user.hwids) + { + LogHelper.info("[%s] HWID: memory: %d | serial %s | hwdiskserial: %s | processorID %s | macAddr %s", user.username, hwid.totalMemory, hwid.serialNumber, hwid.HWDiskSerial, hwid.processorID, hwid.macAddr); + } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java index 765f1273..62818726 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java @@ -7,6 +7,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.dao.LaunchServerDaoFactory; import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.UserHWID; import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl; import pro.gravit.launchserver.hibernate.SessionFactoryManager; import pro.gravit.utils.helper.CommonHelper; @@ -25,6 +26,7 @@ public void preInit(LaunchServer launchServer) { Runnable init = () -> { Configuration cfg = new Configuration() .addAnnotatedClass(User.class) + .addAnnotatedClass(UserHWID.class) .setProperty("hibernate.connection.driver_class", driver) .setProperty("hibernate.connection.url", url) .setProperty("hibernate.connection.username", username) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java index 2d0f6f91..31e42497 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java @@ -4,14 +4,10 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import java.util.Collection; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; import pro.gravit.launcher.ClientPermissions; import pro.gravit.utils.helper.LogHelper; @@ -33,6 +29,12 @@ public class User { public String serverID; private String password_salt; public long permissions; + //TODO: заменить EAGER на LASY и придумать способ сохранить сессию + // [ERROR] org.hibernate.LazyInitializationException: + // failed to lazily initialize a collection of role: pro.gravit.launchserver.dao.User.hwids, could not initialize proxy - no Session + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + public Collection hwids; public void setPassword(String password) { password_salt = SecurityHelper.randomStringAESKey(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java new file mode 100644 index 00000000..6bf53bdd --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -0,0 +1,23 @@ +package pro.gravit.launchserver.dao; + +import pro.gravit.launcher.LauncherAPI; + +import javax.persistence.*; + +@Entity +@Table(name = "users_hwids") +public class UserHWID { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + @LauncherAPI + public long totalMemory = 0; + @LauncherAPI + public String serialNumber; + @LauncherAPI + public String HWDiskSerial; + @LauncherAPI + public String processorID; + @LauncherAPI + public String macAddr; +}