private static void Download(string url, ConcurrentDictionary <string, string> htmlDictionary) { using (var webClient = new SmartWebClient()) { htmlDictionary.TryAdd(url, webClient.DownloadString(url)); } }
void GetChunk() { using (SmartWebClient client = new SmartWebClient(30000)) { // Proxy client.Proxy = client.GetDefaulProxy(); // token //string token = client.DownloadString( // String.Format("{0}/consumer/{1}/{2}/{3}/0/token", Server + "/observer-mode/rest", // "getLastChunkInfo", // Region, // GameId)); ChunkInfo ci = JsonConvert.DeserializeObject <ChunkInfo>(client.DownloadString( String.Format("{0}/consumer/{1}/{2}/{3}/0/token", Server + "/observer-mode/rest", "getLastChunkInfo", Region, GameId))); int ChunkId = ci.chunkId; if (ChunkId == 0) { //Try get chunk once avaliable return; } // Save Replay if (LastChunkNumber == ChunkId) { SaveReplay(client, ChunkId); return; } //Get keyframe if (ChunkId % 2 == 0) { int KeyFrameId = ci.keyFrameId; if (KeyFrameId != 0) { DownloadKey(client, KeyFrameId); } } // Get Current Chunk if (Recording) { DownloadChunk(client, ChunkId); } LastChunkNumber = ChunkId; // Recover MISSING RecoverMissing(client, ci); Thread.Sleep(ci.nextAvailableChunk); } }
public DateTime GetGameStartTime() { try { using (SmartWebClient client = new SmartWebClient(30000)) { // Proxy client.Proxy = client.GetDefaulProxy(); string token = client.DownloadString( String.Format("{0}/consumer/{1}/{2}/{3}/token", this.Server + "/observer-mode/rest", "getGameMetaData", Region, GameId)); GameMetaData gd = JsonConvert.DeserializeObject <GameMetaData>(token); DateTime start = TimeZoneInfo.ConvertTime(DateTime.Parse(gd.startTime), TimeZoneInfo.FindSystemTimeZoneById(TimeZones[Region]), TimeZoneInfo.Local); // TimeSpan ts = new TimeSpan(gd.gameLength * TimeSpan.TicksPerSecond); // DateTime starttime = DateTime.Now.Subtract(ts); return(start); } } catch { } return(DateTime.Now); }
public void GetIP() { try { using (SmartWebClient wbc = new SmartWebClient(4000)) ExternalIp = wbc.DownloadString("https://api.ipify.org/?format=text"); } catch { ExternalIp = "127.0.0.1"; } }
public void LoadAndStart(string gamepath, string deploy, GhostReplay rep) { replay = rep; deploy = deploy.Replace("/", "\\"); StreamName = rep.GameId.ToString() + "-" + rep.Platform; try { using (SmartWebClient wbc = new SmartWebClient(4000)) { string ip = wbc.DownloadString("https://api.ipify.org/?format=text"); cmd = "\"8394\" \"LoLLauncher.exe\" \"\" \"spectator " + ip + ":" + SettingsManager.Settings.GhostStreamPort.ToString() + " " + rep.ObserverKey + " " + rep.GameId.ToString() + " " + rep.Platform + "\""; } } catch { cmd = "\"8394\" \"LoLLauncher.exe\" \"\" \"spectator " + "127.0.0.1" + ":" + SettingsManager.Settings.GhostStreamPort.ToString() + " " + rep.ObserverKey + " " + rep.GameId.ToString() + " " + rep.Platform + "\""; } if (!StreamManager.IsRuning) { StreamManager.InitStream(); } StreamManager.AddStream(rep); //WatchProc = new System.Diagnostics.Process(); //WatchProc.StartInfo.WorkingDirectory = deploy; //WatchProc.StartInfo.UseShellExecute = false; //WatchProc.StartInfo.FileName = Path.Combine(deploy, "League of Legends.exe"); //WatchProc.StartInfo.Arguments = "\"8394\" \"LoLLauncher.exe\" \"\" \"spectator " // + "127.0.0.1:"+SettingsManager.Settings.GhostStreamPort.ToString() + " " // + rep.ObserverKey + " " // + rep.GameId.ToString() + " " // + rep.Platform + "\""; }
private Dictionary <string, string> Extract(string url) { var extractedvalues = new Dictionary <string, string>(); using (var client = new SmartWebClient()) { var webpage = new HtmlDocument(); webpage.LoadHtml(client.DownloadString(url)); var document = webpage; var o = double.Parse("199.0000", CultureInfo.InvariantCulture); var page = document.DocumentNode; var javacointainer = page.QuerySelector("script:contains('sidebarCart')"); var normalprice = double.Parse(GePrice(javacointainer.InnerText, "fullPrice = (\\S+);"), CultureInfo.InvariantCulture); var clientprice = GePrice(javacointainer.InnerText, "\"first_payment\":\"<span>(\\S+)"); extractedvalues.Add("clientprice", clientprice); extractedvalues.Add("normalprice", normalprice.ToString(CultureInfo.InvariantCulture)); } return(extractedvalues); }
void SaveReplay(SmartWebClient client, int ChunkId) { //Sometimes chunk 1 isn't retrieved so get it again... it's like 7 kb so np // Download Chunk 0 DownloadChunk(client, 1); // Download Current Chunk id DownloadChunk(client, ChunkId); if (OnStatusChanged != null) { OnStatusChanged("Saving replay"); } // End Stats string stat = client.DownloadString( String.Format("{0}/consumer/{1}/{2}/{3}/token", Server + "/observer-mode/rest", "endOfGameStats", Region, GameId)); string sum = CurrentReplay.SummonerName; CurrentReplay.ParseStats(Convert.FromBase64String(stat)); CurrentReplay.SummonerName = sum; // Last Chunk Info End string token = client.DownloadString( String.Format("{0}/consumer/{1}/{2}/{3}/0/token", Server + "/observer-mode/rest", "getLastChunkInfo", Region, GameId)); CurrentReplay.ParseLastChunkInfo(token); // Last game meta data token = client.DownloadString( String.Format("{0}/consumer/{1}/{2}/{3}/token", this.Server + "/observer-mode/rest", "getGameMetaData", Region, GameId)); ReplayInfo flags = ReplayInfo.StandardFormat | ReplayInfo.Ghostblade; if (CurrentReplay.IsPBE) { flags |= ReplayInfo.PBE; } if (string.IsNullOrEmpty(CurrentReplay.SummonerName) || CurrentReplay.SummonerName == "Spectator") { flags |= ReplayInfo.Spectator; if (CurrentReplay.GameStats.TeamPlayerParticipantStats.Count > 0) { CurrentReplay.SummonerName = CurrentReplay.GameStats.TeamPlayerParticipantStats[0].SummonerName; } else if (CurrentReplay.GameStats.OtherTeamPlayerParticipantStats.Count > 0) { CurrentReplay.SummonerName = CurrentReplay.GameStats.OtherTeamPlayerParticipantStats[0].SummonerName; } } CurrentReplay.ParseMetaData(token); CurrentReplay.MetaData.clientBackFetchingEnabled = true; CurrentReplay.MetaData.clientBackFetchingFreq = 50; CurrentReplay.MetaData.pendingAvailableChunkInfo.Clear(); CurrentReplay.MetaData.pendingAvailableKeyFrameInfo.Clear(); if (!CurrentReplay.IsPBE) { try { RiotSharp.MatchEndpoint.MatchDetail det = API.GetMatch(RiotTool.PlatformToRegion(Region), GameId); // TODO ADD COMPRESSION FLAG CurrentReplay.PlayerInfos.Map = (byte)det.MapType; CurrentReplay.PlayerInfos.Queue = (byte)det.QueueType; } catch { CurrentReplay.PlayerInfos.Map = 11; CurrentReplay.PlayerInfos.Queue = 4; } } try { CurrentReplay.Save(CurrentReplay.Signer != null, flags); } catch (Exception ex) { if (OnFailedToSave != null) { OnFailedToSave(ex); } } if (OnReplayRecorded != null) { OnReplayRecorded(); } Recording = false; }
public ReplayRecorder(string Server, long GameId, string Region, string Key, GhostReplay rep) { try { this.DownloadTasks = new List <DownloadTask>(); this.GameId = GameId; this.Region = Region; CurrentReplay = rep; Recording = true; if (Directory.Exists(rep.CacheDirectory)) { File.WriteAllText(rep.CacheDirectory + @"\cache.dat", Key); if (!string.IsNullOrEmpty(rep.SummonerName)) { File.WriteAllText(rep.CacheDirectory + @"\summoner.dat", rep.SummonerName); } } if (!Server.StartsWith("127.0.0.1:90")) { this.Server = "http://" + Server; rep.ObserverKey = Key; int ChunkTimeInterval; int LastChunk = 0; using (SmartWebClient client = new SmartWebClient(30000)) { // Proxy client.Proxy = client.GetDefaulProxy(); // Version rep.Version = client.DownloadString(String.Format("{0}/consumer/version", this.Server + "/observer-mode/rest")); // Token string token = client.DownloadString(String.Format("{0}/consumer/{1}/{2}/{3}/token", this.Server + "/observer-mode/rest", "getGameMetaData", Region, GameId)); GameMetaData meta = JsonConvert.DeserializeObject <GameMetaData>(token); ChunkTimeInterval = meta.chunkTimeInterval; LastChunk = meta.endStartupChunkId; } ThreadPool.QueueUserWorkItem(delegate { while (Recording) { try { GetChunk(); RetryAttempt = 0; } catch (Exception ex) { RetryAttempt++; if (OnProblemOccured != null) { OnProblemOccured(this, EventArgs.Empty); } if (RetryAttempt >= 10 && OnFailedToRecord != null) { Recording = false; OnFailedToRecord(ex); } else { Thread.Sleep(15000); } if (RetryAttempt == 1) { Logger.Instance.Log.Error("Failed to record [GET CHUNK]", ex); } } } }); } } catch (Exception ex) { if (OnFailedToRecord != null) { OnFailedToRecord(ex); } Logger.Instance.Log.Error("Failed to record [GLOBAL]", ex); Recording = false; } }