From aaf7de6fbb9cda34f42c4d9947fd7369294d35d9 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Thu, 7 Jan 2021 01:48:29 +0100 Subject: [PATCH] add forum parsers --- .../extensions/parsers/forums/HComment.java | 83 ++++++++++++ .../parsers/forums/HCommentOverview.java | 43 ++++++ .../extensions/parsers/forums/HForum.java | 87 ++++++++++++ .../parsers/forums/HForumOverview.java | 42 ++++++ .../parsers/forums/HForumOverviewType.java | 28 ++++ .../extensions/parsers/forums/HThread.java | 124 ++++++++++++++++++ .../parsers/forums/HThreadOverview.java | 36 +++++ .../parsers/forums/HThreadState.java | 26 ++++ 8 files changed, 469 insertions(+) create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HComment.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HCommentOverview.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HForum.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverview.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverviewType.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HThread.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadOverview.java create mode 100644 G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadState.java diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HComment.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HComment.java new file mode 100644 index 0000000..5fb0a81 --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HComment.java @@ -0,0 +1,83 @@ +package gearth.extensions.parsers.forums; + +import gearth.protocol.HPacket; + +public class HComment { + + private final int commentId; + private final int indexInThread; + private final int userId; + private final String userName; + private final String look; + private final int passedTime; + private final String message; + private final HThreadState state; + private final int adminId; + private final String adminName; + + private final int irrelevantId; + private final int authorPostCount; + + public HComment(HPacket hPacket) { + commentId = hPacket.readInteger(); + indexInThread = hPacket.readInteger(); + userId = hPacket.readInteger(); + userName = hPacket.readString(); + look = hPacket.readString(); + passedTime = hPacket.readInteger(); + message = hPacket.readString(); + state = HThreadState.fromValue(hPacket.readByte()); + adminId = hPacket.readInteger(); + adminName = hPacket.readString(); + irrelevantId = hPacket.readInteger(); + authorPostCount = hPacket.readInteger(); + } + + public int getCommentId() { + return commentId; + } + + public int getIndexInThread() { + return indexInThread; + } + + public int getUserId() { + return userId; + } + + public String getUserName() { + return userName; + } + + public String getLook() { + return look; + } + + public int getPassedTime() { + return passedTime; + } + + public String getMessage() { + return message; + } + + public HThreadState getState() { + return state; + } + + public int getAdminId() { + return adminId; + } + + public String getAdminName() { + return adminName; + } + + public int getIrrelevantId() { + return irrelevantId; + } + + public int getAuthorPostCount() { + return authorPostCount; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HCommentOverview.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HCommentOverview.java new file mode 100644 index 0000000..87098ac --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HCommentOverview.java @@ -0,0 +1,43 @@ +package gearth.extensions.parsers.forums; + +import gearth.protocol.HPacket; + +import java.util.ArrayList; +import java.util.List; + +public class HCommentOverview { + + private final int guildId; + private final int threadId; + private final int startIndex; + private final List comments; + + + public HCommentOverview(HPacket packet) { + guildId = packet.readInteger(); + threadId = packet.readInteger(); + startIndex = packet.readInteger(); + + comments = new ArrayList<>(); + int length = packet.readInteger(); + for (int i = 0; i < length; i++) { + comments.add(new HComment(packet)); + } + } + + public int getGuildId() { + return guildId; + } + + public int getThreadId() { + return threadId; + } + + public int getStartIndex() { + return startIndex; + } + + public List getComments() { + return comments; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForum.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForum.java new file mode 100644 index 0000000..110f5fc --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForum.java @@ -0,0 +1,87 @@ +package gearth.extensions.parsers.forums; + +import gearth.protocol.HPacket; + +public class HForum { + + private final int guildId; + private final String guildName; + private final String guildDescription; + private final String guildBadge; + + private final int unknown1; + private final int rating; + private final int amountComments; + private final int unreadComments; + + private final int lastCommentIndexInForum; + private final int lastCommentUserId; + private final String lastCommentUserName; + private final int lastCommentPassedTime; + + + public HForum(HPacket hPacket) { + guildId = hPacket.readInteger(); + guildName = hPacket.readString(); + guildDescription = hPacket.readString(); + guildBadge = hPacket.readString(); + + unknown1 = hPacket.readInteger(); + rating = hPacket.readInteger(); + amountComments = hPacket.readInteger(); + unreadComments = hPacket.readInteger(); + + lastCommentIndexInForum = hPacket.readInteger(); + lastCommentUserId = hPacket.readInteger(); + lastCommentUserName = hPacket.readString(); + lastCommentPassedTime = hPacket.readInteger(); + } + + public int getGuildId() { + return guildId; + } + + public String getGuildName() { + return guildName; + } + + public String getGuildDescription() { + return guildDescription; + } + + public String getGuildBadge() { + return guildBadge; + } + + public int getUnknown1() { + return unknown1; + } + + public int getRating() { + return rating; + } + + public int getAmountComments() { + return amountComments; + } + + public int getUnreadComments() { + return unreadComments; + } + + public int getLastCommentIndexInForum() { + return lastCommentIndexInForum; + } + + public int getLastCommentUserId() { + return lastCommentUserId; + } + + public String getLastCommentUserName() { + return lastCommentUserName; + } + + public int getLastCommentPassedTime() { + return lastCommentPassedTime; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverview.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverview.java new file mode 100644 index 0000000..9421db2 --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverview.java @@ -0,0 +1,42 @@ +package gearth.extensions.parsers.forums; + +import gearth.protocol.HPacket; + +import java.util.ArrayList; +import java.util.List; + +public class HForumOverview { + + private final HForumOverviewType viewMode; + private final int size; + private final int startIndex; + private final List forums; + + public HForumOverview(HPacket hPacket) { + viewMode = HForumOverviewType.fromValue(hPacket.readInteger()); + size = hPacket.readInteger(); + startIndex = hPacket.readInteger(); + + forums = new ArrayList<>(); + int forumsPageSize = hPacket.readInteger(); + for (int i = 0; i < forumsPageSize; i++) { + forums.add(new HForum(hPacket)); + } + } + + public HForumOverviewType getViewMode() { + return viewMode; + } + + public int getSize() { + return size; + } + + public int getStartIndex() { + return startIndex; + } + + public List getForums() { + return forums; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverviewType.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverviewType.java new file mode 100644 index 0000000..f3a2c62 --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HForumOverviewType.java @@ -0,0 +1,28 @@ +package gearth.extensions.parsers.forums; + +public enum HForumOverviewType { + MOST_ACTIVE(0), + MOST_READ(1), + MY_FORUMS(2); + + private final int val; + HForumOverviewType(int val) { + this.val = val; + } + + public int getVal() { + return val; + } + + public static HForumOverviewType fromValue(int state) { + switch (state) { + case 0: + return MOST_ACTIVE; + case 1: + return MOST_READ; + case 2: + return MY_FORUMS; + } + return MY_FORUMS; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThread.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThread.java new file mode 100644 index 0000000..15a0c37 --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThread.java @@ -0,0 +1,124 @@ +package gearth.extensions.parsers.forums; + +import gearth.protocol.HPacket; + +public class HThread { + + private final int threadId; + + private final int authorId; + private final String authorName; + private final String subject; + + private final boolean pinned; + private final boolean locked; + + private final int passedTime; + private final int ammountComments; + private final int unreadComments; + + private final int lastCommentIndexInForum; + private final int lastCommentAuthorId; + private final String lastCommentAuthorName; + private final int lastCommentPassedTime; + + private final HThreadState state; + private final int adminId; + private final String adminName; + + private final int unknownThreadId; + + public HThread(HPacket hPacket) { + threadId = hPacket.readInteger(); + + authorId = hPacket.readInteger(); + authorName = hPacket.readString(); + subject = hPacket.readString(); + + pinned = hPacket.readBoolean(); + locked = hPacket.readBoolean(); + + passedTime = hPacket.readInteger(); + ammountComments = hPacket.readInteger(); + unreadComments = hPacket.readInteger(); + + lastCommentIndexInForum = hPacket.readInteger(); + lastCommentAuthorId = hPacket.readInteger(); + lastCommentAuthorName = hPacket.readString(); + lastCommentPassedTime = hPacket.readInteger(); + + state = HThreadState.fromValue(hPacket.readByte()); + adminId = hPacket.readInteger(); + adminName = hPacket.readString(); + + unknownThreadId = hPacket.readInteger(); + } + + public int getThreadId() { + return threadId; + } + + public int getAuthorId() { + return authorId; + } + + public String getAuthorName() { + return authorName; + } + + public String getSubject() { + return subject; + } + + public boolean isPinned() { + return pinned; + } + + public boolean isLocked() { + return locked; + } + + public int getPassedTime() { + return passedTime; + } + + public int getAmmountComments() { + return ammountComments; + } + + public int getUnreadComments() { + return unreadComments; + } + + public int getLastCommentIndexInForum() { + return lastCommentIndexInForum; + } + + public int getLastCommentAuthorId() { + return lastCommentAuthorId; + } + + public String getLastCommentAuthorName() { + return lastCommentAuthorName; + } + + public int getLastCommentPassedTime() { + return lastCommentPassedTime; + } + + public HThreadState getState() { + return state; + } + + public int getAdminId() { + return adminId; + } + + public String getAdminName() { + return adminName; + } + + public int getUnknownThreadId() { + return unknownThreadId; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadOverview.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadOverview.java new file mode 100644 index 0000000..7b0671c --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadOverview.java @@ -0,0 +1,36 @@ +package gearth.extensions.parsers.forums; + +import gearth.protocol.HPacket; + +import java.util.ArrayList; +import java.util.List; + +public class HThreadOverview { + + private final int guildId; + private final int startIndex; + private final List threads; + + public HThreadOverview(HPacket hPacket) { + guildId = hPacket.readInteger(); + startIndex = hPacket.readInteger(); + + threads = new ArrayList<>(); + int threadsSize = hPacket.readInteger(); + for (int i = 0; i < threadsSize; i++) { + threads.add(new HThread(hPacket)); + } + } + + public int getGuildId() { + return guildId; + } + + public int getStartIndex() { + return startIndex; + } + + public List getThreads() { + return threads; + } +} diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadState.java b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadState.java new file mode 100644 index 0000000..55e4e17 --- /dev/null +++ b/G-Earth/src/main/java/gearth/extensions/parsers/forums/HThreadState.java @@ -0,0 +1,26 @@ +package gearth.extensions.parsers.forums; + +public enum HThreadState { + OPEN(0), + HIDDEN_BY_ADMIN(10), //DELETED + HIDDEN_BY_STAFF(20); + + public final int state; + + HThreadState(int state) { + this.state = state; + } + + public static HThreadState fromValue(int state) { + switch (state) { + case 0: + return OPEN; + case 10: + return HIDDEN_BY_ADMIN; + case 20: + return HIDDEN_BY_STAFF; + } + + return OPEN; + } +} \ No newline at end of file