diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide')
4 files changed, 31 insertions, 94 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java index 08d5a898..969da396 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java @@ -28,15 +28,13 @@ import kr.syeyoung.dungeonsguide.gamesdk.GameSDK; import kr.syeyoung.dungeonsguide.gamesdk.jna.NativeGameSDK; import kr.syeyoung.dungeonsguide.gamesdk.jna.datastruct.*; import kr.syeyoung.dungeonsguide.gamesdk.jna.enumuration.EDiscordActivityActionType; +import kr.syeyoung.dungeonsguide.gamesdk.jna.enumuration.EDiscordActivityJoinRequestReply; import kr.syeyoung.dungeonsguide.gamesdk.jna.enumuration.EDiscordLogLevel; import kr.syeyoung.dungeonsguide.gamesdk.jna.enumuration.EDiscordResult; import kr.syeyoung.dungeonsguide.gamesdk.jna.interfacestruct.IDiscordActivityEvents; import kr.syeyoung.dungeonsguide.gamesdk.jna.interfacestruct.IDiscordActivityManager; import kr.syeyoung.dungeonsguide.gamesdk.jna.interfacestruct.IDiscordCore; -import kr.syeyoung.dungeonsguide.gamesdk.jna.typedef.DiscordClientID; -import kr.syeyoung.dungeonsguide.gamesdk.jna.typedef.DiscordTimestamp; -import kr.syeyoung.dungeonsguide.gamesdk.jna.typedef.DiscordVersion; -import kr.syeyoung.dungeonsguide.gamesdk.jna.typedef.Int32; +import kr.syeyoung.dungeonsguide.gamesdk.jna.typedef.*; import kr.syeyoung.dungeonsguide.party.PartyInviteViewer; import kr.syeyoung.dungeonsguide.party.PartyJoinRequest; import kr.syeyoung.dungeonsguide.party.PartyManager; @@ -73,15 +71,18 @@ public class RichPresenceManager implements Runnable { callbacks.OnActivityInvite = (eventData, type, user, activity) -> { }; - callbacks.OnActivityJoin = (eventData, secret) -> DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload().method(StompHeader.SEND) + callbacks.OnActivityJoin = (eventData, secret) -> {DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload().method(StompHeader.SEND) .header("destination", "/app/party.askedtojoin") .payload(new JSONObject().put("token", secret).toString())); + System.out.println("Trying to join with token "+secret); + }; callbacks.OnActivityJoinRequest = (eventData, user) -> { PartyJoinRequest partyJoinRequest = new PartyJoinRequest(); partyJoinRequest.setDiscordUser(user); partyJoinRequest.setExpire(System.currentTimeMillis() + 30000); PartyInviteViewer.INSTANCE.joinRequests.add(partyJoinRequest); + System.out.println("Received Join Request from "+user.id.longValue()+" ("+partyJoinRequest.getUsername()+"#"+partyJoinRequest.getDiscriminator()+")"); }; callbacks.OnActivitySpectate = (eventData, secret) -> { @@ -113,6 +114,12 @@ public class RichPresenceManager implements Runnable { private DiscordActivity latestDiscordActivity; + public void respond(DiscordSnowflake userID, EDiscordActivityJoinRequestReply reply) { + activityManager.SendRequestReply.sendRequestReply(activityManager, userID, reply, Pointer.NULL, (callbackData, result) -> { + System.out.println("Discord Returned "+result+" For Replying "+reply+" To "+userID.longValue()+"L"); + }); + } + public void updatePresence() { if (!skyblockStatus.isOnHypixel() || !FeatureRegistry.ADVANCED_RICHPRESENCE.isEnabled() || (!skyblockStatus.isOnSkyblock() && FeatureRegistry.ADVANCED_RICHPRESENCE.<Boolean>getParameter("disablenotskyblock").getValue())) { activityManager.ClearActivity.clearActivity(activityManager, Pointer.NULL, new NativeGameSDK.DiscordCallback() { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java b/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java index 973e5fca..0f591f22 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java @@ -91,86 +91,4 @@ public class GameSDK { System.arraycopy(bts, 0, asdasd, 0, i); return new String(asdasd); } - - public static void main(String args[]) throws InterruptedException { - NativeGameSDK nativeGameSDK = getNativeGameSDK(); - DiscordCreateParams discordCreateParams = new DiscordCreateParams(); - discordCreateParams.client_id = new DiscordClientID(816298079732498473L); - - IDiscordActivityEvents activityEvents = new IDiscordActivityEvents(); - activityEvents.OnActivityInvite = new IDiscordActivityEvents.OnActivityInviteCallback() { - @Override - public void onActivityInvite(Pointer eventData, EDiscordActivityActionType type, DiscordUser user, DiscordActivity activity) { - - } - }; - activityEvents.OnActivityJoin = new IDiscordActivityEvents.OnActivityJoinCallback() { - @Override - public void onActivityJoin(Pointer eventData, String secret) { - - } - }; - activityEvents.OnActivityJoinRequest = new IDiscordActivityEvents.OnActivityJoinRequestCallback() { - @Override - public void onActivityJoinRequest(Pointer eventData, DiscordUser user) { - - } - }; - activityEvents.OnActivitySpectate = new IDiscordActivityEvents.OnActivitySpectateCallback() { - @Override - public void onActivitySpectate(Pointer eventData, String secret) { - - } - }; - activityEvents.write(); - discordCreateParams.activity_events = new IDiscordActivityEvents.ByReference(activityEvents.getPointer()); - - - PointerByReference pointerByReference = new PointerByReference(); - nativeGameSDK.DiscordCreate(new DiscordVersion(NativeGameSDK.DISCORD_VERSION), discordCreateParams, pointerByReference); - IDiscordCore iDiscordCore = new IDiscordCore(pointerByReference.getValue()); - - iDiscordCore.SetLogHook.setLogHook(iDiscordCore, EDiscordLogLevel.DiscordLogLevel_Debug, Pointer.NULL, new IDiscordCore.LogHook() { - @Override - public void hook(Pointer hookData, EDiscordLogLevel level, String message) { - System.out.println(message+" - "+level+" - "+hookData); - } - }); - - DiscordActivity discordActivity = new DiscordActivity(); - discordActivity.activityType = EDiscordActivityType.DiscordActivityType_Playing; - writeString(discordActivity.details, "Dungeons Guide RPC Test Det"); - writeString(discordActivity.state, "Dungeons Guide RPC Test Sta"); - discordActivity.party = new DiscordActivityParty(); - writeString(discordActivity.party.id, "partyid"); - discordActivity.party.discordActivityParty = new DiscordPartySize(); - discordActivity.party.discordActivityParty.current_size = new Int32(4); - discordActivity.party.discordActivityParty.max_size = new Int32(10); - discordActivity.instance = false; - discordActivity.timestamps = new DiscordActivityTimestamps(); - discordActivity.timestamps.start = new DiscordTimestamp(System.currentTimeMillis()); - discordActivity.timestamps.end = new DiscordTimestamp(System.currentTimeMillis()+1000*60*60); - discordActivity.secrets = new DiscordActivitySecrets(); - writeString(discordActivity.secrets.join, "thisisjoinsecret"); - writeString(discordActivity.secrets.spectate, "thisisspectatesecret"); - writeString(discordActivity.secrets.match, "thisismatchsecret"); - discordActivity.assets = new DiscordActivityAssets(); - writeString(discordActivity.assets.large_text, "thisislargetext"); - writeString(discordActivity.assets.large_image, "mort"); - - - - IDiscordActivityManager iDiscordActivityManager = iDiscordCore.GetActivityManager.getActivityManager(iDiscordCore); - iDiscordActivityManager.UpdateActivity.updateActivity(iDiscordActivityManager, discordActivity, Pointer.NULL, new NativeGameSDK.DiscordCallback() { - @Override - public void callback(Pointer callbackData, EDiscordResult result) { - System.out.println("Callback: "+callbackData+" - "+result); - } - }); - - while(true) { - iDiscordCore.RunCallbacks.runCallbacks(iDiscordCore); - Thread.sleep(100); - } - } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java index a045ea22..8588fca1 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java @@ -19,6 +19,8 @@ package kr.syeyoung.dungeonsguide.party; import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.RichPresenceManager; +import kr.syeyoung.dungeonsguide.gamesdk.jna.enumuration.EDiscordActivityJoinRequestReply; import kr.syeyoung.dungeonsguide.utils.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -106,21 +108,21 @@ public class PartyInviteViewer { if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); joinRequest.setTtl(60); -// DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.YES); + RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Yes); return; } if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { joinRequest.setReply(PartyJoinRequest.Reply.DENY); joinRequest.setTtl(60); -// DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.NO); + RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_No); return; } if (joinRequest.getIgnoreRect().contains(mouseX, mouseY)) { joinRequest.setReply(PartyJoinRequest.Reply.IGNORE); joinRequest.setTtl(60); -// DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.IGNORE); + RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Ignore); return; } @@ -194,7 +196,7 @@ public class PartyInviteViewer { Gui.drawRect(0, 0,width,height, 0xFF23272a); Gui.drawRect(2, 2, width-2, height-2, 0XFF2c2f33); { - String avatar = "https://cdn.discordapp.com/avatars/"+partyJoinRequest.getDiscordUser().id.longValue()+"/"+partyJoinRequest.getDiscordUser().avatar+".png"; + String avatar = "https://cdn.discordapp.com/avatars/"+partyJoinRequest.getDiscordUser().id.longValue()+"/"+partyJoinRequest.getAvatar()+".png"; Future<LoadedImage> loadedImageFuture = loadImage(avatar); LoadedImage loadedImage = null; if (loadedImageFuture.isDone()) { @@ -236,12 +238,12 @@ public class PartyInviteViewer { GlStateManager.pushMatrix(); GlStateManager.scale(3.0,3.0,1.0); - fr.drawString(partyJoinRequest.getDiscordUser().username+"", 0,0, 0xFFFFFFFF, true); + fr.drawString(partyJoinRequest.getUsername()+"", 0,0, 0xFFFFFFFF, true); GlStateManager.popMatrix(); GlStateManager.pushMatrix(); - GlStateManager.translate(fr.getStringWidth(partyJoinRequest.getDiscordUser().username+"") * 3 + 1, (int)(fr.FONT_HEIGHT*1.5), 0); - fr.drawString("#"+partyJoinRequest.getDiscordUser().discriminator, 0,0,0xFFaaaaaa, true); + GlStateManager.translate(fr.getStringWidth(partyJoinRequest.getUsername()+"") * 3 + 1, (int)(fr.FONT_HEIGHT*1.5), 0); + fr.drawString("#"+partyJoinRequest.getDiscriminator(), 0,0,0xFFaaaaaa, true); GlStateManager.popMatrix(); GlStateManager.pushMatrix(); GlStateManager.translate(0, fr.FONT_HEIGHT * 3 + 5, 0); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java index 06b04e20..ac2b9561 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java @@ -18,6 +18,7 @@ package kr.syeyoung.dungeonsguide.party; +import kr.syeyoung.dungeonsguide.gamesdk.GameSDK; import kr.syeyoung.dungeonsguide.gamesdk.jna.datastruct.DiscordUser; import lombok.AllArgsConstructor; import lombok.Data; @@ -28,6 +29,15 @@ import java.awt.*; @Data public class PartyJoinRequest { private DiscordUser discordUser; + + public void setDiscordUser(DiscordUser discordUser) { + this.discordUser = discordUser; + username = GameSDK.readString(discordUser.username); + discriminator = GameSDK.readString(discordUser.discriminator); + avatar = GameSDK.readString(discordUser.avatar); + } + + private String username, discriminator, avatar; private long expire; private Rectangle wholeRect = new Rectangle(); |