public Character(string name, string realm, int tries = 0) { _name = name; _realm = realm; _tries = tries; string url = String.Format(Alerts.GetFormattedAlert("CHARURL", realm, name, Configuration.bot.WoWAPIKey)); string stats = Utilities.FetchWebResponse <string>(url); if (stats != "Error fetching data.") { /* Need to replace the key words class and int that come in the * response from Blizzard to m_class and intellect. Otherwise it * won't work. TODO: Find a more elegant solution. */ var replaceClassInJson = new Regex(Regex.Escape("\"class\"")); // Change "class" var replaceIntInJson = new Regex(Regex.Escape("\"int\"")); // Change "int" stats = replaceClassInJson.Replace(stats, "\"m_class\"", 1); // ...to "m_class" stats = replaceIntInJson.Replace(stats, "\"intellect\"", 1); // ...to "intellect" // Convert JSON to CharacterModel object. _character = Utilities.DeserializeJsonToString <WoWCharacterModel>(stats); _success = true; return; } else { Console.WriteLine("Error fetching data from Blizzard API."); return; } // End if (stats != "Error fetching data.") && else } // public Character(string name, string realm)
public ActionResult WoWTestView(string realm, string name, [FromServices] AreaDbContext DB) { WoWModuleModel WoW = new WoWModuleModel("vgf6ne9wt7buaewe48wby99u", 0); WoWCharacterModel character = WoW.getAllInfos(realm, name); ViewData["Level"] = character.level; ViewData["Deaths"] = character.deaths; ViewData["Quests"] = character.questsDone; ViewData["Facepalmed"] = character.facepalmed; ViewData["Fish"] = character.fishCaught; return(View()); }
public ActionResult WoWAuthorized(string state, string code, [FromServices] AreaDbContext DB) { string username = HttpContext.Session.GetString("username"); if (String.IsNullOrEmpty(username)) { username = state; } if (String.IsNullOrEmpty(username)) { return(Redirect("http://localhost:5000")); } var key = "ak8a3kw6ksu5y89t8bx5ct8f4kp5uzv5"; var secret = "eTw9eyBDPMwE7PKKd2QX5pXBNx4VBZkt"; var redirect_uri = "https://8aec6d60.ngrok.io/WoW/WoWAuthorized";//"http://localhost:5000/WoW/WoWAuthorized"; var token_uri = "https://eu.battle.net/oauth/token"; var scope = "wow.profile";; var client = new WebClient(); client.UseDefaultCredentials = true; try { byte[] response = client.UploadValues(token_uri, new NameValueCollection() { { "client_id", key }, { "client_secret", secret }, { "redirect_uri", redirect_uri }, { "scope", scope }, { "grant_type", "authorization_code" }, { "code", code } }); string result = System.Text.Encoding.UTF8.GetString(response); dynamic obj = JsonConvert.DeserializeObject(result); DB.tokens.Add(new Models.Token { type = "WoW", username = username, value = obj["access_token"] }); DB.SaveChanges(); WoWModuleModel WoW = new WoWModuleModel(obj["access_token"].ToString(), 0); foreach (var character in WoW.getCharacters()) { if (String.IsNullOrEmpty(character.guild)) { character.guild = "None"; } if (character.name != "Jtefearlol") { WoWCharacterModel ch = WoW.getAllInfos(character.realm, character.name); DB.wowcharactermodels.Add(new Models.WoWCharacterModel { username = username, name = character.name, realm = character.realm, level = character.level, guild = character.guild, deaths = ch.deaths, facepalmed = ch.facepalmed, questsDone = ch.questsDone, fishCaught = ch.fishCaught }); DB.SaveChanges(); } } } catch { Console.WriteLine("Error in WoWAuthorize"); return(Redirect("http://localhost:5000")); } return(Redirect("http://localhost:5000")); }