private static void HandleCraftList(CraftLibraryListReplyMsgData listMsg) { if (System.CraftInfo.TryGetValue(listMsg.FolderName, out var craftEntries)) { for (var i = 0; i < listMsg.PlayerCraftsCount; i++) { var craftInfo = new CraftBasicEntry { CraftName = listMsg.PlayerCrafts[i].CraftName, CraftType = listMsg.PlayerCrafts[i].CraftType, FolderName = listMsg.PlayerCrafts[i].FolderName }; craftEntries.AddOrUpdate(listMsg.PlayerCrafts[i].CraftName, craftInfo, (key, existingVal) => craftInfo); } } }
public static void SendCraftList(ClientStructure client) { var craftDirectory = Path.Combine(ServerContext.UniverseDirectory, "Crafts"); if (!FileHandler.FolderExists(craftDirectory)) { FileHandler.FolderCreate(craftDirectory); } var players = FileHandler.GetDirectoriesInPath(craftDirectory); for (var i = 0; i < players.Length; i++) { players[i] = players[i].Substring(players[i].LastIndexOf(Path.DirectorySeparatorChar) + 1); } var newMessageData = new CraftLibraryListReplyMsgData { Players = players }; var playerCrafts = new List <KeyValuePair <string, CraftListInfo> >(); foreach (var player in players) { var playerPath = Path.Combine(craftDirectory, player); var vabPath = Path.Combine(playerPath, "VAB"); var sphPath = Path.Combine(playerPath, "SPH"); var subassemplyPath = Path.Combine(playerPath, "SUBASSEMBLY"); var vabCraftNames = new List <string>(); var sphCraftNames = new List <string>(); var subassemblyCraftNames = new List <string>(); var newPlayerCraft = new CraftListInfo { SphExists = FileHandler.FolderExists(sphPath), VabExists = FileHandler.FolderExists(vabPath), SubassemblyExists = FileHandler.FolderExists(subassemplyPath) }; if (newPlayerCraft.VabExists) { vabCraftNames.AddRange( FileHandler.GetFilesInPath(vabPath).Select(Path.GetFileNameWithoutExtension)); } if (newPlayerCraft.VabExists) { sphCraftNames.AddRange( FileHandler.GetFilesInPath(sphPath).Select(Path.GetFileNameWithoutExtension)); } if (newPlayerCraft.VabExists) { subassemblyCraftNames.AddRange( FileHandler.GetFilesInPath(subassemplyPath).Select(Path.GetFileNameWithoutExtension)); } newPlayerCraft.VabCraftNames = vabCraftNames.ToArray(); newPlayerCraft.SphCraftNames = sphCraftNames.ToArray(); newPlayerCraft.SubassemblyCraftNames = subassemblyCraftNames.ToArray(); playerCrafts.Add(new KeyValuePair <string, CraftListInfo>(player, newPlayerCraft)); } newMessageData.PlayerCrafts = playerCrafts.ToArray(); MessageQueuer.SendToClient <CraftLibrarySrvMsg>(client, newMessageData); }