[FEATURE] Предварительная имплементация UserHWID

This commit is contained in:
Gravit 2019-06-07 06:36:32 +07:00
parent 91b7b2cd06
commit 765d47deec
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 38 additions and 6 deletions

View file

@ -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);
}
}
}

View file

@ -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)

View file

@ -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<UserHWID> hwids;
public void setPassword(String password)
{
password_salt = SecurityHelper.randomStringAESKey();

View file

@ -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;
}