Merging changes by NTAuthority from http://tohjo.eu/ntauthority/npsharp

Conflicts:
	src/client/NPSharp.Client.csproj
feature-npv2
Icedream 2015-03-21 19:51:20 +01:00
commit 89d9a3f2c1
5 changed files with 76 additions and 16 deletions

View File

@ -91,15 +91,14 @@ namespace NPSharp.NP
catch (ProtocolViolationException error) catch (ProtocolViolationException error)
{ {
_log.ErrorFormat("Protocol violation: {0}. Disconnect imminent.", error.Message); _log.ErrorFormat("Protocol violation: {0}. Disconnect imminent.", error.Message);
Disconnect();
} }
catch (Exception error) catch (Exception error)
{ {
_log.ErrorFormat("Loop error in RPC read: {0}", error.ToString()); _log.ErrorFormat("Loop error in RPC read: {0}", error.ToString());
Disconnect();
} }
_log.Debug("Now not receiving RPC messages anymore"); _log.Debug("Now not receiving RPC messages anymore");
Disconnect();
}, _cancellationToken); }, _cancellationToken);
_log.Debug("Connect() done"); _log.Debug("Connect() done");
@ -187,9 +186,9 @@ namespace NPSharp.NP
/// Authenticates a server ticket. /// Authenticates a server ticket.
/// </summary> /// </summary>
/// <returns>True if the ticket validation succeeded, otherwise false.</returns> /// <returns>True if the ticket validation succeeded, otherwise false.</returns>
public async Task<bool> ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket) public async Task<TicketValidationResult> ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket)
{ {
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<TicketValidationResult>();
RPC.AttachHandlerForNextMessage(packet => RPC.AttachHandlerForNextMessage(packet =>
{ {
@ -197,7 +196,7 @@ namespace NPSharp.NP
if (result == null) if (result == null)
return; return;
tcs.SetResult(result.Result == 0); tcs.SetResult(new TicketValidationResult(result));
}); });
RPC.Send(new AuthenticateValidateTicketMessage RPC.Send(new AuthenticateValidateTicketMessage

View File

@ -36,6 +36,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>$(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath> <HintPath>$(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\packages\Newtonsoft.Json.7.0.1-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="protobuf-net"> <Reference Include="protobuf-net">
<HintPath>$(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath> <HintPath>$(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
</Reference> </Reference>

View File

@ -1,11 +1,65 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
namespace NPSharp.RPC.Messages.Data namespace NPSharp.RPC.Messages.Data
{ {
/// <summary> /// <summary>
/// Represents the outcome of a ticket validation attempt. /// Represents the outcome of a ticket validation attempt, including eventual NPv2 authentication identifiers passed by the server.
/// </summary> /// </summary>
public enum TicketValidationResult public class TicketValidationResult
{ {
Valid = 0, internal TicketValidationResult(Server.AuthenticateValidateTicketResultMessage message)
Invalid = 1 {
IsValid = message.Result == 0;
Identifiers = ParseIdentifierList(message.Identifiers);
}
internal IEnumerable<string> ParseIdentifierList(string serializedList)
{
// current layer1 implementation uses JSON, formatted as `[ [ <type>, <value> ]... ]` - we'll concatenate these as strings to prevent this implementation detail
// this is consistent with the external API for `profiles` in Citizen itself
JToken jsonValue;
try
{
jsonValue = JToken.Parse(serializedList);
}
catch (FileLoadException)
{
return new string[0];
}
var identifiers = new List<string>();
if (jsonValue.Type == JTokenType.Array)
{
var array = (JArray)jsonValue;
foreach (var identifierToken in array.Children())
{
if (identifierToken.Type == JTokenType.Array)
{
var identifierArray = (JArray)identifierToken;
identifiers.Add(string.Format("{0}:{1}", identifierArray[0], identifierArray[1]));
}
}
}
return identifiers;
}
/// <summary>
/// Whether the ticket is valid or not.
/// </summary>
public bool IsValid { get; private set; }
/// <summary>
/// A list of NPv2 authentication identifiers belonging to the ticket session.
/// </summary>
public IEnumerable<string> Identifiers { get; private set; }
} }
} }

View File

@ -15,5 +15,8 @@ namespace NPSharp.RPC.Messages.Server
[ProtoMember(3)] [ProtoMember(3)]
public int GroupID { get; set; } public int GroupID { get; set; }
[ProtoMember(4, IsRequired = false)]
public string Identifiers { get; set; }
} }
} }

View File

@ -2,5 +2,6 @@
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net45" /> <package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1-beta1" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" /> <package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
</packages> </packages>