diff --git a/data/GameAnnouncement.json b/data/GameAnnouncement.json new file mode 100644 index 000000000..2bce06fdb --- /dev/null +++ b/data/GameAnnouncement.json @@ -0,0 +1,29 @@ +{ +"list": [ + { + "ann_id": 1, + "title": "Welcome to Grasscutter!", + "subtitle": "Welcome", + "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg", + "content": "Hi there!
First of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! Check out our:

〓Discord〓

https://discord.gg/T5vZU6UyeG

〓GitHub〓

https://github.com/Grasscutters/Grasscutter

", + "lang": "es-es" + }, + { + "ann_id": 2, + "title": "How to use announcements", + "subtitle": "How to use", + "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg", + "content": "Tips
>How to use announcements

>Announcement content can use HTML

>The specific content of the announcement is stored in the program directorydata/GameAnnouncement.json, whileGameAnnouncementList.json stores the announcement list data

How to use
>In GameAnnouncement
ParametersDescription
ann_IdAnnouncement unique id
titleShow at the top of the content
subtitletitle shown on the left
bannerDisplay between content and title
contentas u see
langdisplay language
totalAnnouncement quantity


>In GameAnnouncementList
If you want to add an annouement, please add the list data in the announcement type corresponding to GameAnnouncementList, and finally add the announcement content in GameAnnouncement", + "lang": "es-es" + }, + { + "ann_id": 3, + "title": "这是活动公告--This is the event announcement", + "subtitle": "Welcome", + "banner":"https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg", + "content": "Welcome", + "lang": "es-es" + } +], +"total": 3 +} \ No newline at end of file diff --git a/data/GameAnnouncementList.json b/data/GameAnnouncementList.json new file mode 100644 index 000000000..ea3091fc7 --- /dev/null +++ b/data/GameAnnouncementList.json @@ -0,0 +1,119 @@ +{ + "t": "System.currentTimeMillis()", + "list": [ + { + "list": [ + { + "ann_id": 1, + "title": "Welcome to Grasscutter!", + "subtitle": "Welcome", + "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg", + "content": "", + "type_label": "Juego", + "tag_label": "1", + "tag_icon": "https://uploadstatic-sea.mihoyo.com/announcement/2020/03/05/a2588f1a51faee9fa8dfe9aead649dd6_7237021399135895303.png", + "login_alert": 1, + "lang": "es-es", + "start_time": "2020-09-25 04:05:30", + "end_time": "2023-10-30 11:00:00", + "type": 2, + "remind": 0, + "alert": 0, + "tag_start_time": "2000-01-02 15:04:05", + "tag_end_time": "2030-01-02 15:04:05", + "remind_ver": 1, + "has_content": true, + "extra_remind": 0 + }, + { + "ann_id": 2, + "title": "这是游戏公告 -- This is the game announcement", + "subtitle": "This is the game announcement", + "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/85b7163c95745a76d49b3d163d893592_6487108933004985049.jpg", + "content": "", + "type_label": "Juego", + "tag_label": "1", + "tag_icon": "https://uploadstatic-sea.mihoyo.com/announcement/2020/03/05/a2588f1a51faee9fa8dfe9aead649dd6_7237021399135895303.png", + "login_alert": 1, + "lang": "es-es", + "start_time": "2020-09-25 15:12:09", + "end_time": "2030-10-30 11:00:00", + "type": 2, + "remind": 0, + "alert": 0, + "tag_start_time": "2000-01-02 08:04:05", + "tag_end_time": "2030-01-02 08:04:05", + "remind_ver": 1, + "has_content": true, + "extra_remind": 0 + } + ], + "type_id": 2, + "type_label": "Juego" + }, + { + "list": [ + { + "ann_id": 3, + "title": "这是活动公告--This is the event announcement", + "subtitle": "Welcome", + "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg", + "content": "", + "type_label": "Eventos", + "tag_label": "1", + "tag_icon": "https://uploadstatic-sea.mihoyo.com/announcement/2020/03/05/a2588f1a51faee9fa8dfe9aead649dd6_7237021399135895303.png", + "login_alert": 1, + "lang": "es-es", + "start_time": "2020-09-25 04:05:30", + "end_time": "2022-05-02 00:51:00", + "type": 2, + "remind": 0, + "alert": 0, + "tag_start_time": "2000-01-02 15:04:05", + "tag_end_time": "2022-05-02 00:51:00", + "remind_ver": 1, + "has_content": true, + "extra_remind": 0 + } + ], + "type_id": 1, + "type_label": "Eventos" + }, + { + "list": [ + {} + ], + "type_id": 3, + "type_label": "Others" + } + ], + "total": 3, + "type_list": [ + { + "id": 2, + "name": "游戏系统公告", + "mi18n_name": "Juego" + }, + { + "id": 1, + "name": "活动公告", + "mi18n_name": "Eventos" + }, + { + "id": 3, + "name": "其他", + "mi18n_name": "Others" + } + ], + "alert": true, + "alert_id": 2, + "timezone": -5, + "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/AnnouncementHandler.java b/src/main/java/emu/grasscutter/server/dispatch/AnnouncementHandler.java new file mode 100644 index 000000000..333d8ea21 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/dispatch/AnnouncementHandler.java @@ -0,0 +1,35 @@ +package emu.grasscutter.server.dispatch; + +import emu.grasscutter.Grasscutter; +import express.http.HttpContextHandler; +import express.http.Request; +import express.http.Response; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Objects; + +public final class AnnouncementHandler implements HttpContextHandler { + @Override + public void handle(Request request, Response response) throws IOException {//event + if (Objects.equals(request.baseUrl(), "/common/hk4e_global/announcement/api/getAnnContent")) { + response.send("{\"retcode\":0,\"message\":\"OK\",\"data\":" + readToString(new File(Grasscutter.getConfig().DATA_FOLDER + "GameAnnouncement.json")) +"}"); + } else if (Objects.equals(request.baseUrl(), "/common/hk4e_global/announcement/api/getAnnList")) { + String data = readToString(new File(Grasscutter.getConfig().DATA_FOLDER + "GameAnnouncementList.json")).replace("System.currentTimeMillis()",String.valueOf(System.currentTimeMillis())); + response.send("{\"retcode\":0,\"message\":\"OK\",\"data\": "+data +"}"); + } + } + private static String readToString(File file) { + Long filelength = file.length(); + byte[] filecontent = new byte[filelength.intValue()]; + try { + FileInputStream in = new FileInputStream(file); + in.read(filecontent); + in.close(); + } catch (IOException fileNotFoundException) { + fileNotFoundException.printStackTrace(); + } + return new String(filecontent); + } +} \ 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 5fdda7e87..79a103d17 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -408,9 +408,9 @@ public final class DispatchServer { // hk4e-api-os.hoyoverse.com httpServer.all("/common/hk4e_global/announcement/api/getAlertAnn", new DispatchHttpJsonHandler("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}")); // hk4e-api-os.hoyoverse.com - httpServer.all("/common/hk4e_global/announcement/api/getAnnList", new DispatchHttpJsonHandler("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"list\":[],\"total\":0,\"type_list\":[],\"alert\":false,\"alert_id\":0,\"timezone\":0,\"t\":\"" + System.currentTimeMillis() + "\"}}")); + httpServer.all("/common/hk4e_global/announcement/api/getAnnList", new AnnouncementHandler()); // hk4e-api-os-static.hoyoverse.com - httpServer.all("/common/hk4e_global/announcement/api/getAnnContent", new DispatchHttpJsonHandler("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"list\":[],\"total\":0}}")); + httpServer.all("/common/hk4e_global/announcement/api/getAnnContent", new AnnouncementHandler()); // hk4e-sdk-os.hoyoverse.com httpServer.all("/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", new DispatchHttpJsonHandler("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}"));