mirror of https://github.com/icedream/npsharp.git
npserv and npmotd now work together! :)
parent
b13d462f0d
commit
6c685d6a96
|
@ -1,6 +1,7 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HTTP/@EntryIndexedValue">HTTP</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HTTP/@EntryIndexedValue">HTTP</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NP/@EntryIndexedValue">NP</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NP/@EntryIndexedValue">NP</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NPID/@EntryIndexedValue">NPID</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NPID/@EntryIndexedValue">NPID</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RPC/@EntryIndexedValue">RPC</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RPC/@EntryIndexedValue">RPC</s:String>
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using NPSharp.Steam;
|
||||||
|
using Raven.Abstractions.Data;
|
||||||
|
using Raven.Client.Connection;
|
||||||
|
using Raven.Client.Linq;
|
||||||
|
using Raven.Database;
|
||||||
|
using Raven.Database.Linq.PrivateExtensions;
|
||||||
|
|
||||||
|
namespace NPSharp.Authentication
|
||||||
|
{
|
||||||
|
class DummyAuthenticationHandler : IAuthenticationHandler
|
||||||
|
{
|
||||||
|
// TODO: RavenDB integration
|
||||||
|
|
||||||
|
private uint _userID;
|
||||||
|
|
||||||
|
private DocumentDatabase _db;
|
||||||
|
|
||||||
|
public DummyAuthenticationHandler(DocumentDatabase db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password)
|
||||||
|
{
|
||||||
|
return new AuthenticationResult(new CSteamID()
|
||||||
|
{
|
||||||
|
AccountID = _userID++
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthenticationResult AuthenticateUser(NPServerClient client, string token)
|
||||||
|
{
|
||||||
|
return new AuthenticationResult(new CSteamID()
|
||||||
|
{
|
||||||
|
AccountID = _userID++
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TicketValidationResult ValidateTicket(NPServerClient client, NPServerClient server)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,19 +10,19 @@ namespace NPSharp.Authentication
|
||||||
/// Represents a client which can communicate with an authentication endpoint in order to retrieve session
|
/// Represents a client which can communicate with an authentication endpoint in order to retrieve session
|
||||||
/// information, including tokens for authentication with NP servers.
|
/// information, including tokens for authentication with NP servers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AuthenticationHelper
|
public class SessionAuthenticationClient
|
||||||
{
|
{
|
||||||
private readonly string _host;
|
private readonly string _host;
|
||||||
private readonly string _path;
|
private readonly string _path;
|
||||||
private readonly ushort _port;
|
private readonly ushort _port;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="NPSharp.Authentication.AuthenticationHelper" /> class.
|
/// Initializes a new instance of the <see cref="NPSharp.Authentication.SessionAuthenticationClient" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="host">Hostname of the authentication endpoint.</param>
|
/// <param name="host">Hostname of the authentication endpoint.</param>
|
||||||
/// <param name="port">Port of the authentication endpoint.</param>
|
/// <param name="port">Port of the authentication endpoint.</param>
|
||||||
/// <param name="path">Path of the authentication endpoint.</param>
|
/// <param name="path">Path of the authentication endpoint.</param>
|
||||||
public AuthenticationHelper(string host, ushort port = 12003, string path = "/authenticate")
|
public SessionAuthenticationClient(string host, ushort port = 12003, string path = "/authenticate")
|
||||||
{
|
{
|
||||||
_host = host;
|
_host = host;
|
||||||
_port = port;
|
_port = port;
|
||||||
|
@ -74,6 +74,7 @@ namespace NPSharp.Authentication
|
||||||
req.Method = "POST";
|
req.Method = "POST";
|
||||||
req.ContentType = "application/x-www-form-urlencoded";
|
req.ContentType = "application/x-www-form-urlencoded";
|
||||||
req.AllowAutoRedirect = true;
|
req.AllowAutoRedirect = true;
|
||||||
|
req.KeepAlive = false;
|
||||||
using (Stream reqStream = req.GetRequestStream())
|
using (Stream reqStream = req.GetRequestStream())
|
||||||
{
|
{
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(post);
|
byte[] buffer = Encoding.UTF8.GetBytes(post);
|
|
@ -0,0 +1,117 @@
|
||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using log4net;
|
||||||
|
using uhttpsharp;
|
||||||
|
using uhttpsharp.Handlers;
|
||||||
|
using uhttpsharp.Headers;
|
||||||
|
using uhttpsharp.Listeners;
|
||||||
|
using uhttpsharp.RequestProviders;
|
||||||
|
|
||||||
|
namespace NPSharp.Authentication
|
||||||
|
{
|
||||||
|
public class SessionAuthenticationServer
|
||||||
|
{
|
||||||
|
private HttpServer _http;
|
||||||
|
|
||||||
|
private readonly ILog _log;
|
||||||
|
|
||||||
|
public SessionAuthenticationServer()
|
||||||
|
{
|
||||||
|
SupportOldAuthentication = true;
|
||||||
|
_log = LogManager.GetLogger("Auth");
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Func<string, string, SessionAuthenticationResult> Authenticating;
|
||||||
|
|
||||||
|
protected virtual SessionAuthenticationResult OnAuthenticating(string username, string password)
|
||||||
|
{
|
||||||
|
var handler = Authenticating;
|
||||||
|
return handler != null ? handler(username, password) : new SessionAuthenticationResult { Reason = "Login currently disabled" };
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SupportOldAuthentication { get; set; }
|
||||||
|
|
||||||
|
public void Start(ushort port = 12003)
|
||||||
|
{
|
||||||
|
if (_http != null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("This server is already running");
|
||||||
|
}
|
||||||
|
_http = new HttpServer(new HttpRequestProvider());
|
||||||
|
_http.Use(new TcpListenerAdapter(new TcpListener(IPAddress.IPv6Any, port)));
|
||||||
|
_http.Use(new HttpRouter().With("authenticate", new AuthenticateHandler(this)));
|
||||||
|
_http.Use(new AnonymousHttpRequestHandler((ctx, task) =>
|
||||||
|
{
|
||||||
|
ctx.Response = HttpResponse.CreateWithMessage(HttpResponseCode.NotFound, "Not found", ctx.Request.Headers.KeepAliveConnection());
|
||||||
|
return Task.Factory.GetCompleted();
|
||||||
|
}));
|
||||||
|
_http.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class AuthenticateHandler : IHttpRequestHandler
|
||||||
|
{
|
||||||
|
private readonly SessionAuthenticationServer _authServer;
|
||||||
|
|
||||||
|
public AuthenticateHandler(SessionAuthenticationServer sessionAuthenticationServer)
|
||||||
|
{
|
||||||
|
_authServer = sessionAuthenticationServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(IHttpContext context, Func<Task> next)
|
||||||
|
{
|
||||||
|
SessionAuthenticationResult sar;
|
||||||
|
|
||||||
|
var login = Encoding.UTF8.GetString(context.Request.Post.Raw)
|
||||||
|
.Split(new[] {"&&"}, StringSplitOptions.None);
|
||||||
|
if (login.Length != 2)
|
||||||
|
{
|
||||||
|
sar = new SessionAuthenticationResult{Reason = @"Invalid login data"};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sar = _authServer.OnAuthenticating(login[0], login[1]);
|
||||||
|
}
|
||||||
|
catch (Exception error)
|
||||||
|
{
|
||||||
|
_authServer._log.Error(@"Authentication handler error", error);
|
||||||
|
sar = new SessionAuthenticationResult { Reason = @"Internal server error" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Response = new HttpResponse(HttpResponseCode.Ok, sar.ToString(), context.Request.Headers.KeepAliveConnection());
|
||||||
|
return Task.Factory.GetCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
_http.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SessionAuthenticationResult
|
||||||
|
{
|
||||||
|
public bool Success { get; set; }
|
||||||
|
public string Reason { get; set; }
|
||||||
|
public uint UserID { get; set; }
|
||||||
|
public string SessionToken { get; set; }
|
||||||
|
public string UserName { get; set; }
|
||||||
|
public string UserMail { get; set; }
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Join("#",
|
||||||
|
Success ? "ok" : "fail",
|
||||||
|
String.IsNullOrEmpty(Reason) ? (Success ? "Success" : "Unknown error") : Reason,
|
||||||
|
UserID,
|
||||||
|
UserName,
|
||||||
|
UserMail,
|
||||||
|
SessionToken,
|
||||||
|
String.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,7 +93,7 @@ namespace NPSharp
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The handler to use for file requests to this NP server.
|
/// The handler to use for file requests to this NP server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IFileServingHandler FileHandler { get; set; }
|
public IFileServingHandler FileServingHandler { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The handler to use for user avatar requests to this NP server.
|
/// The handler to use for user avatar requests to this NP server.
|
||||||
|
@ -366,7 +366,7 @@ namespace NPSharp
|
||||||
|
|
||||||
client.RPC.AttachHandlerForMessageType<StorageGetPublisherFileMessage>(msg =>
|
client.RPC.AttachHandlerForMessageType<StorageGetPublisherFileMessage>(msg =>
|
||||||
{
|
{
|
||||||
if (FileHandler == null)
|
if (FileServingHandler == null)
|
||||||
{
|
{
|
||||||
client.RPC.Send(new StoragePublisherFileMessage
|
client.RPC.Send(new StoragePublisherFileMessage
|
||||||
{
|
{
|
||||||
|
@ -391,7 +391,7 @@ namespace NPSharp
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] data = FileHandler.ReadPublisherFile(client, msg.FileName);
|
var data = FileServingHandler.ReadPublisherFile(client, msg.FileName);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
{
|
{
|
||||||
client.RPC.Send(new StoragePublisherFileMessage
|
client.RPC.Send(new StoragePublisherFileMessage
|
||||||
|
@ -408,7 +408,8 @@ namespace NPSharp
|
||||||
{
|
{
|
||||||
MessageId = msg.MessageId,
|
MessageId = msg.MessageId,
|
||||||
Result = 0,
|
Result = 0,
|
||||||
FileName = msg.FileName
|
FileName = msg.FileName,
|
||||||
|
FileData = data
|
||||||
});
|
});
|
||||||
_log.DebugFormat("Sent publisher file {0}", msg.FileName);
|
_log.DebugFormat("Sent publisher file {0}", msg.FileName);
|
||||||
}
|
}
|
||||||
|
@ -426,7 +427,7 @@ namespace NPSharp
|
||||||
|
|
||||||
client.RPC.AttachHandlerForMessageType<StorageGetUserFileMessage>(msg =>
|
client.RPC.AttachHandlerForMessageType<StorageGetUserFileMessage>(msg =>
|
||||||
{
|
{
|
||||||
if (FileHandler == null)
|
if (FileServingHandler == null)
|
||||||
{
|
{
|
||||||
client.RPC.Send(new StorageUserFileMessage
|
client.RPC.Send(new StorageUserFileMessage
|
||||||
{
|
{
|
||||||
|
@ -452,7 +453,7 @@ namespace NPSharp
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] data = FileHandler.ReadUserFile(client, msg.FileName);
|
byte[] data = FileServingHandler.ReadUserFile(client, msg.FileName);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
{
|
{
|
||||||
client.RPC.Send(new StorageUserFileMessage
|
client.RPC.Send(new StorageUserFileMessage
|
||||||
|
@ -495,7 +496,7 @@ namespace NPSharp
|
||||||
|
|
||||||
client.RPC.AttachHandlerForMessageType<StorageWriteUserFileMessage>(msg =>
|
client.RPC.AttachHandlerForMessageType<StorageWriteUserFileMessage>(msg =>
|
||||||
{
|
{
|
||||||
if (FileHandler == null)
|
if (FileServingHandler == null)
|
||||||
{
|
{
|
||||||
client.RPC.Send(new StorageWriteUserFileResultMessage
|
client.RPC.Send(new StorageWriteUserFileResultMessage
|
||||||
{
|
{
|
||||||
|
@ -521,7 +522,7 @@ namespace NPSharp
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileHandler.WriteUserFile(client, msg.FileName, msg.FileData);
|
FileServingHandler.WriteUserFile(client, msg.FileName, msg.FileData);
|
||||||
|
|
||||||
client.RPC.Send(new StorageWriteUserFileResultMessage
|
client.RPC.Send(new StorageWriteUserFileResultMessage
|
||||||
{
|
{
|
||||||
|
@ -552,8 +553,10 @@ namespace NPSharp
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
_clients.Add(client);
|
_clients.Add(client);
|
||||||
|
#if !DEBUG
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#endif
|
||||||
_log.Debug("Client connected");
|
_log.Debug("Client connected");
|
||||||
OnClientConnected(client);
|
OnClientConnected(client);
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -564,6 +567,7 @@ namespace NPSharp
|
||||||
}
|
}
|
||||||
_log.Debug("Client disconnected");
|
_log.Debug("Client disconnected");
|
||||||
OnClientDisconnected(client);
|
OnClientDisconnected(client);
|
||||||
|
#if !DEBUG
|
||||||
}
|
}
|
||||||
catch (Exception error)
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
|
@ -571,6 +575,7 @@ namespace NPSharp
|
||||||
client.RPC.Send(new CloseAppMessage {Reason = "Server-side error occurred, try again later."});
|
client.RPC.Send(new CloseAppMessage {Reason = "Server-side error occurred, try again later."});
|
||||||
client.RPC.Close();
|
client.RPC.Close();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
_clients.Remove(client);
|
_clients.Remove(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,11 @@ namespace NPSharp
|
||||||
|
|
||||||
public IEnumerable<FriendDetails> Friends
|
public IEnumerable<FriendDetails> Friends
|
||||||
{
|
{
|
||||||
get { return NP.FriendsHandler.GetFriends(this).ToArray(); }
|
get {
|
||||||
|
return NP.FriendsHandler == null
|
||||||
|
? new FriendDetails[0]
|
||||||
|
: NP.FriendsHandler.GetFriends(this).ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<NPServerClient> FriendConnections
|
public IEnumerable<NPServerClient> FriendConnections
|
||||||
|
|
|
@ -3,7 +3,7 @@ using ProtoBuf;
|
||||||
|
|
||||||
namespace NPSharp.RPC.Messages
|
namespace NPSharp.RPC.Messages
|
||||||
{
|
{
|
||||||
[Packet(1003)]
|
[Packet(1004)]
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public sealed class AuthenticateValidateTicketMessage : RPCClientMessage
|
public sealed class AuthenticateValidateTicketMessage : RPCClientMessage
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,17 +44,33 @@ namespace NPSharp.RPC.Messages
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int l = sock.Receive(header);
|
try
|
||||||
if (l == 0)
|
|
||||||
{
|
{
|
||||||
Log.Debug("Received 0 bytes");
|
var l = sock.Receive(header);
|
||||||
|
if (l == 0)
|
||||||
|
{
|
||||||
|
Log.Debug("Received 0 bytes");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (l < 16)
|
||||||
|
{
|
||||||
|
Log.ErrorFormat("Received incomplete header ({0} bytes of 16 wanted bytes)", l);
|
||||||
|
throw new ProtocolViolationException("Received incomplete header");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SocketException)
|
||||||
|
{
|
||||||
|
if (sock.Connected)
|
||||||
|
throw;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (l < 16)
|
#if !DEBUG
|
||||||
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Received incomplete header ({0} bytes of 16 wanted bytes)", l);
|
Log.Error("Error while reading from network socket", error)
|
||||||
throw new ProtocolViolationException("Received incomplete header");
|
return null;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint signature, length, type, mid;
|
uint signature, length, type, mid;
|
||||||
using (var ms = new MemoryStream(header))
|
using (var ms = new MemoryStream(header))
|
||||||
|
|
|
@ -212,7 +212,7 @@ namespace NPSharp.Steam
|
||||||
if (ReferenceEquals(a, b))
|
if (ReferenceEquals(a, b))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((a == null) || (b == null))
|
if (Equals(a, null) || Equals(b, null))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a.steamid.Data == b.steamid.Data;
|
return a.steamid.Data == b.steamid.Data;
|
||||||
|
|
|
@ -42,19 +42,64 @@
|
||||||
<OutputPath>$(SolutionDir)\bin\$(Configuration)\$(Platform)\</OutputPath>
|
<OutputPath>$(SolutionDir)\bin\$(Configuration)\$(Platform)\</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
||||||
|
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Data.Edm, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Data.OData, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.WindowsAzure.Configuration">
|
||||||
|
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.WindowsAzure.Storage">
|
||||||
|
<HintPath>..\..\packages\WindowsAzure.Storage.2.0.6.1\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Abstractions">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Client.Embedded">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Embedded.2.5.2878\lib\net45\Raven.Client.Embedded.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Client.Lightweight">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Client.Lightweight.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Database">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Database.2.5.2878\lib\net45\Raven.Database.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Data.Services.Client" />
|
||||||
|
<Reference Include="System.Spatial, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="log4net">
|
<Reference Include="log4net">
|
||||||
<HintPath>..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="protobuf-net">
|
<Reference Include="protobuf-net">
|
||||||
<HintPath>..\..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
|
<HintPath>..\..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="uhttpsharp">
|
||||||
|
<HintPath>..\..\packages\uHttpSharp.0.1.4.7\lib\net40\uhttpsharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.XML" />
|
<Reference Include="System.XML" />
|
||||||
<Reference Include="System.Xml.Serialization" />
|
<Reference Include="System.Xml.Serialization" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AuthenticationResult.cs" />
|
<Compile Include="AuthenticationResult.cs" />
|
||||||
|
<Compile Include="Authentication\DummyAuthenticationHandler.cs" />
|
||||||
|
<Compile Include="Authentication\SessionAuthenticationServer.cs" />
|
||||||
<Compile Include="ClientEventArgs.cs" />
|
<Compile Include="ClientEventArgs.cs" />
|
||||||
<Compile Include="ClientEventHandler.cs" />
|
<Compile Include="ClientEventHandler.cs" />
|
||||||
<Compile Include="IAuthenticationHandler.cs" />
|
<Compile Include="IAuthenticationHandler.cs" />
|
||||||
|
@ -103,7 +148,7 @@
|
||||||
<Compile Include="RPC\Messages\StorageWriteUserFileMessage.cs" />
|
<Compile Include="RPC\Messages\StorageWriteUserFileMessage.cs" />
|
||||||
<Compile Include="RPC\Messages\StorageWriteUserFileResultMessage.cs" />
|
<Compile Include="RPC\Messages\StorageWriteUserFileResultMessage.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Authentication\AuthenticationHelper.cs" />
|
<Compile Include="Authentication\SessionAuthenticationClient.cs" />
|
||||||
<Compile Include="RPC\RPCServerStream.cs" />
|
<Compile Include="RPC\RPCServerStream.cs" />
|
||||||
<Compile Include="RPC\RPCStream.cs" />
|
<Compile Include="RPC\RPCStream.cs" />
|
||||||
<Compile Include="Steam\CSteamID.cs" />
|
<Compile Include="Steam\CSteamID.cs" />
|
||||||
|
|
|
@ -108,7 +108,7 @@ namespace NPSharp.CommandLine.File
|
||||||
log.Info("NP connection successful, authenticating...");
|
log.Info("NP connection successful, authenticating...");
|
||||||
|
|
||||||
// Get session token
|
// Get session token
|
||||||
var ah = new AuthenticationHelper(hostname);
|
var ah = new SessionAuthenticationClient(hostname);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ah.Authenticate(username, password);
|
ah.Authenticate(username, password);
|
||||||
|
|
|
@ -94,7 +94,7 @@ namespace NPSharp.CommandLine.MOTD
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get session token
|
// Get session token
|
||||||
var ah = new AuthenticationHelper(hostname);
|
var ah = new SessionAuthenticationClient(hostname);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ah.Authenticate(username, password);
|
ah.Authenticate(username, password);
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||||
</startup>
|
</startup>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
</configuration>
|
</configuration>
|
|
@ -9,18 +9,16 @@ namespace NPSharp.CommandLine.Server
|
||||||
{
|
{
|
||||||
class DummyAuthenticationHandler : IAuthenticationHandler
|
class DummyAuthenticationHandler : IAuthenticationHandler
|
||||||
{
|
{
|
||||||
private uint _userID = 0;
|
private uint _userID = 1;
|
||||||
|
|
||||||
public DummyAuthenticationHandler()
|
|
||||||
{
|
|
||||||
// TODO: Listener on port 12003 accepting HTTP token retrievals
|
|
||||||
}
|
|
||||||
|
|
||||||
public AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password)
|
public AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password)
|
||||||
{
|
{
|
||||||
return new AuthenticationResult(new CSteamID()
|
return new AuthenticationResult(new CSteamID()
|
||||||
{
|
{
|
||||||
AccountID = _userID++
|
AccountID = _userID++,
|
||||||
|
AccountInstance = 1,
|
||||||
|
AccountType = EAccountType.Individual,
|
||||||
|
AccountUniverse = EUniverse.Public
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +26,10 @@ namespace NPSharp.CommandLine.Server
|
||||||
{
|
{
|
||||||
return new AuthenticationResult(new CSteamID()
|
return new AuthenticationResult(new CSteamID()
|
||||||
{
|
{
|
||||||
AccountID = _userID++
|
AccountID = _userID++,
|
||||||
|
AccountInstance = 1,
|
||||||
|
AccountType = EAccountType.Individual,
|
||||||
|
AccountUniverse = EUniverse.Public
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NPSharp.CommandLine.Server
|
||||||
|
{
|
||||||
|
class DummyFileServingHandler : IFileServingHandler
|
||||||
|
{
|
||||||
|
public byte[] ReadUserFile(NPServerClient client, string file)
|
||||||
|
{
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadPublisherFile(NPServerClient client, string file)
|
||||||
|
{
|
||||||
|
switch (file.ToLower())
|
||||||
|
{
|
||||||
|
case "hello_world.txt":
|
||||||
|
return Encoding.UTF8.GetBytes("Hi, this is a test hello_world.txt.");
|
||||||
|
case "motd-english.txt":
|
||||||
|
return
|
||||||
|
Encoding.UTF8.GetBytes(
|
||||||
|
"Hello, this is a test NP server written in C#. Thanks for visiting this server.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUserFile(NPServerClient client, string file, byte[] data)
|
||||||
|
{
|
||||||
|
// Ignore stuff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ using log4net.Appender;
|
||||||
using log4net.Config;
|
using log4net.Config;
|
||||||
using log4net.Core;
|
using log4net.Core;
|
||||||
using log4net.Layout;
|
using log4net.Layout;
|
||||||
|
using NPSharp.Authentication;
|
||||||
|
|
||||||
namespace NPSharp.CommandLine.Server
|
namespace NPSharp.CommandLine.Server
|
||||||
{
|
{
|
||||||
|
@ -70,14 +71,28 @@ namespace NPSharp.CommandLine.Server
|
||||||
|
|
||||||
var log = LogManager.GetLogger("Main");
|
var log = LogManager.GetLogger("Main");
|
||||||
|
|
||||||
|
log.Info("Now starting authentication server...");
|
||||||
|
var auth = new SessionAuthenticationServer();
|
||||||
|
auth.Authenticating += (user, pw) => new SessionAuthenticationResult()
|
||||||
|
{
|
||||||
|
SessionToken = Guid.NewGuid().ToString("N"),
|
||||||
|
UserID = 1,
|
||||||
|
Success = true,
|
||||||
|
UserMail = "anonymous@localhost",
|
||||||
|
UserName = "anonymous"
|
||||||
|
};
|
||||||
|
auth.Start();
|
||||||
|
log.Info("Authentication server started up successfully.");
|
||||||
|
|
||||||
log.Info("Now starting NP server...");
|
log.Info("Now starting NP server...");
|
||||||
var np = new NPServer(3036)
|
var np = new NPServer(3036)
|
||||||
{
|
{
|
||||||
AuthenticationHandler = new DummyAuthenticationHandler(),
|
AuthenticationHandler = new DummyAuthenticationHandler(),
|
||||||
|
FileServingHandler = new DummyFileServingHandler()
|
||||||
// TODO: Implement the other handlers
|
// TODO: Implement the other handlers
|
||||||
};
|
};
|
||||||
np.Start();
|
np.Start();
|
||||||
log.Info("NP server started up and is now ready.");
|
log.Info("NP server started up successfully.");
|
||||||
|
|
||||||
Thread.Sleep(Timeout.Infinite);
|
Thread.Sleep(Timeout.Infinite);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,53 @@
|
||||||
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Data.Edm, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Data.OData, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.WindowsAzure.Configuration">
|
||||||
|
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.WindowsAzure.Storage">
|
||||||
|
<HintPath>..\..\packages\WindowsAzure.Storage.2.0.6.1\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Abstractions">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Client.Embedded">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Embedded.2.5.2878\lib\net45\Raven.Client.Embedded.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Client.Lightweight">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Client.Lightweight.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Raven.Database">
|
||||||
|
<HintPath>..\..\packages\RavenDB.Database.2.5.2878\lib\net45\Raven.Database.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Data.Services.Client" />
|
||||||
|
<Reference Include="System.Spatial, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="uhttpsharp, Version=0.1.5230.25021, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\uHttpSharp.0.1.4.7\lib\net40\uhttpsharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DummyAuthenticationHandler.cs" />
|
<Compile Include="DummyAuthenticationHandler.cs" />
|
||||||
|
<Compile Include="DummyFileServingHandler.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<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="5.0.8" targetFramework="net45" />
|
||||||
|
<package id="uHttpSharp" version="0.1.4.7" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in New Issue