public static IEnumerator RemoveItemsFromClusterio(string bodyName, Dictionary <string, int> clusterioInventory, string itemName, int count, Action <bool> onFinished = null) { if (!BodyHasServer(bodyName)) { Debug.Log(String.Format("XenoIndustrySignpost: Sending a RemoveItemsFromClusterio request to a celestial {0} which has no assigned server!", bodyName)); yield break; } XenoIndustrySignpostBodyAddress address = bodyAddresses[bodyName]; // Connect to the server if we aren't connected yet if (!ClusterioConnector.IsConnected(address.masterIP, address.masterPort)) { ClusterioConnector.ConntectToMaster(address.masterIP, address.masterPort, address.masterAuthToken); } // First, we need to see what items are stored in the Clusterio server, and wait for that request to be finished yield return(XenoIndustryCore.instance.StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory))); // Don't do a remove request if there's not enough items, or if the item isn't there at all if (!clusterioInventory.ContainsKey(itemName) || clusterioInventory[itemName] < count) { yield break; } Dictionary <string, string> sendValues = new Dictionary <string, string>(); sendValues["name"] = itemName; sendValues["count"] = count.ToString(); Debug.Log(String.Format("ClusterioUtil: removing {0} of {1} from item repository", count, itemName)); string apiCommand = "/api/remove"; ClusterioMessage resultMessage = new ClusterioMessage(); yield return(ClusterioConnector.SendPostRequest(address.masterIP, address.masterPort, apiCommand, resultMessage, sendValues)); if (resultMessage.result == ClusterioMessageResult.SUCCESS) { if (onFinished != null) { onFinished(true); } } else { if (onFinished != null) { onFinished(false); } } }
public static IEnumerator AddItemsToClusterio(string bodyName, string itemName, int count, Action <bool> onFinished = null) { if (!BodyHasServer(bodyName)) { Debug.Log(String.Format("XenoIndustrySignpost: Sending a AddItemsToClusterio request to a celestial {0} which has no assigned server!", bodyName)); yield break; } XenoIndustrySignpostBodyAddress address = bodyAddresses[bodyName]; // Connect to the server if we aren't connected yet if (!ClusterioConnector.IsConnected(address.masterIP, address.masterPort)) { ClusterioConnector.ConntectToMaster(address.masterIP, address.masterPort, address.masterAuthToken); } Dictionary <string, string> sendValues = new Dictionary <string, string>(); sendValues["name"] = itemName; sendValues["count"] = count.ToString(); Debug.Log(String.Format("ClusterioUtil: adding {0} of {1} to item repository", count, itemName)); string apiCommand = "/api/place"; ClusterioMessage resultMessage = new ClusterioMessage(); yield return(ClusterioConnector.SendPostRequest(address.masterIP, address.masterPort, apiCommand, resultMessage, sendValues)); if (resultMessage.result == ClusterioMessageResult.SUCCESS) { if (onFinished != null) { onFinished(true); } } else { if (onFinished != null) { onFinished(false); } } }