Skip to content

Commit

Permalink
Merge pull request #299 from LossyDragon/custom-unified
Browse files Browse the repository at this point in the history
Allow custom Unified Services.
  • Loading branch information
LossyDragon authored Nov 30, 2024
2 parents f7288fe + 41afee5 commit 5567e0b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ProtoParser(private val outputDir: File) {
method.responseType
)
responseBlock.addStatement(
"\"${method.methodName}\" -> unifiedMessages!!.handleResponseMsg<%T.Builder>(\n%T::class.java,\npacketMsg\n)",
"\"${method.methodName}\" -> postResponseMsg<%T.Builder>(\n%T::class.java,\npacketMsg\n)",
className,
className
)
Expand All @@ -145,7 +145,7 @@ class ProtoParser(private val outputDir: File) {
method.requestType
)
notificationBlock.addStatement(
"\"${method.methodName}\" -> unifiedMessages!!.handleNotificationMsg<%T.Builder>(\n%T::class.java,\npacketMsg\n)",
"\"${method.methodName}\" -> postNotificationMsg<%T.Builder>(\n%T::class.java,\npacketMsg\n)",
className,
className
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ class SteamUnifiedMessages : ClientMsgHandler() {
}
}

internal fun <TService : GeneratedMessage.Builder<TService>> handleResponseMsg(
internal fun <TResponse : GeneratedMessage.Builder<TResponse>> handleResponseMsg(
serviceClass: Class<out AbstractMessage>,
packetMsg: PacketClientMsgProtobuf,
) {
val callback = ServiceMethodResponse<TService>(serviceClass, packetMsg)
val callback = ServiceMethodResponse<TResponse>(serviceClass, packetMsg)
client.postCallback(callback)
}

internal fun <TService : GeneratedMessage.Builder<TService>> handleNotificationMsg(
internal fun <TNotification : GeneratedMessage.Builder<TNotification>> handleNotificationMsg(
serviceClass: Class<out AbstractMessage>,
packetMsg: PacketClientMsgProtobuf,
) {
val callback = ServiceMethodNotification<TService>(serviceClass, packetMsg)
val callback = ServiceMethodNotification<TNotification>(serviceClass, packetMsg)
client.postCallback(callback)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package `in`.dragonbra.javasteam.steam.handlers.steamunifiedmessages

import com.google.protobuf.AbstractMessage
import com.google.protobuf.GeneratedMessage
import `in`.dragonbra.javasteam.base.PacketClientMsgProtobuf

/**
* @author Lossy
* @since 2024-10-22
*
* Abstract definition of a steam unified messages service.
* @constructor unifiedMessages A reference to the [SteamUnifiedMessages] instance this service was created from.
* @constructor Abstract definition of a steam unified messages service.
* @property unifiedMessages A reference to the [SteamUnifiedMessages] instance this service was created from.
*/
@Suppress("unused")
abstract class UnifiedService(val unifiedMessages: SteamUnifiedMessages? = null) {
Expand All @@ -26,6 +28,32 @@ abstract class UnifiedService(val unifiedMessages: SteamUnifiedMessages? = null)
*/
abstract fun handleNotificationMsg(methodName: String, packetMsg: PacketClientMsgProtobuf)

/**
* Dispatches the provided data as a service method response.
* @param TResponse The type of the response.
* @param serviceClass The proto class of the response
* @param packetMsg The packet message that contains the data.
*/
protected fun <TResponse : GeneratedMessage.Builder<TResponse>> postResponseMsg(
serviceClass: Class<out AbstractMessage>,
packetMsg: PacketClientMsgProtobuf,
) {
unifiedMessages?.handleResponseMsg(serviceClass, packetMsg)
}

/**
* Dispatches the provided data as a service method notification.
* @param TNotification The type of the notification.
* @param serviceClass The proto class of the notification
* @param packetMsg The packet message that contains the data.
*/
protected fun <TNotification : GeneratedMessage.Builder<TNotification>> postNotificationMsg(
serviceClass: Class<out AbstractMessage>,
packetMsg: PacketClientMsgProtobuf,
) {
unifiedMessages?.handleNotificationMsg(serviceClass, packetMsg)
}

/**
* The name of the steam unified messages service.
*/
Expand Down

0 comments on commit 5567e0b

Please sign in to comment.