public Dictionary <Xyz, ushort[]> GetChunksFromDatabase(List <Xyz> chunks, string filename) { if (chunks == null) { return(null); } if (!GameStorePath.IsValidName(filename)) { Console.WriteLine("Invalid backup filename: " + filename); return(null); } if (!Directory.Exists(GameStorePath.gamepathbackup)) { Directory.CreateDirectory(GameStorePath.gamepathbackup); } string finalFilename = Path.Combine(GameStorePath.gamepathbackup, filename + MapManipulator.BinSaveExtension); Dictionary <Xyz, ushort[]> deserializedChunks = new Dictionary <Xyz, ushort[]>(); Dictionary <Xyz, byte[]> serializedChunks = ChunkDb.GetChunksFromFile(d_ChunkDb, chunks, finalFilename); foreach (var k in serializedChunks) { ServerChunk c = null; if (k.Value != null) { c = DeserializeChunk(k.Value); } deserializedChunks.Add(k.Key, c.data); } return(deserializedChunks); }
public ushort[] GetChunkFromDatabase(int x, int y, int z, string filename) { if (MapUtil.IsValidPos(d_Map, x, y, z)) { if (!GameStorePath.IsValidName(filename)) { Console.WriteLine("Invalid backup filename: " + filename); return(null); } if (!Directory.Exists(GameStorePath.gamepathbackup)) { Directory.CreateDirectory(GameStorePath.gamepathbackup); } string finalFilename = Path.Combine(GameStorePath.gamepathbackup, filename + MapManipulator.BinSaveExtension); x = x / chunksize; y = y / chunksize; z = z / chunksize; byte[] serializedChunk = ChunkDb.GetChunkFromFile(d_ChunkDb, x, y, z, finalFilename); if (serializedChunk != null) { ServerChunk c = DeserializeChunk(serializedChunk); return(c.data); } } return(null); }
public void SaveChunksToDatabase(List <Vector3i> chunkPositions, string filename) { if (!GameStorePath.IsValidName(filename)) { Console.WriteLine("Invalid backup filename: " + filename); return; } if (!Directory.Exists(GameStorePath.gamepathbackup)) { Directory.CreateDirectory(GameStorePath.gamepathbackup); } string finalFilename = Path.Combine(GameStorePath.gamepathbackup, filename + MapManipulator.BinSaveExtension); List <DbChunk> dbchunks = new List <DbChunk>(); foreach (Vector3i pos in chunkPositions) { int dx = pos.x / chunksize; int dy = pos.y / chunksize; int dz = pos.z / chunksize; ServerChunk cc = new ServerChunk() { data = this.GetChunk(pos.x, pos.y, pos.z) }; MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, cc); dbchunks.Add(new DbChunk() { Position = new Xyz() { X = dx, Y = dy, Z = dz }, Chunk = ms.ToArray() }); } if (dbchunks.Count != 0) { IChunkDb d_ChunkDb = new ChunkDbCompressed() { d_ChunkDb = new ChunkDbSqlite(), d_Compression = new CompressionGzip() }; d_ChunkDb.SetChunksToFile(dbchunks, finalFilename); } else { Console.WriteLine(string.Format("0 chunks selected. Nothing to do.")); } Console.WriteLine(string.Format("Saved {0} chunk(s) to database.", dbchunks.Count)); }
Dictionary <string, string> GetScriptSources(Server server) { string[] modpaths = new[] { Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine("..", ".."), ".."), "ManicDiggerLib"), "Server"), "Mods"), "Mods" }; for (int i = 0; i < modpaths.Length; i++) { if (File.Exists(Path.Combine(modpaths[i], "current.txt"))) { server.gameMode = File.ReadAllText(Path.Combine(modpaths[i], "current.txt")).Trim(); } else if (Directory.Exists(modpaths[i])) { try { File.WriteAllText(Path.Combine(modpaths[i], "current.txt"), server.gameMode); } catch { } } modpaths[i] = Path.Combine(modpaths[i], server.gameMode); } Dictionary <string, string> scripts = new Dictionary <string, string>(); foreach (string modpath in modpaths) { if (!Directory.Exists(modpath)) { continue; } server.ModPaths.Add(modpath); string[] files = Directory.GetFiles(modpath); foreach (string s in files) { if (!GameStorePath.IsValidName(Path.GetFileNameWithoutExtension(s))) { continue; } if (!(Path.GetExtension(s).Equals(".cs", StringComparison.InvariantCultureIgnoreCase) || Path.GetExtension(s).Equals(".js", StringComparison.InvariantCultureIgnoreCase))) { continue; } string scripttext = File.ReadAllText(s); string filename = new FileInfo(s).Name; scripts[filename] = scripttext; } } return(scripts); }