public ActionResult <Response> Put([FromBody] object json) { var data = json.ToString(); var response = JsonConvert.DeserializeObject <CharacterResponse>(data); try { if (response.FileType == "charsave") { // get json into object var charsaveResponse = JsonConvert.DeserializeObject <CharSaveResponse>(data); // load character data var charsave = new SaveReader("1.13c"); charsave.Read(charsaveResponse.Data); // replace stats and items from response charsave = charsaveResponse.GetCharacter(charsave); var ms = new MemoryStream(charsave.GetBytes(true)); // true is important! return(File(ms, "application/octet-stream", charsave.Character.Name)); } else if (response.FileType == "charitem") { var charitemResponse = JsonConvert.DeserializeObject <CharItemResponse>(data); // load item data var charitem = Item.NewItem(charitemResponse.Data); // replace item data from response charitem = charitemResponse.GetItem(charitem); var ms = new MemoryStream(charitem.GetItemBytes()); return(File(ms, "application/octet-stream", charitemResponse.DisplayData.Title)); } else if (response.FileType == "charinfo") { var charinfo = JsonConvert.DeserializeObject <CharInfo>(data); var ms = new MemoryStream(charinfo.GetBytes()); return(File(ms, "application/octet-stream", charinfo.Name)); } } catch (Exception e) { return(new ErrorResponse(ErrorCode.BAD_DATA, e.Message, e.ToString())); } return(new ErrorResponse(ErrorCode.NOT_SUPPORTED, "Unsupported fileType. Use POST method to retrieve proper data structure.")); }
public CharSaveResponse(SaveReader playerData, string hash = null) { Data = playerData.GetBytes(true); // true is important! Hash = (hash != null) ? hash : Helper.MD5(Data); HashWithOriginalStat = (hash != null) ? hash : Helper.MD5(playerData.GetBytes(true, true)); // true is important!; Version = playerData.Version; TimeStamp = playerData.TimeStamp; // items foreach (var i in playerData.Inventory.PlayerItems) { PlayerItems.Add(new CharItemResponse(i)); } foreach (var i in playerData.Inventory.CorpseItems) { CorpseItems.Add(new CharItemResponse(i)); } foreach (var i in playerData.Inventory.GolemItems) { GolemItems.Add(new CharItemResponse(i)); } foreach (var i in playerData.Inventory.MercItems) { MercItems.Add(new CharItemResponse(i)); } Name = playerData.Character.Name; Class = playerData.Character.Class; Died = playerData.Character.Died; Expansion = playerData.Character.Expansion; Hardcore = playerData.Character.Hardcore; Ladder = playerData.Character.Ladder; HasMercenary = playerData.Character.HasMercenary; MercenaryExp = playerData.Character.MercenaryExp; MercenaryNameId = playerData.Character.MercenaryNameId; MercenaryType = playerData.Character.MercenaryType; Progression = playerData.Character.Progression; BaseHitpoints = playerData.Stat.BaseHitpoints; BaseMana = playerData.Stat.BaseMana; BaseStamina = playerData.Stat.BaseStamina; DeathCount = playerData.Stat.DeathCount; Dexterity = playerData.Stat.Dexterity; Energy = playerData.Stat.Energy; Experience = playerData.Stat.Experience; Gold = playerData.Stat.Gold; GoldBank = playerData.Stat.GoldBank; Hitpoints = playerData.Stat.Hitpoints; KillCount = playerData.Stat.KillCount; Level = playerData.Stat.Level; Mana = playerData.Stat.Mana; SkillPoints = playerData.Stat.SkillPoints; Stamina = playerData.Stat.Stamina; StatPoints = playerData.Stat.StatPoints; Strength = playerData.Stat.Strength; Vitality = playerData.Stat.Vitality; for (var i = 0; i < playerData.Skill.Length; i++) { Skills.Add(byte.Parse(playerData.Skill[i].ToString())); } }