Skip to content

Commit

Permalink
Merge pull request #53 from timas130/sit/chinese-server
Browse files Browse the repository at this point in the history
feat: add support for chinese server
  • Loading branch information
Luzefiru authored Jun 6, 2024
2 parents 56da3b2 + aae3007 commit 218dbd4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/get-url.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
$gamePath - is the folder where Wuthering Waves is installed, the default folder is named "Wuthering Waves Game".
#>
$gamePath="C:\Program Files\Epic Games\WutheringWavesj3oFh\Wuthering Waves Game";
$logFile="$gamePath\Client\Saved\Logs\Client.log";if(-not(Test-Path $logFile)){Write-Host "`nThe file '$logFile' does not exist." -ForegroundColor Red;Write-Host "Did you set your Game Installation Path properly?" -ForegroundColor Magenta;Read-Host "Press any key to exit";exit}$latestUrlEntry=Get-Content $logFile|Select-String "https://aki-gm-resources-oversea.aki-game.net"|Select-Object -Last 1;if($null-ne $latestUrlEntry){$urlPattern='url":"(.*?)"';$url=[regex]::Match($latestUrlEntry.ToString(),$urlPattern).Groups[1].Value;if($url){Write-Host "`nConvene Record URL: $url";Set-Clipboard $url;Write-Host "`nURL copied to clipboard. Please paste to Wuwa Tracker and click the Import History button." -ForegroundColor Green}else{Write-Host "No URL found."}}else{Write-Host "`nNo matching entries found in the log file. Please open your Convene History first!" -ForegroundColor Red}
$logFile="$gamePath\Client\Saved\Logs\Client.log";if(-not(Test-Path $logFile)){Write-Host "`nThe file '$logFile' does not exist." -ForegroundColor Red;Write-Host "Did you set your Game Installation Path properly?" -ForegroundColor Magenta;Read-Host "Press any key to exit";exit}$latestUrlEntry=Get-Content $logFile|Select-String -Pattern "https://aki-gm-resources-oversea.aki-game.net|https://aki-gm-resources.aki-game.com"|Select-Object -Last 1;if($null-ne $latestUrlEntry){$urlPattern='url":"(.*?)"';$url=[regex]::Match($latestUrlEntry.ToString(),$urlPattern).Groups[1].Value;if($url){Write-Host "`nConvene Record URL: $url";Set-Clipboard $url;Write-Host "`nURL copied to clipboard. Please paste to Wuwa Tracker and click the Import History button." -ForegroundColor Green}else{Write-Host "No URL found."}}else{Write-Host "`nNo matching entries found in the log file. Please open your Convene History first!" -ForegroundColor Red}
2 changes: 1 addition & 1 deletion src/lib/createImportScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* @returns a string containing the script the user will paste & run into PowerShell
*/
export default function createImportScript(gamePath: string) {
return `$gamePath="${gamePath}";$logFile="$gamePath\\Client\\Saved\\Logs\\Client.log";if(-not(Test-Path $logFile)){Write-Host "\`nThe file '$logFile' does not exist." -ForegroundColor Red;Write-Host "Did you set your Game Installation Path properly?" -ForegroundColor Magenta;Read-Host "Press any key to exit";exit}$latestUrlEntry=Get-Content $logFile | Select-String "https://aki-gm-resources-oversea.aki-game.net" | Select-Object -Last 1;if($null -ne $latestUrlEntry){$urlPattern='url":"(.*?)"';$url=[regex]::Match($latestUrlEntry.ToString(),$urlPattern).Groups[1].Value;if($url){Write-Host"";Write-Host "Convene Record URL: $url";Set-Clipboard $url;Write-Host"";Write-Host "URL copied to clipboard. Please paste to Wuwa Tracker and click the Import History button." -ForegroundColor Green}else{Write-Host "No URL found."}}else{Write-Host "\`nNo matching entries found in the log file. Please open your Convene History first!" -ForegroundColor Red}`;
return `$gamePath="${gamePath}";$logFile="$gamePath\\Client\\Saved\\Logs\\Client.log";if(-not(Test-Path $logFile)){Write-Host "\`nThe file '$logFile' does not exist." -ForegroundColor Red;Write-Host "Did you set your Game Installation Path properly?" -ForegroundColor Magenta;Read-Host "Press any key to exit";exit}$latestUrlEntry=Get-Content $logFile | Select-String -Pattern "https://aki-gm-resources-oversea.aki-game.net|https://aki-gm-resources.aki-game.com" | Select-Object -Last 1;if($null -ne $latestUrlEntry){$urlPattern='url":"(.*?)"';$url=[regex]::Match($latestUrlEntry.ToString(),$urlPattern).Groups[1].Value;if($url){Write-Host"";Write-Host "Convene Record URL: $url";Set-Clipboard $url;Write-Host"";Write-Host "URL copied to clipboard. Please paste to Wuwa Tracker and click the Import History button." -ForegroundColor Green}else{Write-Host "No URL found."}}else{Write-Host "\`nNo matching entries found in the log file. Please open your Convene History first!" -ForegroundColor Red}`;
}
1 change: 1 addition & 0 deletions src/lib/extractGachaRecordQueryArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function extractGachaRecordQueryArgs(
playerId: parsedQueryArgs.player_id,
recordId: parsedQueryArgs.record_id,
serverId: parsedQueryArgs.svr_id,
serverArea: parsedQueryArgs.svr_area,
};

