Skip to content

Commit eec457a

Browse files
authored
fix(msmp): add checks for browser target
1 parent e9817c1 commit eec457a

16 files changed

Lines changed: 108 additions & 24 deletions

File tree

.github/pr_assignment_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
addReviewers: true
2+
reviewers:
3+
- Aliorpse
4+
numberOfReviewers: 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: PR Assignment
2+
on:
3+
pull_request:
4+
types: [opened, ready_for_review]
5+
6+
jobs:
7+
add-reviews:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: kentaro-m/[email protected]
11+
with:
12+
configuration-path: ".github/pr_assignment_config.yml"
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
name: PR Validation
1+
name: PR ABI Validation
22

33
on:
4-
pull_request:
5-
branches: [ main ]
4+
pull_request_review:
5+
types: [submitted]
66

77
jobs:
88
validate:
9+
if: github.event.review.state == 'approved'
910
runs-on: ubuntu-latest
1011

1112
steps:
1213
- uses: actions/checkout@v4
14+
with:
15+
ref: ${{ github.event.pull_request.head.sha }}
1316

14-
- name: Grant execute permission to gradlew
15-
run: chmod +x ./gradlew
17+
- name: Check Review Status
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const { data: reviews } = await github.rest.pulls.listReviews({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
pull_number: context.payload.pull_request.number,
25+
});
26+
27+
const latestReviews = {};
28+
reviews.forEach(r => {
29+
latestReviews[r.user.login] = r.state;
30+
});
31+
32+
const states = Object.values(latestReviews);
33+
const allApproved = states.every(state => state === 'APPROVED') && states.length > 0;
34+
35+
if (!allApproved) {
36+
console.log("Skipping ABI validation because not all reviewers approved.");
37+
process.exit(0);
38+
}
1639
1740
- name: Set up JDK
1841
uses: actions/setup-java@v4
@@ -21,5 +44,8 @@ jobs:
2144
java-version: 21
2245
cache: 'gradle'
2346

47+
- name: Grant execute permission
48+
run: chmod +x ./gradlew
49+
2450
- name: ABI Validation
2551
run: ./gradlew checkLegacyAbi -Pfull-build=true --no-configuration-cache

CONTRIBUTING.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ Welcome to contribute to this project! To ensure an effective collaboration, ple
44

55
## Pull Requests
66

7-
- Open an issue to discuss changes before coding.
8-
- Fork the repository and create a new branch named like "feat/my-feature".
9-
- Write your codes and tests in the new branch.
10-
- Follow [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html).
11-
- add `Pfull-build=true` to abi-validating related tasks.
12-
- run `./gradlew checkLegacyAbi` to check your changes. If including a breaking change, run `./gradlew updateLegacyAbi`.
13-
- Use concise, descriptive PR titles with prefixes like `feat:` or `fix:`.
14-
- Link PRs to issues with `Closes #xx`.
15-
- Create a pull request to the `main` branch.
7+
1. Open an issue to discuss changes.
8+
2. Fork the repository and create a new branch named like `feat/my-feature`, code in it.
9+
3. add `Pfull-build=true` to abi-validating related tasks, for full build is disabled to boost dev build speed.
10+
4. run `./gradlew checkLegacyAbi` to check your changes. If including a breaking change, run `./gradlew updateLegacyAbi`.
11+
5. When creating PR, use a concise, descriptive PR title with prefixes like `feat:` or `fix:`.Please open the PR against the `main` branch.
12+
13+

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# mcutils
22

