diff --git a/buildSrc/src/main/kotlin/in/dragonbra/generators/rpc/parser/ProtoParser.kt b/buildSrc/src/main/kotlin/in/dragonbra/generators/rpc/parser/ProtoParser.kt index 927b4fd5..0d7ed77c 100644 --- a/buildSrc/src/main/kotlin/in/dragonbra/generators/rpc/parser/ProtoParser.kt +++ b/buildSrc/src/main/kotlin/in/dragonbra/generators/rpc/parser/ProtoParser.kt @@ -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 ) @@ -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 ) diff --git a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/SteamUnifiedMessages.kt b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/SteamUnifiedMessages.kt index 04938086..570a2336 100644 --- a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/SteamUnifiedMessages.kt +++ b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/SteamUnifiedMessages.kt @@ -157,19 +157,19 @@ class SteamUnifiedMessages : ClientMsgHandler() { } } - internal fun > handleResponseMsg( + internal fun > handleResponseMsg( serviceClass: Class, packetMsg: PacketClientMsgProtobuf, ) { - val callback = ServiceMethodResponse(serviceClass, packetMsg) + val callback = ServiceMethodResponse(serviceClass, packetMsg) client.postCallback(callback) } - internal fun > handleNotificationMsg( + internal fun > handleNotificationMsg( serviceClass: Class, packetMsg: PacketClientMsgProtobuf, ) { - val callback = ServiceMethodNotification(serviceClass, packetMsg) + val callback = ServiceMethodNotification(serviceClass, packetMsg) client.postCallback(callback) } } diff --git a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/UnifiedService.kt b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/UnifiedService.kt index c678cb99..5078a51e 100644 --- a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/UnifiedService.kt +++ b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamunifiedmessages/UnifiedService.kt @@ -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) { @@ -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 > postResponseMsg( + serviceClass: Class, + 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 > postNotificationMsg( + serviceClass: Class, + packetMsg: PacketClientMsgProtobuf, + ) { + unifiedMessages?.handleNotificationMsg(serviceClass, packetMsg) + } + /** * The name of the steam unified messages service. */