Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Android release

# Publishes Infinite Loop for Android <version> as the release android-v<version>. That tag is what the app's updater
# looks for (UpdateChecker.TAG_PREFIX), together with the assets Infinite-Loop.apk and SHA256SUMS. The release also
# carries Infinite-Loop-Android.zip, which the app's "Install server" / "Update Runtime" step downloads.
#
# The maintainer bumps versionName and versionCode in Scripts/android/launcher/app/build.gradle.kts in a commit
# first; this workflow refuses to run when versionName and the input disagree. Run it from the default branch.
#
# Repository secrets (Settings > Secrets and variables > Actions) — the SAME signing key as earlier releases, because
# Android refuses to update an app that is signed with a different key:
# ASCNET_KEYSTORE_BASE64 the release keystore, base64 encoded on one line
# ASCNET_KEYSTORE_PASSWORD
# ASCNET_KEY_ALIAS
# ASCNET_KEY_PASSWORD
on:
workflow_dispatch:
inputs:
version:
description: "Android app version, e.g. 0.4.0 (must equal versionName); the release tag is android-v<version>"
required: true
type: string
notes:
description: "Release notes (optional)"
required: false
type: string
default: ""

permissions:
contents: read

concurrency:
group: android-release
cancel-in-progress: false

env:
VERSION: ${{ inputs.version }}
# The built app updates from the repository that publishes it, so no edit of gradle.properties is needed here or in a fork.
ORG_GRADLE_PROJECT_updateRepository: ${{ github.repository }}

jobs:
# The two native pieces of the on-device runtime are built here, not committed: the detector as a static musl binary (it
# also runs under Android's shell) and UnityPy's extension for CPython 3.12 on Linux ARM64, which PyPI does not ship.
# Termux's Ubuntu 24.04 guest has the same glibc as this runner image.
arm-runtime:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v5

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Build the mod detector
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends musl-tools
rustup target add aarch64-unknown-linux-musl
cargo build --release --locked --manifest-path Scripts/android/moddetect/Cargo.toml --target aarch64-unknown-linux-musl
mkdir -p runtime
cp Scripts/android/moddetect/target/aarch64-unknown-linux-musl/release/ascnet-moddetect runtime/moddetect-aarch64
# Static: no dynamic loader, so it runs wherever the phone's kernel does.
! readelf -l runtime/moddetect-aarch64 | grep -q INTERP

- name: Build the UnityPy wheel
run: |
set -euo pipefail
python -m pip install --upgrade pip setuptools wheel
mkdir -p runtime/wheels
python -m pip wheel --no-deps --no-binary UnityPy "UnityPy==1.25.2" -w runtime/wheels
test -s runtime/wheels/unitypy-1.25.2-cp312-cp312-linux_aarch64.whl

- uses: actions/upload-artifact@v4
with:
name: android-runtime
path: runtime
if-no-files-found: error

release:
needs: arm-runtime
# pack.ps1 finds apksigner.bat, so it needs a Windows runner.
runs-on: windows-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5

- name: Check version, branch, tag and secrets
shell: bash
env:
GH_TOKEN: ${{ github.token }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
KEYSTORE_BASE64: ${{ secrets.ASCNET_KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.ASCNET_KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.ASCNET_KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.ASCNET_KEY_PASSWORD }}
run: |
set -euo pipefail
[[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){1,3}$ ]] || { echo "version must look like 0.4.0"; exit 1; }
[ "$GITHUB_REF_NAME" = "$DEFAULT_BRANCH" ] || { echo "run from $DEFAULT_BRANCH, not $GITHUB_REF_NAME"; exit 1; }
name="$(sed -n 's/^ *versionName = "\(.*\)"$/\1/p' Scripts/android/launcher/app/build.gradle.kts | head -n 1)"
echo "input=$VERSION versionName=$name"
[ "$name" = "$VERSION" ] || { echo "versionName is $name: bump build.gradle.kts in a commit first"; exit 1; }
missing=""
for secret in KEYSTORE_BASE64 KEYSTORE_PASSWORD KEY_ALIAS KEY_PASSWORD; do
[ -n "${!secret}" ] || missing="$missing ASCNET_$secret"
done
[ -z "$missing" ] || { echo "missing repository secrets:$missing (see the comment at the top of this workflow)"; exit 1; }
if gh release view "android-v$VERSION" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "release android-v$VERSION already exists"; exit 1
fi

- uses: actions/download-artifact@v4
with:
name: android-runtime
path: Scripts/android/runtime

- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "17"

- uses: actions/setup-dotnet@v5
with:
dotnet-version: "8.0.x"

- name: Build, sign and package
shell: pwsh
env:
KEYSTORE_BASE64: ${{ secrets.ASCNET_KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.ASCNET_KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.ASCNET_KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.ASCNET_KEY_PASSWORD }}
run: |
$keystore = Join-Path $env:RUNNER_TEMP 'release.jks'
[IO.File]::WriteAllBytes($keystore, [Convert]::FromBase64String($env:KEYSTORE_BASE64))
$env:ASCNET_KEYSTORE = $keystore
$env:ASCNET_KEYSTORE_PASSWORD = $env:KEYSTORE_PASSWORD
$env:ASCNET_KEY_ALIAS = $env:KEY_ALIAS
$env:ASCNET_KEY_PASSWORD = $env:KEY_PASSWORD
try {
& ./Scripts/android/pack.ps1 -OutputDirectory dist
} finally {
Remove-Item -Force -ErrorAction SilentlyContinue $keystore
}

