public void HandleMessage(IMessageData messageData) { var msgData = messageData as CraftLibraryBaseMsgData; if (msgData == null) { return; } switch (msgData.CraftMessageType) { case CraftMessageType.LIST_REPLY: { var data = (CraftLibraryListReplyMsgData)messageData; var playerList = data.PlayerCrafts; foreach (var playerCraft in playerList) { var vabExists = playerCraft.Value.VabExists; var sphExists = playerCraft.Value.SphExists; var subassemblyExists = playerCraft.Value.SubassemblyExists; Debug.Log($"[LMP]: Player: {playerCraft.Key}, VAB: {vabExists}, SPH: {sphExists}, SUBASSEMBLY {subassemblyExists}"); if (vabExists) { var vabCrafts = playerCraft.Value.VabCraftNames; foreach (var vabCraft in vabCrafts) { var cce = new CraftChangeEntry(); cce.PlayerName = playerCraft.Key; cce.CraftType = CraftType.VAB; cce.CraftName = vabCraft; System.QueueCraftAdd(cce); } } if (sphExists) { var sphCrafts = playerCraft.Value.SphCraftNames; foreach (var sphCraft in sphCrafts) { var cce = new CraftChangeEntry(); cce.PlayerName = playerCraft.Key; cce.CraftType = CraftType.SPH; cce.CraftName = sphCraft; System.QueueCraftAdd(cce); } } if (subassemblyExists) { var subassemblyCrafts = playerCraft.Value.SubassemblyCraftNames; foreach (var subassemblyCraft in subassemblyCrafts) { var cce = new CraftChangeEntry(); cce.PlayerName = playerCraft.Key; cce.CraftType = CraftType.SUBASSEMBLY; cce.CraftName = subassemblyCraft; System.QueueCraftAdd(cce); } } } MainSystem.Singleton.NetworkState = ClientState.CRAFTLIBRARY_SYNCED; } break; case CraftMessageType.ADD_FILE: { var data = (CraftLibraryAddMsgData)messageData; var cce = new CraftChangeEntry { PlayerName = data.PlayerName, CraftType = data.UploadType, CraftName = data.UploadName }; System.QueueCraftAdd(cce); ChatSystem.Singleton.Queuer.QueueChannelMessage(SettingsSystem.ServerSettings.ConsoleIdentifier, "", cce.PlayerName + " shared " + cce.CraftName + " (" + cce.CraftType + ")"); } break; case CraftMessageType.DELETE_FILE: { var data = (CraftLibraryDeleteMsgData)messageData; var cce = new CraftChangeEntry(); cce.PlayerName = data.PlayerName; cce.CraftType = data.CraftType; cce.CraftName = data.CraftName; System.QueueCraftDelete(cce); } break; case CraftMessageType.RESPOND_FILE: { var data = (CraftLibraryRespondMsgData)messageData; var cre = new CraftResponseEntry { PlayerName = data.PlayerName, CraftType = data.RequestedType, CraftName = data.RequestedName }; var hasCraft = data.HasCraft; if (hasCraft) { cre.CraftData = data.CraftData; System.QueueCraftResponse(cre); } else { ScreenMessages.PostScreenMessage( "Craft " + cre.CraftName + " from " + cre.PlayerName + " not available", 5f, ScreenMessageStyle.UPPER_CENTER); } } break; } }
public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is CraftLibraryBaseMsgData msgData)) { return; } switch (msgData.CraftMessageType) { case CraftMessageType.ListReply: { var data = (CraftLibraryListReplyMsgData)msgData; for (var i = 0; i < data.PlayerCraftsCount; i++) { if (data.PlayerCrafts[i].Crafts.VabExists) { for (var j = 0; j < data.PlayerCrafts[i].Crafts.VabCraftCount; j++) { System.QueueCraftAdd(new CraftChangeEntry { PlayerName = data.PlayerCrafts[i].PlayerName, CraftType = CraftType.Vab, CraftName = data.PlayerCrafts[i].Crafts.VabCraftNames[j] }); } } if (data.PlayerCrafts[i].Crafts.SphExists) { for (var j = 0; j < data.PlayerCrafts[i].Crafts.SphCraftCount; j++) { System.QueueCraftAdd(new CraftChangeEntry { PlayerName = data.PlayerCrafts[i].PlayerName, CraftType = CraftType.Sph, CraftName = data.PlayerCrafts[i].Crafts.SphCraftNames[j] }); } } if (data.PlayerCrafts[i].Crafts.SubassemblyExists) { for (var j = 0; j < data.PlayerCrafts[i].Crafts.SubassemblyCraftCount; j++) { System.QueueCraftAdd(new CraftChangeEntry { PlayerName = data.PlayerCrafts[i].PlayerName, CraftType = CraftType.Subassembly, CraftName = data.PlayerCrafts[i].Crafts.SubassemblyCraftNames[j] }); } } } MainSystem.NetworkState = ClientState.CraftlibrarySynced; } break; case CraftMessageType.AddFile: { var data = (CraftLibraryAddMsgData)msgData; var cce = new CraftChangeEntry { PlayerName = data.PlayerName, CraftType = data.UploadType, CraftName = data.UploadName }; System.QueueCraftAdd(cce); SystemsContainer.Get <ChatSystem>().Queuer.QueueChannelMessage(SettingsSystem.ServerSettings.ConsoleIdentifier, "", $"{cce.PlayerName} shared {cce.CraftName} ({cce.CraftType})"); } break; case CraftMessageType.DeleteFile: { var data = (CraftLibraryDeleteMsgData)msgData; var cce = new CraftChangeEntry { PlayerName = data.PlayerName, CraftType = data.CraftType, CraftName = data.CraftName }; System.QueueCraftDelete(cce); } break; case CraftMessageType.RespondFile: { var data = (CraftLibraryRespondMsgData)msgData; var craftData = Common.TrimArray(data.CraftData, data.NumBytes); var cre = new CraftResponseEntry { PlayerName = data.PlayerName, CraftType = data.RequestedType, CraftName = data.RequestedName, CraftData = craftData }; System.QueueCraftResponse(cre); } break; } }
public void QueueCraftResponse(CraftResponseEntry entry) { CraftResponseQueue.Enqueue(entry); }
public void HandleMessage(IMessageData messageData) { var msgData = messageData as CraftLibraryBaseMsgData; if (msgData == null) { return; } switch (msgData.CraftMessageType) { case CraftMessageType.ListReply: { var data = (CraftLibraryListReplyMsgData)messageData; var playerList = data.PlayerCrafts; foreach (var playerCraft in playerList) { var vabExists = playerCraft.Value.VabExists; var sphExists = playerCraft.Value.SphExists; var subassemblyExists = playerCraft.Value.SubassemblyExists; LunaLog.Log($"[LMP]: Player: {playerCraft.Key}, VAB: {vabExists}, SPH: {sphExists}, SUBASSEMBLY {subassemblyExists}"); if (vabExists) { var vabCrafts = playerCraft.Value.VabCraftNames; foreach (var vabCraft in vabCrafts) { var cce = new CraftChangeEntry { PlayerName = playerCraft.Key, CraftType = CraftType.Vab, CraftName = vabCraft }; System.QueueCraftAdd(cce); } } if (sphExists) { var sphCrafts = playerCraft.Value.SphCraftNames; foreach (var sphCraft in sphCrafts) { var cce = new CraftChangeEntry { PlayerName = playerCraft.Key, CraftType = CraftType.Sph, CraftName = sphCraft }; System.QueueCraftAdd(cce); } } if (subassemblyExists) { var subassemblyCrafts = playerCraft.Value.SubassemblyCraftNames; foreach (var subassemblyCraft in subassemblyCrafts) { var cce = new CraftChangeEntry { PlayerName = playerCraft.Key, CraftType = CraftType.Subassembly, CraftName = subassemblyCraft }; System.QueueCraftAdd(cce); } } } SystemsContainer.Get <MainSystem>().NetworkState = ClientState.CraftlibrarySynced; } break; case CraftMessageType.AddFile: { var data = (CraftLibraryAddMsgData)messageData; var cce = new CraftChangeEntry { PlayerName = data.PlayerName, CraftType = data.UploadType, CraftName = data.UploadName }; System.QueueCraftAdd(cce); SystemsContainer.Get <ChatSystem>().Queuer.QueueChannelMessage(SettingsSystem.ServerSettings.ConsoleIdentifier, "", $"{cce.PlayerName} shared {cce.CraftName} ({cce.CraftType})"); } break; case CraftMessageType.DeleteFile: { var data = (CraftLibraryDeleteMsgData)messageData; var cce = new CraftChangeEntry { PlayerName = data.PlayerName, CraftType = data.CraftType, CraftName = data.CraftName }; System.QueueCraftDelete(cce); } break; case CraftMessageType.RespondFile: { var data = (CraftLibraryRespondMsgData)messageData; var cre = new CraftResponseEntry { PlayerName = data.PlayerName, CraftType = data.RequestedType, CraftName = data.RequestedName }; var hasCraft = data.HasCraft; if (hasCraft) { cre.CraftData = data.CraftData; System.QueueCraftResponse(cre); } } break; } }