33
[![CodeFactor](https://www.codefactor.io/repository/github/aliorpse/mcutils/badge)](https://www.codefactor.io/repository/github/aliorpse/mcutils)
4-
[![Maven Central](https://maven-badges.sml.io/sonatype-central/tech.aliorpse.mcutils/mcutils-shared/badge.svg)](https://central.sonatype.com/artifact/tech.aliorpse.mcutils/mcutils-shared)
4+
![Maven Central](https://maven-badges.sml.io/sonatype-central/tech.aliorpse.mcutils/mcutils-shared/badge.svg)
55
[![View on DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Aliorpse/mcutils)
66

7-
A Kotlin multiplatform library provides utility functions for Minecraft-related queries.
7+
mcutils is a lightweight **Kotlin Multiplatform** library for Minecraft Java related queries, such as server
8+
ping/management, fetching player profile, etc.
9+
10+
## Supported platforms
11+
12+
* **Kotlin/JVM**
13+
* **Kotlin/JS, WasmJS** on
14+
* nodejs
15+
* browser *(except modules that depend on ktor-network, see [build.gradle.kts](build.gradle.kts) for more details)*
16+
* **Kotlin/Native** on
17+
* linuxX64 (X64/Arm64)
18+
* mingw (X64)
19+
* ios (X64/Arm64)
20+
* iosSimulator (Arm64)
21+
* macos (X64/Arm64)
22+
* androidNative (X64/Arm64)
823

924
## Modules
1025

@@ -13,4 +28,9 @@ A Kotlin multiplatform library provides utility functions for Minecraft-related
1328
- [Remote Console (RCON)](mcutils-rcon/README.md): Execute commands remotely on the server.
1429
- [Player Profile](mcutils-player/README.md): Retrieve player UUIDs and profiles.
1530

16-
Check out the project's [dokka](https://aliorpse.github.io/mcutils/) for the full API reference.
31+
Click on the links for module-specific documents, or check out the project's [dokka](https://aliorpse.github.io/mcutils/) for the full API reference.
32+
33+
34+
## Contributing
35+
36+
Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for more details.

mcutils-msmp/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Minecraft Server Management Protocol (MSMP)
22

3-
`tech.aliorpse.mcutils:mcutils-msmp:$version`
3+
`tech.aliorpse.mcutils:mcutils-msmp`
44

55
> [!tip]
66
> This module requires a Ktor client engine (e.g., `ktor-client-cio`).
@@ -29,7 +29,8 @@ client.use { client ->
2929
val players = client.players.get()
3030
println("Online players: ${players.size}")
3131

32-
// Await client to be closed (e.g., server stopping or manual close)
32+
// Wait for the client to close (e.g., server stopping or manual close)
33+
// You could use `coroutineScope { ... }` for the same effect, but you know it will add an indentation level.
3334
client.await()
3435
}
3536
```
@@ -76,7 +77,7 @@ client.on<PlayerJoinedEvent> {
7677
val event = client.awaitEvent<ServerStartedEvent>()
7778
```
7879

79-
You don't need to re-register listeners after reconnection. eventFlow will be empty when reconnecting.
80+
Note: Event subscriptions persist across reconnections, but no events are buffered during the disconnected period.
8081

8182
### Lifecycle
8283

mcutils-msmp/src/commonMain/kotlin/tech/aliorpse/mcutils/internal/MsmpLifecycleManager.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import tech.aliorpse.mcutils.api.MsmpState
3030
import tech.aliorpse.mcutils.entity.ServerStoppingEvent
3131
import tech.aliorpse.mcutils.internal.util.DispatchersIO
3232
import tech.aliorpse.mcutils.internal.util.WebSocketClientProvider.webSocketClient
33+
import tech.aliorpse.mcutils.internal.util.isBrowser
3334
import kotlin.math.min
3435
import kotlin.math.pow
3536
import kotlin.random.Random
@@ -143,7 +144,11 @@ internal class MsmpLifecycleManager(
143144
*/
144145
private suspend fun connectSession(): Boolean = coroutineScope {
145146
val session = webSocketClient.webSocketSession(target) {
146-
header(HttpHeaders.Authorization, "Bearer $token")
147+
if (isBrowser) {
148+
header(HttpHeaders.SecWebSocketProtocol, "minecraft-v1,$token")
149+
} else {
150+
header(HttpHeaders.Authorization, "Bearer $token")
151+
}
147152
timeout { connectTimeoutMillis = config.connectTimeout }
148153
}
149154

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package tech.aliorpse.mcutils.internal.util
2+
3+
internal expect val isBrowser: Boolean
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package tech.aliorpse.mcutils.internal.util
2+
3+
internal actual val isBrowser: Boolean =
4+
js("typeof window !== 'undefined' && typeof window.document !== 'undefined'")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package tech.aliorpse.mcutils.internal.util
2+
3+
internal actual val isBrowser: Boolean = false

0 commit comments

Comments
 (0)