return GachaRecordQueryArgsSchema.parse(gachaRecordQueryArgs);
Expand Down
20 changes: 20 additions & 0 deletions src/lib/getServerUrlByArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ServerArea, ServerAreaEnum } from "@/types/ServerArea";

/**
* Returns the base upstream server URL for the specified server area.
*
* @example
* const area = ServerArea.global;
* const baseUrl = getServerUrlByArea(area); // https://gmserver-api.aki-game2.net
*
* @param area the server area
* @returns base URL for the area
*/
export default function getServerUrlByArea(area: ServerAreaEnum): string {
switch (area) {
case ServerArea.global:
return "https://gmserver-api.aki-game2.net";
case ServerArea.cn:
return "https://gmserver-api.aki-game2.com";
}
}
2 changes: 1 addition & 1 deletion src/lib/isValidConveneHistoryUrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function isValidConveneHistoryUrl(s: string) {
const conveneHistoryUrlRegex =
/^https:\/\/aki-gm-resources-oversea\.aki-game\.net\/aki\/gacha\/index\.html\#\/record\?(?=.*\bplayer_id=\w+\b)(?=.*\brecord_id=\w+\b)(?=.*\bsvr_id=\w+\b).*$/;
/^https:\/\/(?:aki-gm-resources-oversea\.aki-game\.net|aki-gm-resources\.aki-game\.com)\/aki\/gacha\/index\.html\#\/record\?(?=.*\bplayer_id=\w+\b)(?=.*\brecord_id=\w+\b)(?=.*\bsvr_id=\w+\b).*$/;
return conveneHistoryUrlRegex.test(s);
}
7 changes: 4 additions & 3 deletions src/services/fetchGachaRecordByCardPoolType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
GachaRecordQueryArgs,
} from "@/types/GachaRecordQuery";
import axios from "axios";
import getServerUrlByArea from "@/lib/getServerUrlByArea";

/**
* Fetches the gacha records of a cardPoolType given the `GachaRecordQueryArgs` fetched from a user's Convene History URL fetched from the game logs.
Expand Down Expand Up @@ -43,9 +44,9 @@ export default async function fetchGachaRecordByCardPoolType(
cardPoolType: number,
args: GachaRecordQueryArgs,
): Promise<GachaRecordQueryResult> {
// TODO: Consider decoupling this when this API endpoint is reused in multiple places
const BASE_URL = "https://gmserver-api.aki-game2.net";
const requestUrl = `${BASE_URL}/gacha/record/query`;
const baseUrl = getServerUrlByArea(args.serverArea);

const requestUrl = `${baseUrl}/gacha/record/query`;
const requestBody = {
cardPoolType: cardPoolType,
languageCode: args.languageCode,
Expand Down
2 changes: 2 additions & 0 deletions src/types/GachaRecordQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from "zod";
import { LanguageCodeEnumSchema } from "./LanguageCode";
import { ServerAreaEnumSchema } from "./ServerArea";

export const ResourceType = {
Resonators: "Resonators",
Expand All @@ -13,6 +14,7 @@ export const GachaRecordQueryArgsSchema = z.object({
playerId: z.string(),
recordId: z.string(),
serverId: z.string(),
serverArea: ServerAreaEnumSchema,
});
export type GachaRecordQueryArgs = z.infer<typeof GachaRecordQueryArgsSchema>;

Expand Down
11 changes: 11 additions & 0 deletions src/types/ServerArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

export const ServerArea = {
global: "global",
cn: "cn",
} as const;

export const ServerAreaEnumSchema = z
.nativeEnum(ServerArea)
.default(ServerArea.global);
export type ServerAreaEnum = z.infer<typeof ServerAreaEnumSchema>;

0 comments on commit 218dbd4

Please sign in to comment.