private void Update()
        {
            safeDisplay = display;
            if (workerEnabled)
            {
                while (craftAddQueue.Count > 0)
                {
                    CraftChangeEntry cce = craftAddQueue.Dequeue();
                    AddCraftEntry(cce.playerName, cce.craftType, cce.craftName);
                }

                while (craftDeleteQueue.Count > 0)
                {
                    CraftChangeEntry cce = craftDeleteQueue.Dequeue();
                    DeleteCraftEntry(cce.playerName, cce.craftType, cce.craftName);
                }

                while (craftResponseQueue.Count > 0)
                {
                    CraftResponseEntry cre = craftResponseQueue.Dequeue();
                    SaveCraftFile(cre.craftType, cre.craftName, cre.craftData);
                }

                if (uploadCraftName != null)
                {
                    UploadCraftFile(uploadCraftType, uploadCraftName);
                    uploadCraftName = null;
                    uploadCraftType = CraftType.VAB;
                }

                if (downloadCraftName != null)
                {
                    DownloadCraftFile(selectedPlayer, downloadCraftType, downloadCraftName);
                    downloadCraftName = null;
                    downloadCraftType = CraftType.VAB;
                }

                if (deleteCraftName != null)
                {
                    DeleteCraftEntry(dmpSettings.playerName, deleteCraftType, deleteCraftName);
                    using (MessageWriter mw = new MessageWriter())
                    {
                        mw.Write <int>((int)CraftMessageType.DELETE_FILE);
                        mw.Write <string>(dmpSettings.playerName);
                        mw.Write <int>((int)deleteCraftType);
                        mw.Write <string>(deleteCraftName);
                        networkWorker.SendCraftLibraryMessage(mw.GetMessageBytes());
                    }
                    deleteCraftName = null;
                    deleteCraftType = CraftType.VAB;
                }

                if (displayCraftUploadingMessage && ((Client.realtimeSinceStartup - lastCraftMessageCheck) > CRAFT_MESSAGE_CHECK_INTERVAL))
                {
                    lastCraftMessageCheck = Client.realtimeSinceStartup;
                    if (craftUploadMessage != null)
                    {
                        craftUploadMessage.duration = 0f;
                    }
                    if (finishedUploadingCraft)
                    {
                        displayCraftUploadingMessage = false;
                        craftUploadMessage           = ScreenMessages.PostScreenMessage("Craft uploaded!", 2f, ScreenMessageStyle.UPPER_CENTER);
                    }
                    else
                    {
                        craftUploadMessage = ScreenMessages.PostScreenMessage("Uploading craft...", 1f, ScreenMessageStyle.UPPER_CENTER);
                    }
                }
            }
        }
 private void HandleCraftLibrary(byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData, false))
     {
         CraftMessageType messageType = (CraftMessageType)mr.Read<int>();
         switch (messageType)
         {
             case CraftMessageType.LIST:
                 {
                     string[] playerList = mr.Read<string[]>();
                     foreach (string player in playerList)
                     {
                         bool vabExists = mr.Read<bool>();
                         bool sphExists = mr.Read<bool>();
                         bool subassemblyExists = mr.Read<bool>();
                         DarkLog.Debug("Player: " + player + ", VAB: " + vabExists + ", SPH: " + sphExists + ", SUBASSEMBLY" + subassemblyExists);
                         if (vabExists)
                         {
                             string[] vabCrafts = mr.Read<string[]>();
                             foreach (string vabCraft in vabCrafts)
                             {
                                 CraftChangeEntry cce = new CraftChangeEntry();
                                 cce.playerName = player;
                                 cce.craftType = CraftType.VAB;
                                 cce.craftName = vabCraft;
                                 CraftLibraryWorker.fetch.QueueCraftAdd(cce);
                             }
                         }
                         if (sphExists)
                         {
                             string[] sphCrafts = mr.Read<string[]>();
                             foreach (string sphCraft in sphCrafts)
                             {
                                 CraftChangeEntry cce = new CraftChangeEntry();
                                 cce.playerName = player;
                                 cce.craftType = CraftType.SPH;
                                 cce.craftName = sphCraft;
                                 CraftLibraryWorker.fetch.QueueCraftAdd(cce);
                             }
                         }
                         if (subassemblyExists)
                         {
                             string[] subassemblyCrafts = mr.Read<string[]>();
                             foreach (string subassemblyCraft in subassemblyCrafts)
                             {
                                 CraftChangeEntry cce = new CraftChangeEntry();
                                 cce.playerName = player;
                                 cce.craftType = CraftType.SUBASSEMBLY;
                                 cce.craftName = subassemblyCraft;
                                 CraftLibraryWorker.fetch.QueueCraftAdd(cce);
                             }
                         }
                     }
                 }
                 break;
             case CraftMessageType.ADD_FILE:
                 {
                     CraftChangeEntry cce = new CraftChangeEntry();
                     cce.playerName = mr.Read<string>();
                     cce.craftType = (CraftType)mr.Read<int>();
                     cce.craftName = mr.Read<string>();
                     CraftLibraryWorker.fetch.QueueCraftAdd(cce);
                     ChatWorker.fetch.QueueChannelMessage(ChatWorker.fetch.consoleIdentifier, "", cce.playerName + " shared " + cce.craftName + " (" + cce.craftType + ")");
                 }
                 break;
             case CraftMessageType.DELETE_FILE:
                 {
                     CraftChangeEntry cce = new CraftChangeEntry();
                     cce.playerName = mr.Read<string>();
                     cce.craftType = (CraftType)mr.Read<int>();
                     cce.craftName = mr.Read<string>();
                     CraftLibraryWorker.fetch.QueueCraftDelete(cce);
                 }
                 break;
             case CraftMessageType.RESPOND_FILE:
                 {
                     CraftResponseEntry cre = new CraftResponseEntry();
                     cre.playerName = mr.Read<string>();
                     cre.craftType = (CraftType)mr.Read<int>();
                     cre.craftName = mr.Read<string>();
                     bool hasCraft = mr.Read<bool>();
                     if (hasCraft)
                     {
                         cre.craftData = mr.Read<byte[]>();
                         CraftLibraryWorker.fetch.QueueCraftResponse(cre);
                     }
                     else
                     {
                         ScreenMessages.PostScreenMessage("Craft " + cre.craftName + " from " + cre.playerName + " not available", 5f, ScreenMessageStyle.UPPER_CENTER);
                     }
                 }
                 break;
         }
     }
 }
 public void QueueCraftResponse(CraftResponseEntry entry)
 {
     craftResponseQueue.Enqueue(entry);
 }
 public void QueueCraftResponse(CraftResponseEntry entry)
 {
     craftResponseQueue.Enqueue(entry);
 }