mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 06:41:31 +01:00
sockets bye
This commit is contained in:
parent
09081da4fd
commit
e59f74b885
@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -25,8 +25,10 @@ import net.silentclient.client.gui.util.BackgroundPanorama;
|
|||||||
import net.silentclient.client.keybinds.KeyBindManager;
|
import net.silentclient.client.keybinds.KeyBindManager;
|
||||||
import net.silentclient.client.mixin.SilentClientTweaker;
|
import net.silentclient.client.mixin.SilentClientTweaker;
|
||||||
import net.silentclient.client.mixin.accessors.MinecraftAccessor;
|
import net.silentclient.client.mixin.accessors.MinecraftAccessor;
|
||||||
|
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
|
||||||
import net.silentclient.client.mods.ModInstances;
|
import net.silentclient.client.mods.ModInstances;
|
||||||
import net.silentclient.client.mods.SettingsManager;
|
import net.silentclient.client.mods.SettingsManager;
|
||||||
|
import net.silentclient.client.mods.settings.CosmeticsMod;
|
||||||
import net.silentclient.client.mods.settings.FPSBoostMod;
|
import net.silentclient.client.mods.settings.FPSBoostMod;
|
||||||
import net.silentclient.client.mods.settings.GeneralMod;
|
import net.silentclient.client.mods.settings.GeneralMod;
|
||||||
import net.silentclient.client.mods.util.PingSource;
|
import net.silentclient.client.mods.util.PingSource;
|
||||||
@ -49,7 +51,6 @@ import javax.net.ssl.HttpsURLConnection;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.management.GarbageCollectorMXBean;
|
import java.lang.management.GarbageCollectorMXBean;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -87,7 +88,6 @@ public class Client {
|
|||||||
private FriendsResponse friends;
|
private FriendsResponse friends;
|
||||||
public int playersCount = 0;
|
public int playersCount = 0;
|
||||||
private CPSTracker cpsTracker;
|
private CPSTracker cpsTracker;
|
||||||
private SilentSocket silentSocket;
|
|
||||||
public static BackgroundPanorama backgroundPanorama;
|
public static BackgroundPanorama backgroundPanorama;
|
||||||
private KeyBindManager keyBindManager;
|
private KeyBindManager keyBindManager;
|
||||||
private IMetadataSerializer iMetadataSerializer;
|
private IMetadataSerializer iMetadataSerializer;
|
||||||
@ -183,13 +183,6 @@ public class Client {
|
|||||||
EventManager.register(this);
|
EventManager.register(this);
|
||||||
EventManager.register(SneakHandler.getInstance());
|
EventManager.register(SneakHandler.getInstance());
|
||||||
EventManager.register(AnimationHandler.getInstance());
|
EventManager.register(AnimationHandler.getInstance());
|
||||||
logger.info("INITIALISING > silent-socket");
|
|
||||||
try {
|
|
||||||
silentSocket = new SilentSocket("https://socket.silentclient.net");
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
Client.logger.catching(e);
|
|
||||||
}
|
|
||||||
silentSocket.Connect(Client.getInstance().getUserData().getAccessToken());
|
|
||||||
memoryDebug("CLIENT_POST_INIT");
|
memoryDebug("CLIENT_POST_INIT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +190,8 @@ public class Client {
|
|||||||
memoryDebug("CLIENT_PRE_START");
|
memoryDebug("CLIENT_PRE_START");
|
||||||
logger.info("---------[ Silent Client Starting ]--------------");
|
logger.info("---------[ Silent Client Starting ]--------------");
|
||||||
try {
|
try {
|
||||||
|
logger.info("STARTING > registering-player");
|
||||||
|
Players.register();
|
||||||
logger.info("STARTING > sc-account");
|
logger.info("STARTING > sc-account");
|
||||||
PlayerResponse acc = updateAccount();
|
PlayerResponse acc = updateAccount();
|
||||||
|
|
||||||
@ -363,7 +358,7 @@ public class Client {
|
|||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
logger.info("---------[ Silent Client Stopping ]--------------");
|
logger.info("---------[ Silent Client Stopping ]--------------");
|
||||||
logger.info("STOPPING > silent-socket");
|
logger.info("STOPPING > silent-socket");
|
||||||
silentSocket.Disconnect();
|
Players.unregister();
|
||||||
logger.info("-------------------------------------------------");
|
logger.info("-------------------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +369,30 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateUserInformation() {
|
public void updateUserInformation() {
|
||||||
silentSocket.getSocket().emit("refresh", Minecraft.getMinecraft().getSession().getUsername().toLowerCase());
|
if(Client.getInstance().getAccount() != null) {
|
||||||
|
(new Thread("updateUserInformation") {
|
||||||
|
public void run() {
|
||||||
|
PlayerResponse cosmetics = updateAccount();
|
||||||
|
|
||||||
|
if(cosmetics != null) {
|
||||||
|
Client.getInstance().setAccount(cosmetics.getAccount());
|
||||||
|
|
||||||
|
Client.getInstance().getCosmetics().setMyCapes(cosmetics.getAccount().getCosmetics().getCapes());
|
||||||
|
Client.getInstance().getCosmetics().setMyWings(cosmetics.getAccount().getCosmetics().getWings());
|
||||||
|
Client.getInstance().getCosmetics().setMyIcons(cosmetics.getAccount().getCosmetics().getIcons());
|
||||||
|
Client.getInstance().getCosmetics().setMyBandanas(cosmetics.getAccount().getCosmetics().getBandanas());
|
||||||
|
Client.getInstance().getCosmetics().setMyHats(cosmetics.getAccount().getCosmetics().getHats());
|
||||||
|
Client.getInstance().getCosmetics().setMyShields(cosmetics.getAccount().getCosmetics().getShields());
|
||||||
|
Client.getInstance().getSettingsManager().getSettingByClass(CosmeticsMod.class, "Cape Shoulders").setValBoolean(cosmetics.getAccount().getCapeShoulders());
|
||||||
|
Client.getInstance().getSettingsManager().getSettingByClass(CosmeticsMod.class, "Cape Type").setValString(cosmetics.getAccount().getCapeType().equals("dynamic_curved") ? "Dynamic Curved" : cosmetics.getAccount().getCapeType().equals("curved_rectangle") ? "Curved Rectangle" : "Rectangle");
|
||||||
|
if(Minecraft.getMinecraft().thePlayer != null) {
|
||||||
|
((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$setCapeType(cosmetics.getAccount().getCapeType());
|
||||||
|
((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$setShoulders(cosmetics.getAccount().getCapeShoulders());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFriendsList() {
|
public void updateFriendsList() {
|
||||||
@ -421,26 +439,13 @@ public class Client {
|
|||||||
|
|
||||||
public PlayerResponse updateAccount() {
|
public PlayerResponse updateAccount() {
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://api.silentclient.net/account");
|
String content = Requests.post("https://api.silentclient.net/account/update", new JSONObject().append("server", Minecraft.getMinecraft().getCurrentServerData() != null ? Minecraft.getMinecraft().getCurrentServerData().serverIP : null).toString());
|
||||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
|
||||||
con.setRequestMethod("GET");
|
|
||||||
con.setRequestProperty("User-Agent", "SilentClient");
|
|
||||||
con.setRequestProperty("Authorization", "Bearer " + Client.getInstance().getUserData().getAccessToken());
|
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
||||||
String inputLine;
|
|
||||||
StringBuffer content = new StringBuffer();
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
|
||||||
content.append(inputLine);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
con.disconnect();
|
|
||||||
GsonBuilder builder = new GsonBuilder();
|
GsonBuilder builder = new GsonBuilder();
|
||||||
Gson gson = builder.create();
|
Gson gson = builder.create();
|
||||||
|
|
||||||
PlayerResponse response = gson.fromJson(content.toString(), PlayerResponse.class);
|
return gson.fromJson(content, PlayerResponse.class);
|
||||||
return response;
|
} catch (Exception e) {
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -455,7 +460,7 @@ public class Client {
|
|||||||
if(getSettingsManager() != null && getSettingsManager().getSettingByClass(FPSBoostMod.class, "Do memory debug").getValBoolean()) {
|
if(getSettingsManager() != null && getSettingsManager().getSettingByClass(FPSBoostMod.class, "Do memory debug").getValBoolean()) {
|
||||||
memoryDebug("Interval: " + l);
|
memoryDebug("Interval: " + l);
|
||||||
}
|
}
|
||||||
silentSocket.getSocket().emit("update_information", (Minecraft.getMinecraft().getCurrentServerData() != null ? Minecraft.getMinecraft().getCurrentServerData().serverIP : "null"));
|
this.updateUserInformation();
|
||||||
}
|
}
|
||||||
if(Client.getInstance().getAccount() != null) {
|
if(Client.getInstance().getAccount() != null) {
|
||||||
if(Client.getInstance().getAccount().isBanned() && banerror == false) {
|
if(Client.getInstance().getAccount().isBanned() && banerror == false) {
|
||||||
@ -519,7 +524,6 @@ public class Client {
|
|||||||
nextPing = 10;
|
nextPing = 10;
|
||||||
this.updateUserInformation();
|
this.updateUserInformation();
|
||||||
Client.logger.info("Update Connection Server: " + event.getServerData().serverIP);
|
Client.logger.info("Update Connection Server: " + event.getServerData().serverIP);
|
||||||
silentSocket.getSocket().emit("update_information", event.getServerData().serverIP);
|
|
||||||
Server.setHypixel(Server.checkIsHypixel());
|
Server.setHypixel(Server.checkIsHypixel());
|
||||||
Server.setRuHypixel(Server.checkIsRuHypixel());
|
Server.setRuHypixel(Server.checkIsRuHypixel());
|
||||||
}
|
}
|
||||||
@ -531,7 +535,6 @@ public class Client {
|
|||||||
nextPing = 10;
|
nextPing = 10;
|
||||||
this.updateUserInformation();
|
this.updateUserInformation();
|
||||||
Client.logger.info("Update Connection Server: null");
|
Client.logger.info("Update Connection Server: null");
|
||||||
silentSocket.getSocket().emit("update_information", "");
|
|
||||||
Server.setHypixel(Server.checkIsHypixel());
|
Server.setHypixel(Server.checkIsHypixel());
|
||||||
Server.setRuHypixel(Server.checkIsRuHypixel());
|
Server.setRuHypixel(Server.checkIsRuHypixel());
|
||||||
}
|
}
|
||||||
@ -543,7 +546,6 @@ public class Client {
|
|||||||
nextPing = 10;
|
nextPing = 10;
|
||||||
this.updateUserInformation();
|
this.updateUserInformation();
|
||||||
Client.logger.info("Update Connection Server: null");
|
Client.logger.info("Update Connection Server: null");
|
||||||
silentSocket.getSocket().emit("update_information", "");
|
|
||||||
Server.setHypixel(Server.checkIsHypixel());
|
Server.setHypixel(Server.checkIsHypixel());
|
||||||
Server.setRuHypixel(Server.checkIsRuHypixel());
|
Server.setRuHypixel(Server.checkIsRuHypixel());
|
||||||
}
|
}
|
||||||
@ -581,10 +583,6 @@ public class Client {
|
|||||||
return "v" + version + "-" + getBuildData().getCommit() + "-" + getBuildData().getBranch();
|
return "v" + version + "-" + getBuildData().getCommit() + "-" + getBuildData().getBranch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SilentSocket getSilentSocket() {
|
|
||||||
return silentSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cosmetics getCosmetics() {
|
public Cosmetics getCosmetics() {
|
||||||
return cosmetics;
|
return cosmetics;
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,8 @@ public class AccountManager {
|
|||||||
Session session = new Session(account.username, nameToUuid(account.username), account.mc_access_token != null ? account.mc_access_token : "0", account.mc_access_token != null ? "msa" : "legacy");
|
Session session = new Session(account.username, nameToUuid(account.username), account.mc_access_token != null ? account.mc_access_token : "0", account.mc_access_token != null ? "msa" : "legacy");
|
||||||
((MinecraftExt) Minecraft.getMinecraft()).setSession(session);
|
((MinecraftExt) Minecraft.getMinecraft()).setSession(session);
|
||||||
Client.getInstance().getUserData().setAccessToken(selected.access_token);
|
Client.getInstance().getUserData().setAccessToken(selected.access_token);
|
||||||
Client.getInstance().getSilentSocket().Disconnect();
|
Players.unregister();
|
||||||
Client.getInstance().getSilentSocket().Connect(selected.access_token);
|
Players.register();
|
||||||
}
|
}
|
||||||
PlayerResponse acc = Client.getInstance().updateAccount();
|
PlayerResponse acc = Client.getInstance().updateAccount();
|
||||||
if(acc != null) {
|
if(acc != null) {
|
||||||
|
@ -2,14 +2,12 @@ package net.silentclient.client.utils;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.silentclient.client.Client;
|
import net.silentclient.client.Client;
|
||||||
import net.silentclient.client.cosmetics.HatData;
|
import net.silentclient.client.cosmetics.HatData;
|
||||||
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
|
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
|
||||||
import net.silentclient.client.mods.settings.CosmeticsMod;
|
|
||||||
import net.silentclient.client.utils.types.PlayerResponse;
|
import net.silentclient.client.utils.types.PlayerResponse;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -17,6 +15,7 @@ import java.util.WeakHashMap;
|
|||||||
|
|
||||||
public class Players {
|
public class Players {
|
||||||
public static final Map<String, PlayerResponse.Account> playersCache = new WeakHashMap<>();
|
public static final Map<String, PlayerResponse.Account> playersCache = new WeakHashMap<>();
|
||||||
|
public static boolean isLoading = false;
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
playersCache.clear();
|
playersCache.clear();
|
||||||
@ -92,53 +91,29 @@ public class Players {
|
|||||||
|
|
||||||
return result.isOnline() ? "true" : "false";
|
return result.isOnline() ? "true" : "false";
|
||||||
} else {
|
} else {
|
||||||
|
Players.isLoading = true;
|
||||||
Client.logger.info("Loading Account of " + name.toLowerCase());
|
Client.logger.info("Loading Account of " + name.toLowerCase());
|
||||||
playersCache.put(name.toLowerCase(), null);
|
playersCache.put(name.toLowerCase(), null);
|
||||||
Client.getInstance().getSilentSocket().getSocket().emit("account", name.toLowerCase());
|
(new Thread("loadingAccountOf"+name) {
|
||||||
|
public void run() {
|
||||||
|
PlayerResponse response = getAccount(name.toLowerCase());
|
||||||
|
if(response != null && response.getAccount() != null) {
|
||||||
|
playersCache.put(response.getAccount().getUsername(), response.getAccount());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Client.logger.catching(e);
|
||||||
|
}
|
||||||
|
Players.isLoading = false;
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleAccount(PlayerResponse.Account account) {
|
public static void handleAccount(PlayerResponse.Account account) {
|
||||||
if(account.getUsername().toLowerCase().equals(Minecraft.getMinecraft().getSession().getUsername().toLowerCase().toString())) {
|
|
||||||
Client.getInstance().setAccount(account);
|
|
||||||
|
|
||||||
Client.getInstance().getCosmetics().setMyCapes(account.getCosmetics().getCapes());
|
|
||||||
Client.getInstance().getCosmetics().setMyWings(account.getCosmetics().getWings());
|
|
||||||
Client.getInstance().getCosmetics().setMyIcons(account.getCosmetics().getIcons());
|
|
||||||
Client.getInstance().getCosmetics().setMyBandanas(account.getCosmetics().getBandanas());
|
|
||||||
Client.getInstance().getCosmetics().setMyHats(account.getCosmetics().getHats());
|
|
||||||
Client.getInstance().getCosmetics().setMyShields(account.getCosmetics().getShields());
|
|
||||||
Client.getInstance().getSettingsManager().getSettingByClass(CosmeticsMod.class, "Cape Shoulders").setValBoolean(account.getCapeShoulders());
|
|
||||||
Client.getInstance().getSettingsManager().getSettingByClass(CosmeticsMod.class, "Cape Type").setValString(account.getCapeType().equals("dynamic_curved") ? "Dynamic Curved" : account.getCapeType().equals("curved_rectangle") ? "Curved Rectangle" : "Rectangle");
|
|
||||||
if(Minecraft.getMinecraft().thePlayer != null) {
|
|
||||||
((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$setCapeType(account.getCapeType());
|
|
||||||
((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$setShoulders(account.getCapeShoulders());
|
|
||||||
Players.getPlayerStatus(false, ((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getNameClear(), EntityPlayer.getUUID(Minecraft.getMinecraft().thePlayer.getGameProfile()), Minecraft.getMinecraft().thePlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(Minecraft.getMinecraft().theWorld != null && getPlayerEntityByName(account.original_username) != null) {
|
|
||||||
Client.logger.info("Account processing: " + account.getUsername());
|
|
||||||
if(playersCache.containsKey(account.getUsername())) {
|
|
||||||
playersCache.remove(account.getUsername());
|
|
||||||
}
|
|
||||||
playersCache.put(account.getUsername(), account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityPlayer getPlayerEntityByName(String name)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < Minecraft.getMinecraft().theWorld.playerEntities.size(); ++i)
|
|
||||||
{
|
|
||||||
EntityPlayer entityplayer = (EntityPlayer)Minecraft.getMinecraft().theWorld.playerEntities.get(i);
|
|
||||||
|
|
||||||
if (name.equalsIgnoreCase(entityplayer.getName()))
|
|
||||||
{
|
|
||||||
return entityplayer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerResponse getAccount(String name) {
|
public static PlayerResponse getAccount(String name) {
|
||||||
@ -154,4 +129,26 @@ public class Players {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
try {
|
||||||
|
String content = Requests.post("https://api.silentclient.net/account/set_online", new JSONObject().append("online", true).toString());
|
||||||
|
|
||||||
|
Client.logger.info("STARTING > registering-player > response: " + content);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Client.logger.catching(e);
|
||||||
|
Client.logger.info("STARTING > registering-player > ERROR: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unregister() {
|
||||||
|
try {
|
||||||
|
String content = Requests.post("https://api.silentclient.net/account/set_online", new JSONObject().append("online", true).toString());
|
||||||
|
|
||||||
|
Client.logger.info("STOPPING > unregistering-player > response: " + content.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Client.logger.catching(e);
|
||||||
|
Client.logger.error("STOPPING > unregistering-player > ERROR: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,92 +0,0 @@
|
|||||||
package net.silentclient.client.utils;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import io.socket.client.IO;
|
|
||||||
import io.socket.client.Socket;
|
|
||||||
import io.socket.emitter.Emitter.Listener;
|
|
||||||
import net.silentclient.client.Client;
|
|
||||||
import net.silentclient.client.utils.types.NotificationResponse;
|
|
||||||
import net.silentclient.client.utils.types.PlayerResponse;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
public class SilentSocket {
|
|
||||||
private Socket sock;
|
|
||||||
private URI _url;
|
|
||||||
private String _token;
|
|
||||||
|
|
||||||
private Listener connectListener;
|
|
||||||
private Listener disconectListener;
|
|
||||||
private Listener accountListener;
|
|
||||||
private Listener notificationListener;
|
|
||||||
private Listener errorListener;
|
|
||||||
|
|
||||||
public SilentSocket(String server) throws URISyntaxException {
|
|
||||||
_url = new URI(server);
|
|
||||||
sock = IO.socket(_url);
|
|
||||||
connectListener = arg0 -> {
|
|
||||||
Client.logger.info("Connected to Silent Socket!");
|
|
||||||
sock.emit("set_token", _token);
|
|
||||||
};
|
|
||||||
|
|
||||||
disconectListener = arg0 -> Client.logger.info("Disconnected from Silent Socket!");
|
|
||||||
|
|
||||||
notificationListener = arg0 -> {
|
|
||||||
try {
|
|
||||||
GsonBuilder builder = new GsonBuilder();
|
|
||||||
Gson gson = builder.create();
|
|
||||||
NotificationResponse response = gson.fromJson(arg0[0].toString(), NotificationResponse.class);
|
|
||||||
Client.logger.info("Received notification via API: " + arg0[0].toString());
|
|
||||||
NotificationUtils.showNotification(response.getStatus(), response.getMessage());
|
|
||||||
} catch (Exception err) {
|
|
||||||
Client.logger.catching(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
accountListener = arg0 -> {
|
|
||||||
try {
|
|
||||||
GsonBuilder builder = new GsonBuilder();
|
|
||||||
Gson gson = builder.create();
|
|
||||||
PlayerResponse response = gson.fromJson(arg0[0].toString(), PlayerResponse.class);
|
|
||||||
if(response.getAccount() != null) {
|
|
||||||
Client.logger.info("Received account via Websocket: " + response.getAccount().getUsername());
|
|
||||||
Players.handleAccount(response.getAccount());
|
|
||||||
}
|
|
||||||
} catch (Exception err) {
|
|
||||||
Client.logger.catching(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
errorListener = arg0 -> Client.logger.error("Silent Socket Error!");
|
|
||||||
|
|
||||||
sock.on(Socket.EVENT_CONNECT, connectListener)
|
|
||||||
.on(Socket.EVENT_RECONNECT, connectListener)
|
|
||||||
.on(Socket.EVENT_DISCONNECT, disconectListener)
|
|
||||||
.on(Socket.EVENT_ERROR, errorListener)
|
|
||||||
.on("account", accountListener)
|
|
||||||
.on("notification", notificationListener)
|
|
||||||
.on("update_information", arg0 -> Client.logger.info("User information updated: " + arg0[0].toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket getSocket() {
|
|
||||||
return sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Connect(String token) throws JSONException {
|
|
||||||
_token = token;
|
|
||||||
|
|
||||||
sock.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Disconnect() {
|
|
||||||
sock.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getConnected() {
|
|
||||||
return sock.connected();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user