From e3b137d8b38ebc188b6e73c444deab9f87ab3a61 Mon Sep 17 00:00:00 2001 From: WuYi Date: Mon, 20 Jan 2025 18:38:06 +0800 Subject: [PATCH] =?UTF-8?q?-=E6=96=B0=E5=A2=9E=E6=B8=B8=E6=88=8F=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=94=A8=E4=BA=8E=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/helper/ClientStarter.java | 10 ++++- src/main/java/helper/cache/GameDataCache.java | 10 ++++- .../java/helper/enums/GameStatusEnum.java | 4 ++ src/main/java/helper/enums/WSSEventEnum.java | 4 +- src/main/java/helper/http/RequestSgpUtil.java | 14 ++---- .../helper/services/sgp/RegionSgpApi.java | 22 +++++++++ .../helper/services/wss/WSSEventTrigger.java | 7 +++ src/main/java/helper/utils/ProcessUtil.java | 45 +++++++++++++++++++ 8 files changed, 101 insertions(+), 15 deletions(-) diff --git a/src/main/java/helper/ClientStarter.java b/src/main/java/helper/ClientStarter.java index 501039d..6b451ee 100644 --- a/src/main/java/helper/ClientStarter.java +++ b/src/main/java/helper/ClientStarter.java @@ -23,7 +23,10 @@ public class ClientStarter { public void initLcu() throws Exception { LeagueClientBO leagueClientBO = ProcessUtil.getClientProcess(); if (leagueClientBO.equals(new LeagueClientBO())) { - throw new NoProcessException(); + leagueClientBO = ProcessUtil.getClientProcessByWmic(); + if(leagueClientBO.equals(new LeagueClientBO())){ + throw new NoProcessException(); + } } RequestLcuUtil requestUtil = new RequestLcuUtil(leagueClientBO); AppCache.api = new LinkLeagueClientApi(requestUtil); @@ -32,7 +35,10 @@ public void initLcu() throws Exception { public void initSgp() throws Exception { LeagueClientBO leagueClientBO = ProcessUtil.getClientProcess(); if (leagueClientBO.equals(new LeagueClientBO())) { - throw new NoProcessException(); + leagueClientBO = ProcessUtil.getClientProcessByWmic(); + if(leagueClientBO.equals(new LeagueClientBO())){ + throw new NoProcessException(); + } } if (AppCache.api == null) { throw new NoLcuApiException(); diff --git a/src/main/java/helper/cache/GameDataCache.java b/src/main/java/helper/cache/GameDataCache.java index 909dc2f..3ccf177 100644 --- a/src/main/java/helper/cache/GameDataCache.java +++ b/src/main/java/helper/cache/GameDataCache.java @@ -1,6 +1,7 @@ package helper.cache; import helper.bo.*; +import helper.exception.NoProcessException; import helper.utils.ProcessUtil; import lombok.extern.slf4j.Slf4j; @@ -141,7 +142,14 @@ public static void cacheSelectGameMode() { public static void cacheLeagueClient() { try { - leagueClient = ProcessUtil.getClientProcess(); + LeagueClientBO leagueClientBO = ProcessUtil.getClientProcess(); + if (leagueClientBO.equals(new LeagueClientBO())) { + leagueClientBO = ProcessUtil.getClientProcessByWmic(); + if (leagueClientBO.equals(new LeagueClientBO())) { + throw new NoProcessException(); + } + } + leagueClient = leagueClientBO; } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/helper/enums/GameStatusEnum.java b/src/main/java/helper/enums/GameStatusEnum.java index 3d56969..1752820 100644 --- a/src/main/java/helper/enums/GameStatusEnum.java +++ b/src/main/java/helper/enums/GameStatusEnum.java @@ -42,6 +42,10 @@ public enum GameStatusEnum { * 等待结算页面 */ WaitingForStats, + /** + * 终止 + */ + TerminatedInError, /** * 游戏结束 */ diff --git a/src/main/java/helper/enums/WSSEventEnum.java b/src/main/java/helper/enums/WSSEventEnum.java index 8571883..7155492 100644 --- a/src/main/java/helper/enums/WSSEventEnum.java +++ b/src/main/java/helper/enums/WSSEventEnum.java @@ -1,5 +1,6 @@ package helper.enums; +import helper.services.wss.ChampSelectData; import lombok.Getter; import java.util.Arrays; @@ -12,8 +13,9 @@ public enum WSSEventEnum { //MATCHMAKING_READY("OnJsonApiEvent_lol-matchmaking_v1_ready-check", MatchmakingReadyData.class, "Update"), // GAMEFLOW_SESSION("OnJsonApiEvent_lol-gameflow_v1_session", GameflowSessionUpdateData.class, "Update"), - GAMEFLOW_PHASE("OnJsonApiEvent_lol-gameflow_v1_gameflow-phase", String.class, "Update"); + GAMEFLOW_PHASE("OnJsonApiEvent_lol-gameflow_v1_gameflow-phase", String.class, "Update"), //CHAMP_SELECT("OnJsonApiEvent_lol-champ-select_v1_session", ChampSelectData.class, "Update"); + SGP_TOKEN("OnJsonApiEvent_entitlements_v1_token",String.class, "Update"); private Class data; diff --git a/src/main/java/helper/http/RequestSgpUtil.java b/src/main/java/helper/http/RequestSgpUtil.java index a2ec69d..dcf5ed4 100644 --- a/src/main/java/helper/http/RequestSgpUtil.java +++ b/src/main/java/helper/http/RequestSgpUtil.java @@ -59,7 +59,7 @@ private void addRequestLog() { }).build(); } - private void buildSgpHeaders(String token) { + public void buildSgpHeaders(String token) { defaultHeaders = new HashMap<>(1); defaultHeaders.put("Authorization", "Bearer " + token); client = HttpClient.newInstance().newBuilder().addInterceptor(chain -> { @@ -76,11 +76,7 @@ public String callString(Request request) throws IOException { if (response.code() == 200) { return body.string(); } else if (response.code() == 401) { - String sgpAccessToken = AppCache.api.getSgpAccessToken(); - buildSgpHeaders(sgpAccessToken); - String twiceCall = this.callString(request); - buildNewToken(sgpAccessToken); - return twiceCall; + log.error("401"); } return ""; } @@ -91,11 +87,7 @@ public byte[] callStream(Request request) throws IOException { if (response.code() == 200) { return body.bytes(); } else if (response.code() == 401) { - String sgpAccessToken = AppCache.api.getSgpAccessToken(); - buildSgpHeaders(sgpAccessToken); - byte[] twiceCall = callStream(request); - buildNewToken(sgpAccessToken); - return twiceCall; + log.error("401"); } return null; } diff --git a/src/main/java/helper/services/sgp/RegionSgpApi.java b/src/main/java/helper/services/sgp/RegionSgpApi.java index 21e65d1..104e19a 100644 --- a/src/main/java/helper/services/sgp/RegionSgpApi.java +++ b/src/main/java/helper/services/sgp/RegionSgpApi.java @@ -217,11 +217,25 @@ public SgpSummonerInfoBo getSummerInfoByPuuid(String region, String puuid) throw return null; } + /** + * 获取回放文件 人多的大区获取不了 + * @param region + * @param gameId + * @return + * @throws IOException + */ public byte[] getReplay(String region, Long gameId) throws IOException { String endpoint = "/match-history-query/v3/product/lol/matchId/" + region + "_" + gameId + "/infoType/replay"; return requestSpgUtil.doGetByte(endpoint, region); } + /** + * 获取当前房间的模式 + * @param region + * @param puuid + * @return + * @throws IOException + */ public Integer getPartiesLedgeQueueId(String region, String puuid) throws IOException { String endpoint = "/parties-ledge/v1/players/" + puuid; String req = requestSpgUtil.doGet(endpoint, region); @@ -234,4 +248,12 @@ public Integer getPartiesLedgeQueueId(String region, String puuid) throws IOExce } return json.getJSONObject("currentParty").getJSONObject("gameMode").getInteger("queueId"); } + + /** + * 设置sgp的token + * @param sgpToken + */ + public void SetSgpToken(String sgpToken){ + this.requestSpgUtil.buildSgpHeaders(sgpToken); + } } diff --git a/src/main/java/helper/services/wss/WSSEventTrigger.java b/src/main/java/helper/services/wss/WSSEventTrigger.java index c3adb61..52014e0 100644 --- a/src/main/java/helper/services/wss/WSSEventTrigger.java +++ b/src/main/java/helper/services/wss/WSSEventTrigger.java @@ -1,5 +1,7 @@ package helper.services.wss; +import com.alibaba.fastjson2.JSONObject; +import helper.cache.AppCache; import helper.enums.GameStatusEnum; import helper.enums.WSSEventEnum; import helper.services.strategy.StrategyStarter; @@ -21,6 +23,11 @@ public static void eventRun(WSSEventEnum eventEnum, String data) { log.error(e.getMessage()); } break; + case SGP_TOKEN: + JSONObject json = JSONObject.parseObject(data); + String sgpToken = json.getString("accessToken"); + AppCache.sgpApi.SetSgpToken(sgpToken); + break; default: break; } diff --git a/src/main/java/helper/utils/ProcessUtil.java b/src/main/java/helper/utils/ProcessUtil.java index acf0fdd..e590c44 100644 --- a/src/main/java/helper/utils/ProcessUtil.java +++ b/src/main/java/helper/utils/ProcessUtil.java @@ -56,4 +56,49 @@ public static LeagueClientBO getClientProcess() throws IOException { return leagueClientBO; } + /** + * 通过进程名查询出进程的启动命令,解析出需要的客户端token和端口 + */ + public static LeagueClientBO getClientProcessByWmic() throws IOException { + String cmd = "WMIC PROCESS WHERE \"name='LeagueClientUx.exe'\" GET commandline"; + BufferedReader reader = null; + Process process = null; + LeagueClientBO leagueClientBO = new LeagueClientBO(); + try { + process = Runtime.getRuntime().exec(cmd); + // windows 命令必须gbk编码 + reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "gb2312")); + String line; + + while ((line = reader.readLine()) != null) { + Matcher appPortMatcher = appPortPattern.matcher(line); + Matcher tokenPatternMatcher = tokenPattern.matcher(line); + Matcher reginPatternMatcher = reginPattern.matcher(line); + if (tokenPatternMatcher.find()) { + leagueClientBO.setToken(tokenPatternMatcher.group(1)); + } + if (appPortMatcher.find()) { + leagueClientBO.setPort(appPortMatcher.group(1)); + } + if (reginPatternMatcher.find()) { + leagueClientBO.setRegion(reginPatternMatcher.group(1)); + } + } + return leagueClientBO; + } finally { + if (reader != null) { + try { + reader.close(); + } catch (Exception e) { + log.error("查询lol进程失败", e); + } + } + if (process != null) { + process.getErrorStream().close(); + process.getOutputStream().close(); + } + } + + } + }