Skip to content

Commit

Permalink
Merge branch 'master' into feature/manager
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jun 30, 2024
2 parents 86e69ff + 43b4e1a commit 4e95f36
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 25 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,24 @@ jobs:
with:
java-version: 17
distribution: temurin
- name: Get previous build number
id: getPreviousBuild
run: |
PREVIOUS_TAG=$(git for-each-ref --sort=-version:refname --count 1 --format="%(refname:short)" "refs/tags/*")
echo result=${PREVIOUS_TAG} >> $GITHUB_OUTPUT
- name: Get current build number
id: getCurrentBuild
if: success()
env:
PREVIOUS_BUILD: ${{ steps.getPreviousBuild.outputs.result }}
run: echo result=$((++PREVIOUS_BUILD)) >> $GITHUB_OUTPUT
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
gradle-home-cache-cleanup: true
env:
BUILD_NUMBER: ${{ steps.getCurrentBuild.outputs.result }}
- uses: actions/upload-artifact@v3
if: success()
with:
Expand All @@ -45,17 +58,6 @@ jobs:
name: MCXboxBroadcastStandalone
path: bootstrap/standalone/build/libs/MCXboxBroadcastStandalone.jar
if-no-files-found: error
- name: Get previous build number
id: getPreviousBuild
run: |
PREVIOUS_TAG=$(git for-each-ref --sort=-version:refname --count 1 --format="%(refname:short)" "refs/tags/*")
echo result=${PREVIOUS_TAG} >> $GITHUB_OUTPUT
- name: Get current build number
id: getCurrentBuild
if: success()
env:
PREVIOUS_BUILD: ${{ steps.getPreviousBuild.outputs.result }}
run: echo result=$((++PREVIOUS_BUILD)) >> $GITHUB_OUTPUT
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
Expand Down
11 changes: 11 additions & 0 deletions bootstrap/geyser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ dependencies {
compileOnly(libs.bundles.geyser)
}

sourceSets {
main {
blossom {
val info = GitInfo(indraGit)
resources {
property("version", info.version)
}
}
}
}

nameJar("MCXboxBroadcastExtension")

description = "bootstrap-geyser"
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rtm516.mcxboxbroadcast.bootstrap.geyser;

import com.rtm516.mcxboxbroadcast.core.BuildData;
import com.rtm516.mcxboxbroadcast.core.Logger;
import com.rtm516.mcxboxbroadcast.core.SessionInfo;
import com.rtm516.mcxboxbroadcast.core.SessionManager;
Expand Down Expand Up @@ -97,6 +98,15 @@ public void onCommandDefine(GeyserDefineCommandsEvent event) {
}
})
.build());

event.register(Command.builder(this)
.source(CommandSource.class)
.name("version")
.description("Get the version of the extension.")
.executor((source, command, args) -> {
source.sendMessage("MCXboxBroadcast Extension " + BuildData.VERSION);
})
.build());
}

