mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 09:09:46 +03:00
[FEATURE] Расширенная имплементация UserHWID
This commit is contained in:
parent
765d47deec
commit
cbfbc3c63b
4 changed files with 75 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launchserver.dao;
|
package pro.gravit.launchserver.dao;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.OshiHWID;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -7,6 +9,7 @@ public interface UserDAO {
|
||||||
User findById(int id);
|
User findById(int id);
|
||||||
User findByUsername(String username);
|
User findByUsername(String username);
|
||||||
User findByUUID(UUID uuid);
|
User findByUUID(UUID uuid);
|
||||||
|
List<UserHWID> findHWID(OshiHWID hwid);
|
||||||
void save(User user);
|
void save(User user);
|
||||||
void update(User user);
|
void update(User user);
|
||||||
void delete(User user);
|
void delete(User user);
|
||||||
|
|
|
@ -1,23 +1,58 @@
|
||||||
package pro.gravit.launchserver.dao;
|
package pro.gravit.launchserver.dao;
|
||||||
|
|
||||||
import pro.gravit.launcher.LauncherAPI;
|
import pro.gravit.launcher.HWID;
|
||||||
|
import pro.gravit.launcher.OshiHWID;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users_hwids")
|
@Table(name = "users_hwids")
|
||||||
public class UserHWID {
|
public class UserHWID implements HWID {
|
||||||
|
private transient Supplier<OshiHWID> 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
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
@LauncherAPI
|
|
||||||
public long totalMemory = 0;
|
public long totalMemory = 0;
|
||||||
@LauncherAPI
|
|
||||||
public String serialNumber;
|
public String serialNumber;
|
||||||
@LauncherAPI
|
|
||||||
public String HWDiskSerial;
|
public String HWDiskSerial;
|
||||||
@LauncherAPI
|
|
||||||
public String processorID;
|
public String processorID;
|
||||||
@LauncherAPI
|
|
||||||
public String macAddr;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.OshiHWID;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
import pro.gravit.launchserver.dao.UserDAO;
|
import pro.gravit.launchserver.dao.UserDAO;
|
||||||
|
import pro.gravit.launchserver.dao.UserHWID;
|
||||||
|
|
||||||
public class DefaultUserDAOImpl implements UserDAO {
|
public class DefaultUserDAOImpl implements UserDAO {
|
||||||
public DefaultUserDAOImpl(LaunchServer srv) { }
|
public DefaultUserDAOImpl(LaunchServer srv) { }
|
||||||
|
@ -25,6 +27,11 @@ public User findByUUID(UUID uuid) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserHWID> findHWID(OshiHWID hwid) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(User user) {
|
public void save(User user) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
|
@ -11,9 +11,11 @@
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.OshiHWID;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
import pro.gravit.launchserver.dao.UserDAO;
|
import pro.gravit.launchserver.dao.UserDAO;
|
||||||
|
import pro.gravit.launchserver.dao.UserHWID;
|
||||||
import pro.gravit.launchserver.hibernate.SessionFactoryManager;
|
import pro.gravit.launchserver.hibernate.SessionFactoryManager;
|
||||||
|
|
||||||
public class HibernateUserDAOImpl implements UserDAO {
|
public class HibernateUserDAOImpl implements UserDAO {
|
||||||
|
@ -53,6 +55,27 @@ public User findByUUID(UUID uuid) {
|
||||||
return ret.size() == 0 ? null : ret.get(0);
|
return ret.size() == 0 ? null : ret.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserHWID> findHWID(OshiHWID hwid) {
|
||||||
|
EntityManager em = manager.fact.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<UserHWID> personCriteria = cb.createQuery(UserHWID.class);
|
||||||
|
Root<UserHWID> 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<UserHWID> ret = em.createQuery(personCriteria).getResultList();
|
||||||
|
em.close();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public void save(User user) {
|
public void save(User user) {
|
||||||
try (Session session = manager.fact.openSession()) {
|
try (Session session = manager.fact.openSession()) {
|
||||||
Transaction tx1 = session.beginTransaction();
|
Transaction tx1 = session.beginTransaction();
|
||||||
|
|
Loading…
Reference in a new issue