From 20e3b8ffda1e695ba479da243e1892ea359d1bf3 Mon Sep 17 00:00:00 2001 From: ShiroSaki <62388797+ShigemoriHakura@users.noreply.github.com> Date: Sat, 14 May 2022 04:31:27 +0800 Subject: [PATCH 1/7] add support for announcement page --- .gitignore | 1 + data/GameAnnouncementList.json | 10 ++- .../server/dispatch/DispatchServer.java | 6 ++ .../http/AnnouncementIndexHandler.java | 61 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/server/dispatch/http/AnnouncementIndexHandler.java diff --git a/.gitignore b/.gitignore index 6fd78ed3b..9a298a89a 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,4 @@ BuildConfig.java # macOS .DS_Store +data/hk4e/announcement/ diff --git a/data/GameAnnouncementList.json b/data/GameAnnouncementList.json index f6566960a..7464b3b0f 100644 --- a/data/GameAnnouncementList.json +++ b/data/GameAnnouncementList.json @@ -57,5 +57,13 @@ "mi18n_name": "Activity" } ], - "timezone": -5 + "timezone": -5, + "alert": false, + "alert_id": 0, + "pic_list": [], + "pic_total": 0, + "pic_type_list": [], + "pic_alert": false, + "pic_alert_id": 0, + "static_sign": "" } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 7e439a1a4..7153542a4 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -16,6 +16,7 @@ import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo; import emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo; import emu.grasscutter.server.dispatch.authentication.AuthenticationHandler; import emu.grasscutter.server.dispatch.authentication.DefaultAuthenticationHandler; +import emu.grasscutter.server.dispatch.http.AnnouncementIndexHandler; import emu.grasscutter.server.dispatch.http.GachaDetailsHandler; import emu.grasscutter.server.dispatch.http.GachaRecordHandler; import emu.grasscutter.server.dispatch.json.*; @@ -443,6 +444,11 @@ public final class DispatchServer { // gacha details httpServer.get("/gacha/details", new GachaDetailsHandler()); + // announcement index + httpServer.get("/hk4e/announcement/*", new AnnouncementIndexHandler()); + httpServer.get("/sw.js", new AnnouncementIndexHandler()); + httpServer.get("/dora/lib/vue/2.6.11/vue.min.js", new AnnouncementIndexHandler()); + // static file support for plugins httpServer.raw().config.precompressStaticFiles = false; // If this isn't set to false, files such as images may appear corrupted when serving static files diff --git a/src/main/java/emu/grasscutter/server/dispatch/http/AnnouncementIndexHandler.java b/src/main/java/emu/grasscutter/server/dispatch/http/AnnouncementIndexHandler.java new file mode 100644 index 000000000..7e55eac7e --- /dev/null +++ b/src/main/java/emu/grasscutter/server/dispatch/http/AnnouncementIndexHandler.java @@ -0,0 +1,61 @@ +package emu.grasscutter.server.dispatch.http; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.Account; +import emu.grasscutter.utils.FileUtils; +import emu.grasscutter.utils.Utils; +import express.http.HttpContextHandler; +import express.http.Request; +import express.http.Response; + +import java.io.File; +import java.io.IOException; +import java.util.Objects; + +import static emu.grasscutter.Configuration.DATA; + +public class AnnouncementIndexHandler implements HttpContextHandler { + private final String render_template; + private final String render_swjs; + private final String render_vueminjs; + + public AnnouncementIndexHandler() { + File template = new File(Utils.toFilePath(DATA("/hk4e/announcement/index.html"))); + File swjs = new File(Utils.toFilePath(DATA("/hk4e/announcement/sw.js"))); + File vueminjs = new File(Utils.toFilePath(DATA("/hk4e/announcement/vue.min.js"))); + this.render_template = template.exists() ? new String(FileUtils.read(template)) : null; + this.render_swjs = swjs.exists() ? new String(FileUtils.read(swjs)) : null; + this.render_vueminjs = vueminjs.exists() ? new String(FileUtils.read(vueminjs)) : null; + } + + @Override + public void handle(Request req, Response res) throws IOException { + if (Objects.equals(req.path(), "/sw.js")) { + res.send(render_swjs); + }else if(Objects.equals(req.path(), "/hk4e/announcement/index.html")) { + res.send(render_template); + }else if(Objects.equals(req.path(), "/dora/lib/vue/2.6.11/vue.min.js")){ + res.send(render_vueminjs); + }else{ + File renderFile = new File(Utils.toFilePath(DATA(req.path()))); + if(renderFile.exists()){ + String ext = req.path().substring(req.path().lastIndexOf(".") + 1); + switch(ext){ + case "css": + res.type("text/css"); + res.send(FileUtils.read(renderFile)); + break; + case "js": + default: + res.send(FileUtils.read(renderFile)); + break; + } + }else{ + Grasscutter.getLogger().info( "File not exist: " + req.path()); + } + } + + + } +} From 922359d6e6ba7e87ce7e62a24cb07a678c234712 Mon Sep 17 00:00:00 2001 From: muhammadeko Date: Sat, 14 May 2022 07:50:36 +0700 Subject: [PATCH 2/7] add negative permission check --- src/main/java/emu/grasscutter/game/Account.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 6c3daf61a..39fb8969e 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -144,12 +144,20 @@ public class Account { } public boolean hasPermission(String permission) { - if (this.permissions.contains(permission) || this.permissions.contains("*")) { + if (this.permissions.contains(permission)) { return true; } + if(this.permissions.contains("*") && this.permissions.contains("-"+permission)) { + return false; + } + String[] permissionParts = permission.split("\\."); for (String p : this.permissions) { + if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) { + return false; + } if (permissionMatchesWildcard(p, permissionParts)) { + Grasscutter.getLogger().info("Permission " + p + " matches " + permission); return true; } } From 855a098aa7210ab78bd6d78d7d8855ccd09ee461 Mon Sep 17 00:00:00 2001 From: muhammadeko Date: Sat, 14 May 2022 11:32:33 +0700 Subject: [PATCH 3/7] fix logic and some cleaning --- .../java/emu/grasscutter/game/Account.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 39fb8969e..518bd4786 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -144,24 +144,22 @@ public class Account { } public boolean hasPermission(String permission) { - if (this.permissions.contains(permission)) { - return true; - } - if(this.permissions.contains("*") && this.permissions.contains("-"+permission)) { - return false; - } + + if (this.permissions.contains(permission)) return true; + if(this.permissions.contains("*") && this.permissions.size() == 1) return true; String[] permissionParts = permission.split("\\."); for (String p : this.permissions) { + if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) { + Grasscutter.getLogger().info("Permission " + permission + " denied to " + this.username); return false; } - if (permissionMatchesWildcard(p, permissionParts)) { - Grasscutter.getLogger().info("Permission " + p + " matches " + permission); - return true; - } + + if (permissionMatchesWildcard(p, permissionParts)) return true; } - return false; + + return this.permissions.contains("*"); } public boolean removePermission(String permission) { From 4f553f6694f53dba4c0b5bba6ffa6caee72a2b9f Mon Sep 17 00:00:00 2001 From: muhammadeko Date: Sat, 14 May 2022 11:34:09 +0700 Subject: [PATCH 4/7] remove log --- src/main/java/emu/grasscutter/game/Account.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 518bd4786..84873ec61 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -150,12 +150,7 @@ public class Account { String[] permissionParts = permission.split("\\."); for (String p : this.permissions) { - - if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) { - Grasscutter.getLogger().info("Permission " + permission + " denied to " + this.username); - return false; - } - + if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) return false; if (permissionMatchesWildcard(p, permissionParts)) return true; } From 3c654cf0302b4b43b0315ae39607fccf5bcf5951 Mon Sep 17 00:00:00 2001 From: luluxiaoyu <58876608+luluxiaoyu@users.noreply.github.com> Date: Sat, 14 May 2022 09:30:40 +0800 Subject: [PATCH 5/7] Update zh-TW.json --- src/main/resources/languages/zh-TW.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/resources/languages/zh-TW.json b/src/main/resources/languages/zh-TW.json index 2b6fe34ff..caf37d0d7 100644 --- a/src/main/resources/languages/zh-TW.json +++ b/src/main/resources/languages/zh-TW.json @@ -215,6 +215,14 @@ "success": "座標:%s, %s, %s\n場景ID:%s", "description": "獲取目前所在位置的座標。" }, + "quest": { + "description": "添加或完成任務", + "usage": "quest [任務ID]", + "added": "已添加任務 %s", + "finished": "已完成任務 %s", + "not_found": "未找到任務", + "invalid_id": "無效的任務ID" + }, "reload": { "reload_start": "正在重新加載設定檔。", "reload_done": "重新加載已完成。", From 470007a6c0bc9b117985d4de973b7193d0ff737f Mon Sep 17 00:00:00 2001 From: zrll_ <46812903+zrll12@users.noreply.github.com> Date: Sat, 14 May 2022 15:12:57 +0800 Subject: [PATCH 6/7] Fix connot execute quest command in console --- .../java/emu/grasscutter/command/commands/QuestCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/QuestCommand.java b/src/main/java/emu/grasscutter/command/commands/QuestCommand.java index 70fae0120..affbfa769 100644 --- a/src/main/java/emu/grasscutter/command/commands/QuestCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/QuestCommand.java @@ -37,7 +37,7 @@ public final class QuestCommand implements CommandHandler { switch (cmd) { case "add" -> { - GameQuest quest = sender.getQuestManager().addQuest(questId); + GameQuest quest = targetPlayer.getQuestManager().addQuest(questId); if (quest != null) { CommandHandler.sendMessage(sender, translate(sender, "commands.quest.added", questId)); @@ -47,7 +47,7 @@ public final class QuestCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found")); } case "finish" -> { - GameQuest quest = sender.getQuestManager().getQuestById(questId); + GameQuest quest = targetPlayer.getQuestManager().getQuestById(questId); if (quest == null) { CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found")); From 741e5749ad4b242efce1ad42dea903136f7ccd4f Mon Sep 17 00:00:00 2001 From: lsCoding666 <73888354+lsCoding666@users.noreply.github.com> Date: Sat, 14 May 2022 21:28:02 +0800 Subject: [PATCH 7/7] new command join and remove to force join or remove avatars into your current team (#549) * feat:new command "join" and "remove" to force join or remove avatar in your current team * fix:change MaxAvatarsInTeam from 9 to 4 * feat:update & merge branch.Translate fix --- .../command/commands/JoinCommand.java | 46 +++++++++++++++++++ .../command/commands/RemoveCommand.java | 43 +++++++++++++++++ src/main/resources/languages/en-US.json | 9 ++++ src/main/resources/languages/zh-CN.json | 9 ++++ src/main/resources/languages/zh-TW.json | 5 ++ 5 files changed, 112 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/JoinCommand.java create mode 100644 src/main/java/emu/grasscutter/command/commands/RemoveCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/JoinCommand.java b/src/main/java/emu/grasscutter/command/commands/JoinCommand.java new file mode 100644 index 000000000..4dac15dd7 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/JoinCommand.java @@ -0,0 +1,46 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp; + +import java.util.ArrayList; +import java.util.List; + +import static emu.grasscutter.utils.Language.translate; + +@Command(label = "join", usage = "join [AvatarIDs] such as\"join 10000038 10000039\"", + description = "commands.join.description", permission = "player.join") +public class JoinCommand implements CommandHandler { + + @Override + public void execute(Player sender, Player targetPlayer, List args) { + List avatarIds = new ArrayList<>(); + for (String arg : args) { + try { + int avatarId = Integer.parseInt(arg); + avatarIds.add(avatarId); + } catch (Exception ignored) { + ignored.printStackTrace(); + CommandHandler.sendMessage(sender, translate("commands.generic.invalid.avatarId")); + return; + } + } + + + for (int i = 0; i < args.size(); i++) { + Avatar avatar = sender.getAvatars().getAvatarById(avatarIds.get(i)); + if (avatar == null || sender.getTeamManager().getCurrentTeamInfo().contains(avatar)) { + CommandHandler.sendMessage(sender, translate("commands.generic.invalid.avatarId")); + return; + } + sender.getTeamManager().getCurrentTeamInfo().addAvatar(avatar); + } + + // Packet + sender.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(sender, sender.getTeamManager().getCurrentTeamInfo())); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java b/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java new file mode 100644 index 000000000..a40b42698 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java @@ -0,0 +1,43 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp; + +import java.util.ArrayList; +import java.util.List; + +import static emu.grasscutter.utils.Language.translate; + +@Command(label = "remove", usage = "remove [indexOfYourTeams] index start from 1", + description = "commands.remove.description", permission = "player.remove") +public class RemoveCommand implements CommandHandler { + + @Override + public void execute(Player sender, Player targetPlayer, List args) { + List avatarIds = new ArrayList<>(); + for (String arg : args) { + try { + int avatarId = Integer.parseInt(arg); + avatarIds.add(avatarId); + } catch (Exception ignored) { + ignored.printStackTrace(); + CommandHandler.sendMessage(sender, translate("commands.remove.invalid_index")); + return; + } + } + + for (int i = 0; i < avatarIds.size(); i++) { + if (avatarIds.get(i) > sender.getTeamManager().getCurrentTeamInfo().getAvatars().size() || avatarIds.get(i) <= 0) { + CommandHandler.sendMessage(sender, translate("commands.remove.invalid_index")); + return; + } + sender.getTeamManager().getCurrentTeamInfo().removeAvatar(avatarIds.get(i) - 1); + } + + // Packet + sender.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(sender, sender.getTeamManager().getCurrentTeamInfo())); + } +} diff --git a/src/main/resources/languages/en-US.json b/src/main/resources/languages/en-US.json index 02945e6d4..32631db1f 100644 --- a/src/main/resources/languages/en-US.json +++ b/src/main/resources/languages/en-US.json @@ -176,6 +176,10 @@ "success": "All characters have been healed.", "description": "Heal all characters in your current team." }, + "join": { + "usage": "Usage: join [AvatarIDs] such as\"join 10000038 10000039\"", + "description": "force join avatar into your team" + }, "kick": { "player_kick_player": "Player [%s:%s] has kicked player [%s:%s]", "server_kick_player": "Kicking player [%s:%s]", @@ -228,6 +232,11 @@ "reload_done": "Reload complete.", "description": "Reload server config" }, + "remove": { + "usage": "Usage: remove [indexOfYourTeams] index start from 1", + "invalid_index": "index start from 1", + "description": "force remove avatar into your team" + }, "resetConst": { "reset_all": "Reset all avatars' constellations.", "success": "Constellations for %s have been reset. Please relog to see changes.", diff --git a/src/main/resources/languages/zh-CN.json b/src/main/resources/languages/zh-CN.json index aaeac5a86..5f379540b 100644 --- a/src/main/resources/languages/zh-CN.json +++ b/src/main/resources/languages/zh-CN.json @@ -176,6 +176,10 @@ "success": "已治疗所有角色。", "description": "治疗当前队伍的角色" }, + "join": { + "usage": "用法:join <角色IDs> 例如\"join 10000038 10000039\"空格分开", + "description": "强制将角色加入到当前队伍中" + }, "kick": { "player_kick_player": "玩家 [%s:%s] 已将 [%s:%s] 踢出。", "server_kick_player": "正在踢出玩家 [%s:%s]...", @@ -228,6 +232,11 @@ "reload_done": "重载完成。", "description": "重载配置文件和数据" }, + "remove": { + "usage": "用法: remove [indexOfYourTeams] 从1开始", + "invalid_index": "下标从1开始", + "description": "强制移除队内角色" + }, "resetConst": { "reset_all": "重置所有角色的命座。", "success": "已重置 %s 的命座,重新登录后生效。", diff --git a/src/main/resources/languages/zh-TW.json b/src/main/resources/languages/zh-TW.json index caf37d0d7..25f92f869 100644 --- a/src/main/resources/languages/zh-TW.json +++ b/src/main/resources/languages/zh-TW.json @@ -228,6 +228,11 @@ "reload_done": "重新加載已完成。", "description": "重新加載設定檔和數據。" }, + "remove": { + "usage": "用法: remove [indexOfYourTeams] 从1开始", + "invalid_index": "下標從1開始", + "description": "强制移除對内角色" + }, "resetConst": { "reset_all": "重設所有角色的命座。", "success": "已重設 %s 的命座,重新登入後將會生效。",