aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.gradle18
-rwxr-xr-xoptions.txt6
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java118
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java13
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java6
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/e.java23
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureAutoAcceptReparty.java3
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java219
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java58
9 files changed, 386 insertions, 78 deletions
diff --git a/build.gradle b/build.gradle
index d4aeae83..e3dbaebb 100755
--- a/build.gradle
+++ b/build.gradle
@@ -17,11 +17,6 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.github.johnrengelman.shadow'
-java {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
-}
-
/*
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
plugins {
@@ -32,6 +27,10 @@ version = "2.0"
group= "kr.syeyoung.dungeonsguide" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "dungeonsguide"
+sourceCompatibility=1.8
+targetCompatibility=1.8
+
+
minecraft {
version = "1.8.9-11.15.1.1722"
runDir = "run"
@@ -48,11 +47,13 @@ minecraft {
repositories {
jcenter()
mavenCentral()
+ maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'org.jetbrains:annotations-java5:19.0.0'
compile "org.java-websocket:Java-WebSocket:1.5.1"
- compile 'com.jagrosh:DiscordIPC:0.4'
+ compile 'com.github.Vatuu:discord-rpc:1.6.2'
+ compile "org.json:json:20171018"
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
@@ -104,11 +105,8 @@ processResources
shadowJar {
dependencies {
include(dependency("org.java-websocket:Java-WebSocket:1.5.1"))
- include(dependency("org.slf4j:slf4j-api:1.7.25"))
- include(dependency("com.jagrosh:DiscordIPC:0.4"))
include(dependency("org.json:json:20171018"))
- include(dependency("com.kohlschutter.junixsocket:junixsocket-common:2.0.4"))
- include(dependency("com.kohlschutter.junixsocket:junixsocket-native-common:2.0.4"))
+ include(dependency("com.github.Vatuu:discord-rpc:1.6.2"))
}
}
diff --git a/options.txt b/options.txt
index 046d6bf2..785c59d1 100755
--- a/options.txt
+++ b/options.txt
@@ -10,7 +10,7 @@ bobView:true
anaglyph3d:false
maxFps:120
fboEnable:true
-difficulty:1
+difficulty:3
fancyGraphics:true
ao:2
renderClouds:fast
@@ -24,7 +24,7 @@ chatLinks:true
chatLinksPrompt:true
chatOpacity:1.0
snooperEnabled:true
-fullscreen:true
+fullscreen:false
enableVsync:true
useVbo:true
hideServerAddress:false
@@ -94,7 +94,7 @@ key_start editing session:19
key_send and save bombdefuse solution:33
key_navigate to next secret. (Req option enabled at /dg):34
key_toggle Pathfind. (Req option enabled at /dg):47
-soundCategory_master:0.07284768
+soundCategory_master:1.0
soundCategory_music:0.0
soundCategory_record:1.0
soundCategory_weather:1.0
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java
index f3b75d41..422d15e1 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java
@@ -1,67 +1,61 @@
package kr.syeyoung.dungeonsguide;
-import com.jagrosh.discordipc.IPCClient;
-import com.jagrosh.discordipc.IPCListener;
-import com.jagrosh.discordipc.entities.Packet;
-import com.jagrosh.discordipc.entities.RichPresence;
-import com.jagrosh.discordipc.entities.User;
-import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
import kr.syeyoung.dungeonsguide.events.SkyblockJoinedEvent;
import kr.syeyoung.dungeonsguide.events.SkyblockLeftEvent;
+import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
+import kr.syeyoung.dungeonsguide.party.PartyManager;
+import kr.syeyoung.dungeonsguide.stomp.StompHeader;
+import kr.syeyoung.dungeonsguide.stomp.StompPayload;
+import net.arikia.dev.drpc.DiscordEventHandlers;
+import net.arikia.dev.drpc.DiscordRPC;
+import net.arikia.dev.drpc.DiscordRichPresence;
+import net.arikia.dev.drpc.DiscordUser;
+import net.arikia.dev.drpc.callbacks.*;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.json.JSONObject;
-import java.time.OffsetDateTime;
-
-public class RichPresenceManager implements IPCListener {
+public class RichPresenceManager implements JoinRequestCallback, JoinGameCallback, ErroredCallback, DisconnectedCallback {
public static RichPresenceManager INSTANCE = new RichPresenceManager();
- private IPCClient ipcClient;
- public void setup() throws NoDiscordClientException {
- ipcClient = new IPCClient(816298079732498473L);
- ipcClient.setListener(this);
- ipcClient.connect();
- }
-
- @Override
- public void onReady(IPCClient client) {
- updatePresence();
- }
-
- @Override
- public void onActivityJoinRequest(IPCClient client, String secret, User user) {
- System.out.println(user.getAsMention()+" wanna join");
- }
-
- @Override
- public void onPacketReceived(IPCClient client, Packet packet) {
- System.out.println("Packet recv from rpc "+packet);
- }
-
- @Override
- public void onDisconnect(IPCClient client, Throwable t) {
- t.printStackTrace();
- try {
- setup();
- } catch (NoDiscordClientException e) {
- e.printStackTrace();
- }
+ public void setup() {
+ DiscordRPC.discordInitialize("816298079732498473", new DiscordEventHandlers.Builder()
+ .setReadyEventHandler(new ReadyCallback() {
+ @Override
+ public void apply(DiscordUser user) {
+ updatePresence();
+ }
+ })
+ .setJoinRequestEventHandler(this)
+ .setJoinGameEventHandler(this)
+ .setErroredEventHandler(this)
+ .setDisconnectedEventHandler(this).build(), true);
}
private SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus();
public void updatePresence() {
- if (!skyblockStatus.isOnHypixel()) {
- ipcClient.sendRichPresence(null);
+ nextUpdate= System.currentTimeMillis() + 10000L;
+ if (!skyblockStatus.isOnHypixel() || !FeatureRegistry.ADVANCED_RICHPRESENCE.isEnabled()) {
+ DiscordRPC.discordClearPresence();
} else {
- ipcClient.sendRichPresence(new RichPresence.Builder()
- .setJoinSecret(""));
+ DiscordRichPresence.Builder richPresenceBuilder = new DiscordRichPresence.Builder(skyblockStatus.getDungeonName());
+ richPresenceBuilder.setBigImage("mort", "mort")
+ .setParty(PartyManager.INSTANCE.getPartyID(), 1, 5);
+
+ if (skyblockStatus.getContext() != null) {
+ long init = skyblockStatus.getContext().getInit();
+ richPresenceBuilder.setStartTimestamps(init);
+ } else {
+ if (PartyManager.INSTANCE.isAllowAskToJoin())
+ richPresenceBuilder.setSecrets(PartyManager.INSTANCE.getAskToJoinSecret(), null);
+ }
+ richPresenceBuilder.setDetails("Dungeons Guide RichPresence Test");
+ DiscordRPC.discordUpdatePresence(richPresenceBuilder.build());
}
}
- private String JOIN_SECRET;
-
@SubscribeEvent
public void joinSkyblock(SkyblockJoinedEvent skyblockJoinedEvent) {
@@ -71,4 +65,38 @@ public class RichPresenceManager implements IPCListener {
public void leaveSkyblock(SkyblockLeftEvent skyblockLeftEvent) {
updatePresence();
}
+
+ private String lastLoc = "";
+ private long nextUpdate = System.currentTimeMillis() + 10000L;
+ @SubscribeEvent
+ public void tick(TickEvent.ClientTickEvent clientTickEvent) {
+ try {
+ if (skyblockStatus.isOnSkyblock() && !lastLoc.equalsIgnoreCase(skyblockStatus.getDungeonName())) {
+ lastLoc = skyblockStatus.getDungeonName()+"";
+ updatePresence();
+ } else if (nextUpdate < System.currentTimeMillis()) {
+ updatePresence();
+ }
+ } catch (Exception e) {e.printStackTrace();}
+ }
+
+ @Override
+ public void apply(int errorCode, String message) {
+ System.out.println("ERROR! "+errorCode+ " - "+message);
+ setup();
+ }
+
+ @Override
+ public void apply(String joinSecret) {
+ System.out.println("OK JOINNNNNNNNNNNNNNNNNN "+joinSecret);
+ e.getDungeonsGuide().getStompConnection().send(new StompPayload().method(StompHeader.SEND)
+ .header("destination", "/app/party.askedtojoin")
+ .payload(new JSONObject().put("token", joinSecret).toString()));
+ }
+
+ @Override
+ public void apply(DiscordUser user) {
+ System.out.println(user.username+" wants to join");
+ DiscordRPC.discordRespond(user.userId, DiscordRPC.DiscordReply.YES);
+ }
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java
index b8b15fa3..455b8930 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java
@@ -10,6 +10,7 @@ import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry;
import kr.syeyoung.dungeonsguide.e;
import kr.syeyoung.dungeonsguide.events.DungeonLeftEvent;
+import kr.syeyoung.dungeonsguide.party.PartyManager;
import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor;
import kr.syeyoung.dungeonsguide.utils.AhUtils;
import kr.syeyoung.dungeonsguide.utils.MapUtils;
@@ -233,6 +234,17 @@ public class CommandDungeonsGuide extends CommandBase {
// e.printStackTrace();
// }
// }
+ } else if (args[0].equalsIgnoreCase("asktojoin") || args[0].equalsIgnoreCase("atj")) {
+ if (!PartyManager.INSTANCE.isCanInvite()) {
+ sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cYou don't have perms in the party to invite people!"));
+ } else {
+ PartyManager.INSTANCE.toggleAllowAskToJoin();
+ sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fToggled Ask to join to "+(PartyManager.INSTANCE.isAllowAskToJoin() ? "§eon" : "§coff")));
+ }
+ } else if (args[0].equals("partyid")) {
+ sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fInternal Party id: "+PartyManager.INSTANCE.getPartyID()));
+ } else if (args[0].equalsIgnoreCase("loc")) {
+ sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fYou're in "+e.getDungeonsGuide().getSkyblockStatus().getDungeonName()));
} else {
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg §7-§fOpens configuration gui"));
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg gui §7-§fOpens configuration gui"));
@@ -243,6 +255,7 @@ public class CommandDungeonsGuide extends CommandBase {
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg brand §7-§f View server brand."));
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg reparty §7-§f Reparty."));
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg info §7-§f View Current DG User info."));
+ sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg asktojoin or /dg atj §7-§f Toggle ask to join"));
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java
index 49d3da4e..2966f67b 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java
@@ -52,7 +52,10 @@ public class DungeonContext {
private List<String[]> milestoneReached = new ArrayList<String[]>();
@Getter
@Setter
- private int BossRoomEnterSeconds = -1;
+ private long BossRoomEnterSeconds = -1;
+ @Getter
+ @Setter
+ private long init = -1;
@Getter
@Setter
private BlockPos bossroomSpawnPos = null;
@@ -88,6 +91,7 @@ public class DungeonContext {
mapProcessor = new MapProcessor(this);
DungeonSpecificDataProvider doorFinder = DungeonSpecificDataProviderRegistry.getDoorFinder(((SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus()).getDungeonName());
trapRoomGen = doorFinder.isTrapSpawn(e.getDungeonsGuide().getSkyblockStatus().getDungeonName());
+ init = System.currentTimeMillis();
}
public void createEvent(DungeonEventData eventData) {
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java
index 5bc3f0d7..478ea8b5 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/e.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java
@@ -1,7 +1,5 @@
package kr.syeyoung.dungeonsguide;
-import com.jagrosh.discordipc.entities.RichPresence;
-import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
import kr.syeyoung.dungeonsguide.commands.*;
import kr.syeyoung.dungeonsguide.config.Config;
import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry;
@@ -10,6 +8,7 @@ import kr.syeyoung.dungeonsguide.eventlistener.FeatureListener;
import kr.syeyoung.dungeonsguide.eventlistener.PacketListener;
import kr.syeyoung.dungeonsguide.events.StompConnectedEvent;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
+import kr.syeyoung.dungeonsguide.party.PartyManager;
import kr.syeyoung.dungeonsguide.stomp.CloseListener;
import kr.syeyoung.dungeonsguide.stomp.StompClient;
import kr.syeyoung.dungeonsguide.stomp.StompInterface;
@@ -69,6 +68,9 @@ public class e implements c, CloseListener {
@Getter
CommandReparty commandReparty;
+
+ private String stompURL = "wss://dungeonsguide.kro.kr/ws";
+// private String stompURL = "ws://localhost/ws";
public void init(FMLInitializationEvent event) {
ProgressManager.ProgressBar progressbar = ProgressManager.push("DungeonsGuide", 4);
@@ -92,6 +94,10 @@ public class e implements c, CloseListener {
MinecraftForge.EVENT_BUS.register(new PacketListener());
MinecraftForge.EVENT_BUS.register(new Keybinds());
+ RichPresenceManager.INSTANCE.setup();
+ MinecraftForge.EVENT_BUS.register(RichPresenceManager.INSTANCE);
+ MinecraftForge.EVENT_BUS.register(PartyManager.INSTANCE);
+
AhUtils.registerTimer();
progressbar.step("Downloading Roomdatas");
@@ -103,18 +109,14 @@ public class e implements c, CloseListener {
Keybinds.register();
+
progressbar.step("Opening connection");
try {
- stompConnection = new StompClient(new URI("wss://dungeonsguide.kro.kr/ws"), authenticator.c(), this);
+ stompConnection = new StompClient(new URI(stompURL), authenticator.c(), this);
+ MinecraftForge.EVENT_BUS.post(new StompConnectedEvent(stompConnection));
} catch (Exception e) {
throw new RuntimeException(e);
}
- try {
- RichPresenceManager.INSTANCE.setup();
- } catch (NoDiscordClientException e) {
- e.printStackTrace();
- }
- MinecraftForge.EVENT_BUS.register(RichPresenceManager.INSTANCE);
progressbar.step("Loading Config");
@@ -169,11 +171,10 @@ public class e implements c, CloseListener {
@Override
public void run() {
try {
- stompConnection = new StompClient(new URI("wss://dungeonsguide.kro.kr/ws"), authenticator.c(), e.this);
+ stompConnection = new StompClient(new URI(stompURL), authenticator.c(), e.this);
MinecraftForge.EVENT_BUS.post(new StompConnectedEvent(stompConnection));
} catch (Exception e) {
e.printStackTrace();
- connectStomp();
}
}
}, 5L, TimeUnit.SECONDS);
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureAutoAcceptReparty.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureAutoAcceptReparty.java
index 081beb19..fdbf5e5f 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureAutoAcceptReparty.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureAutoAcceptReparty.java
@@ -53,9 +53,8 @@ public class FeatureAutoAcceptReparty extends SimpleFeature implements ChatListe
break;
}
}
- System.out.println(lastDisband + " - "+equals);
- if (equals) {
+ if (equals && isEnabled()) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/p join "+lastDisband);
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java
new file mode 100644
index 00000000..08492ae8
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java
@@ -0,0 +1,219 @@
+package kr.syeyoung.dungeonsguide.party;
+
+import kr.syeyoung.dungeonsguide.RichPresenceManager;
+import kr.syeyoung.dungeonsguide.commands.CommandReparty;
+import kr.syeyoung.dungeonsguide.e;
+import kr.syeyoung.dungeonsguide.events.SkyblockJoinedEvent;
+import kr.syeyoung.dungeonsguide.events.StompConnectedEvent;
+import kr.syeyoung.dungeonsguide.stomp.StompInterface;
+import kr.syeyoung.dungeonsguide.stomp.StompMessageHandler;
+import kr.syeyoung.dungeonsguide.stomp.StompPayload;
+import kr.syeyoung.dungeonsguide.stomp.StompSubscription;
+import kr.syeyoung.dungeonsguide.utils.TextUtils;
+import lombok.Getter;
+import net.minecraft.client.Minecraft;
+import net.minecraftforge.client.event.ClientChatReceivedEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import scala.util.parsing.json.JSON;
+
+import java.security.SecureRandom;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class PartyManager implements StompMessageHandler {
+ public static final PartyManager INSTANCE = new PartyManager();
+
+ @Getter
+ private String partyID = null;
+ @Getter
+ private String askToJoinSecret = null;
+
+ private SecureRandom random = new SecureRandom();
+ private static final String validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
+
+ @Getter
+ private boolean allowAskToJoin = false;
+ @Getter
+ private boolean canInvite = false;
+
+ public void toggleAllowAskToJoin() {
+ if (canInvite) allowAskToJoin = !allowAskToJoin;
+ if (allowAskToJoin) {
+ generateNewAskToJoinSecret();
+ }
+ }
+
+ public void setPartyID(String partyID) {
+ if (this.partyID != null && partyID == null) {
+ JSONObject object = new JSONObject();
+ object.put("members", new JSONArray());
+ StompInterface stompInterface = e.getDungeonsGuide().getStompConnection();
+ stompInterface.send(new StompPayload().payload(object.toString()).header("destination", "/app/party.join"));
+ }
+ this.partyID = partyID;
+ this.askToJoinSecret = null;
+
+ if (partyID != null && !partyID.equals(this.partyID)) {
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -");
+ } else {
+ canInvite = true;
+ allowAskToJoin = false;
+ }
+
+ if (allowAskToJoin) {
+ generateNewAskToJoinSecret();
+ } else {
+ RichPresenceManager.INSTANCE.updatePresence();
+ }
+ }
+
+ public void generateNewAskToJoinSecret() {
+ if (partyID == null) {
+ JSONObject object = new JSONObject();
+ object.put("members", new JSONArray());
+ StompInterface stompInterface = e.getDungeonsGuide().getStompConnection();
+ stompInterface.send(new StompPayload().payload(object.toString()).header("destination", "/app/party.join"));
+ }
+
+ StringBuilder secretBuilder = new StringBuilder();
+ for (int i = 0; i < 20; i++) {
+ secretBuilder.append(validChars.charAt(random.nextInt(validChars.length())));
+ }
+ this.askToJoinSecret = secretBuilder.toString();
+
+ StompInterface stompInterface = e.getDungeonsGuide().getStompConnection();
+ stompInterface.send(new StompPayload().payload(new JSONObject().put("secret", askToJoinSecret).toString()).header("destination", "/app/party.setjoinsecret"));
+ RichPresenceManager.INSTANCE.updatePresence();
+ }
+
+ private boolean partyJoin = false;
+ private Set<String> members = new HashSet<>();
+ private Map<String, Long> recentlyJoined = new HashMap<>();
+ @SubscribeEvent
+ public void onMessage(ClientChatReceivedEvent chatReceivedEvent) {
+ if (chatReceivedEvent.type == 2) return;
+
+ String str = chatReceivedEvent.message.getFormattedText();
+
+ if (str.startsWith("§eYou have joined ")) {
+ setPartyID(null);
+ members.clear();
+ String strs[] = TextUtils.stripColor(str).split(" ");
+ for (String s : strs) {
+ if (s.endsWith("'s")) {
+ members.add(s.substring(0, s.indexOf("'s")));
+ partyJoin = true;
+ break;
+ }
+ }
+ } else if (str.startsWith("§eYou'll be partying with: ")) {
+ String[] players = TextUtils.stripColor(str.substring(27)).split(" ");
+ for (String player : players) {
+ if (player.startsWith("[")) continue;
+ members.add(player);
+ }
+ } else if (str.equals("§9§m-----------------------------§r")) {
+ if (partyJoin) {
+ partyJoin = false;
+ // REQ PARTY JOIN
+
+ JSONArray jsonArray = new JSONArray();
+ for (String member : members) {
+ jsonArray.put(member);
+ }
+ JSONObject object = new JSONObject();
+ object.put("members", jsonArray);
+ StompInterface stompInterface = e.getDungeonsGuide().getStompConnection();
+ stompInterface.send(new StompPayload().payload(object.toString()).header("destination", "/app/party.join"));
+ }
+ } else if (str.endsWith("§ejoined the party.§r")) {
+ String asd = null;
+ for (String s : TextUtils.stripColor(str).split(" ")) {
+ if (s.startsWith("[")) continue;
+ asd = s;
+ }
+ if (asd != null)
+ recentlyJoined.put(asd, System.currentTimeMillis());
+ } else if ((str.equals("§eYou left the party.§r")
+ || str.equals("§cThe party was disbanded because all invites expired and the party was empty§r"))
+ ){
+ setPartyID(null);
+ } else if (str.startsWith("§6Party Members ")) {
+ partyJoin = true;
+ members.clear();
+ } else if (str.startsWith("§cYou are not currently in a party.§r")) {
+ members.clear();
+ setPartyID(null);
+ } else if (str.startsWith("§eParty ") && str.contains(":")) {
+ String playerNames = TextUtils.stripColor(str.split(":")[1]);
+ for (String s : playerNames.split(" ")) {
+ if (s.isEmpty()) continue;
+ if (s.equals("●")) continue;
+ if (s.startsWith("[")) continue;
+ members.add(s);
+ }
+ } else if (str.equals("§cYou are not allowed to invite players.§r")) {
+ canInvite = false;
+ allowAskToJoin = false;
+ askToJoinSecret = "";
+ RichPresenceManager.INSTANCE.updatePresence();
+ } else if (str.equals("§cCouldn't find a player with that name!§r")) {
+ canInvite = true;
+ } else if (str.endsWith("§aenabled All Invite§r")) {
+ canInvite = true;
+ } else if (str.endsWith("§cdisabled All Invite§r")) {
+ canInvite = false;
+ allowAskToJoin = false;
+ askToJoinSecret = "";
+ RichPresenceManager.INSTANCE.updatePresence();
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -");
+ }
+ }
+
+ @SubscribeEvent
+ public void onSBJoin(SkyblockJoinedEvent skyblockJoinedEvent) {
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl");
+ }
+
+ @Override
+ public void handle(StompInterface stompInterface, StompPayload stompPayload) {
+ JSONObject object = new JSONObject(stompPayload.payload());
+ if ("/queue/party.check".equals(stompPayload.headers().get("destination"))) {
+ String playerName = object.getString("player");
+ String token = object.getString("token");
+ Long loong = recentlyJoined.get(playerName);
+ if (loong == null) {
+ stompInterface.send(new StompPayload().payload(new JSONObject().put("status", "failure").put("token", token).toString()).header("destination", "/app/party.check.resp"));
+ } else if (loong > System.currentTimeMillis() - 2000){
+ stompInterface.send(new StompPayload().payload(new JSONObject().put("status", "success").put("token", token).toString()).header("destination", "/app/party.check.resp"));
+ }
+ } else if ("/queue/party.join".equals(stompPayload.headers().get("destination"))) {
+ String playerName = object.getString("player");
+ String secret = object.getString("secret");
+ if (secret.equals(askToJoinSecret) && partyID != null) {
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite "+playerName);
+ }
+ } else {
+ String str = object.getString("status");
+ if ("success".equals(str)) {
+ setPartyID(object.getString("partyId"));
+ } else {
+ setPartyID(null);
+ }
+ }
+ }
+
+ @SubscribeEvent
+ public void stompConnect(StompConnectedEvent stompConnectedEvent) {
+ stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder()
+ .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/user/queue/party.resp").build());
+ stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder()
+ .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/user/queue/party.check").build());
+ stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder()
+ .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/user/queue/party.join").build());
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java
index e61892fc..e6626370 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java
@@ -9,6 +9,7 @@ import sun.security.ssl.SSLSocketFactoryImpl;
import javax.net.ssl.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.net.Socket;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStore;
@@ -54,7 +55,50 @@ public class StompClient extends WebSocketClient implements StompInterface {
b.load(null, null);
b.setCertificateEntry(Integer.toString(1), a);
- X509TrustManager trustManager = new X509TrustManager() {
+ X509TrustManager trustManager = new X509ExtendedTrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
+ for (X509Certificate x509Certificate : x509Certificates) {
+ if (x509Certificate.equals(a)) {
+ return;
+ }
+ }
+ throw new CertificateException("invalid");
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
+
+ for (X509Certificate x509Certificate : x509Certificates) {
+ if (x509Certificate.equals(a)) {
+ return;
+ }
+ }
+ throw new CertificateException("invalid");
+ }
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
+
+ for (X509Certificate x509Certificate : x509Certificates) {
+ if (x509Certificate.equals(a)) {
+ return;
+ }
+ }
+ throw new CertificateException("invalid");
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
+
+ for (X509Certificate x509Certificate : x509Certificates) {
+ if (x509Certificate.equals(a)) {
+ return;
+ }
+ }
+ throw new CertificateException("invalid");
+ }
+
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
for (X509Certificate x509Certificate : x509Certificates) {
@@ -83,7 +127,6 @@ public class StompClient extends WebSocketClient implements StompInterface {
SSLContext d = SSLContext.getInstance("TLSv1.2");
d.init(null, new TrustManager[]{ trustManager}, null);
-
return d.getSocketFactory();
}
public StompClient(URI serverUri, final String token, CloseListener closeListener) throws Exception {
@@ -108,6 +151,7 @@ public class StompClient extends WebSocketClient implements StompInterface {
@Getter
private StompPayload errorPayload;
+
@Override
public void onOpen(ServerHandshake handshakedata) {
send(new StompPayload().method(StompHeader.CONNECT)
@@ -137,10 +181,12 @@ public class StompClient extends WebSocketClient implements StompInterface {
);
}
} catch (Exception e) {
- send(new StompPayload().method(StompHeader.NACK)
- .header("id",payload.headers().get("ack")).getBuilt()
- );
e.printStackTrace();
+ if (stompSubscription.getAckMode() != StompSubscription.AckMode.AUTO) {
+ send(new StompPayload().method(StompHeader.NACK)
+ .header("id",payload.headers().get("ack")).getBuilt()
+ );
+ }
}
} else if (payload.method() == StompHeader.RECEIPT) {
String receipt_id = payload.headers().get("receipt-id");
@@ -176,7 +222,7 @@ public class StompClient extends WebSocketClient implements StompInterface {
payload.method(StompHeader.SEND);
if (payload.headers().get("receipt") != null)
receiptMap.put(Integer.parseInt(payload.headers().get("receipt")), payload);
- send(payload);
+ send(payload.getBuilt());
}
@Override