public void Parse(StreamWriter sw, string path) { Action <StreamWriter> function; map.TryGetValue(path, out function); try { function(sw); } catch (NullReferenceException e) { SerializedError error = new SerializedError(404, "Invalid request."); sw.WriteLine(JsonConvert.SerializeObject(error)); } }
public void getWorld(StreamWriter sw) { try { SerializedWorld world = new SerializedWorld(); WorldFileData currentWorld = Main.ActiveWorldFileData; world.name = currentWorld.Name; world.creationTime = currentWorld.CreationTime; world.hardmode = currentWorld.IsHardMode; world.evilBiome = currentWorld.HasCorruption ? "corruption" : "crimson"; world.size = currentWorld.WorldSizeName; world.seed = currentWorld.Seed; world.expert = currentWorld.IsExpertMode; sw.WriteLine(JsonConvert.SerializeObject(world)); } catch (NullReferenceException _) { SerializedError serializedError = new SerializedError(500, "World isn't started yet on the server."); sw.WriteLine(JsonConvert.SerializeObject(serializedError)); } catch (Exception e) { SerializedError serializedError = new SerializedError(500, e.Message); sw.WriteLine(JsonConvert.SerializeObject(serializedError)); } }