diff --git a/src/client/NP/NPClient.cs b/src/client/NP/NPClient.cs
index 27ba3dd..414e996 100644
--- a/src/client/NP/NPClient.cs
+++ b/src/client/NP/NPClient.cs
@@ -91,15 +91,14 @@ namespace NPSharp.NP
catch (ProtocolViolationException error)
{
_log.ErrorFormat("Protocol violation: {0}. Disconnect imminent.", error.Message);
- Disconnect();
}
catch (Exception error)
{
_log.ErrorFormat("Loop error in RPC read: {0}", error.ToString());
- Disconnect();
}
_log.Debug("Now not receiving RPC messages anymore");
+ Disconnect();
}, _cancellationToken);
_log.Debug("Connect() done");
@@ -187,9 +186,9 @@ namespace NPSharp.NP
/// Authenticates a server ticket.
///
/// True if the ticket validation succeeded, otherwise false.
- public async Task ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket)
+ public async Task ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket)
{
- var tcs = new TaskCompletionSource();
+ var tcs = new TaskCompletionSource();
RPC.AttachHandlerForNextMessage(packet =>
{
@@ -197,7 +196,7 @@ namespace NPSharp.NP
if (result == null)
return;
- tcs.SetResult(result.Result == 0);
+ tcs.SetResult(new TicketValidationResult(result));
});
RPC.Send(new AuthenticateValidateTicketMessage
diff --git a/src/client/NPSharp.Client.csproj b/src/client/NPSharp.Client.csproj
index 50af11e..8702151 100644
--- a/src/client/NPSharp.Client.csproj
+++ b/src/client/NPSharp.Client.csproj
@@ -36,6 +36,9 @@
False
$(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll
+
+ ..\..\..\..\packages\Newtonsoft.Json.7.0.1-beta1\lib\net45\Newtonsoft.Json.dll
+
$(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll
diff --git a/src/client/RPC/Messages/Data/TicketValidationResult.cs b/src/client/RPC/Messages/Data/TicketValidationResult.cs
index 87056fd..d98e622 100644
--- a/src/client/RPC/Messages/Data/TicketValidationResult.cs
+++ b/src/client/RPC/Messages/Data/TicketValidationResult.cs
@@ -1,11 +1,65 @@
+using System.Collections.Generic;
+using System.IO;
+
+using Newtonsoft.Json.Linq;
+
namespace NPSharp.RPC.Messages.Data
{
///
- /// 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.
///
- public enum TicketValidationResult
- {
- Valid = 0,
- Invalid = 1
+ public class TicketValidationResult
+ {
+ internal TicketValidationResult(Server.AuthenticateValidateTicketResultMessage message)
+ {
+ IsValid = message.Result == 0;
+
+ Identifiers = ParseIdentifierList(message.Identifiers);
+ }
+
+ internal IEnumerable ParseIdentifierList(string serializedList)
+ {
+ // current layer1 implementation uses JSON, formatted as `[ [ , ]... ]` - 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();
+
+ 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;
+ }
+
+ ///
+ /// Whether the ticket is valid or not.
+ ///
+ public bool IsValid { get; private set; }
+
+ ///
+ /// A list of NPv2 authentication identifiers belonging to the ticket session.
+ ///
+ public IEnumerable Identifiers { get; private set; }
}
}
\ No newline at end of file
diff --git a/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs b/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs
index 1f55659..32eef88 100644
--- a/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs
+++ b/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs
@@ -14,6 +14,9 @@ namespace NPSharp.RPC.Messages.Server
public UInt64 NPID { get; set; }
[ProtoMember(3)]
- public int GroupID { get; set; }
+ public int GroupID { get; set; }
+
+ [ProtoMember(4, IsRequired = false)]
+ public string Identifiers { get; set; }
}
}
\ No newline at end of file
diff --git a/src/client/packages.config b/src/client/packages.config
index 9c39bb2..1f02dcb 100644
--- a/src/client/packages.config
+++ b/src/client/packages.config
@@ -1,6 +1,7 @@
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file