1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Tie in loading to main program

This commit is contained in:
Starbeamrainbowlabs 2017-07-23 22:02:24 +01:00
parent 02a527d6b4
commit d19135d486
3 changed files with 42 additions and 5 deletions

View file

@ -23,7 +23,7 @@ namespace Nibriboard
private HttpServer httpServer; private HttpServer httpServer;
private ClientSettings clientSettings; private ClientSettings clientSettings;
private RippleSpaceManager planeManager = new RippleSpaceManager() { SourceFilename = "./test.ripplespace.zip" }; private RippleSpaceManager planeManager;
private readonly CancellationTokenSource clientManagerCanceller = new CancellationTokenSource(); private readonly CancellationTokenSource clientManagerCanceller = new CancellationTokenSource();
private NibriClientManager clientManager; private NibriClientManager clientManager;
@ -31,10 +31,18 @@ namespace Nibriboard
public readonly int CommandPort = 31587; public readonly int CommandPort = 31587;
public readonly int Port = 31586; public readonly int Port = 31586;
public NibriboardServer(int inPort = 31586) public NibriboardServer(string pathToRippleSpace, int inPort = 31586)
{ {
Port = inPort; Port = inPort;
// Load the specified packed ripple space file if it exists - otherwise save it to disk
if(File.Exists(pathToRippleSpace)) {
planeManager = RippleSpaceManager.FromFile(pathToRippleSpace).Result;
} else {
Log.WriteLine("[NibriboardServer] Couldn't find packed ripple space at {0} - creating new ripple space instead.", pathToRippleSpace);
planeManager = new RippleSpaceManager() { SourceFilename = pathToRippleSpace };
}
clientSettings = new ClientSettings() { clientSettings = new ClientSettings() {
SecureWebSocket = false, SecureWebSocket = false,
WebSocketHost = "192.168.0.56", WebSocketHost = "192.168.0.56",

View file

@ -9,12 +9,41 @@ namespace Nibriboard
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
string packedRippleSpaceFile = "./default.ripplespace.zip";
for(int i = 0; i < args.Length; i++)
{
switch(args[i])
{
case "-h":
case "--help":
Console.WriteLine("Nibriboard Server");
Console.WriteLine("By Starbeamrainbowlabs");
Console.WriteLine();
Console.WriteLine("Usage:");
Console.WriteLine(" ./Nibriboard.exe [options]");
Console.WriteLine();
Console.WriteLine("Options:");
Console.WriteLine(" -h --help Shows this message");
Console.WriteLine(" -f --file [filepath] Specify the path to the packed ripplespace file to load. Defaults to '{0}'.", packedRippleSpaceFile);
Console.WriteLine();
return;
case "-f":
case "--file":
packedRippleSpaceFile = args[++i];
break;
}
}
Log.WriteLine("[core] Starting Nibriboard."); Log.WriteLine("[core] Starting Nibriboard.");
Log.WriteLine("[core] Detected embedded files: "); Log.WriteLine("[core] Detected embedded files: ");
EmbeddedFiles.WriteResourceList(); EmbeddedFiles.WriteResourceList();
NibriboardServer server = new NibriboardServer(); Log.WriteLine("[core] Loading ripple space from \"{0}\".", packedRippleSpaceFile);
NibriboardServer server = new NibriboardServer(packedRippleSpaceFile);
Task.WaitAll( Task.WaitAll(
server.Start(), server.Start(),
server.StartCommandListener() server.StartCommandListener()

View file

@ -153,7 +153,7 @@ namespace Nibriboard.RippleSpace
Log.WriteLine("[Command/Save] Save complete in {0}ms", timer.ElapsedMilliseconds); Log.WriteLine("[Command/Save] Save complete in {0}ms", timer.ElapsedMilliseconds);
} }
public async Task<RippleSpaceManager> FromFile(string filename) public static async Task<RippleSpaceManager> FromFile(string filename)
{ {
if(!File.Exists(filename)) if(!File.Exists(filename))
throw new FileNotFoundException($"Error: Couldn't find the packed ripplespace at {filename}"); throw new FileNotFoundException($"Error: Couldn't find the packed ripplespace at {filename}");
@ -165,7 +165,7 @@ namespace Nibriboard.RippleSpace
using(IReader rippleSpaceUnpacker = ReaderFactory.Open(packedRippleSpaceStream)) using(IReader rippleSpaceUnpacker = ReaderFactory.Open(packedRippleSpaceStream))
{ {
Log.WriteLine($"[Core] Unpacking ripplespace packed with {rippleSpaceUnpacker.ArchiveType} from {filename}."); Log.WriteLine($"[Core] Unpacking ripplespace packed with {rippleSpaceUnpacker.ArchiveType} from {filename}.");
rippleSpaceUnpacker.WriteAllToDirectory(UnpackedDirectory); rippleSpaceUnpacker.WriteAllToDirectory(rippleSpace.UnpackedDirectory);
} }
Log.WriteLine("[Core] done!"); Log.WriteLine("[Core] done!");