- name: Check the packaged files
shell: bash
run: |
set -euo pipefail
for f in Infinite-Loop.apk SHA256SUMS Infinite-Loop-Android.zip; do
[ -s "dist/$f" ] || { echo "dist/$f is missing"; exit 1; }
done
# pack.ps1 writes the manifest with CRLF on Windows; the app and update-runtime.sh both accept that.
tr -d '\r' < dist/SHA256SUMS > sums.txt
grep -q ' Infinite-Loop.apk$' sums.txt && grep -q ' Infinite-Loop-Android.zip$' sums.txt \
|| { echo "SHA256SUMS does not list the APK and the zip"; exit 1; }
(cd dist && sha256sum -c ../sums.txt)

- name: Create the release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
NOTES: ${{ inputs.notes }}
run: |
set -euo pipefail
notes="${NOTES:-Infinite Loop for Android $VERSION}"
# Not "latest": the desktop launcher's release check reads releases/latest.
gh release create "android-v$VERSION" dist/Infinite-Loop.apk dist/SHA256SUMS dist/Infinite-Loop-Android.zip \
--repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --title "Infinite Loop for Android $VERSION" \
--notes "$notes" --latest=false

- name: Verify the release is what the updater expects
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
sleep 5
gh release view "android-v$VERSION" --repo "$GITHUB_REPOSITORY" --json tagName,isDraft,isPrerelease,assets > release.json
jq -e --arg tag "android-v$VERSION" '.tagName == $tag and .isDraft == false and .isPrerelease == false' release.json
for f in Infinite-Loop.apk SHA256SUMS Infinite-Loop-Android.zip; do
jq -e --arg f "$f" '[.assets[] | select(.name == $f)] | length == 1' release.json
done
3 changes: 2 additions & 1 deletion .github/workflows/server-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ jobs:
--character-progression-compat-only \
--inventory-equip-compat-only \
--guild-core-compat-only \
--login-account-compat-only; do
--login-account-compat-only \
--android-compat-only; do
echo "::group::AscNet.Test $sw"
dotnet AscNet.Test.dll "$sw"
echo "::endgroup::"
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ AscNet.Launcher/target/
AscNet.Patch/target/
AscNet.Patch/VersionShim/bin/
AscNet.Patch/VersionShim/obj/
Scripts/android/moddetect/target/
Scripts/android/runtime/moddetect-aarch64
Scripts/android/runtime/wheels/*.whl
Scripts/android/runtime/rish/rish_shizuku.dex

# macOS metadata
.DS_Store
Expand Down
5 changes: 5 additions & 0 deletions AscNet.Common/Database/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class Account
return collection.AsQueryable().FirstOrDefault(x => x.Username == username);
}

public static List<string> Usernames()
{
return collection.AsQueryable().Select(x => x.Username).ToList();
}

public static Account? FromUsername(string username, string password)
{
Account? account = FromUsername(username);
Expand Down
60 changes: 47 additions & 13 deletions AscNet.Common/Util/ClientRegions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Text.RegularExpressions;

namespace AscNet.Common.Util;

Expand All @@ -14,26 +15,59 @@ public static class ClientRegions
{
public const string Default = "en";
public static readonly string[] GateRegions = ["tw", "kr", "jp", "cn"];
private static readonly ConcurrentDictionary<string, string> byPlayerToken = new();
public static IEnumerable<string> AndroidGateRegions => GateRegions.Prepend(Default);
private static readonly ConcurrentDictionary<string, (string Region, bool IsAndroid)> byPlayerToken = new();

public static void Remember(string playerToken, string region) => byPlayerToken[playerToken] = region;
public static void Remember(string playerToken, string region, bool isAndroid = false) =>
byPlayerToken[playerToken] = (region, isAndroid);

public static string? Recall(string playerToken) => byPlayerToken.GetValueOrDefault(playerToken);
public static string? Recall(string playerToken) => byPlayerToken.TryGetValue(playerToken, out var profile) ? profile.Region : null;
public static bool IsAndroid(string playerToken) => byPlayerToken.TryGetValue(playerToken, out var profile) && profile.IsAndroid;
public static bool IsAndroidGatePath(string? path) => AndroidRegionFromGate(path) is not null;
public static string? AndroidRegionFromPackage(string? package) => RegionOfPackage(package);

/// <summary>The region of an SDK package id; null for EN (and unknown packages, which keep the shared EN tables).</summary>
public static string? FromPackage(string? package) => package switch
public static string? FromPackage(string? package)
{
"com.kurogame.punishing.grayraven.tw" => "tw",
"com.kurogame.punishing.grayraven.kr" => "kr",
"com.kurogame.punishing.grayraven.jp" => "jp",
"com.kurogame.haru.kuro" or "com.kurogame.haru.hero" => "cn",
_ => null
};
string? region = RegionOfPackage(package);
return region == Default ? null : region;
}

// The region is the id's suffix, not a fixed list: store builds of one region differ only in the prefix (Google Play adds
// ".gplay.", JP's uses the herogame publisher). Keep identical to Scripts/android/relay.py and launcher ClientPackages.java.
private static readonly Regex PackagePattern = new(
@"\Acom\.(?:kurogame|herogame)\.(?:gplay\.)?(?:punishing\.grayraven\.(?<region>en|jp|tw|kr)|haru\.(?:kuro|hero))\z",
RegexOptions.CultureInvariant);

private static string? RegionOfPackage(string? package)
{
if (package is null) return null;
Match match = PackagePattern.Match(package);
if (!match.Success) return null;
return match.Groups["region"].Success ? match.Groups["region"].Value : "cn";
}

/// <summary>The gate path's region: <c>/api/Login/Login-tw</c> is "tw", plain <c>/api/Login/Login</c> is EN.</summary>
public static string FromGatePath(string? path) =>
path is not null && path.StartsWith(GatePrefix, StringComparison.Ordinal) && GateRegions.Contains(path[GatePrefix.Length..])
? path[GatePrefix.Length..] : Default;
public static string FromGatePath(string? path)
{
string? suffix = path?.TrimEnd('/');
string? androidRegion = AndroidRegionFromGate(suffix);
if (androidRegion is not null) return androidRegion;
return suffix is not null && suffix.StartsWith(GatePrefix, StringComparison.Ordinal) && GateRegions.Contains(suffix[GatePrefix.Length..])
? suffix[GatePrefix.Length..] : Default;
}

private static string? AndroidRegionFromGate(string? path)
{
const string platformSuffix = "-android";
string? route = path?.TrimEnd('/');
if (route is null || route.Length <= GatePrefix.Length + platformSuffix.Length
|| !route.StartsWith(GatePrefix, StringComparison.OrdinalIgnoreCase)
|| !route.EndsWith(platformSuffix, StringComparison.OrdinalIgnoreCase))
return null;
string region = route[GatePrefix.Length..^platformSuffix.Length].ToLowerInvariant();
return AndroidGateRegions.Contains(region) ? region : null;
}

private const string GatePrefix = "/api/Login/Login-";
}
15 changes: 13 additions & 2 deletions AscNet.GameServer/Handlers/AccountModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public static void LoginRequestHandler(Session session, Packet.Request packet)
}

session.player = player;
session.IsAndroidClient = ClientRegions.IsAndroid(player.Token);
(session.character, session.stage, session.inventory) = LoadPlayerCollections(player.PlayerData.Id, player.GatherRewards);
savePlayer |= player.NormalizeEquipReferences(session.character.Equips.Select(equip => equip.Id).ToHashSet());
if (savePlayer)
Expand Down Expand Up @@ -368,6 +369,8 @@ public static void ReconnectRequestHandler(Session session, Packet.Request packe
player.Save();
}

if (session.player is null)
session.IsAndroidClient = ClientRegions.IsAndroid(player.Token);
session.player = player;
session.ContinuePushSequenceFrom(request.LastMsgSeqNo);
session.SendResponse(new ReconnectResponse
Expand Down Expand Up @@ -545,7 +548,7 @@ internal static NotifyBriefStoryData BuildNotifyBriefStoryData(Player player)

internal static void SendLoginState(Session session)
{
session.SendPush(BuildNotifyLogin(session));
SendNotifyLogin(session, BuildNotifyLogin(session));
}

private static TimeLimitCtrlConfigList MakeTimeLimitControl(long id, long startTime, long endTime)
Expand Down Expand Up @@ -753,6 +756,14 @@ private static List<dynamic> BuildPurchaseClientInfoLoginData(Player player)
.ToList();
}

private static void SendNotifyLogin(Session session, NotifyLogin payload)
{
if (session.IsAndroidClient)
session.SendPush("NotifyLogin", AndroidNotifyLoginSerializer.Serialize(payload, isAndroid: true));
else
session.SendPush(payload);
}

private static NotifyLogin BuildNotifyLogin(Session session) =>
BuildNotifyLogin(session, DateTimeOffset.UtcNow.ToUnixTimeSeconds());

Expand Down Expand Up @@ -1384,7 +1395,7 @@ static void DoLogin(Session session, bool updateLoginAccounting)
NotifyPurchaseRecommendConfig purchaseRecommendConfig = BuildPurchaseRecommendConfig();
// Seed the manual before NotifyLogin fires login-complete; the late full push refreshes Lotto/Purchase after cache initialization.
session.SendPush(WheelchairManualModule.BuildPayload(session, DateTimeOffset.UtcNow));
session.SendPush(notifyLogin);
SendNotifyLogin(session, notifyLogin);
if (headTimeout is not null)
session.SendPush(headTimeout);
session.SendPush(notifyPayInfo);
Expand Down
Loading
Loading