private static matchstatsJson getCurrentMatchStats(CookieContainer cookieContainer) { matchstatsJson matchStatsJson = null; string matchStats = null; try { var request = (HttpWebRequest)WebRequest.Create("http://www.saltybet.com/ajax_get_stats.php"); request.CookieContainer = cookieContainer; var response = (HttpWebResponse)request.GetResponse(); using (var responseStream = response.GetResponseStream()) { if (responseStream != null) { var encoding = Encoding.GetEncoding("utf-8"); var StreamReader = new StreamReader(responseStream, encoding); matchStats = StreamReader.ReadToEnd(); } } response.Close(); response.Dispose(); request.Abort(); } catch { Console.WriteLine("cannot retrieve match stats"); } return(matchStatsJson = JsonConvert.DeserializeObject <matchstatsJson>(matchStats)); }
static void Main(string[] args) { string oauth = File.ReadAllText("oauth.txt"); StreamReader readCookie = File.OpenText("cookie.txt"); cookieText = readCookie.ReadToEnd(); Console.WriteLine(cookieText); Console.WriteLine(oauth); //sqlCon.ConnectionString = sqlConnectString; mySqlCon.ConnectionString = mySqlConnectString; matchstatsJson currentMatch = null; startOver: try { //test connecting to chat irc = new ircClient("irc.chat.twitch.tv", 6667, "fapvamp", oauth); irc.joinRoom("saltybet"); //test if cookie is good, if cookie is not in place, or expired then currentMatch.p1Name will be null and error. currentMatch = getCurrentMatchStats(makeCookieContainer()); string s = currentMatch.p1name; } catch (Exception e) { Console.WriteLine("can't find your cookie or your cookie is expired! please place in the same directory as the program and name it cookie.txt"); Console.WriteLine("file should contain 2 parts: __cfduid and PHPSESSID"); Console.WriteLine("e.g."); Console.WriteLine("__cfduid=d2222290be446ee5e3c0b5436d6e852236466187773; PHPSESSID=g89dkhgtfpp2d9j3vh1lpr8x23"); Console.WriteLine("press any key to close the program"); Console.WriteLine(e); Console.ReadKey(); return; } while (true) { try { //monitor chat for when we should start betting or listen for results of current match string message = irc.readMessage(); if (message.Contains(waifu) && (message.Contains("Bets are OPEN") || message.Contains("Bets are locked"))) { //bets are open or closed high importance Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(message); Console.ResetColor(); buildCurrentMatch(makeCookieContainer()); } } catch (Exception e) { //something went wrong, start all over //rewrite to remove goto Console.WriteLine(e); goto startOver; } } }
private static List <fighter> buildFighters(matchstatsJson currentMatch) { List <fighter> Fighters = new List <fighter>(); fighter RedFighter1 = null; fighter RedFighter2 = null; fighter BlueFighter1 = null; fighter BlueFighter2 = null; if (currentMatch.p1name.Contains("/") || currentMatch.p2name.Contains("/")) { //3-4 player match string[] redNames = currentMatch.p1name.Replace("'", "").Split('/'); string[] redTotalMatches = currentMatch.p1totalmatches.Split('/'); string[] redWinRate = currentMatch.p1winrate.Split('/'); string[] redTier = currentMatch.p1tier.Split('/'); string[] redLife = currentMatch.p1life.Split('/'); string[] redAuthor = currentMatch.p1author.Split('/'); string[] redPalette = currentMatch.p1palette.Split('/'); string[] blueNames = currentMatch.p2name.Replace("'", "").Split('/'); string[] blueTotalMatches = currentMatch.p2totalmatches.Split('/'); string[] blueWinRate = currentMatch.p2winrate.Split('/'); string[] blueTier = currentMatch.p2tier.Split('/'); string[] blueLife = currentMatch.p2life.Split('/'); string[] blueAuthor = currentMatch.p2author.Split('/'); string[] bluePalette = currentMatch.p2palette.Split('/'); RedFighter1 = new fighter(redNames[0], Convert.ToInt32(redTotalMatches[0]), Convert.ToInt32(redWinRate[0]), redTier[0], Convert.ToInt32(redLife[0]), redAuthor[0], Convert.ToInt32(redPalette[0])); if (redNames.Count() > 1) { RedFighter2 = new fighter(redNames[1], Convert.ToInt32(redTotalMatches[1]), Convert.ToInt32(redWinRate[1]), redTier[1], Convert.ToInt32(redLife[1]), redAuthor[1], Convert.ToInt32(redPalette[1])); } BlueFighter1 = new fighter(blueNames[0], Convert.ToInt32(blueTotalMatches[0]), Convert.ToInt32(blueWinRate[0]), blueTier[0], Convert.ToInt32(blueLife[0]), blueAuthor[0], Convert.ToInt32(bluePalette[0])); Fighters.Add(RedFighter1); if (RedFighter2 != null) { Fighters.Add(RedFighter2); } Fighters.Add(BlueFighter1); if (blueNames.Count() > 1) { BlueFighter2 = new fighter(blueNames[1], Convert.ToInt32(blueTotalMatches[1]), Convert.ToInt32(blueWinRate[1]), blueTier[1], Convert.ToInt32(blueLife[1]), blueAuthor[1], Convert.ToInt32(bluePalette[1])); Fighters.Add(BlueFighter2); } } else { //2 player match string redNames = currentMatch.p1name; string redTotalMatches = currentMatch.p1totalmatches; string redWinRate = currentMatch.p1winrate; string redTier = currentMatch.p1tier; string redLife = currentMatch.p1life; string redAuthor = currentMatch.p1author; string redPalette = currentMatch.p1palette; string blueNames = currentMatch.p2name; string blueTotalMatches = currentMatch.p2totalmatches; string blueWinRate = currentMatch.p2winrate; string blueTier = currentMatch.p2tier; string blueLife = currentMatch.p2life; string blueAuthor = currentMatch.p2author; string bluePalette = currentMatch.p2palette; RedFighter1 = new fighter(redNames, Convert.ToInt32(redTotalMatches), Convert.ToInt32(redWinRate), redTier, Convert.ToInt32(redLife), redAuthor, Convert.ToInt32(redPalette)); BlueFighter1 = new fighter(blueNames, Convert.ToInt32(blueTotalMatches), Convert.ToInt32(blueWinRate), blueTier, Convert.ToInt32(blueLife), blueAuthor, Convert.ToInt32(bluePalette)); Fighters.Add(RedFighter1); Fighters.Add(BlueFighter1); } return(Fighters); }
private static void buildCurrentMatch(CookieContainer cookieContainer) { //happens when waifu says bets are open //add fight to db if it doesn't exist, then wait for win or loss message, update who won. //if fight does exist, offer advice on who to bet on, wait for win/loss, update who won. gameCrash: int balance = getBalance(cookieContainer); mySqlCon.ConnectionString = mySqlConnectString; stateJson currentState = getCurrentState(); matchstatsJson currentMatch = getCurrentMatchStats(makeCookieContainer()); List <fighter> currentFighters = buildFighters(currentMatch); string RedTeam = currentState.p1name; string BlueTeam = currentState.p2name; int countFighters = currentFighters.Count; double redChanceToWin = 0; mySqlCon.Open(); try { //figure out how to bet by getting bet mode currentMode = setBetMode(currentState); setBetModifier(currentMode); } catch (Exception e) { Console.WriteLine("Cannot set bet modifier"); Console.WriteLine(e); } match newMatch = new match(currentFighters); redChanceToWin = newMatch.getRedChanceToWin(mySqlCon); Console.WriteLine("red chance to win: " + redChanceToWin); try { bool fighting = true; Console.WriteLine("Current Salt: " + balance); Console.WriteLine("Salt gained/lost on last bet: " + (balance - oldBalance)); makeBet(cookieContainer, currentFighters, balance, redChanceToWin, currentMode); Console.WriteLine("Waiting for winner"); while (fighting) { string message = irc.readMessage(); if (message.Contains(waifu)) { if (message.Contains(RedTeam) && message.Contains("wins")) { Console.WriteLine(message); updateELOs(newMatch, redChanceToWin, true); isRedTeam = true; recordWL(redChanceToWin); Console.WriteLine("Red wins!"); Console.WriteLine("W/L: " + wins + "/" + losses); mySqlCon.Close(); fighting = false; } else if (message.Contains(BlueTeam) && message.Contains("wins")) { Console.WriteLine(message); updateELOs(newMatch, redChanceToWin, false); isRedTeam = false; recordWL(redChanceToWin); Console.WriteLine("Blue wins!"); Console.WriteLine("W/L: " + wins + "/" + losses); mySqlCon.Close(); fighting = false; } else if (message.Contains("Bets are OPEN")) { Console.WriteLine(message); Console.WriteLine("We missed the winner message or the game possibly crashed, start over"); fighting = false; mySqlCon.Close(); goto gameCrash; } } } } catch (Exception e) { Console.WriteLine(e); mySqlCon.Close(); //Console.WriteLine("Could not Connect to DB"); } }