diff --git a/core/AllMusic.java b/core/AllMusic.java index b2bc1816..6f0207c5 100644 --- a/core/AllMusic.java +++ b/core/AllMusic.java @@ -15,8 +15,10 @@ import com.coloryr.allmusic.server.core.sql.DataSql; import com.coloryr.allmusic.server.core.sql.IEconomy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import java.io.*; +import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; @@ -69,7 +71,7 @@ public class AllMusic { /** * Cookie对象 */ - public static CookieObj cookie; + public static List cookie; /** * 经济插件对象 */ @@ -391,11 +393,12 @@ public class AllMusic { reader = new InputStreamReader(Files.newInputStream(cookieFile.toPath()), StandardCharsets.UTF_8); bf = new BufferedReader(reader); - cookie = new Gson().fromJson(bf, CookieObj.class); + Type listType = new TypeToken>(){}.getType(); + cookie = new Gson().fromJson(bf, listType); bf.close(); reader.close(); - if (cookie == null || cookie.cookieStore == null) { - cookie = new CookieObj(); + if (cookie == null) { + cookie = new ArrayList<>(); saveCookie(); } diff --git a/core/command/CommandEX.java b/core/command/CommandEX.java index 453f9b7f..6697c7e2 100644 --- a/core/command/CommandEX.java +++ b/core/command/CommandEX.java @@ -30,10 +30,10 @@ public class CommandEX { commandList.put("nextpage", new CommandNextPage()); commandList.put("lastpage", new CommandLastPage()); commandList.put("hud", new CommandHud()); - commandList.put("reload", new CommandReload()); commandList.put("push", new CommandPush()); commandList.put("cancel", new CommandCancel()); + commandAdminList.put("reload", new CommandReload()); commandAdminList.put("next", new CommandNext()); commandAdminList.put("ban", new CommandBan()); commandAdminList.put("unban", new CommandUnban()); @@ -45,7 +45,6 @@ public class CommandEX { commandAdminList.put("clearlist", new CommandClearList()); commandAdminList.put("clearban", new CommandClearBanList()); commandAdminList.put("clearbanplayer", new CommandClearBanPlayerList()); - commandAdminList.put("cookie", new CommandCookie()); commandAdminList.put("test", new CommandTest()); } diff --git a/core/command/sub/CommandCookie.java b/core/command/sub/CommandCookie.java deleted file mode 100644 index 0cf7f114..00000000 --- a/core/command/sub/CommandCookie.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.coloryr.allmusic.server.core.command.sub; - -import com.coloryr.allmusic.server.core.AllMusic; -import com.coloryr.allmusic.server.core.command.ACommand; -import com.coloryr.allmusic.server.core.objs.MyCookie; -import org.apache.hc.client5.http.impl.cookie.BasicClientCookie; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -public class CommandCookie extends ACommand { - @Override - public void execute(Object sender, String name, String[] args) { - if (args.length != 2) { - AllMusic.side.sendMessage(sender, "§d[AllMusic3]§c没有Cookie数据"); - return; - } - if (AllMusic.side.isPlayer(sender)) { - AllMusic.side.sendMessage(sender, "§d[AllMusic3]§c请在控制台上操作"); - return; - } - AllMusic.side.sendMessage(sender, "§d[AllMusic3]§d设置网易云账户,请点一首歌测试是否生效"); - try { - String cookie = args[1]; - String[] cookies = cookie.split(";"); - List list = new ArrayList<>(); - for (String item : cookies) { - String[] cookieitem = item.split("="); - MyCookie cookie1 = new MyCookie(); - if (cookieitem.length == 1) { - cookie1.key = cookieitem[0]; - cookie1.value = ""; - } else { - cookie1.key = cookieitem[0]; - cookie1.value = cookieitem[1]; - } - list.add(cookie1); - } - AllMusic.cookie.cookieStore.put("music.163.com", list); - - AllMusic.saveCookie(); - } catch (Exception e) { - AllMusic.side.sendMessage(sender, "§d[AllMusic3]§c错误的cookie"); - e.printStackTrace(); - } - } -} diff --git a/core/music/api/HttpClientUtil.java b/core/music/api/HttpClientUtil.java index 29b8544c..19c34b85 100644 --- a/core/music/api/HttpClientUtil.java +++ b/core/music/api/HttpClientUtil.java @@ -1,8 +1,8 @@ package com.coloryr.allmusic.server.core.music.api; import com.coloryr.allmusic.server.core.AllMusic; +import com.coloryr.allmusic.server.core.objs.CookieObj; import com.coloryr.allmusic.server.core.objs.HttpResObj; -import com.coloryr.allmusic.server.core.objs.MyCookie; import com.coloryr.allmusic.server.core.objs.api.EncResObj; import com.coloryr.allmusic.server.core.objs.enums.EncryptType; import com.google.gson.JsonElement; @@ -24,7 +24,6 @@ import org.apache.hc.core5.http.NameValuePair; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.message.BasicNameValuePair; import org.apache.hc.core5.util.Timeout; -import org.checkerframework.checker.units.qual.A; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -62,29 +61,28 @@ public class HttpClientUtil { private static CookieStore createCookieStore() { BasicCookieStore cookieStore = new BasicCookieStore(); - // 从 AllMusic.cookie.cookieStore 加载 cookies - List storedCookies = AllMusic.cookie.cookieStore.get("music.163.com"); - if (storedCookies != null) { - for (MyCookie cookie : storedCookies) { - BasicClientCookie cookie1 = new BasicClientCookie(cookie.key, cookie.value); - cookie1.setExpiryDate(Instant.MAX); - cookie1.setDomain("163.com"); - cookieStore.addCookie(cookie1); - } + for (CookieObj cookie : AllMusic.cookie) { + BasicClientCookie cookie1 = new BasicClientCookie(cookie.name, cookie.value); + cookie1.setExpiryDate(Instant.MAX); + cookie1.setDomain(cookie.domain); + cookie1.setPath(cookie.path); + cookie1.setHttpOnly(cookie.hostOnly); + cookie1.setHttpOnly(cookie.httpOnly); + cookieStore.addCookie(cookie1); } return cookieStore; } private static void saveCookies(CookieStore cookieStore) { List cookies = cookieStore.getCookies(); - List list = new ArrayList<>(); for (Cookie cookie : cookies) { - MyCookie cookie1 = new MyCookie(); - cookie1.key = cookie.getName(); - cookie1.value = cookie.getValue(); - list.add(cookie1); + CookieObj obj = new CookieObj(); + obj.domain = cookie.getDomain(); + obj.hostOnly = cookie.isHttpOnly(); + obj.httpOnly = cookie.isHttpOnly(); + obj.name = cookie.getName(); + obj.value = cookie.getValue(); } - AllMusic.cookie.cookieStore.put("music.163.com", list); AllMusic.saveCookie(); } diff --git a/core/objs/CookieObj.java b/core/objs/CookieObj.java index b80fe201..770c2857 100644 --- a/core/objs/CookieObj.java +++ b/core/objs/CookieObj.java @@ -1,9 +1,11 @@ package com.coloryr.allmusic.server.core.objs; -import java.util.HashMap; -import java.util.List; - public class CookieObj { - public HashMap> cookieStore = new HashMap<>(); + public String domain; + public boolean hostOnly; + public boolean httpOnly; + public String name; + public String path; + public String value; } diff --git a/core/objs/MyCookie.java b/core/objs/MyCookie.java deleted file mode 100644 index eec3329b..00000000 --- a/core/objs/MyCookie.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.coloryr.allmusic.server.core.objs; - -public class MyCookie { - public String key; - public String value; -} diff --git a/version b/version index 678fd88a..084e244c 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.5.3 \ No newline at end of file +3.6.0 \ No newline at end of file