private void restart() {
Expand All @@ -111,6 +121,9 @@ private void restart() {
@Subscribe
public void onPostInitialize(GeyserPostInitializeEvent event) {
logger = new ExtensionLoggerImpl(this.logger());

logger.info("Starting MCXboxBroadcast Extension " + BuildData.VERSION);

sessionManager = new SessionManager(new FileStorageManager(this.dataFolder().toString()), logger);

// Load the config file
Expand Down Expand Up @@ -170,9 +183,12 @@ public void onBedrockPing(GeyserBedrockPingEvent event) {
return;
}

// Allows support for motd passthrough
// Allows support for motd and player count passthrough
sessionInfo.setHostName(event.primaryMotd());
sessionInfo.setWorldName(event.secondaryMotd());

sessionInfo.setPlayers(event.playerCount());
sessionInfo.setMaxPlayers(event.maxPlayerCount());
}


Expand All @@ -194,9 +210,7 @@ private void createSession() {
}

private void tick() {
// Update the player count for the session
try {
sessionInfo.setPlayers(this.geyserApi().onlineConnections().size());
sessionManager.updateSession(sessionInfo);
} catch (SessionUpdateException e) {
sessionManager.logger().error("Failed to update session information!", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: mcxboxbroadcast
name: MCXboxBroadcast
version: 1.0
main: com.rtm516.mcxboxbroadcast.bootstrap.geyser.MCXboxBroadcastExtension
api: "1.0.1"
authors: [ "rtm516" ]
version: {{ version }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rtm516.mcxboxbroadcast.bootstrap.standalone;

import com.rtm516.mcxboxbroadcast.core.BuildData;
import com.rtm516.mcxboxbroadcast.core.Logger;
import net.minecrell.terminalconsole.SimpleTerminalConsole;
import org.apache.logging.log4j.Level;
Expand Down Expand Up @@ -96,6 +97,7 @@ protected void runCommand(String command) {
default -> warn("Unknown accounts command: " + args[1]);
}
}
case "version" -> info("MCXboxBroadcast Standalone " + BuildData.VERSION);
case "help" -> {
info("Available commands:");
info("exit - Exit the application");
Expand All @@ -104,6 +106,7 @@ protected void runCommand(String command) {
info("accounts list - List sub-accounts");
info("accounts add <sub-session-id> - Add a sub-account");
info("accounts remove <sub-session-id> - Remove a sub-account");
info("version - Display the version");
}
default -> warn("Unknown command: " + commandNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.nukkitx.protocol.bedrock.BedrockClient;
import com.nukkitx.protocol.bedrock.BedrockPong;
import com.rtm516.mcxboxbroadcast.core.BuildData;
import com.rtm516.mcxboxbroadcast.core.SessionInfo;
import com.rtm516.mcxboxbroadcast.core.SessionManager;
import com.rtm516.mcxboxbroadcast.core.configs.StandaloneConfig;
Expand All @@ -30,6 +31,8 @@ public class StandaloneMain {
public static void main(String[] args) throws Exception {
logger = new StandaloneLoggerImpl(LoggerFactory.getLogger(StandaloneMain.class));

logger.info("Starting MCXboxBroadcast Standalone " + BuildData.VERSION);

String configFileName = "config.yml";
File configFile = new File(configFileName);

Expand Down
2 changes: 2 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ repositories {

dependencies {
implementation(libs.shadow)
implementation(libs.indra.git)
implementation(libs.blossom)
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
plugins {
`java-library`
`maven-publish`

// Allow blossom to mark sources root of templates
idea
id("net.kyori.indra.git")
id("net.kyori.blossom")
}

repositories {
Expand Down
36 changes: 36 additions & 0 deletions build-logic/src/main/kotlin/gitinfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import net.kyori.indra.git.IndraGitExtension

// Modified from https://github.com/GeyserMC/Geyser/blob/ca2312c7f68c54f32314c40c2c1db5d9cda5a0b2/core/build.gradle.kts#L111-L143
class GitInfo(indraGit: IndraGitExtension) {
val branch: String
val commit: String
val commitAbbrev: String

val gitVersion: String
val version: String
val buildNumber: Int

val commitMessage: String
val repository: String

init {
branch = indraGit.branchName() ?: "DEV"

val commit = indraGit.commit()
this.commit = commit?.name ?: "0".repeat(40)
commitAbbrev = commit?.name?.substring(0, 7) ?: "0".repeat(7)

gitVersion = "git-${branch}-${commitAbbrev}"
buildNumber = (System.getenv("BUILD_NUMBER"))?.let { Integer.parseInt(it) } ?: -1

if (buildNumber == -1) {
version = "DEV ($gitVersion)"
} else {
version = "build ${buildNumber} ($gitVersion)"
}

val git = indraGit.git()
commitMessage = git?.commit()?.message ?: ""
repository = git?.repository?.config?.getString("remote", "origin", "url") ?: ""
}
}
16 changes: 16 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ dependencies {
api(libs.minecraftauth)
}

sourceSets {
main {
blossom {
val info = GitInfo(indraGit)
javaSources {
property("version", info.version)
property("gitVersion", info.gitVersion)
property("buildNumber", info.buildNumber.toString())
property("branch", info.branch)
property("commit", info.commit)
property("repository", info.repository)
}
}
}
}

description = "core"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.rtm516.mcxboxbroadcast.core;

// Replaced at compile time by blossom
public class BuildData {
public static final String VERSION = "{{ version }}";
public static final String GIT_VERSION = "{{ gitVersion }}";
public static final String BUILD_NUMBER = "{{ buildNumber }}";
public static final String BRANCH = "{{ branch }}";
public static final String COMMIT = "{{ commit }}";
public static final String REPOSITORY = "{{ repository }}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Constants {
public static final URI FOLLOWERS = URI.create("https://peoplehub.xboxlive.com/users/me/people/followers");
public static final URI SOCIAL = URI.create("https://peoplehub.xboxlive.com/users/me/people/social");
public static final URI SOCIAL_SUMMARY = URI.create("https://social.xboxlive.com/users/me/summary");
public static final URI BLOCK = URI.create("https://privacy.xboxlive.com/users/me/people/never");

/**
* From the ConnectionType enum in the game
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import com.google.gson.JsonParseException;
import com.rtm516.mcxboxbroadcast.core.configs.FriendSyncConfig;
import com.rtm516.mcxboxbroadcast.core.exceptions.XboxFriendsException;
import com.rtm516.mcxboxbroadcast.core.models.FriendModifyResponse;
import com.rtm516.mcxboxbroadcast.core.models.FriendStatusResponse;
import com.rtm516.mcxboxbroadcast.core.models.friend.BlockRequest;
import com.rtm516.mcxboxbroadcast.core.models.friend.FriendModifyResponse;
import com.rtm516.mcxboxbroadcast.core.models.friend.FriendStatusResponse;
import com.rtm516.mcxboxbroadcast.core.models.session.FollowerResponse;

import java.io.IOException;
Expand Down Expand Up @@ -311,15 +312,18 @@ private void internalProcess() {

if (modifyResponse.code() == 1028) {
logger.error("Friend list full, unable to add " + entry.getValue() + " (" + entry.getKey() + ") as a friend");
break;
} else if (modifyResponse.code() == 1011) {
// The friend wasn't added successfully so remove them from the list
// This seems to happen in some cases, I assume from the user blocking us or having account restrictions
toAdd.remove(entry.getKey());
// TODO Remove these people from following us (block and unblock)
}

logger.warn("Failed to add " + entry.getValue() + " (" + entry.getKey() + ") as a friend: (" + response.statusCode() + ") " + response.body());
// Remove these people from following us (block and unblock)
forceUnfollow(entry.getKey());

logger.warn("Removed " + entry.getValue() + " (" + entry.getKey() + ") as a friend due to account restrictions");
} else {
logger.warn("Failed to add " + entry.getValue() + " (" + entry.getKey() + ") as a friend: (" + response.statusCode() + ") " + response.body());
}
}
} catch (IOException | InterruptedException e) {
logger.error("Failed to add " + entry.getValue() + " (" + entry.getKey() + ") as a friend: " + e.getMessage());
Expand Down Expand Up @@ -377,4 +381,38 @@ private void internalProcess() {
}
});
}

/**
* Force a user to unfollow us
* This works by blocking and unblocking them
*
* @param xuid The XUID of the user to target
*/
public void forceUnfollow(String xuid) {
HttpRequest blockRequest = HttpRequest.newBuilder()
.uri(Constants.BLOCK)
.header("Authorization", sessionManager.getTokenHeader())
.PUT(HttpRequest.BodyPublishers.ofString(Constants.GSON.toJson(new BlockRequest(xuid))))
.build();

try {
HttpResponse<Void> blockResponse = httpClient.send(blockRequest, HttpResponse.BodyHandlers.discarding());
if (blockResponse.statusCode() != 200) {
throw new RuntimeException("Failed to block user: " + blockResponse.statusCode());
}

HttpRequest unblockRequest = HttpRequest.newBuilder()
.uri(Constants.BLOCK)
.header("Authorization", sessionManager.getTokenHeader())
.method("DELETE", HttpRequest.BodyPublishers.ofString(Constants.GSON.toJson(new BlockRequest(xuid))))
.build();

HttpResponse<Void> unblockResponse = httpClient.send(blockRequest, HttpResponse.BodyHandlers.discarding());
if (unblockResponse.statusCode() != 200) {
throw new RuntimeException("Failed to unblock user: " + blockResponse.statusCode());
}
} catch (IOException | InterruptedException e) {
logger.error("Failed to force unfollow user: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.rtm516.mcxboxbroadcast.core.models.friend;

public record BlockRequest (String xuid) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rtm516.mcxboxbroadcast.core.models;
package com.rtm516.mcxboxbroadcast.core.models.friend;

public record FriendModifyResponse(
int code,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rtm516.mcxboxbroadcast.core.models;
package com.rtm516.mcxboxbroadcast.core.models.friend;

import java.time.Instant;

Expand Down
13 changes: 11 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ geyser ="2.3.1-SNAPSHOT"
jackson = "2.14.0"
java-websocket = "1.5.3"
nimbus-jose-jwt = "9.23"
shadow = "8.1.1"
log4j = "2.20.0"
jline = "3.23.0"
terminalconsoleappender = "1.3.0"
Expand All @@ -16,6 +15,10 @@ spring-security-test = "6.3.1"
junit = "1.10.2"
spring-dependency = "1.1.5" # Spring Dependency Management Plugin

shadow = "8.1.1"
indra = "3.1.3"
blossom = "2.1.0"

[libraries]
bedrock-common = { group = "com.nukkitx.protocol", name = "bedrock-common", version.ref = "bedrock-common" }
geyser-api = { group = "org.geysermc.geyser", name = "api", version.ref = "geyser" }
Expand All @@ -28,7 +31,11 @@ gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson"}

java-websocket = { group = "org.java-websocket", name = "Java-WebSocket", version.ref = "java-websocket" }
nimbus-jose-jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version.ref = "nimbus-jose-jwt" }

# Plugins
shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow" }
indra-git = { group = "net.kyori", name = "indra-git", version.ref = "indra" }
blossom = { group = "net.kyori", name = "blossom", version.ref = "blossom" }

terminalconsoleappender = { group = "net.minecrell", name = "terminalconsoleappender", version.ref = "terminalconsoleappender" }

Expand Down Expand Up @@ -86,5 +93,7 @@ spring-test = [

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
indra-git = { id = "net.kyori.indra.git", version.ref = "indra" }
blossom = { id = "net.kyori.blossom", version.ref = "blossom" }
spring-boot = { id = "org.springframework.boot", version.ref = "spring" }
spring-dependency = { id = "io.spring.dependency-management", version.ref = "spring-dependency" }
spring-dependency = { id = "io.spring.dependency-management", version.ref = "spring-dependency" }

0 comments on commit 4e95f36

Please sign in to comment.