Commit 92b103d5 authored by Hotaru's avatar Hotaru Committed by Melledy
Browse files

Fix UTF-8 encoding in announcements

parent 12c7c8f8
{
"list": [
{
"ann_id": 1,
"title": "<b>Welcome to Grasscutter!</b>",
"subtitle": "<b>Welcome</b>",
"banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
"content": "Hi there!<br>First of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! Check out our:<br><div><p style=\"white-space: pre-wrap;\"><strong>¡þDiscord¡þ</strong></p><p style=\"white-space: pre-wrap;\"><a href=\"https://discord.gg/T5vZU6UyeG\">https://discord.gg/T5vZU6UyeG</a></p><p style=\"white-space: pre-wrap;\"><strong>¡þGitHub¡þ</strong></p><p style=\"white-space: pre-wrap;\"><a href=\"https://github.com/Grasscutters/Grasscutter\">https://github.com/Grasscutters/Grasscutter</a></p></div>",
"lang": "es-es"
},
{
"ann_id": 2,
"title": "<b>How to use announcements</b>",
"subtitle": "<b>How to use</b>",
"banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
"content": "<strong>Tips<br></strong>>How to use announcements<br><br>>Announcement content can use HTML<br><br>>The specific content of the announcement is stored in the program directory<code>data/GameAnnouncement.json</code>, while<code>GameAnnouncementList.json</code> stores the announcement list data<br><br><strong>How to use</strong><br>>In <code>GameAnnouncement</code><table><thead><thead><tr><th>Parameters</th><th>Description</th></thead></thead><thbody><thead><tr><th>ann_Id</th><th>Announcement unique id</th></thead><thead><tr><th>title</th><th>Show at the top of the content</th></thead><thead><tr><th>subtitle</th><th>title shown on the left</th></thead><thead><tr><th>banner</th><th>Display between content and title</th></thead><thead><tr><th>content</th><th>as u see</th></thead><thead><tr><th>lang</th><th>display language</th></thead><thead><tr><th>total</th><th>Announcement quantity</th></thead></thbody></table><br><br>>In <code>GameAnnouncementList</code><br>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": "<b>ÕâÊǻ¹«¸æ--This is the event announcement</b>",
"subtitle": "<b>Welcome</b>",
"banner":"https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg",
"content": "Welcome",
"lang": "es-es"
}
],
"total": 3
"list": [
{
"ann_id": 1,
"title": "<strong>Welcome to Grasscutter!</strong>",
"subtitle": "Welcome!",
"banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
"content": "<p>Hi there!</p><p>First of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you!</p><br><p><strong>〓Discord〓</strong></p><a href=\"https://discord.gg/T5vZU6UyeG\">https://discord.gg/T5vZU6UyeG</a><br><br><p><strong>〓GitHub〓</strong><a href=\"https://github.com/Grasscutters/Grasscutter\">https://github.com/Grasscutters/Grasscutter</a>",
"lang": "en-US"
},
{
"ann_id": 2,
"title": "<strong>How to use announcements</strong>",
"subtitle": "How to use announcements",
"banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
"content": "<p>Announcement content uses HTML. The specific content of the announcement is stored in the program directory <code>GameAnnouncement.json</code>, while <code>GameAnnouncementList.json</code> stores the announcement list data.</p><h2><code>GameAnnouncement</code></h2><table><tr><th>Parameter</th><th>Description</th></tr><tr><td>ann_id</td><td>Unique ID</td></tr><tr><td>title</td><td>Title shown at the top of the content</td></tr><tr><td>subtitle</td><td>Short title shown on the left</td></tr><tr><td>banner</td><td>Image to display between content and title</td></tr><tr><td>content</td><td>Content body in HTML</td></tr><tr><td>lang</td><td>Language code for this entry</td></tr></table><h2><code>GameAnnouncementList</code></h2><p>If you want to add an announcement, please add the list data in the announcement type corresponding to <code>GameAnnouncementList</code>, and finally add the announcement content in <code>GameAnnouncement</code>.</p>",
"lang": "en-US"
}
],
"total": 2
}
\ No newline at end of file
......@@ -5,115 +5,57 @@
"list": [
{
"ann_id": 1,
"title": "<b>Welcome to Grasscutter!</b>",
"subtitle": "<b>Welcome</b>",
"title": "<strong>Welcome to Grasscutter!</strong>",
"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
"type_label": "System",
"lang": "en-US",
"start_time": "2020-09-25 04:05:30",
"end_time": "2030-10-30 11:00:00",
"content": "",
"has_content": true
},
{
"ann_id": 2,
"title": "<b>这是游戏公告 -- This is the game announcement</b>",
"subtitle": "<b>This is the game announcement</b>",
"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": "<b>这是活动公告--This is the event announcement</b>",
"subtitle": "<b>Welcome</b>",
"title": "<strong>How to use announcements</strong>",
"subtitle": "How to use announcements",
"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_label": "System",
"lang": "en-US",
"start_time": "2020-09-25 04:05:30",
"end_time": "2030-10-30 11:00:00",
"content": "",
"has_content": true
}
],
"type_id": 1,
"type_label": "Eventos"
"type_id": 2,
"type_label": "System"
},
{
"list": [
{}
],
"type_id": 3,
"type_label": "Others"
"type_label": "Events"
}
],
"total": 3,
"total": 2,
"type_list": [
{
"id": 2,
"name": "游戏系统公告",
"mi18n_name": "Juego"
"name": "游戏系统公告",
"mi18n_name": "System"
},
{
"id": 1,
"name": "活动公告",
"mi18n_name": "Eventos"
},
{
"id": 3,
"name": "其他",
"mi18n_name": "Others"
"name": "活动公告",
"mi18n_name": "Activity"
}
],
"alert": true,
"alert_id": 2,
"timezone": -5,
"pic_list": [
],
"pic_total": 0,
"pic_type_list": [
],
"pic_alert": false,
"pic_alert_id": 0,
"static_sign": ""
"timezone": -5
}
\ No newline at end of file
......@@ -5,34 +5,39 @@ 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.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import static emu.grasscutter.Configuration.*;
public final class AnnouncementHandler implements HttpContextHandler {
@Override
public void handle(Request request, Response response) throws IOException {//event
public void handle(Request request, Response response) throws IOException {
if (Objects.equals(request.baseUrl(), "/common/hk4e_global/announcement/api/getAnnContent")) {
response.send("{\"retcode\":0,\"message\":\"OK\",\"data\":" + readToString(new File(DATA("GameAnnouncement.json"))) +"}");
String data = readToString(Paths.get(DATA("GameAnnouncement.json")));
response.send("{\"retcode\":0,\"message\":\"OK\",\"data\":" + data + "}");
} else if (Objects.equals(request.baseUrl(), "/common/hk4e_global/announcement/api/getAnnList")) {
String data = readToString(new File(DATA("GameAnnouncementList.json"))).replace("System.currentTimeMillis()",String.valueOf(System.currentTimeMillis()));
response.send("{\"retcode\":0,\"message\":\"OK\",\"data\": "+data +"}");
String data = readToString(Paths.get(DATA("GameAnnouncementList.json")))
.replace("System.currentTimeMillis()", String.valueOf(System.currentTimeMillis()));
response.send("{\"retcode\":0,\"message\":\"OK\",\"data\": " + data + "}");
}
}
@SuppressWarnings("ResultOfMethodCallIgnored")
private static String readToString(File file) {
long length = file.length();
byte[] content = new byte[(int) length];
private static String readToString(Path path) {
String content = "";
try {
FileInputStream in = new FileInputStream(file);
in.read(content); in.close();
content = Files.readString(path, StandardCharsets.UTF_8);
} catch (IOException ignored) {
Grasscutter.getLogger().warn("File not found: " + file.getAbsolutePath());
Grasscutter.getLogger().warn("Unable to open file " + path.toAbsolutePath());
}
return new String(content);
return content;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment