From c438f08d7aa9fa64874769a0c4c3913dbbe733f7 Mon Sep 17 00:00:00 2001
From: Gravit <gravit.min@ya.ru>
Date: Tue, 7 Apr 2020 19:05:58 +0700
Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?=
 =?UTF-8?q?=D1=80=D0=BA=D0=B0=20HWID?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../secure/HardwareReportResponse.java        |  4 +-
 .../test/PrintHardwareInfoCommand.java        | 48 +++++++++++++++++++
 .../launcher/managers/ConsoleManager.java     |  2 +
 .../gravit/launcher/utils/HWIDProvider.java   | 17 +++++++
 .../request/secure/HardwareReportRequest.java |  2 +
 5 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java

diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java
index 83b87337..c9aa8db2 100644
--- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java
+++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java
@@ -1,12 +1,12 @@
 package pro.gravit.launchserver.socket.response.secure;
 
 import io.netty.channel.ChannelHandlerContext;
+import pro.gravit.launcher.request.secure.HardwareReportRequest;
 import pro.gravit.launchserver.socket.Client;
 import pro.gravit.launchserver.socket.response.SimpleResponse;
 
 public class HardwareReportResponse extends SimpleResponse {
-    public String pathToJava;
-    public String javaVersion;
+    public HardwareReportRequest.HardwareInfo hardware;
 
     @Override
     public String getType() {
diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java
new file mode 100644
index 00000000..2d7a879e
--- /dev/null
+++ b/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java
@@ -0,0 +1,48 @@
+package pro.gravit.launcher.console.test;
+
+import pro.gravit.launcher.utils.HWIDProvider;
+import pro.gravit.utils.command.Command;
+import pro.gravit.utils.helper.LogHelper;
+
+public class PrintHardwareInfoCommand extends Command {
+    @Override
+    public String getArgsDescription() {
+        return "[]";
+    }
+
+    @Override
+    public String getUsageDescription() {
+        return "print your hardware info and timings";
+    }
+
+    @Override
+    public void invoke(String... args) throws Exception {
+        LogHelper.info("Your Hardware ID:");
+        long startTime = System.currentTimeMillis();
+        long currentTime;
+        HWIDProvider provider = new HWIDProvider();
+        currentTime = System.currentTimeMillis();
+        LogHelper.info("Create HWIDProvider instance: %d ms", currentTime - startTime);
+        startTime = System.currentTimeMillis();
+        int bitness = provider.getBitness();
+        long totalMemory = provider.getTotalMemory();
+        boolean isBattery = provider.isBattery();
+        currentTime = System.currentTimeMillis();
+        LogHelper.info("Bitness: %d, totalMemory: %d(%.3f GB), battery %s, TIME: %d ms", bitness, totalMemory, (double)totalMemory / (1024.0*1024.0*1024.0), Boolean.toString(isBattery), currentTime - startTime);
+        startTime = System.currentTimeMillis();
+        int logicalProcessors = provider.getProcessorLogicalCount();
+        int physicalProcessors = provider.getProcessorPhysicalCount();
+        long processorMaxFreq = provider.getProcessorMaxFreq();
+        currentTime = System.currentTimeMillis();
+        LogHelper.info("Processors || logical: %d physical %d freq %d, TIME: %d ms", logicalProcessors, physicalProcessors, processorMaxFreq, currentTime - startTime);
+        startTime = System.currentTimeMillis();
+        String hwDiskID = provider.getHWDiskID();
+        currentTime = System.currentTimeMillis();
+        LogHelper.info("HWDiskID %s, TIME: %d ms", hwDiskID, currentTime - startTime);
+        startTime = System.currentTimeMillis();
+        String baseboardSerial = provider.getBaseboardSerialNumber();
+        currentTime = System.currentTimeMillis();
+        LogHelper.info("BaseboardSerial %s, TIME: %d ms", baseboardSerial, currentTime - startTime);
+        LogHelper.info("Hardware ID end");
+    }
+}
diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java
index c0d6543d..641be710 100644
--- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java
+++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java
@@ -4,6 +4,7 @@
 import pro.gravit.launcher.LauncherEngine;
 import pro.gravit.launcher.client.events.ClientUnlockConsoleEvent;
 import pro.gravit.launcher.console.UnlockCommand;
+import pro.gravit.launcher.console.test.PrintHardwareInfoCommand;
 import pro.gravit.utils.command.CommandHandler;
 import pro.gravit.utils.command.JLineCommandHandler;
 import pro.gravit.utils.command.StdCommandHandler;
@@ -44,6 +45,7 @@ public static void registerCommands() {
         handler.registerCommand("gc", new GCCommand());
         handler.registerCommand("clear", new ClearCommand(handler));
         handler.registerCommand("unlock", new UnlockCommand());
+        handler.registerCommand("printhardware", new PrintHardwareInfoCommand());
     }
 
     public static boolean checkUnlockKey(String key) {
diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java
index 3f8aa00d..bdf41d46 100644
--- a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java
+++ b/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java
@@ -1,6 +1,7 @@
 package pro.gravit.launcher.utils;
 
 import oshi.SystemInfo;
+import oshi.hardware.Display;
 import oshi.hardware.HWDiskStore;
 import oshi.hardware.HardwareAbstractionLayer;
 import oshi.hardware.PowerSource;
@@ -63,6 +64,20 @@ public String getHWDiskID()
         }
         return null;
     }
+    public byte[] getDisplayID()
+    {
+        Display[] displays = hardware.getDisplays();
+        if(displays == null || displays.length == 0) return null;
+        for(Display display : displays)
+        {
+            return display.getEdid();
+        }
+        return null;
+    }
+    public String getBaseboardSerialNumber()
+    {
+        return hardware.getComputerSystem().getBaseboard().getSerialNumber();
+    }
     public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial)
     {
         HardwareReportRequest.HardwareInfo info = new HardwareReportRequest.HardwareInfo();
@@ -75,6 +90,8 @@ public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial)
         if(needSerial)
         {
             info.hwDiskId = getHWDiskID();
+            info.displayId = getDisplayID();
+            info.baseboardSerialNumber = getBaseboardSerialNumber();
         }
         return info;
     }
diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java
index 857d6c97..2f7fd075 100644
--- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java
+++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java
@@ -18,5 +18,7 @@ public static class HardwareInfo {
         public long processorMaxFreq;
         public boolean battery;
         public String hwDiskId;
+        public byte[] displayId;
+        public String baseboardSerialNumber;
     }
 }