aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/torui/coflsky
diff options
context:
space:
mode:
authorFlorian Rinke <develop@torui.de>2021-09-23 21:49:38 +0200
committerFlorian Rinke <develop@torui.de>2021-09-23 21:49:38 +0200
commit832403ba363d29d0252702c626405cbc9ba4d7bd (patch)
treed5a059c4ba6b052c66388ede716b394be6e41cb0 /src/main/java/de/torui/coflsky
parent6c6170f129f20ba70e633de5f28a409590a94f2f (diff)
downloadCOFL-832403ba363d29d0252702c626405cbc9ba4d7bd.tar.gz
COFL-832403ba363d29d0252702c626405cbc9ba4d7bd.tar.bz2
COFL-832403ba363d29d0252702c626405cbc9ba4d7bd.zip
Added UUID detection
Diffstat (limited to 'src/main/java/de/torui/coflsky')
-rw-r--r--src/main/java/de/torui/coflsky/CoflSky.java35
-rw-r--r--src/main/java/de/torui/coflsky/EventRegistry.java6
-rw-r--r--src/main/java/de/torui/coflsky/websocket/WSClient.java3
-rw-r--r--src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java3
4 files changed, 24 insertions, 23 deletions
diff --git a/src/main/java/de/torui/coflsky/CoflSky.java b/src/main/java/de/torui/coflsky/CoflSky.java
index 97fa29f..e5be925 100644
--- a/src/main/java/de/torui/coflsky/CoflSky.java
+++ b/src/main/java/de/torui/coflsky/CoflSky.java
@@ -39,13 +39,11 @@ public class CoflSky
public static final String VERSION = "1.0";
public static WSClientWrapper Wrapper;
- public static String PlayerUUID = "";
-
@EventHandler
public void init(FMLInitializationEvent event) throws URISyntaxException
{
- //Minecraft.getSessionInfo().forEach((a,b) -> System.out.println("Key=" + a + " value=" + b));
+ Minecraft.getSessionInfo().forEach((a,b) -> System.out.println("Key=" + a + " value=" + b));
//System.out.println("Loggerfactory: " + LoggerFactory.getILoggerFactory());
// Logger log = LoggerFactory.getLogger(CoflSky.class);
@@ -58,28 +56,28 @@ public class CoflSky
System.out.println(">>>Started");
String username = Minecraft.getSessionInfo().get("X-Minecraft-Username");
- System.out.println(">>> Username= " + username);
- /*try {
- QueryUUID("pingulinoo");
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }*/
+ String uuid = QueryUUID(username);
+ System.out.println(">>> Username= " + username + " with UUID=" + uuid );
String URI = "https://api.mojang.com/profiles/minecraft";
- CoflSky.Wrapper = new WSClientWrapper("ws://sky-commands.coflnet.com/modsocket?version=" + CoflSky.VERSION + "&uuid=");
+ //CoflSky.Wrapper = new WSClientWrapper("wss://sky-commands.coflnet.com/modsocket?version=" + CoflSky.VERSION + "&uuid=");
+ CoflSky.Wrapper = new WSClientWrapper("ws://sky-mod.coflnet.com/modsocket?version=" + CoflSky.VERSION + "&uuid=" + uuid);
if(event.getSide() == Side.CLIENT)
ClientCommandHandler.instance.registerCommand(new CoflSkyCommand());
MinecraftForge.EVENT_BUS.register(new EventRegistry());
}
-
- public static String QueryUUID(String username) throws MalformedURLException {
- URL url = new URL("https://api.mojang.com/profiles/minecraft");
- HttpURLConnection con;
+ private static class UUIDHelper {
+ public String id;
+ public String name;
+ }
+ public static String QueryUUID(String username) {
+
try {
+ URL url = new URL("https://api.mojang.com/profiles/minecraft");
+ HttpURLConnection con;
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
@@ -105,14 +103,17 @@ public class CoflSky
String resString = result.toString("UTF-8");
System.out.println("Result= " + resString);
-
+ UUIDHelper[] helpers = WSClient.gson.fromJson(resString, UUIDHelper[].class);
+ if(helpers.length == 1) {
+ return helpers[0].id;
+ }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- return null;
+ return UUID.randomUUID().toString();
}
diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java
index 4d125f0..06f94cd 100644
--- a/src/main/java/de/torui/coflsky/EventRegistry.java
+++ b/src/main/java/de/torui/coflsky/EventRegistry.java
@@ -20,12 +20,12 @@ public class EventRegistry{
@SubscribeEvent
public void onConnectedToServerEvent(ClientConnectedToServerEvent event) {
- if(!event.isLocal ) {
+ /* if(!event.isLocal ) {
//String serverIP = Minecraft.getMinecraft().getCurrentServerData().serverIP;
/* if(false && serverIP.equals("hypixel.net")) {
- }*/
+ }*
//UUID.randomUUID().toString();
//String id = FMLClientHandler.instance().getClient().thePlayer.getUniqueID().toString();
@@ -37,7 +37,7 @@ public class EventRegistry{
System.out.println("Connected to server");
CoflSky.Wrapper.start();
System.out.println("CoflSky started");
- }
+ }*/
}
@SubscribeEvent
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClient.java b/src/main/java/de/torui/coflsky/websocket/WSClient.java
index c893bb1..7fb8e34 100644
--- a/src/main/java/de/torui/coflsky/websocket/WSClient.java
+++ b/src/main/java/de/torui/coflsky/websocket/WSClient.java
@@ -45,7 +45,7 @@ public class WSClient extends WebSocketAdapter {
public void start() throws IOException, WebSocketException, NoSuchAlgorithmException {
WebSocketFactory factory = new WebSocketFactory();
- // Create a custom SSL context.
+ /*// Create a custom SSL context.
SSLContext context = NaiveSSLContext.getInstance("TLS");
// Set the custom SSL context.
@@ -63,6 +63,7 @@ public class WSClient extends WebSocketAdapter {
// verification. You can disable the hostname verification
// by calling WebSocketFactory.setVerifyHostname(false).
factory.setVerifyHostname(false);
+ factory.*/
this.socket = factory.createSocket(uri);
this.socket.addListener(this);
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java b/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java
index 90b8059..96a2729 100644
--- a/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java
+++ b/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java
@@ -24,10 +24,9 @@ public class WSClientWrapper {
public synchronized void start() {
if(!isRunning) {
- String uuid = CoflSky.PlayerUUID;
try {
- socket = new WSClient(new URI(uri + uuid));
+ socket = new WSClient(new URI(uri));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();