From 10192e88a4517f568dd3cf9719a087208ddec118 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 8 Jan 2018 22:55:39 +0000 Subject: [PATCH] [server] Disambiguate NibriboardServer, and fix ShouldAcceptConnection in NibriboardApp --- Nibriboard/Client/NibriClient.cs | 8 +- Nibriboard/ClientFiles/package-lock.json | 912 ------------------- Nibriboard/NibriboardApp.cs | 35 +- Nibriboard/NibriboardServer.cs | 6 +- Nibriboard/RippleSpace/Plane.cs | 2 +- Nibriboard/RippleSpace/RippleSpaceManager.cs | 18 +- Nibriboard/Userspace/UserManager.cs | 7 +- 7 files changed, 47 insertions(+), 941 deletions(-) diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs index e2b8d2e..4475d7b 100644 --- a/Nibriboard/Client/NibriClient.cs +++ b/Nibriboard/Client/NibriClient.cs @@ -303,7 +303,7 @@ namespace Nibriboard.Client HandshakeResponseMessage handshakeResponse = new HandshakeResponseMessage(); handshakeResponse.Id = Id; handshakeResponse.Colour = Colour; - foreach(Plane plane in manager.SpaceManager.Planes) + foreach(Plane plane in manager.NibriServer.PlaneManager.Planes) handshakeResponse.Planes.Add(plane.Name); Send(handshakeResponse); @@ -323,14 +323,14 @@ namespace Nibriboard.Client // Create a new plane with the specified name if it doesn't exist already // future we might want to allow the user to specify the chunk size - if(manager.SpaceManager[message.NewPlaneName] == default(Plane)) - manager.SpaceManager.CreatePlane(new PlaneInfo(message.NewPlaneName)); + if(manager.NibriServer.PlaneManager[message.NewPlaneName] == default(Plane)) + manager.NibriServer.PlaneManager.CreatePlane(new PlaneInfo(message.NewPlaneName)); // Remove the event listener from the old plane if there is indeed an old plane to remove it from if(CurrentPlane != null) CurrentPlane.OnChunkUpdate -= handleChunkUpdateEvent; // Swap out the current plane - CurrentPlane = manager.SpaceManager[message.NewPlaneName]; + CurrentPlane = manager.NibriServer.PlaneManager[message.NewPlaneName]; // Attach a listener to the new plane CurrentPlane.OnChunkUpdate += handleChunkUpdateEvent; diff --git a/Nibriboard/ClientFiles/package-lock.json b/Nibriboard/ClientFiles/package-lock.json index e08e5f0..7e89bcf 100644 --- a/Nibriboard/ClientFiles/package-lock.json +++ b/Nibriboard/ClientFiles/package-lock.json @@ -310,7 +310,6 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", - "fsevents": "1.1.3", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -848,910 +847,6 @@ "to-css": "1.2.1" } }, - "fsevents": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz", - "integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==", - "dev": true, - "optional": true, - "requires": { - "nan": "2.8.0", - "node-pre-gyp": "0.6.39" - }, - "dependencies": { - "abbrev": { - "version": "1.1.0", - "bundled": true, - "dev": true, - "optional": true - }, - "ajv": { - "version": "4.11.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - } - }, - "ansi-regex": { - "version": "2.1.1", - "bundled": true, - "dev": true - }, - "aproba": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "are-we-there-yet": { - "version": "1.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "delegates": "1.0.0", - "readable-stream": "2.2.9" - } - }, - "asn1": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "assert-plus": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "asynckit": { - "version": "0.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws-sign2": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws4": { - "version": "1.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "balanced-match": { - "version": "0.4.2", - "bundled": true, - "dev": true - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "block-stream": { - "version": "0.0.9", - "bundled": true, - "dev": true, - "requires": { - "inherits": "2.0.3" - } - }, - "boom": { - "version": "2.10.1", - "bundled": true, - "dev": true, - "requires": { - "hoek": "2.16.3" - } - }, - "brace-expansion": { - "version": "1.1.7", - "bundled": true, - "dev": true, - "requires": { - "balanced-match": "0.4.2", - "concat-map": "0.0.1" - } - }, - "buffer-shims": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "caseless": { - "version": "0.12.0", - "bundled": true, - "dev": true, - "optional": true - }, - "co": { - "version": "4.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "code-point-at": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "combined-stream": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "requires": { - "delayed-stream": "1.0.0" - } - }, - "concat-map": { - "version": "0.0.1", - "bundled": true, - "dev": true - }, - "console-control-strings": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "core-util-is": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "cryptiles": { - "version": "2.0.5", - "bundled": true, - "dev": true, - "requires": { - "boom": "2.10.1" - } - }, - "dashdash": { - "version": "1.14.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "debug": { - "version": "2.6.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ms": "2.0.0" - } - }, - "deep-extend": { - "version": "0.4.2", - "bundled": true, - "dev": true, - "optional": true - }, - "delayed-stream": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "delegates": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "detect-libc": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "ecc-jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "extend": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "extsprintf": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "forever-agent": { - "version": "0.6.1", - "bundled": true, - "dev": true, - "optional": true - }, - "form-data": { - "version": "2.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.15" - } - }, - "fs.realpath": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "fstream": { - "version": "1.0.11", - "bundled": true, - "dev": true, - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - } - }, - "fstream-ignore": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" - } - }, - "gauge": { - "version": "2.7.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aproba": "1.1.1", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" - } - }, - "getpass": { - "version": "0.1.7", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "glob": { - "version": "7.1.2", - "bundled": true, - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "graceful-fs": { - "version": "4.1.11", - "bundled": true, - "dev": true - }, - "har-schema": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "har-validator": { - "version": "4.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - } - }, - "has-unicode": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "hawk": { - "version": "3.1.3", - "bundled": true, - "dev": true, - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - } - }, - "hoek": { - "version": "2.16.3", - "bundled": true, - "dev": true - }, - "http-signature": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.0" - } - }, - "inflight": { - "version": "1.0.6", - "bundled": true, - "dev": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "bundled": true, - "dev": true - }, - "ini": { - "version": "1.3.4", - "bundled": true, - "dev": true, - "optional": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "requires": { - "number-is-nan": "1.0.1" - } - }, - "is-typedarray": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "isstream": { - "version": "0.1.2", - "bundled": true, - "dev": true, - "optional": true - }, - "jodid25519": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "json-schema": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsonify": "0.0.0" - } - }, - "json-stringify-safe": { - "version": "5.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "jsonify": { - "version": "0.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "jsprim": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "mime-db": { - "version": "1.27.0", - "bundled": true, - "dev": true - }, - "mime-types": { - "version": "2.1.15", - "bundled": true, - "dev": true, - "requires": { - "mime-db": "1.27.0" - } - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "dev": true, - "requires": { - "brace-expansion": "1.1.7" - } - }, - "minimist": { - "version": "0.0.8", - "bundled": true, - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "bundled": true, - "dev": true, - "requires": { - "minimist": "0.0.8" - } - }, - "ms": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "node-pre-gyp": { - "version": "0.6.39", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "detect-libc": "1.0.2", - "hawk": "3.1.3", - "mkdirp": "0.5.1", - "nopt": "4.0.1", - "npmlog": "4.1.0", - "rc": "1.2.1", - "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", - "tar": "2.2.1", - "tar-pack": "3.4.0" - } - }, - "nopt": { - "version": "4.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" - } - }, - "npmlog": { - "version": "4.1.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "oauth-sign": { - "version": "0.8.2", - "bundled": true, - "dev": true, - "optional": true - }, - "object-assign": { - "version": "4.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "once": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "requires": { - "wrappy": "1.0.2" - } - }, - "os-homedir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "os-tmpdir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "osenv": { - "version": "0.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "performance-now": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "process-nextick-args": { - "version": "1.0.7", - "bundled": true, - "dev": true - }, - "punycode": { - "version": "1.4.1", - "bundled": true, - "dev": true, - "optional": true - }, - "qs": { - "version": "6.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "rc": { - "version": "1.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "readable-stream": { - "version": "2.2.9", - "bundled": true, - "dev": true, - "requires": { - "buffer-shims": "1.0.0", - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "1.0.1", - "util-deprecate": "1.0.2" - } - }, - "request": { - "version": "2.81.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.0.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.0.1" - } - }, - "rimraf": { - "version": "2.6.1", - "bundled": true, - "dev": true, - "requires": { - "glob": "7.1.2" - } - }, - "safe-buffer": { - "version": "5.0.1", - "bundled": true, - "dev": true - }, - "semver": { - "version": "5.3.0", - "bundled": true, - "dev": true, - "optional": true - }, - "set-blocking": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "signal-exit": { - "version": "3.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "sntp": { - "version": "1.0.9", - "bundled": true, - "dev": true, - "requires": { - "hoek": "2.16.3" - } - }, - "sshpk": { - "version": "1.13.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jodid25519": "1.0.2", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "string-width": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - } - }, - "string_decoder": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "stringstream": { - "version": "0.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "strip-ansi": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, - "strip-json-comments": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "tar": { - "version": "2.2.1", - "bundled": true, - "dev": true, - "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" - } - }, - "tar-pack": { - "version": "3.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.2.9", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" - } - }, - "tough-cookie": { - "version": "2.3.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "bundled": true, - "dev": true, - "optional": true - }, - "uid-number": { - "version": "0.0.6", - "bundled": true, - "dev": true, - "optional": true - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "uuid": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "verror": { - "version": "1.3.6", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "extsprintf": "1.0.2" - } - }, - "wide-align": { - "version": "1.1.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "string-width": "1.0.2" - } - }, - "wrappy": { - "version": "1.0.2", - "bundled": true, - "dev": true - } - } - }, "get-caller-file": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz", @@ -2244,13 +1339,6 @@ "to-px": "1.0.1" } }, - "nan": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz", - "integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=", - "dev": true, - "optional": true - }, "node-fingerprint": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/node-fingerprint/-/node-fingerprint-0.0.2.tgz", diff --git a/Nibriboard/NibriboardApp.cs b/Nibriboard/NibriboardApp.cs index 7dbc797..7a0d8f4 100644 --- a/Nibriboard/NibriboardApp.cs +++ b/Nibriboard/NibriboardApp.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using Nibriboard.Client; using Nibriboard.Client.Messages; using Nibriboard.RippleSpace; +using Nibriboard.Userspace; using SBRL.GlidingSquirrel.Http; using SBRL.GlidingSquirrel.Websocket; using SBRL.Utilities; @@ -17,7 +18,7 @@ namespace Nibriboard public string FilePrefix { get; set; } public ClientSettings ClientSettings { get; set; } - public RippleSpaceManager SpaceManager { get; set; } + public NibriboardServer NibriServer { get; set; } } public class NibriboardApp : WebsocketServer @@ -25,10 +26,7 @@ namespace Nibriboard private string filePrefix; private List embeddedFiles = new List(EmbeddedFiles.ResourceList); - /// - /// The ripple space manager that this client manager is connected to. - /// - public RippleSpaceManager SpaceManager { get; private set; } + public NibriboardServer NibriServer; public LineIncubator LineIncubator = new LineIncubator(); @@ -48,12 +46,27 @@ namespace Nibriboard public NibriboardApp(NibriboardAppStartInfo startInfo, IPAddress inBindAddress, int inPort) : base(inBindAddress, inPort) { clientSettings = startInfo.ClientSettings; - SpaceManager = startInfo.SpaceManager; + NibriServer = startInfo.NibriServer; filePrefix = startInfo.FilePrefix; MimeTypeOverrides.Add(".ico", "image/x-icon"); } + public override bool ShouldAcceptConnection(HttpRequest connectionRequest, HttpResponse connectionResponse) + { + HttpBasicAuthCredentials credentials = connectionRequest.BasicAuthCredentials; + User user = NibriServer.AccountManager.GetByName(credentials.Username); + if (user == null || user.CheckPassword(credentials.Password)) { + // Authentication failed! + connectionResponse.ResponseCode = HttpResponseCode.Forbidden; + connectionResponse.ContentType = "text/plain"; + connectionResponse.SetBody("Error: Invalid username or password."); + return false; + } + + // Authentication suceeded :D + return true; + } public override Task HandleClientConnected(object sender, ClientConnectedEventArgs eventArgs) { @@ -86,6 +99,10 @@ namespace Nibriboard return HttpConnectionAction.Continue; } + if (!ShouldAcceptConnection(request, response)) { + return HttpConnectionAction.Continue; + } + if(request.Url == "/Settings.json") { @@ -204,12 +221,6 @@ namespace Nibriboard ); } - public override bool ShouldAcceptConnection(HttpRequest connectionRequest, HttpResponse connectionResponse) - { - // TODO: Implement support for user accounts here - return true; - } - #endregion } } diff --git a/Nibriboard/NibriboardServer.cs b/Nibriboard/NibriboardServer.cs index ff46e51..5ca09d1 100644 --- a/Nibriboard/NibriboardServer.cs +++ b/Nibriboard/NibriboardServer.cs @@ -14,7 +14,7 @@ namespace Nibriboard { /// /// The main Nibriboard server. - /// This class manages not only the connected clients, but also holds the master reference to the . + /// This class manages not only the connected clients, but also holds the master reference to the . /// public class NibriboardServer { @@ -62,7 +62,7 @@ namespace Nibriboard } else { Log.WriteLine("[NibriboardServer] Couldn't find packed ripple space at {0} - creating new ripple space instead.", pathToRippleSpace); - PlaneManager = new RippleSpaceManager(pathToRippleSpace); + PlaneManager = new RippleSpace.RippleSpaceManager(pathToRippleSpace); } // Next, load the user account data @@ -84,7 +84,7 @@ namespace Nibriboard AppServer = new NibriboardApp(new NibriboardAppStartInfo() { FilePrefix = "Nibriboard.obj.client_dist", ClientSettings = clientSettings, - SpaceManager = PlaneManager + NibriServer = this }, IPAddress.Any, Port); // Command Console Server setup diff --git a/Nibriboard/RippleSpace/Plane.cs b/Nibriboard/RippleSpace/Plane.cs index 71b1440..f80ca7e 100644 --- a/Nibriboard/RippleSpace/Plane.cs +++ b/Nibriboard/RippleSpace/Plane.cs @@ -315,7 +315,7 @@ namespace Nibriboard.RippleSpace // Ask the chunk to save itself, but only if it isn't empty if (loadedChunkItem.Value.IsEmpty) { - // Delete the existing chunk file, if it + // Delete the existing chunk file, if it exists if (File.Exists(chunkDestinationFilename)) File.Delete(chunkDestinationFilename); diff --git a/Nibriboard/RippleSpace/RippleSpaceManager.cs b/Nibriboard/RippleSpace/RippleSpaceManager.cs index 999181c..2a4e189 100644 --- a/Nibriboard/RippleSpace/RippleSpaceManager.cs +++ b/Nibriboard/RippleSpace/RippleSpaceManager.cs @@ -4,17 +4,14 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Diagnostics; using System.Linq; -using SharpCompress.Readers; using Nibriboard.Utilities; -using SharpCompress.Writers; -using SharpCompress.Common; namespace Nibriboard.RippleSpace { public class RippleSpaceManager { /// - /// The temporary directory in which we are currently storing our unpacked planes temporarily. + /// The temporary directory in which we are strong out data. /// public string SourceDirectory { get; set; } @@ -141,7 +138,7 @@ namespace Nibriboard.RippleSpace // Save the planes to disk List> planeSavers = new List>(); - StreamWriter indexWriter = new StreamWriter(SourceDirectory + "index.list"); + StreamWriter indexWriter = new StreamWriter(Path.Combine(SourceDirectory, "index.list")); foreach(Plane currentPlane in Planes) { // Add the plane to the index @@ -178,19 +175,24 @@ namespace Nibriboard.RippleSpace Log.WriteLine($"[Core] Loading ripplespace from {sourceDirectory}."); // Load the planes in - if (!File.Exists(rippleSpace.SourceDirectory + "index.list")) + if (!File.Exists(Path.Combine(rippleSpace.SourceDirectory, "index.list"))) throw new InvalidDataException($"Error: The ripplespace at {sourceDirectory} doesn't appear to contain an index file."); Log.WriteLine("[Core] Importing planes"); Stopwatch timer = Stopwatch.StartNew(); - StreamReader planeList = new StreamReader(sourceDirectory + "index.list"); + StreamReader planeList = new StreamReader(Path.Combine(sourceDirectory, "index.list")); List> planeLoaders = new List>(); string nextPlaneName = string.Empty; while ((nextPlaneName = await planeList.ReadLineAsync()) != null) { - planeLoaders.Add(Plane.FromDirectory(CalcPaths.PlaneDirectory(sourceDirectory, nextPlaneName))); + string nextPlaneDirectory = CalcPaths.PlaneDirectory(sourceDirectory, nextPlaneName); + if (!Directory.Exists(nextPlaneDirectory)) { + Log.WriteLine($"[Core] Warning: Couldn't find listed plane {nextPlaneName} when loading ripplespace."); + continue; + } + planeLoaders.Add(Plane.FromDirectory(nextPlaneDirectory)); } await Task.WhenAll(planeLoaders); diff --git a/Nibriboard/Userspace/UserManager.cs b/Nibriboard/Userspace/UserManager.cs index af82151..c57f482 100644 --- a/Nibriboard/Userspace/UserManager.cs +++ b/Nibriboard/Userspace/UserManager.cs @@ -148,7 +148,12 @@ namespace Nibriboard.Userspace /// The user with the specified name. public User GetByName(string username) { - return Users.Find((User user) => user.Username == username); + try { + return Users.Find((User user) => user.Username == username); + } + catch (NullReferenceException) { + return null; + } } ///