Skip to content

Commit

Permalink
-新增游戏状态用于修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
WuYi5451 committed Jan 20, 2025
1 parent 42b1676 commit e3b137d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/main/java/helper/ClientStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/helper/cache/GameDataCache.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper.cache;

import helper.bo.*;
import helper.exception.NoProcessException;
import helper.utils.ProcessUtil;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/helper/enums/GameStatusEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public enum GameStatusEnum {
* 等待结算页面
*/
WaitingForStats,
/**
* 终止
*/
TerminatedInError,
/**
* 游戏结束
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/helper/enums/WSSEventEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package helper.enums;

import helper.services.wss.ChampSelectData;
import lombok.Getter;

import java.util.Arrays;
Expand All @@ -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;

Expand Down
14 changes: 3 additions & 11 deletions src/main/java/helper/http/RequestSgpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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 "";
}
Expand All @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/helper/services/sgp/RegionSgpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
7 changes: 7 additions & 0 deletions src/main/java/helper/services/wss/WSSEventTrigger.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/helper/utils/ProcessUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}

}

0 comments on commit e3b137d

Please sign in to comment.