Skip to content

Commit

Permalink
Merge pull request #298 from asLody/reduce-sc
Browse files Browse the repository at this point in the history
Refactor content service initialization to use lazy delegation
  • Loading branch information
LossyDragon authored Nov 29, 2024
2 parents 28f32e4 + b235dc1 commit f7288fe
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import kotlinx.coroutines.async
* This handler is used for interacting with content server directory on the Steam network.
*/
class SteamContent : ClientMsgHandler() {
private val contentService: ContentServerDirectory by lazy {
val unifiedMessages = client.getHandler(SteamUnifiedMessages::class.java)
?: throw NullPointerException("Unable to get SteamUnifiedMessages handler")
unifiedMessages.createService<ContentServerDirectory>()
}

/**
* Load a list of servers from the Content Server Directory Service.
Expand All @@ -37,8 +42,6 @@ class SteamContent : ClientMsgHandler() {
maxNumServers?.let { this.maxServers = it }
}.build()

val unifiedMessages = client.getHandler(SteamUnifiedMessages::class.java)!!
val contentService = unifiedMessages.createService<ContentServerDirectory>()
val message = contentService.getServersForSteamPipe(request).toDeferred().await()
val response = message.body.build()

Expand Down Expand Up @@ -83,8 +86,6 @@ class SteamContent : ClientMsgHandler() {
localBranchPasswordHash?.let { this.branchPasswordHash = it }
}.build()

val unifiedMessages = client.getHandler(SteamUnifiedMessages::class.java)!!
val contentService = unifiedMessages.createService<ContentServerDirectory>()
val message = contentService.getManifestRequestCode(request).toDeferred().await()
val response = message.body.build()

Expand Down Expand Up @@ -112,8 +113,6 @@ class SteamContent : ClientMsgHandler() {
this.hostName = hostName
}.build()

val unifiedMessages = client.getHandler(SteamUnifiedMessages::class.java)!!
val contentService = unifiedMessages.createService<ContentServerDirectory>()
val message = contentService.getCDNAuthToken(request).toDeferred().await()

return@async AuthToken(message)
Expand Down

0 comments on commit f7288fe

Please sign in to comment.