diff --git a/src/libnpsharp/Authentication/DummyAuthenticationHandler.cs b/src/libnpsharp/Authentication/DummyAuthenticationHandler.cs deleted file mode 100644 index 3c6b703..0000000 --- a/src/libnpsharp/Authentication/DummyAuthenticationHandler.cs +++ /dev/null @@ -1,51 +0,0 @@ -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(); - } - } -} diff --git a/src/libnpsharp/Authentication/SessionAuthenticationServer.cs b/src/libnpsharp/Authentication/SessionAuthenticationServer.cs index 3783ceb..09b71e3 100644 --- a/src/libnpsharp/Authentication/SessionAuthenticationServer.cs +++ b/src/libnpsharp/Authentication/SessionAuthenticationServer.cs @@ -57,7 +57,10 @@ namespace NPSharp.Authentication { throw new InvalidOperationException("This server is already running"); } + + _log.Debug("Starting authentication server..."); _http = new HttpServer(new HttpRequestProvider()); + _http.Use(new TcpListenerAdapter(new TcpListener(IPAddress.Any, port))); _http.Use(new TcpListenerAdapter(new TcpListener(IPAddress.IPv6Any, port))); _http.Use(new HttpRouter().With("authenticate", new AuthenticateHandler(this))); _http.Use(new AnonymousHttpRequestHandler((ctx, task) => @@ -67,6 +70,7 @@ namespace NPSharp.Authentication return Task.Factory.GetCompleted(); })); _http.Start(); + _log.Debug("Done starting authentication server."); } /// diff --git a/src/libnpsharp/RPC/Messages/RPCMessage.cs b/src/libnpsharp/RPC/Messages/RPCMessage.cs index 24eda52..48becbf 100644 --- a/src/libnpsharp/RPC/Messages/RPCMessage.cs +++ b/src/libnpsharp/RPC/Messages/RPCMessage.cs @@ -67,7 +67,7 @@ namespace NPSharp.RPC.Messages #if !DEBUG catch (Exception error) { - Log.Error("Error while reading from network socket", error) + Log.Error("Error while reading from network socket", error); return null; } #endif @@ -97,7 +97,7 @@ namespace NPSharp.RPC.Messages using (var ms = new MemoryStream(buffer)) { - Type[] types = Assembly.GetExecutingAssembly().GetTypes().Where( + var types = Assembly.GetExecutingAssembly().GetTypes().Where( t => t.IsSubclassOf(typeof (T)) && diff --git a/src/libnpsharp/libnpsharp.csproj b/src/libnpsharp/libnpsharp.csproj index 22fe9f2..06c9c48 100644 --- a/src/libnpsharp/libnpsharp.csproj +++ b/src/libnpsharp/libnpsharp.csproj @@ -42,48 +42,14 @@ $(SolutionDir)\bin\$(Configuration)\$(Platform)\ - ..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll - - False - ..\..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll - - - False - ..\..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll - - - ..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll - - - ..\..\packages\WindowsAzure.Storage.2.0.6.1\lib\net40\Microsoft.WindowsAzure.Storage.dll - ..\..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Abstractions.dll - - - ..\..\packages\RavenDB.Embedded.2.5.2878\lib\net45\Raven.Client.Embedded.dll - - - ..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Client.Lightweight.dll - - - ..\..\packages\RavenDB.Database.2.5.2878\lib\net45\Raven.Database.dll - - - - - - False - ..\..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll - ..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll @@ -98,7 +64,6 @@ - diff --git a/src/npfile/Program.cs b/src/npfile/Program.cs index 6b2936f..efa0faf 100644 --- a/src/npfile/Program.cs +++ b/src/npfile/Program.cs @@ -91,11 +91,28 @@ namespace NPSharp.CommandLine.File return; } - string hostname = args[0]; - ushort port = ushort.Parse(args[1]); - string username = args[2]; - string password = args[3]; - int hport = args.Length > 4 ? ushort.Parse(args[4]) : 5680; + var hostname = args[0]; + var port = ushort.Parse(args[1]); + var username = args[2]; + var password = args[3]; + var hport = args.Length > 4 ? ushort.Parse(args[4]) : 5680; + + // Get session token + var ah = new SessionAuthenticationClient(hostname); + try + { + ah.Authenticate(username, password); + log.Info("NP authentication successful."); + } + catch (Exception err) + { +#if DEBUG + log.ErrorFormat("Could not authenticate: {0}", err); +#else + log.ErrorFormat("Could not authenticate: {0}", err.Message); +#endif + return; + } // NP connection setup log.DebugFormat("Connecting to {0}:{1}...", hostname, port); @@ -105,26 +122,14 @@ namespace NPSharp.CommandLine.File log.Error("Connection to NP server failed."); return; } - log.Info("NP connection successful, authenticating..."); - - // Get session token - var ah = new SessionAuthenticationClient(hostname); - try - { - ah.Authenticate(username, password); - np.AuthenticateWithToken(ah.SessionToken).Wait(); - log.Info("NP authentication successful."); - } - catch (Exception err) + if (!np.AuthenticateWithToken(ah.SessionToken).Result) { np.Disconnect(); -#if DEBUG - log.ErrorFormat("Could not authenticate: {0}", err); -#else - log.ErrorFormat("Could not authenticate: {0}", err.Message); -#endif + log.Error("Authentication to NP server failed."); return; } + log.Info("NP connection successful, authenticating..."); + // HTTP server using (var httpServer = new HttpServer(new HttpRequestProvider())) diff --git a/src/npserv/Database/User.cs b/src/npserv/Database/User.cs new file mode 100644 index 0000000..cb853bf --- /dev/null +++ b/src/npserv/Database/User.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using BCryptClass = BCrypt.Net.BCrypt; + +namespace NPSharp.CommandLine.Server.Database +{ + class Session + { + public Session() + { + Id = Guid.NewGuid().ToString("N"); + } + public string Id { get; set; } + public User User { get; set; } + public DateTime ExpiryTime { get; set; } + public TimeSpan ExpiresIn { get { return ExpiryTime - DateTime.Now; } } + public bool IsValid { get { return ExpiryTime >= DateTime.Now; } } + } + + class User + { + public uint Id { get; set; } + public string UserName { get; set; } + public string UserMail { get; set; } + public string PasswordHash { get; set; } + public DateTime LastLogin { get; set; } + public List BanIDs { get; set; } + public List CheatDetectionIDs { get; set; } + public List FriendIDs { get; set; } + + public bool ComparePassword(string pw) + { + return BCryptClass.Verify(pw, PasswordHash); + } + } + + class UserFile + { + public string Id { get; set; } + public string FileName { get; set; } + public uint UserID { get; set; } + public byte[] FileData { get; set; } + } + + class PublisherFile + { + public string Id { get; set; } + public string FileName { get; set; } + public byte[] FileData { get; set; } + } + + class Ban + { + public Ban() + { + Id = Guid.NewGuid().ToString("N"); + } + public string Id { get; set; } + public string Reason { get; set; } + public DateTime ExpiryTime { get; set; } + public TimeSpan ExpiresIn { get { return ExpiryTime - DateTime.Now; } } + public bool IsValid { get { return ExpiryTime >= DateTime.Now; } } + } + + class CheatDetection + { + public CheatDetection() + { + Id = Guid.NewGuid().ToString("N"); + } + public string Id { get; set; } + public uint CheatId { get; set; } + public uint UserId { get; set; } + public string Reason { get; set; } + public DateTime ExpiryTime { get; set; } + public TimeSpan ExpiresIn { get { return ExpiryTime - DateTime.Now; } } + public bool IsValid { get { return ExpiryTime >= DateTime.Now; } } + } +} diff --git a/src/npserv/DummyAuthenticationHandler.cs b/src/npserv/DummyAuthenticationHandler.cs deleted file mode 100644 index 1e44fe2..0000000 --- a/src/npserv/DummyAuthenticationHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NPSharp.Steam; - -namespace NPSharp.CommandLine.Server -{ - class DummyAuthenticationHandler : IAuthenticationHandler - { - private uint _userID = 1; - - public AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password) - { - return new AuthenticationResult(new CSteamID() - { - AccountID = _userID++, - AccountInstance = 1, - AccountType = EAccountType.Individual, - AccountUniverse = EUniverse.Public - }); - } - - public AuthenticationResult AuthenticateUser(NPServerClient client, string token) - { - return new AuthenticationResult(new CSteamID() - { - AccountID = _userID++, - AccountInstance = 1, - AccountType = EAccountType.Individual, - AccountUniverse = EUniverse.Public - }); - } - - public AuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey) - { - throw new NotImplementedException(); - } - - public TicketValidationResult ValidateTicket(NPServerClient client, NPServerClient server) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/npserv/DummyFileServingHandler.cs b/src/npserv/DummyFileServingHandler.cs deleted file mode 100644 index df9dbcc..0000000 --- a/src/npserv/DummyFileServingHandler.cs +++ /dev/null @@ -1,35 +0,0 @@ -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 - } - } -} diff --git a/src/npserv/LICENSE.txt b/src/npserv/LICENSE.txt new file mode 100644 index 0000000..d2109f0 --- /dev/null +++ b/src/npserv/LICENSE.txt @@ -0,0 +1,14 @@ +Copyright (c) 2006 Damien Miller (jBCrypt) +Copyright (c) 2013 Ryan D. Emerle (.Net port) + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/src/npserv/Program.cs b/src/npserv/Program.cs index 720eb2e..732637a 100644 --- a/src/npserv/Program.cs +++ b/src/npserv/Program.cs @@ -1,20 +1,217 @@ using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; +using System.Threading.Tasks; using log4net; using log4net.Appender; using log4net.Config; using log4net.Core; using log4net.Layout; using NPSharp.Authentication; +using NPSharp.CommandLine.Server.Database; +using Raven.Client; +using Raven.Client.Embedded; +using Raven.Client.Linq; +using Raven.Database.Server; namespace NPSharp.CommandLine.Server { class Program { + private static ILog _log; + private static IDocumentStore _database; + private static IDocumentSession _db; + private static SessionAuthenticationServer _authServer; + private static NPServer _np; + static void Main() { + InitializeLogging(); + _log.Info("NP server is about to start up, this might take a few seconds..."); - // log4net setup + InitializeDatabase(); + InitializeAuthServer(); + InitializeNPServer(); + + _log.Info("NP server started up successfully."); + Thread.Sleep(Timeout.Infinite); + } + + static void InitializeDatabase() + { + _log.Debug("Starting Raven database..."); + +#if DEBUG + Directory.CreateDirectory(@"Raven"); + Directory.CreateDirectory(@"Raven\CompiledIndexCache"); +#endif + Directory.CreateDirectory(@"Database"); + + NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(12002); + var database = new EmbeddableDocumentStore + { + DataDirectory = "Database", + UseEmbeddedHttpServer = true + }; + database.Configuration.Port = 12002; + database.Configuration.AllowLocalAccessWithoutAuthorization = true; + database.Configuration.DataDirectory = "Database"; + _database = database.Initialize(); + + _database.Conventions.IdentityTypeConvertors.Add(new UInt32Converter()); + + // Set up initial admin user + _db = _database.OpenSession(); + //using (var db = _database.OpenSession()) + //{ + if (!_db.Query().Any()) + { + _log.Warn("Creating default admin user because no users could be found in the database..."); + var adminUser = new User() + { + BanIDs = new List(), + CheatDetectionIDs = new List(), + FriendIDs = new List(), + PasswordHash = BCrypt.Net.BCrypt.HashPassword("test"), + UserMail = "admin@localhost", + UserName = "admin" + }; + _db.Store(adminUser); + _db.SaveChanges(); + _log.Warn("Default admin user created. For details see below."); + _log.Warn("\tUsername: admin"); + _log.Warn("\tPassword: test"); + _log.Warn("This only happens when no users can be found in the database. Change the details or create a new user to access the server asap!"); + } + //} + + // Endless loop to clean up expired stuff + Task.Factory.StartNew(() => + { + while (_database != null && !_database.WasDisposed) + { + using (var db = _database.OpenSession()) + { + var expiredSessions = db.Query().Where(s => !s.IsValid).ToArray(); + foreach (var session in expiredSessions) + db.Delete(session); + + var expiredBans = db.Query().Where(b => !b.IsValid).ToArray(); + foreach (var ban in expiredBans) + db.Delete(ban); + + var expiredCheatDetections = db.Query().Where(cd => !cd.IsValid).ToArray(); + foreach (var cd in expiredCheatDetections) + db.Delete(cd); + + _log.DebugFormat( + "Purging {0} invalid sessions, {1} invalid bans and {2} invalid cheat detections", + expiredSessions.Length, + expiredBans.Length, + expiredCheatDetections.Length); + + db.SaveChanges(); + } + + Thread.Sleep(TimeSpan.FromMinutes(5)); + } + }); + } + + static void InitializeAuthServer() + { + _log.Debug("Starting authentication server..."); + _authServer = new SessionAuthenticationServer(); + _authServer.Authenticating += (loginUsername, loginPassword) => + { + //using (var db = _database.OpenSession()) + //{ + var resp = new SessionAuthenticationResult(); + + // Check if we have any user to which the given credentials fit + var users = _db + // database processing + .Query() + .Customize(x => x + .Include(o => o.BanIDs) + .Include(o => o.CheatDetectionIDs)) + .Where(u => u.UserName == loginUsername) + .ToArray() + + // local processing + .Where(u => u.ComparePassword(loginPassword)) + .ToArray(); + if (!users.Any()) + { + resp.Reason = + "Login details are incorrect. Please check your username and password and try again."; + return resp; + } + var user = users.Single(); + + // Check if user is banned + var bans = _db.Load(user.BanIDs); + if (bans.Any(b => b.IsValid)) + { + var ban = bans.First(b => b.IsValid); + resp.Reason = string.Format("You're currently banned: {0} (expires in {1})", ban.Reason, + ban.ExpiresIn.ToString("g")); // TODO: Format as d days h hours m minutes and s seconds + return resp; + } + + // Check if user was hacking + var cheatDetections = _db.Load(user.CheatDetectionIDs); + if (cheatDetections.Any(b => b.IsValid)) + { + var ban = cheatDetections.First(b => b.IsValid); + resp.Reason = string.Format("You have been seen using a cheat: {0} (expires in {1})", ban.Reason, + ban.ExpiresIn.ToString("g")); // TODO: Format as d days h hours m minutes and s seconds + return resp; + } + + // Create a session for this user + var session = new Session() + { + ExpiryTime = DateTime.Now + TimeSpan.FromMinutes(5), + User = user + }; + _db.Store(session); + + // Update user's last login time + user.LastLogin = DateTime.Now; + _db.Store(user); + + resp.UserID = user.Id; + resp.UserMail = user.UserMail; + resp.UserName = user.UserName; + resp.SessionToken = session.Id; + resp.Success = true; + + // Save everything to the database now + _db.SaveChanges(); + + return resp; + //} + }; + _authServer.Start(); + } + + private static void InitializeNPServer() + { + _log.Debug("Starting NP server..."); + _np = new NPServer(3036) + { + AuthenticationHandler = new RavenDatabaseAuthenticationHandler(_database), + FileServingHandler = new RavenDatabaseFileServingHandler(_database) + // TODO: Implement the other handlers + }; + _np.Start(); + } + + static void InitializeLogging() + { if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) { var appender = new ConsoleAppender @@ -69,32 +266,7 @@ namespace NPSharp.CommandLine.Server BasicConfigurator.Configure(new IAppender[] { appender, new DebugAppender { Layout = appender.Layout, Threshold = Level.All } }); } - 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..."); - var np = new NPServer(3036) - { - AuthenticationHandler = new DummyAuthenticationHandler(), - FileServingHandler = new DummyFileServingHandler() - // TODO: Implement the other handlers - }; - np.Start(); - log.Info("NP server started up successfully."); - - Thread.Sleep(Timeout.Infinite); + _log = LogManager.GetLogger("Main"); } } } diff --git a/src/npserv/RavenDatabaseAuthenticationHandler.cs b/src/npserv/RavenDatabaseAuthenticationHandler.cs new file mode 100644 index 0000000..0c6a59c --- /dev/null +++ b/src/npserv/RavenDatabaseAuthenticationHandler.cs @@ -0,0 +1,65 @@ +using System; +using NPSharp.CommandLine.Server.Database; +using NPSharp.Steam; +using Raven.Client; + +namespace NPSharp.CommandLine.Server +{ + class RavenDatabaseAuthenticationHandler : IAuthenticationHandler + { + //private readonly IDocumentStore _database; + private readonly IDocumentSession _db; + + public RavenDatabaseAuthenticationHandler(IDocumentStore database) + { + //_database = database; + _db = database.OpenSession(); + } + + ~RavenDatabaseAuthenticationHandler() + { + _db.Dispose(); + } + + public AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password) + { + // Nah, authenticating this way is deprecated as fuck. + return new AuthenticationResult(); + } + + public AuthenticationResult AuthenticateUser(NPServerClient client, string token) + { + //using (var db = _database.OpenSession()) + //{ + var session = _db.Load(token); + if (session == null) + { + // Invalid session token + return new AuthenticationResult(); + } + + // Remove session now since we don't need it anymore + _db.Delete(session); + _db.SaveChanges(); + + return new AuthenticationResult(new CSteamID() + { + AccountID = session.User.Id, + AccountInstance = 1, + AccountType = EAccountType.Individual, + AccountUniverse = EUniverse.Public + }); + //} + } + + public AuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey) + { + throw new NotImplementedException(); + } + + public TicketValidationResult ValidateTicket(NPServerClient client, NPServerClient server) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/npserv/RavenDatabaseFileServingHandler.cs b/src/npserv/RavenDatabaseFileServingHandler.cs new file mode 100644 index 0000000..e66d428 --- /dev/null +++ b/src/npserv/RavenDatabaseFileServingHandler.cs @@ -0,0 +1,98 @@ +using System.Linq; +using System.Text; +using NPSharp.CommandLine.Server.Database; +using Raven.Client; + +namespace NPSharp.CommandLine.Server +{ + class RavenDatabaseFileServingHandler : IFileServingHandler + { + private readonly IDocumentStore _database; + + public RavenDatabaseFileServingHandler(IDocumentStore database) + { + _database = database; + } + + protected byte[] GetDefaultUserFile(string file) + { + switch (file) + { + case "iw4.stat": + return new byte[8 * 1024]; + default: + return null; + } + } + + protected byte[] GetDefaultPublisherFile(string file) + { + switch (file) + { + case "hello_world.txt": + case "motd-english.txt": + case "motd-german.txt": + case "motd-french.txt": + case "motd-russian.txt": + case "motd-spanish.txt": + return Encoding.UTF8.GetBytes("hello"); + case "playerlog.csv": + case "social_tu1.cfg": + case "heatmap.raw": + case "online_mp.img": + return new byte[0]; + default: + return null; + } + } + + public byte[] ReadUserFile(NPServerClient client, string file) + { + using (var db = _database.OpenSession()) + { + var userfile = db + .Query() + .Customize(uf => uf.Include(o => o.UserID)) + .SingleOrDefault(uf => + uf.FileName == file + && db.Load(uf.UserID).Id == client.UserID.AccountID); + + return userfile == null ? null : userfile.FileData; + } + } + + public byte[] ReadPublisherFile(NPServerClient client, string file) + { + using (var db = _database.OpenSession()) + { + var pubfiles = + db.Query() + .Where(uf => uf.FileName == file) + .ToArray(); + + return !pubfiles.Any() ? GetDefaultPublisherFile(file) : pubfiles.Single().FileData; + } + } + + public void WriteUserFile(NPServerClient client, string file, byte[] data) + { + using (var db = _database.OpenSession()) + { + var userfile = db + .Query() + .Customize(uf => uf.Include(o => o.UserID)) + .SingleOrDefault(uf => + uf.FileName == file + && db.Load(uf.UserID).Id == client.UserID.AccountID) + ?? new UserFile(); + + userfile.UserID = client.UserID.AccountID; + userfile.FileData = data; + userfile.FileName = file; + + db.Store(userfile); + db.SaveChanges(); + } + } + } +} diff --git a/src/npserv/UInt32Converter.cs b/src/npserv/UInt32Converter.cs new file mode 100644 index 0000000..58da796 --- /dev/null +++ b/src/npserv/UInt32Converter.cs @@ -0,0 +1,24 @@ +using System; +using Raven.Client.Converters; + +namespace NPSharp.CommandLine.Server +{ + public class UInt32Converter : ITypeConverter + { + public bool CanConvertFrom(Type sourceType) + { + return sourceType == typeof(uint); + } + public string ConvertFrom(string tag, object value, bool allowNull) + { + var val = (uint)value; + if (val == 0 && allowNull) + return null; + return tag + value; + } + public object ConvertTo(string value) + { + return uint.Parse(value); + } + } +} diff --git a/src/npserv/npserv.csproj b/src/npserv/npserv.csproj index 678892d..91bc783 100644 --- a/src/npserv/npserv.csproj +++ b/src/npserv/npserv.csproj @@ -39,36 +39,37 @@ $(SolutionDir)\bin\$(Configuration)\$(Platform)\ + + ..\..\packages\BCrypt-Official.0.1.109\lib\BCrypt.Net.dll + ..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll - False ..\..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll - False ..\..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll - + ..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll - + ..\..\packages\WindowsAzure.Storage.2.0.6.1\lib\net40\Microsoft.WindowsAzure.Storage.dll ..\..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll - + ..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Abstractions.dll - + ..\..\packages\RavenDB.Embedded.2.5.2878\lib\net45\Raven.Client.Embedded.dll - + ..\..\packages\RavenDB.Client.2.5.2878\lib\net45\Raven.Client.Lightweight.dll - + ..\..\packages\RavenDB.Database.2.5.2878\lib\net45\Raven.Database.dll @@ -77,20 +78,22 @@ - False ..\..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll + False ..\..\packages\uHttpSharp.0.1.4.7\lib\net40\uhttpsharp.dll - - + + + + @@ -102,6 +105,9 @@ libnpsharp + + +