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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins {

allprojects {
group = "in.dragonbra"
version = "1.6.0"
version = "1.6.1-SNAPSHOT"
}

repositories {
Expand Down
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
[versions]
# Java / Kotlin versions
java = "11"
kotlin = "2.1.0" # https://kotlinlang.org/docs/releases.html#release-details
kotlin = "2.1.10" # https://kotlinlang.org/docs/releases.html#release-details
dokka = "2.0.0" # https://mvnrepository.com/artifact/org.jetbrains.dokka/dokka-gradle-plugin
kotlinter = "5.0.1" # https://plugins.gradle.org/plugin/org.jmailen.kotlinter

# Standard Library versions
bouncyCastle = "1.79" # https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on
bouncyCastle = "1.80" # https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on
commons-io = "2.18.0" # https://mvnrepository.com/artifact/commons-io/commons-io
commons-lang3 = "3.17.0" # https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
commons-validator = "1.9.0" # https://mvnrepository.com/artifact/commons-validator/commons-validator
gson = "2.11.0" # https://mvnrepository.com/artifact/com.google.code.gson/gson
gson = "2.12.1" # https://mvnrepository.com/artifact/com.google.code.gson/gson
jacoco = "0.8.12" # https://www.eclemma.org/jacoco
kotlin-coroutines = "1.10.1" # https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
okHttp = "5.0.0-alpha.14" # https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
protobuf = "4.29.2" # https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
protobuf = "4.29.3" # https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
protobuf-gradle = "0.9.4" # https://mvnrepository.com/artifact/com.google.protobuf/protobuf-gradle-plugin
publishPlugin = "1.3.0" # https://mvnrepository.com/artifact/io.github.gradle-nexus/publish-plugin
qrCode = "1.0.1" # https://mvnrepository.com/artifact/pro.leaco.qrcode/console-qrcode
xz = "1.10" # https://mvnrepository.com/artifact/org.tukaani/xz

# Testing Lib versions
commonsCodec = "1.17.1" # https://mvnrepository.com/artifact/commons-codec/commons-codec
commonsCodec = "1.18.0" # https://mvnrepository.com/artifact/commons-codec/commons-codec
junit5 = "5.11.4" # https://mvnrepository.com/artifact/org.junit/junit-bom
mockWebServer = "5.0.0-alpha.14" # https://mvnrepository.com/artifact/com.squareup.okhttp3/mockwebserver3-junit5
mockitoVersion = "5.14.2" # https://mvnrepository.com/artifact/org.mockito/mockito-core
mockitoVersion = "5.15.2" # https://mvnrepository.com/artifact/org.mockito/mockito-core

[libraries]
bouncyCastle = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncyCastle" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import in.dragonbra.javasteam.steam.handlers.steamfriends.SteamFriends;
import in.dragonbra.javasteam.steam.handlers.steamfriends.callback.FriendAddedCallback;
import in.dragonbra.javasteam.steam.handlers.steamfriends.callback.FriendsListCallback;
import in.dragonbra.javasteam.steam.handlers.steamfriends.callback.PersonaStatesCallback;
import in.dragonbra.javasteam.steam.handlers.steamfriends.callback.PersonaStateCallback;
import in.dragonbra.javasteam.steam.handlers.steamuser.LogOnDetails;
import in.dragonbra.javasteam.steam.handlers.steamuser.SteamUser;
import in.dragonbra.javasteam.steam.handlers.steamuser.callback.AccountInfoCallback;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void run() {

manager.subscribe(AccountInfoCallback.class, this::onAccountInfo);
manager.subscribe(FriendsListCallback.class, this::onFriendList);
manager.subscribe(PersonaStatesCallback.class, this::onPersonaStates);
manager.subscribe(PersonaStateCallback.class, this::onPersonaState);
manager.subscribe(FriendAddedCallback.class, this::onFriendAdded);

isRunning = true;
Expand Down Expand Up @@ -203,10 +203,10 @@ private void onFriendAdded(FriendAddedCallback callback) {
System.out.println(callback.getPersonaName() + " is now a friend");
}

private void onPersonaStates(PersonaStatesCallback callback) {
private void onPersonaState(PersonaStateCallback callback) {
// this callback is received when the persona state (friend information) of a friend changes

// for this sample we'll simply display the names of the friends
System.out.println("State change: " + callback.getName() + " " + callback.getState());
System.out.println("State change: " + callback.getName() + " | " + callback.getState() + " | " + callback.getStatusFlags());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package `in`.dragonbra.javasteam.steam.authentication

import `in`.dragonbra.javasteam.enums.EOSType
import `in`.dragonbra.javasteam.protobufs.steamclient.SteammessagesAuthSteamclient.EAuthTokenPlatformType
import `in`.dragonbra.javasteam.util.HardwareUtils
import `in`.dragonbra.javasteam.util.Utils

/**
Expand All @@ -23,7 +24,8 @@ class AuthSessionDetails {
/**
* Gets or Sets the device name (or user agent). By default, "<DeviceName>(JavaSteam)" will be used.
*/
var deviceFriendlyName: String?
@JvmField
var deviceFriendlyName: String? = HardwareUtils.getMachineName(true)

/**
* Gets or sets the platform type that the login will be performed for.
Expand Down Expand Up @@ -62,9 +64,4 @@ class AuthSessionDetails {
*/
@JvmField
var authenticator: IAuthenticator? = null

init {
val machineName = System.getenv("COMPUTERNAME") ?: System.getenv("HOSTNAME")
deviceFriendlyName = "$machineName (JavaSteam)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.IgnoreFrien
import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.NicknameCallback
import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.NicknameListCallback
import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.PersonaChangeCallback
import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.PersonaStatesCallback
import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.PersonaStateCallback
import `in`.dragonbra.javasteam.steam.handlers.steamfriends.callback.ProfileInfoCallback
import `in`.dragonbra.javasteam.steam.handlers.steamuser.callback.AccountInfoCallback
import `in`.dragonbra.javasteam.steam.steamclient.callbackmgr.CallbackMsg
Expand Down Expand Up @@ -530,7 +530,7 @@ class SteamFriends : ClientMsgHandler() {

/**
* Requests persona state for a list of specified SteamID.
* Results are returned in [PersonaStatesCallback].
* Results are returned in [PersonaStateCallback].
*
* @param steamIdList A list of SteamIDs to request the info of.
* @param requestedInfo The requested info flags. If none specified, this uses [SteamConfiguration.defaultPersonaStateFlags].
Expand All @@ -554,7 +554,7 @@ class SteamFriends : ClientMsgHandler() {

/**
* Requests persona state for a specified SteamID.
* Results are returned in [PersonaStatesCallback].
* Results are returned in [PersonaStateCallback].
*
* @param steamID A SteamID to request the info of.
* @param requestedInfo The requested info flags. If none specified, this uses [SteamConfiguration.defaultPersonaStateFlags].
Expand Down Expand Up @@ -781,7 +781,7 @@ class SteamFriends : ClientMsgHandler() {
}

perState.body.friendsList.forEach { friend ->
PersonaStatesCallback(friend).also(client::postCallback)
PersonaStateCallback(friend, flags).also(client::postCallback)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import java.util.*
/**
* This callback is fired in response to someone changing their friend details over the network.
*/
@Suppress("unused")
class PersonaStatesCallback(friend: CMsgClientPersonaState.Friend) : CallbackMsg() {
@Suppress("unused", "CanBePrimaryConstructorProperty")
class PersonaStateCallback(
friend: CMsgClientPersonaState.Friend,
statusFlags: EnumSet<EClientPersonaStateFlag>,
) : CallbackMsg() {

/**
* Gets the status flags. This shows what has changed.
*/
val statusFlags: EnumSet<EClientPersonaStateFlag> = EClientPersonaStateFlag.from(friend.personaStateFlags)
val statusFlags: EnumSet<EClientPersonaStateFlag> = statusFlags

/**
* Gets the friend's [SteamID]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import `in`.dragonbra.javasteam.enums.EUIMode
import `in`.dragonbra.javasteam.steam.authentication.AuthSessionDetails
import `in`.dragonbra.javasteam.steam.authentication.SteamAuthentication
import `in`.dragonbra.javasteam.types.SteamID
import `in`.dragonbra.javasteam.util.HardwareUtils
import `in`.dragonbra.javasteam.util.Utils

/**
Expand Down Expand Up @@ -48,16 +49,8 @@ data class LogOnDetails(
var requestSteam2Ticket: Boolean = false,
var clientOSType: EOSType = Utils.getOSType(),
var clientLanguage: String = "english",
var machineName: String = "",
var machineName: String = HardwareUtils.getMachineName(true),
var chatMode: ChatMode = ChatMode.DEFAULT,
var uiMode: EUIMode = EUIMode.Unknown,
var isSteamDeck: Boolean = false,
) {
init {
var envName = System.getenv("COMPUTERNAME")
if (envName == null) {
envName = System.getenv("HOSTNAME")
}
machineName = "$envName (JavaSteam)"
}
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ class LoggedOnCallback : CallbackMsg {
*/
var parentalSettings: ParentalSettings? = null

/**
* Gets the id of the family group a user is joined in.
*/
var familyGroupId: Long = 0L
private set

constructor(packetMsg: IPacketMsg) {
if (!packetMsg.isProto) {
handleNonProtoLogon(packetMsg)
Expand Down Expand Up @@ -177,6 +183,8 @@ class LoggedOnCallback : CallbackMsg {
logger.error("Failed to parse parental settings", e)
}
}

familyGroupId = resp.familyGroupId
}

constructor(result: EResult) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/in/dragonbra/javasteam/types/AsyncJobMultiple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class AsyncJobMultiple<T : CallbackMsg>(
private val finishCondition: (T) -> Boolean?,
) : AsyncJob(client, jobId) {

class ResultSet(
class ResultSet<T : CallbackMsg>(
var complete: Boolean = false,
var failed: Boolean = false,
var results: List<CallbackMsg> = listOf(),
var results: List<T> = listOf(),
)

private val future = CompletableFuture<ResultSet>()
private val future = CompletableFuture<ResultSet<T>>()

private val results = mutableListOf<T>()

Expand All @@ -33,15 +33,15 @@ class AsyncJobMultiple<T : CallbackMsg>(
}

@Deprecated("Use toFuture() instead", ReplaceWith("toFuture()"))
fun toDeferred(): CompletableFuture<ResultSet> = toFuture()
fun toDeferred(): CompletableFuture<ResultSet<T>> = toFuture()

fun toFuture(): CompletableFuture<ResultSet> = future
fun toFuture(): CompletableFuture<ResultSet<T>> = future

suspend fun await(): ResultSet = future.await()
suspend fun await(): ResultSet<T> = future.await()

@Suppress("unused")
@Throws(CancellationException::class)
fun runBlock(): ResultSet = toFuture().get()
fun runBlock(): ResultSet<T> = toFuture().get()

override fun addResult(callback: CallbackMsg): Boolean {
@Suppress("UNCHECKED_CAST")
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/in/dragonbra/javasteam/util/HardwareUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package in.dragonbra.javasteam.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.*;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
Expand Down Expand Up @@ -191,34 +194,44 @@ private static String readLshal() {
}

public static String getMachineName() {
return getMachineName(false);
}

public static String getMachineName(boolean addTag) {
if (MACHINE_NAME != null) {
return MACHINE_NAME;
}


if (SystemUtils.IS_OS_ANDROID) {
MACHINE_NAME = getAndroidDeviceName();
} else {
MACHINE_NAME = getDeviceName();
}

if (MACHINE_NAME == null || MACHINE_NAME.isEmpty()) {
if (StringUtils.isBlank(MACHINE_NAME)) {
MACHINE_NAME = "Unknown";
}

return MACHINE_NAME;
if (addTag || MACHINE_NAME.contains("Unknown")) {
return MACHINE_NAME + " (JavaSteam)";
} else {
return MACHINE_NAME;
}
}

private static String getDeviceName() {
try {
Process process = Runtime.getRuntime().exec("hostname");

try (var inputStreamReader = new InputStreamReader(process.getInputStream());
var reader = new BufferedReader(inputStreamReader)) {
return reader.readLine().trim();
var hostname = SystemUtils.getHostName();
if (StringUtils.isBlank(hostname)) {
try {
// Last fallback.
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostname = null;
}
} catch (IOException e) {
return null;
}

return hostname;
}

private static String getAndroidDeviceName() {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/in/dragonbra/javasteam/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ public static int adlerHash(byte[] input) {

/**
* Validate a file against Steam3 Chunk data
* @param fs FileInputStream to read from
*
* @param fs FileInputStream to read from
* @param chunkData Array of ChunkData to validate against
* @return List of ChunkData that are needed
* @throws IOException If there's an error reading the file
* @throws ClosedChannelException If this channel is closed
* @throws IOException If there's an error reading the file
* @throws ClosedChannelException If this channel is closed
* @throws IllegalArgumentException If the new position is negative
*/
@SuppressWarnings("resource")
Expand Down
Loading
Loading