Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
voided committed Mar 10, 2013
2 parents 9e3596c + 65b72c1 commit 4aa37ba
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ProtoBuf;
using System.IO;
using System.Linq;
using SteamKit2.Internal;

namespace SteamKit2
{
Expand All @@ -16,50 +17,62 @@ public partial class SteamUnifiedMessages : ClientMsgHandler
/// </summary>
public class ServiceMethodResponse : CallbackMsg
{
internal ServiceMethodResponse( EResult res, string methodName, byte[] response )
{
Result = res;
ResponseRaw = response;

var methodParts = methodName.Split( '.' );
ServiceName = methodParts.First();
RpcName = string.Join( ".", methodParts.Skip( 1 ) );
}

/// <summary>
/// Gets the result of the message.
/// </summary>
public EResult Result { get; private set; }

/// <summary>
/// Gets the raw binary response
/// Gets the raw binary response.
/// </summary>
public byte[] ResponseRaw { get; private set; }

/// <summary>
/// Gets the name of the Service
/// Gets the name of the Service.
/// </summary>
public string ServiceName { get; private set; }

/// <summary>
/// Gets the name of the RPC method
/// Gets the name of the RPC method.
/// </summary>
public string RpcName { get; private set; }

/// <summary>
/// Gets the full name of the service method. This takes the form ServiceName.RpcName
/// Gets the full name of the service method. This takes the form ServiceName.RpcName.
/// </summary>
public string MethodName
{
get { return ServiceName + "." + RpcName; }
}


#if STATIC_CALLBACKS
internal ServiceMethodResponse( SteamClient client, EResult result, CMsgClientServiceMethodResponse resp )
: base( client )
#else
internal ServiceMethodResponse( EResult result, CMsgClientServiceMethodResponse resp )
#endif
{
Result = result;
ResponseRaw = resp.serialized_method_response;

if ( resp.method_name != null )
{
var methodParts = resp.method_name.Split( '.' );

ServiceName = methodParts.FirstOrDefault();
RpcName = string.Join( ".", methodParts.Skip( 1 ) );
}
}


/// <summary>
/// Deserializes the response into a protobuf object.
/// </summary>
/// <typeparam name="T">Protobuf type of the response message</typeparam>
/// <typeparam name="T">Protobuf type of the response message.</typeparam>
/// <returns>The response to the message sent through <see cref="SteamUnifiedMessages"/>.</returns>
public T GetDeserializedResponse<T>()
where T : IExtensible
{
using ( var ms = new MemoryStream( ResponseRaw ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,21 @@ namespace SteamKit2
/// </summary>
public partial class SteamUnifiedMessages : ClientMsgHandler
{
/// <summary>
/// Handles a client message. This should not be called directly.
/// </summary>
/// <param name="packetMsg">The packet message that contains the data.</param>
public override void HandleMsg( IPacketMsg packetMsg )
{
switch ( packetMsg.MsgType )
{
case EMsg.ClientServiceMethodResponse:
HandleClientServiceMethodResponse( packetMsg );
break;
}
}

/// <summary>
/// Sends a message
/// Sends a message.
/// </summary>
/// <typeparam name="T">A protobuf type</typeparam>
/// <typeparam name="T">The type of a protobuf object.</typeparam>
/// <param name="name">Name of the RPC endpoint. Takes the format ServiceName.RpcName</param>
/// <param name="message">The message to send</param>
/// <param name="message">The message to send.</param>
/// <param name="isNotification">Whether this message is a notification or not.</param>
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="SteamClient.JobCallback&lt;T&gt;"/>.</returns>
public JobID SendMessage<T>( string name, T message, bool isNotification = false)
/// <returns>The JobID of the request. This can be used to find the appropriate <see cref="SteamClient.JobCallback&lt;T&gt;"/>.</returns>
public JobID SendMessage<T>( string name, T message, bool isNotification = false )
where T : IExtensible
{
var msg = new ClientMsgProtobuf<CMsgClientServiceMethod>( EMsg.ClientServiceMethod );
msg.SourceJobID = Client.GetNextJobID();

using ( var ms = new MemoryStream() )
{
Serializer.Serialize( ms, message );
Expand All @@ -58,17 +46,38 @@ public JobID SendMessage<T>( string name, T message, bool isNotification = false
return msg.SourceJobID;
}


/// <summary>
/// Handles a client message. This should not be called directly.
/// </summary>
/// <param name="packetMsg">The packet message that contains the data.</param>
public override void HandleMsg( IPacketMsg packetMsg )
{
switch ( packetMsg.MsgType )
{
case EMsg.ClientServiceMethodResponse:
HandleClientServiceMethodResponse( packetMsg );
break;
}
}

void HandleClientServiceMethodResponse( IPacketMsg packetMsg )
{
var response = new ClientMsgProtobuf<CMsgClientServiceMethodResponse>( packetMsg );

var methodName = response.Body.method_name;
var serializedMessage = response.Body.serialized_method_response;
#if STATIC_CALLBACKS
var responseCallback = new ServiceMethodResponse( Client, ( EResult )response.ProtoHeader.eresult, response.Body );
var jobCallback = new SteamClient.JobCallback<ServiceMethodResponse>( Client, response.TargetJobID, responseCallback );

var responseCallback = new ServiceMethodResponse( (EResult)response.ProtoHeader.eresult, methodName, serializedMessage );
SteamClient.PostCallback( jobCallback );
#else
var responseCallback = new ServiceMethodResponse( ( EResult )response.ProtoHeader.eresult, response.Body );
var jobCallback = new SteamClient.JobCallback<ServiceMethodResponse>( response.TargetJobID, responseCallback );

Client.PostCallback( jobCallback );
#endif

}

}
}
}

0 comments on commit 4aa37ba

Please sign in to comment.