mirror of https://github.com/icedream/npsharp.git
Merging changes by NTAuthority from http://tohjo.eu/ntauthority/npsharp
Conflicts: src/client/NPSharp.Client.csprojfeature-npv2
commit
89d9a3f2c1
|
@ -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.
|
||||
/// </summary>
|
||||
/// <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 =>
|
||||
{
|
||||
|
@ -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
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>$(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\..\..\..\packages\Newtonsoft.Json.7.0.1-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="protobuf-net">
|
||||
<HintPath>$(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
@ -1,11 +1,65 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NPSharp.RPC.Messages.Data
|
||||
{
|
||||
/// <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>
|
||||
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<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; }
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.3" targetFramework="net45" />
|
||||
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<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" />
|
||||
</packages>
|
Loading…
Reference in New Issue