Skip to content

Commit

Permalink
Merge pull request #273 from LossyDragon/steamclient
Browse files Browse the repository at this point in the history
Steamclient updates
  • Loading branch information
LossyDragon authored Aug 31, 2024
2 parents 34ec343 + 751cfd8 commit 0a46ecd
Show file tree
Hide file tree
Showing 45 changed files with 1,269 additions and 1,582 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="javasteam [wrapper --gradle-version 8.7]" type="GradleRunConfiguration" factoryName="Gradle" nameIsGenerated="true">
<configuration default="false" name="javasteam [wrapper --gradle-version 8.10]" type="GradleRunConfiguration" factoryName="Gradle" nameIsGenerated="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
Expand All @@ -12,7 +12,7 @@
<list>
<option value="wrapper" />
<option value="--gradle-version" />
<option value="8.7" />
<option value="8.10" />
</list>
</option>
<option name="vmOptions" />
Expand Down
26 changes: 9 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tasks.dokkaJavadoc {
}
}

// Make sure Maven Publishing gets javadock
// Make sure Maven Publishing gets javadoc
// https://stackoverflow.com/a/71172854
lateinit var javadocArtifact: PublishArtifact
tasks {
Expand Down Expand Up @@ -127,7 +127,12 @@ dependencies {
/* Artifact publishing */
nexusPublishing {
repositories {
sonatype()
sonatype {
val ossrhUsername: String by project
val ossrhPassword: String by project
username = ossrhUsername
password = ossrhPassword
}
}
}

Expand All @@ -145,12 +150,12 @@ publishing {
scm {
connection = "scm:git:git://github.com/Longi94/JavaSteam.git"
developerConnection = "scm:git:ssh://github.com:Longi94/JavaSteam.git"
url = "http://github.com/Longi94/JavaSteam/tree/master"
url = "https://github.com/Longi94/JavaSteam/tree/master"
}
licenses {
license {
name = "MIT License"
url = "http://www.opensource.org/licenses/mit-license.php"
url = "https://www.opensource.org/licenses/mit-license.php"
}
}
developers {
Expand All @@ -163,19 +168,6 @@ publishing {
}
}
}
repositories {
maven {
val snapshotRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
val stagingRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else stagingRepoUrl
credentials {
val ossrhUsername: String by project
val ossrhPassword: String by project
username = ossrhUsername
password = ossrhPassword
}
}
}
}

signing {
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# These are usually filled out in your global gradle properties

signing.keyId=
signing.password=
signing.secretKeyRingFile=~/.gnupg/secring.gpg

ossrhUsername=
ossrhPassword=

org.gradle.jvmargs=-Xmx2048m
org.gradle.jvmargs=-Xmx2048m
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlin-coroutines = "1.8.0" # https://mvnrepository.com/artifact/org.jetbrains.k
okHttp = "5.0.0-alpha.12" # https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
protobuf = "4.26.1" # 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.1.0" # https://mvnrepository.com/artifact/io.github.gradle-nexus/publish-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

# Testing Lib versions
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.gson.JsonParser;
import in.dragonbra.javasteam.enums.EResult;
import in.dragonbra.javasteam.steam.authentication.*;
import in.dragonbra.javasteam.steam.handlers.steamunifiedmessages.SteamUnifiedMessages;
import in.dragonbra.javasteam.steam.handlers.steamuser.LogOnDetails;
import in.dragonbra.javasteam.steam.handlers.steamuser.SteamUser;
import in.dragonbra.javasteam.steam.handlers.steamuser.callback.LoggedOffCallback;
Expand All @@ -31,8 +30,6 @@ public class SampleLogonAuthentication implements Runnable {

private SteamClient steamClient;

private SteamUnifiedMessages unifiedMessages;

private CallbackManager manager;

private SteamUser steamUser;
Expand All @@ -43,6 +40,8 @@ public class SampleLogonAuthentication implements Runnable {

private final String pass;

private String previouslyStoredGuardData; // For the sake of this sample, we do not persist guard data

public SampleLogonAuthentication(String user, String pass) {
this.user = user;
this.pass = pass;
Expand All @@ -62,15 +61,19 @@ public static void main(String[] args) {
@Override
public void run() {

// create our steamclient instance
// // If any configuration needs to be set; such as connection protocol api key, etc., you can configure it like so.
// var configuration = SteamConfiguration.create(config -> {
// config.withProtocolTypes(ProtocolTypes.WEB_SOCKET);
// });
// // create our steamclient instance with custom configuration.
// steamClient = new SteamClient(configuration);

// create our steamclient instance using default configuration
steamClient = new SteamClient();

// create the callback manager which will route callbacks to function calls
manager = new CallbackManager(steamClient);

// get the steam unified messages handler, which is used for sending and receiving responses from the unified service api
unifiedMessages = steamClient.getHandler(SteamUnifiedMessages.class);

// get the steamuser handler, which is used for logging on after successfully connecting
steamUser = steamClient.getHandler(SteamUser.class);

Expand All @@ -97,25 +100,45 @@ public void run() {
}
}

@SuppressWarnings("DanglingJavadoc")
private void onConnected(ConnectedCallback callback) {
System.out.println("Connected to Steam! Logging in " + user + "...");

var shouldRememberPassword = false;

AuthSessionDetails authDetails = new AuthSessionDetails();
authDetails.username = user;
authDetails.password = pass;
authDetails.persistentSession = false;
authDetails.persistentSession = shouldRememberPassword;

// See NewGuardData comment below.
authDetails.guardData = previouslyStoredGuardData;

/**
* {@link UserConsoleAuthenticator} is the default authenticator implementation provided by JavaSteam
* for ease of use which blocks the thread and asks for user input to enter the code.
* However, if you require special handling (e.g. you have the TOTP secret and can generate codes on the fly),
* you can implement your own {@link IAuthenticator}.
*/
authDetails.authenticator = new UserConsoleAuthenticator();

try {
// get the authentication handler, which used for authenticating with Steam
SteamAuthentication auth = new SteamAuthentication(steamClient, unifiedMessages);

CredentialsAuthSession authSession = auth.beginAuthSessionViaCredentials(authDetails);
// Begin authenticating via credentials.
var authSession = steamClient.getAuthentication().beginAuthSessionViaCredentials(authDetails);

// Note: This is blocking, it would be up to you to make it non-blocking for Java.
// Note: Kotlin uses should use ".pollingWaitForResult()" as its a suspending function.
AuthPollResult pollResponse = authSession.pollingWaitForResultCompat().get();

if (pollResponse.getNewGuardData() != null) {
// When using certain two factor methods (such as email 2fa), guard data may be provided by Steam
// for use in future authentication sessions to avoid triggering 2FA again (this works similarly to the old sentry file system).
// Do note that this guard data is also a JWT token and has an expiration date.
previouslyStoredGuardData = pollResponse.getNewGuardData();
}

// Logon to Steam with the access token we have received
// Note that we are using RefreshToken for logging on here
LogOnDetails details = new LogOnDetails();
details.setUsername(pollResponse.getAccountName());
details.setAccessToken(pollResponse.getRefreshToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class SampleLogonQRAuthentication implements Runnable, IChallengeUrlChang

private SteamClient steamClient;

private SteamUnifiedMessages unifiedMessages;

private CallbackManager manager;

private SteamUser steamUser;
Expand All @@ -63,9 +61,6 @@ public void run() {
// create the callback manager which will route callbacks to function calls
manager = new CallbackManager(steamClient);

// get the steam unified messages handler, which is used for sending and receiving responses from the unified service api
unifiedMessages = steamClient.getHandler(SteamUnifiedMessages.class);

// get the steamuser handler, which is used for logging on after successfully connecting
steamUser = steamClient.getHandler(SteamUser.class);

Expand Down Expand Up @@ -95,7 +90,7 @@ public void run() {
private void onConnected(ConnectedCallback callback) {
try {
// get the authentication handler, which used for authenticating with Steam
SteamAuthentication auth = new SteamAuthentication(steamClient, unifiedMessages);
SteamAuthentication auth = new SteamAuthentication(steamClient);

QrAuthSession authSession = auth.beginAuthSessionViaQR(new AuthSessionDetails());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class SampleWebCookie implements Runnable {

private SteamClient steamClient;

private SteamUnifiedMessages unifiedMessages;

private SteamAuthentication auth;

private CallbackManager manager;
Expand Down Expand Up @@ -69,9 +67,6 @@ public void run() {
// create the callback manager which will route callbacks to function calls
manager = new CallbackManager(steamClient);

// get the steam unified messages handler, which is used for sending and receiving responses from the unified service api
unifiedMessages = steamClient.getHandler(SteamUnifiedMessages.class);

// get the steamuser handler, which is used for logging on after successfully connecting
steamUser = steamClient.getHandler(SteamUser.class);

Expand Down Expand Up @@ -108,7 +103,7 @@ private void onConnected(ConnectedCallback callback) {
authSessionDetails.authenticator = new UserConsoleAuthenticator();

// get the authentication handler, which used for authenticating with Steam
auth = new SteamAuthentication(steamClient, unifiedMessages);
auth = new SteamAuthentication(steamClient);

try {
CredentialsAuthSession authSession = auth.beginAuthSessionViaCredentials(authSessionDetails);
Expand Down
17 changes: 2 additions & 15 deletions javasteam-tf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ publishing {
scm {
connection = "scm:git:git://github.com/Longi94/JavaSteam.git"
developerConnection = "scm:git:ssh://github.com:Longi94/JavaSteam.git"
url = "http://github.com/Longi94/JavaSteam/tree/master"
url = "https://github.com/Longi94/JavaSteam/tree/master"
}
licenses {
license {
name = "MIT License"
url = "http://www.opensource.org/licenses/mit-license.php"
url = "https://www.opensource.org/licenses/mit-license.php"
}
}
developers {
Expand All @@ -62,19 +62,6 @@ publishing {
}
}
}
repositories {
maven {
val snapshotRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
val stagingRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else stagingRepoUrl
credentials {
val ossrhUsername: String by project
val ossrhPassword: String by project
username = ossrhUsername
password = ossrhPassword
}
}
}
}

signing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ class AuthPollResult(response: CAuthentication_PollAuthSessionStatus_Response.Bu
* Supply it in [AuthSessionDetails.guardData] for future logins to avoid resending an email.
* This value should be stored per account.
*/
val newGuardData: String = response.newGuardData
val newGuardData: String? = response.newGuardData
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ import kotlin.coroutines.cancellation.CancellationException
*
* @constructor Initializes a new instance of the [SteamAuthentication] class.
* @param steamClient this instance will be associated with.
* @param unifiedMessages the unified messages service.
*/
class SteamAuthentication(private val steamClient: SteamClient, unifiedMessages: SteamUnifiedMessages) {
class SteamAuthentication(private val steamClient: SteamClient) {

companion object {
// private val logger = LogManager.getLogger(SteamAuthentication::class.java)
}

internal val authenticationService: Authentication = Authentication(unifiedMessages)
internal val authenticationService: Authentication

init {
val unifiedMessages = steamClient.getHandler(SteamUnifiedMessages::class.java)
?: throw NullPointerException("Unable to get SteamUnifiedMessages handler")

authenticationService = Authentication(unifiedMessages)
}

/**
* Gets public key for the provided account name which can be used to encrypt the account password.
Expand Down
Loading

0 comments on commit 0a46ecd

Please sign in to comment.