From cbfbc3c63b36291386a2f264164fc934f3dcc0ca Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 7 Jun 2019 12:30:31 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A0=D0=B0=D1=81=D1=88=D0=B8?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B8=D0=BC=D0=BF=D0=BB?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=86=D0=B8=D1=8F=20UserHW?= =?UTF-8?q?ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/dao/UserDAO.java | 3 ++ .../pro/gravit/launchserver/dao/UserHWID.java | 49 ++++++++++++++++--- .../dao/impl/DefaultUserDAOImpl.java | 7 +++ .../dao/impl/HibernateUserDAOImpl.java | 23 +++++++++ 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java index e400ff79..667ca4b0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java @@ -1,5 +1,7 @@ package pro.gravit.launchserver.dao; +import pro.gravit.launcher.OshiHWID; + import java.util.List; import java.util.UUID; @@ -7,6 +9,7 @@ public interface UserDAO { User findById(int id); User findByUsername(String username); User findByUUID(UUID uuid); + List findHWID(OshiHWID hwid); void save(User user); void update(User user); void delete(User user); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index 6bf53bdd..9d2b3f9a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -1,23 +1,58 @@ package pro.gravit.launchserver.dao; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.HWID; +import pro.gravit.launcher.OshiHWID; import javax.persistence.*; +import java.util.function.Supplier; @Entity @Table(name = "users_hwids") -public class UserHWID { +public class UserHWID implements HWID { + private transient Supplier oshiSupp = () -> { + OshiHWID hwid = new OshiHWID(); + hwid.HWDiskSerial = this.HWDiskSerial; + hwid.macAddr = this.macAddr; + hwid.processorID = this.processorID; + hwid.serialNumber = this.serialNumber; + hwid.totalMemory = this.totalMemory; + return hwid; + }; + private transient OshiHWID oshi = null; @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; + + public boolean banned; + public OshiHWID toHWID() + { + if(oshi == null) oshi = oshiSupp.get(); + return oshi; + } + + @Override + public String getSerializeString() { + return toHWID().getSerializeString(); + } + + @Override + public int getLevel() { + return toHWID().getLevel(); + } + + @Override + public int compare(HWID hwid) { + return toHWID().compare(hwid); + } + + @Override + public boolean isNull() { + return toHWID().isNull(); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java index 31027e1a..107e5686 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java @@ -4,9 +4,11 @@ import java.util.List; import java.util.UUID; +import pro.gravit.launcher.OshiHWID; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; +import pro.gravit.launchserver.dao.UserHWID; public class DefaultUserDAOImpl implements UserDAO { public DefaultUserDAOImpl(LaunchServer srv) { } @@ -25,6 +27,11 @@ public User findByUUID(UUID uuid) { return null; } + @Override + public List findHWID(OshiHWID hwid) { + return new ArrayList<>(); + } + @Override public void save(User user) { throw new UnsupportedOperationException(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java index fe4b8686..80246de1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java @@ -11,9 +11,11 @@ import org.hibernate.Session; import org.hibernate.Transaction; +import pro.gravit.launcher.OshiHWID; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; +import pro.gravit.launchserver.dao.UserHWID; import pro.gravit.launchserver.hibernate.SessionFactoryManager; public class HibernateUserDAOImpl implements UserDAO { @@ -53,6 +55,27 @@ public User findByUUID(UUID uuid) { return ret.size() == 0 ? null : ret.get(0); } + @Override + public List findHWID(OshiHWID hwid) { + EntityManager em = manager.fact.createEntityManager(); + em.getTransaction().begin(); + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery personCriteria = cb.createQuery(UserHWID.class); + Root rootUser = personCriteria.from(UserHWID.class); + personCriteria.select(rootUser).where( + cb.or( + cb.equal(rootUser.get("totalMemory"), hwid.totalMemory), + cb.equal(rootUser.get("HWDiskSerial"), hwid.HWDiskSerial), + cb.equal(rootUser.get("serialNumber"), hwid.serialNumber), + cb.equal(rootUser.get("processorID"), hwid.processorID), + cb.equal(rootUser.get("macAddr"), hwid.macAddr) + ) + ); + List ret = em.createQuery(personCriteria).getResultList(); + em.close(); + return ret; + } + public void save(User user) { try (Session session = manager.fact.openSession()) { Transaction tx1 = session.beginTransaction();