public List <Node> DownloadDatabase() { List <Node> nodeList = new List <Node>(); using (MySqlConnection conn = new MySqlConnection(GetConnectionString())) { conn.Open(); MySqlCommand sqlCommand = new MySqlCommand("SELECT * FROM computers", conn); using (MySqlConnection cn1 = new MySqlConnection(GetConnectionString())) { cn1.Open(); using (MySqlDataReader reader = sqlCommand.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { Node newNode = null; int type = reader.GetInt32(3); if (type == 4) { newNode = new PlayerTerminal(); ((PlayerTerminal)newNode).ownerId = reader.GetInt32(2); } else { newNode = new Node(); } newNode.id = reader.GetInt32(0); newNode.ip = reader.GetString(1); newNode.ownerId = reader.GetInt32(2); MySqlCommand fileCommand = new MySqlCommand("SELECT * FROM files WHERE computerId = @0", cn1); fileCommand.Parameters.Add(new MySqlParameter("0", newNode.id)); List <File> computerFiles = new List <File>(); using (MySqlDataReader fileReader = fileCommand.ExecuteReader()) { if (fileReader.HasRows) { while (fileReader.Read()) { int fileType = fileReader.GetByte(3); string fileName = fileReader.GetString(1); Console.WriteLine($"Creating file {fileName} with id {fileReader.GetInt32(0)}"); File newFile = newNode.fileSystem.CreateFile(fileReader.GetInt32(0), newNode, newNode.fileSystem.rootFile, fileName); newFile.isFolder = fileType == 1; newFile.ParentId = fileReader.GetInt32(2); newFile.ReadPriv = (Group)fileReader.GetInt32(8); newFile.WritePriv = (Group)fileReader.GetInt32(7); newFile.Content = fileReader.GetString(5); newFile.SetType(fileReader.GetInt32(4)); computerFiles.Add(newFile); if (newFile.ParentId == 0) { newNode.SetRoot(newFile); } } } } ComputerManager.FixFolder(computerFiles, newNode.fileSystem.rootFile); nodeList.Add(newNode); } } } } } return(nodeList); }
public List <Node> DownloadDatabase() { List <Node> nodeList = new List <Node>(); using (MySqlConnection conn = new MySqlConnection(GetConnectionString())) { conn.Open(); MySqlCommand sqlCommand = new MySqlCommand("SELECT * FROM computers", conn); using (MySqlConnection cn1 = new MySqlConnection(GetConnectionString())) { cn1.Open(); using (MySqlDataReader reader = sqlCommand.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { Node newNode = new Node { id = reader.GetInt32(0), ip = reader.GetString(1), ownerId = reader.GetInt32(2) }; MySqlCommand fileCommand = new MySqlCommand("SELECT * FROM files WHERE computerId = @0", cn1); fileCommand.Parameters.Add(new MySqlParameter("0", newNode.id)); List <File> computerFiles = new List <File>(); using (MySqlDataReader fileReader = fileCommand.ExecuteReader()) { if (fileReader.HasRows) { while (fileReader.Read()) { int fileType = fileReader.GetByte(3); string fileName = fileReader.GetString(1); Logger.Info($"Creating file {fileName} with id {fileReader.GetInt32(0)}"); File newFile = newNode.fileSystem.CreateFile(fileReader.GetInt32(0), newNode, newNode.fileSystem.rootFile, fileName); newFile.isFolder = fileType == 1; newFile.ParentId = fileReader.GetInt32(2); newFile.OwnerId = fileReader.GetInt32(9); newFile.Group = (Group)fileReader.GetInt32(7); newFile.Permissions.PermissionValue = fileReader.GetInt32(8); newFile.Content = fileReader.GetString(5); newFile.SetType(fileReader.GetInt32(4)); computerFiles.Add(newFile); if (newFile.ParentId == 0) { newNode.SetRoot(newFile); } } } } ComputerManager.FixFolder(computerFiles, newNode.fileSystem.rootFile); newNode.ParseLogs(); nodeList.Add(newNode); } } } } } using (MySqlConnection conn = new MySqlConnection(GetConnectionString())) { conn.Open(); MySqlCommand command = new MySqlCommand("SELECT checksum, type FROM binaries", conn); using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Server.Instance.GetCompileManager().AddType(reader.GetInt32("checksum"), reader.GetString("type")); } } } return(nodeList); }