public static async Task <string> WorldPublishRequest(string worldId) { // Make sure the world is owned, i.e. it has the "__#" format. if (worldId != "__WORLD") { UIHandler.AddNotification(UIAlertType.Error, "Invalid World", "You can only publish your own world. Access it in the Main Menu.", 300); return("fail"); } // Make sure we have the world loaded: if (Systems.handler.worldContent == null || Systems.handler.worldContent.worldId != worldId) { UIHandler.AddNotification(UIAlertType.Error, "Invalid World", "The world did not have a valid ID, or was not loaded correctly.", 300); return("fail"); } UIHandler.AddNotification(UIAlertType.Warning, "Publishing World", "Please wait while we attempt to publish your world...", 180); // All checks have passed. Attempt to publish the world. try { // Attach Login Cookies WebHandler.AttachLoginCookiesToRequest(GameValues.CreoAPI); // Run the World Post StringContent content = new StringContent(JsonConvert.SerializeObject(Systems.handler.worldContent.data), Encoding.UTF8, "application/json"); var response = await Systems.httpClient.PostAsync(GameValues.CreoAPI + "world/" + worldId, content); string responseStr = await response.Content.ReadAsStringAsync(); WorldAPIFormat json = JsonConvert.DeserializeObject <WorldAPIFormat>(responseStr); if (json.success == false) { if (json.reason is string) { UIHandler.AddNotification(UIAlertType.Error, "Unable to Publish", json.reason, 300); } return("fail"); } else { WebHandler.ResponseMessage = ""; } UIHandler.AddNotification(UIAlertType.Success, "World Published", "World Code: " + json.worldId, 3000); return(responseStr); } catch (Exception ex) { return("fail"); } }
public static async Task <string> LevelPublishRequestAsync(string levelId) { // Must be logged in: if (!WebHandler.IsLoggedIn()) { return("fail"); } // Make sure we have the level loaded: if (Systems.handler.levelContent == null || Systems.handler.levelContent.levelId != levelId) { UIHandler.AddNotification(UIAlertType.Error, "Level Not Loaded", "The level did not load correctly. Unable to publish.", 300); return("fail"); } // Make sure the level is owned, i.e. it has the "__#" format. if (levelId.IndexOf("__") != 0) { UIHandler.AddNotification(UIAlertType.Error, "Invalid Access", "You can only publish levels that are stored on the \"My Levels\" screen.", 300); return("fail"); } string testId = levelId.Replace("__", ""); bool success = byte.TryParse(testId, out byte levelNum); if (!success) { UIHandler.AddNotification(UIAlertType.Error, "Invalid Format", "The level file was formatted incorrectly. Cannot publish.", 300); return("fail"); } if (levelNum > GameValues.MaxLevelsAllowedPerUser) { UIHandler.AddNotification(UIAlertType.Error, "Exceeds Allowance", "Can only publish up to " + GameValues.MaxLevelsAllowedPerUser + " levels. This level (#" + levelNum + ") is invalid.", 300); return("fail"); } UIHandler.AddNotification(UIAlertType.Warning, "Publishing Level", "Please wait while we attempt to publish your level...", 180); // All checks have passed. Attempt to publish the level. try { // Attach Login Cookies WebHandler.AttachLoginCookiesToRequest(GameValues.CreoAPI); // Run the Level Post StringContent content = new StringContent(JsonConvert.SerializeObject(Systems.handler.levelContent.data), Encoding.UTF8, "application/json"); var response = await Systems.httpClient.PostAsync(GameValues.CreoAPI + "level/" + levelNum, content); string responseStr = await response.Content.ReadAsStringAsync(); LevelAPIFormat json = JsonConvert.DeserializeObject <LevelAPIFormat>(responseStr); if (json.success == false) { if (json.reason is string) { UIHandler.AddNotification(UIAlertType.Error, "Unable to Publish", json.reason, 300); } return("fail"); } else { WebHandler.ResponseMessage = ""; } UIHandler.AddNotification(UIAlertType.Success, "Level Published", "Level Code: " + json.levelId, 3000); return(responseStr); } catch (Exception ex) { return("fail"); } }