void SetupDatabase() { banDB = new Facepunch.Sqlite.Database(); banDB.Open($"{ConVar.Server.rootFolder}/ServerUsers.db"); if (!banDB.TableExists(TableName)) { //group is a reserved word: using usergroup instead banDB.Execute($"CREATE TABLE {TableName} ( steamid INTEGER PRIMARY KEY, usergroup INTEGER, username TEXT, notes TEXT )"); OnServerSaveUsers(); } }
private void RestoreLoadedImages() { orderPending = true; int failed = 0; Dictionary <string, byte[]> oldFiles = new Dictionary <string, byte[]>(); for (int i = imageIdentifiers.imageIds.Count - 1; i >= 0; i--) { var image = imageIdentifiers.imageIds.ElementAt(i); uint imageId; if (!uint.TryParse(image.Value, out imageId)) { continue; } byte[] bytes = FileStorage.server.Get(imageId, FileStorage.Type.png, imageIdentifiers.lastCEID); if (bytes != null) { oldFiles.Add(image.Key, bytes); } else { failed++; imageIdentifiers.imageIds.Remove(image.Key); } } Facepunch.Sqlite.Database db = new Facepunch.Sqlite.Database(); try { db.Open($"{ConVar.Server.rootFolder}/sv.files.0.db"); db.Execute("DELETE FROM data WHERE entid = ?", imageIdentifiers.lastCEID); db.Close(); } catch { } loadOrders.Enqueue(new LoadOrder("Image restoration from previous database", oldFiles)); PrintWarning($"{imageIdentifiers.imageIds.Count - failed} images queued for restoration, {failed} images failed"); imageIdentifiers.lastCEID = CommunityEntity.ServerInstance.net.ID; SaveData(); orderPending = false; ServerMgr.Instance.StartCoroutine(ProcessLoadOrders()); }