public virtual void InitializeAsync(CancellationTokenSource cancellationTokenSource, ITaskManager taskManager, IHttpDownloaderContainer httpDownloaderContainer, IErrorFeedback errorFeedback, IProxySearchFeedback proxySearchFeedback, IGeoIP geoIP, IRatingManager ratingManager) { CancellationTokenSource = cancellationTokenSource; TaskManager = taskManager; HttpDownloaderContainer = httpDownloaderContainer; ErrorFeedback = errorFeedback; ProxySearchFeedback = proxySearchFeedback; GeoIP = geoIP; RatingManager = ratingManager; IAsyncInitialization asyncInitialization = DetailsProvider as IAsyncInitialization; if (asyncInitialization != null) { asyncInitialization.InitializeAsync(cancellationTokenSource, taskManager, httpDownloaderContainer, errorFeedback, proxySearchFeedback, geoIP, ratingManager); } TaskManager.Tasks.CollectionChanged += (sender, e) => { if (e.Action == NotifyCollectionChangedAction.Remove) { StartCheckProxiesTaskIfRequired(); } }; }
public void InitializeAsync(CancellationTokenSource cancellationTokenSource, ITaskManager taskManager, IHttpDownloaderContainer httpDownloaderContainer, IErrorFeedback errorFeedback, IProxySearchFeedback proxySearchFeedback, IGeoIP geoIP, IRatingManager ratingManager) { this.httpDownloaderContainer = httpDownloaderContainer; TaskItem taskItem = taskManager.Create(Resources.ConfigureProviderOfProxyDetails); taskItem.UpdateDetails(Resources.DetermineCurrentIPAddress); initializatinTask = httpDownloaderContainer.HttpDownloader .GetContentOrNull(MyIPUrl, null, cancellationTokenSource) .ContinueWith(task => { try { if (task.Result != null) { IPAddress.TryParse(task.Result.Trim(), out myIPAddress); } } finally { taskItem.Dispose(); } }); }
public void InitializeAsync(CancellationTokenSource cancellationTokenSource, ITaskManager taskManager, IHttpDownloaderContainer httpDownloaderContainer, IErrorFeedback errorFeedback, IProxySearchFeedback proxySearchFeedback, IGeoIP geoIP) { this.httpDownloaderContainer = httpDownloaderContainer; TaskItem taskItem = taskManager.Create(Resources.ConfigureProviderOfProxyDetails); taskItem.UpdateDetails(Resources.DetermineCurrentIPAddress); initializatinTask = httpDownloaderContainer.HttpDownloader .GetContentOrNull(MyIPUrl, null, cancellationTokenSource) .ContinueWith(task => { try { if (task.Result != null) { IPAddress.TryParse(task.Result.Trim(), out myIPAddress); } } finally { taskItem.Dispose(); } }); }
public Application(ISearchEngine searchEngine, IProxyChecker checker, IHttpDownloaderContainer httpDownloaderContainer, IGeoIP geoIP = null, IProxyProvider proxyProvider = null, ITaskManager taskManager = null) { this.searchEngine = searchEngine; this.checker = checker; this.httpDownloaderContainer = httpDownloaderContainer; this.proxyProvider = proxyProvider ?? new ProxyProvider(); this.geoIP = geoIP ?? new TurnOffGeoIP(); this.taskManager = taskManager ?? new TaskManager(); }
public Application(ISearchEngine searchEngine, IProxyChecker checker, IHttpDownloaderContainer httpDownloaderContainer, IGeoIP geoIP = null, IRatingManager ratingManager = null, IProxyProvider proxyProvider = null, ITaskManager taskManager = null) { this.searchEngine = searchEngine; this.checker = checker; this.httpDownloaderContainer = httpDownloaderContainer; this.proxyProvider = proxyProvider ?? new ProxyProvider(); this.geoIP = geoIP ?? new TurnOffGeoIP(); this.taskManager = taskManager ?? new TaskManager(); this.ratingManager = ratingManager ?? new DisabledRatingManager(); }
public Application Create(TaskItem task, ProxySearchFeedback feedback) { Context.Set(new CancellationTokenSource()); Context.Set <IHttpDownloaderContainer>(HttpDownloaderContainer); task.UpdateDetails(Resources.ReadingConfigurationOfSelectedSearch); IDetectable searchEngineDetectable = DetectableManager.CreateDetectableInstance <ISearchEngine>(Settings.SelectedTabSettings.SearchEngineDetectableType); IDetectable proxyCheckerDetectable = DetectableManager.CreateDetectableInstance <IProxyChecker>(Settings.SelectedTabSettings.ProxyCheckerDetectableType); IDetectable geoIPDetectable = DetectableManager.CreateDetectableInstance <IGeoIP>(Settings.GeoIPDetectableType); ISearchEngine searchEngine = DetectableManager.CreateImplementationInstance <ISearchEngine>(searchEngineDetectable, Settings.SelectedTabSettings.SearchEngineSettings, searchEngineDetectable.InterfaceSettings); feedback.ExportAllowed = !(searchEngine is FolderSearchEngine); task.UpdateDetails(Resources.PreparingProxyProvider); IProxyProvider proxyProvider = new ProxyProvider(Context.Get <IBlackList>(), new ParseMethodsProvider(Settings.ParseDetails)); task.UpdateDetails(Resources.PreparingProxyChecker); IProxyChecker proxyChecker = DetectableManager.CreateImplementationInstance <IProxyChecker>(proxyCheckerDetectable, Settings.SelectedTabSettings.ProxyCheckerSettings, proxyCheckerDetectable.InterfaceSettings); task.UpdateDetails(Resources.PreparingGeoIpService); IGeoIP geoIP = DetectableManager.CreateImplementationInstance <IGeoIP>(geoIPDetectable, Settings.GeoIPSettings, geoIPDetectable.InterfaceSettings); task.UpdateDetails(Resources.PreparingApplication); Application application = new Application(searchEngine, proxyChecker, HttpDownloaderContainer, geoIP, Context.Get <IRatingManager>(), proxyProvider, Context.Get <ITaskManager>()); application.ProxyAlive += feedback.OnAliveProxy; application.OnError += Context.Get <IErrorFeedback>().SetException; return(application); }
public override void InitializeAsync(CancellationTokenSource cancellationTokenSource, ITaskManager taskManager, IHttpDownloaderContainer httpDownloaderContainer, IErrorFeedback errorFeedback, IProxySearchFeedback proxySearchFeedback, IGeoIP geoIP, IRatingManager ratingManager) { base.InitializeAsync(cancellationTokenSource, taskManager, httpDownloaderContainer, errorFeedback, proxySearchFeedback, geoIP, ratingManager); TaskItem taskItem = taskManager.Create(Resources.ConfiguringProxyChecker); try { taskItem.UpdateDetails(string.Format(Resources.DownloadingFormat, Url)); initializatinTask = httpDownloaderContainer.HttpDownloader.GetContentOrNull(Url, null, cancellationTokenSource) .ContinueWith(task => { try { if (task.Result == null) { errorFeedback.SetException(new InvalidOperationException(string.Format(Resources.CannotDownloadContent, Url))); cancellationTokenSource.Cancel(); } else { analyzedText = AnalyzeText(task.Result); } } finally { taskItem.Dispose(); } }); } catch (TaskCanceledException) { } }
public IndexModel(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IGeoIP geoIp) { Configuration = configuration; GeoIP = geoIp; _hostingEnvironment = hostingEnvironment; }
private void Message(UnturnedPlayer player, bool @join) { try { if (State != PluginState.Loaded) { return; } IGeoIP geoip = null; if (Config.ShowJoinCountry && @join) { try { SteamGameServerNetworking.GetP2PSessionState(player.CSteamID, out P2PSessionState_t pConnectionState); string iPFromUInt = Parser.getIPFromUInt32(pConnectionState.m_nRemoteIP); #if DEBUG UnturnedChat.Say($"[DEBUG] CSteamID: {player.CSteamID}"); UnturnedChat.Say($"[DEBUG] iPFromUInt: {iPFromUInt}"); iPFromUInt = new System.Net.WebClient().DownloadString("https://ipinfo.io/ip").Replace("\n", "").Trim(); #endif var url = string.Empty; if (Config.GeoIpProvider.Contains("ipinfo")) { url = $"http://ipinfo.io/{iPFromUInt}/json"; } else if (Config.GeoIpProvider.Contains("ipapi")) { url = $"http://ip-api.com/json/{iPFromUInt}"; } var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.UserAgent = "Unturned/Rocket"; request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; var content = string.Empty; using (var response = (HttpWebResponse)request.GetResponse()) using (var stream = response.GetResponseStream()) using (var sr = new StreamReader(stream)) content = sr.ReadToEnd(); if (!string.IsNullOrWhiteSpace(content)) { if (Config.GeoIpProvider.Contains("ipinfo")) { geoip = JsonConvert.DeserializeObject <IpInfo>(content); if ((geoip as IpInfo).Bogon) { geoip = null; } } else if (Config.GeoIpProvider.Contains("ipapi")) { geoip = JsonConvert.DeserializeObject <IpApi>(content); if ((geoip as IpApi).Status != "success") { geoip = null; } } } } catch (Exception ex) { Logger.LogException(ex); } if (geoip != null && Config.Countries != null) { if (geoip.Country.Length == 2 && Config.Countries.Any(m => m.Key == geoip.Country)) { geoip.Country = Config.Countries.First(m => m.Key == geoip.Country).Value; } } #if DEBUG if (geoip != null) { UnturnedChat.Say($"[DEBUG] Country: {geoip.Country}"); } #endif } var message = string.Empty; if (!R.Permissions.HasPermission(player, "broadcast.vanish")) { if ((R.Permissions.HasPermission(player, "broadcast.group") || player.IsAdmin) && Config.GroupMessages) { var group = R.Permissions.GetGroups(player, false).FirstOrDefault(); if (!Config.ExtendedMessages) { message = Translate(@join ? "connect_group_message" : "disconnect_group_message", group != null ? group.DisplayName + ": " : "", player.CharacterName); if (geoip != null && @join) { message = Translate("connect_group_message_country", group != null ? group.DisplayName + ": " : "", player.CharacterName, geoip.Country); } UnturnedChat.Say(message, @join ? Config.JoinMessage : Config.LeaveMessage); } else { foreach (var sdgPlayer in Provider.clients) { if (sdgPlayer != null) { if (R.Permissions.HasPermission(new RocketPlayer(sdgPlayer.playerID.steamID.ToString()), "broadcast.extended") || sdgPlayer.isAdmin) { message = Translate(@join ? "connect_group_message_extended" : "disconnect_group_message_extended", group != null ? group.DisplayName + ": " : "", player.CharacterName, player.SteamName, player.CSteamID.ToString()); if (geoip != null && @join) { message = Translate("connect_group_message_country_extended", group != null ? group.DisplayName + ": " : "", player.CharacterName, player.SteamName, player.CSteamID.ToString(), geoip.Country); } } else { message = Translate(@join ? "connect_group_message" : "disconnect_group_message", group != null ? group.DisplayName + ": " : "", player.CharacterName); if (geoip != null && @join) { message = Translate("connect_group_message_country", group != null ? group.DisplayName + ": " : "", player.CharacterName, geoip.Country); } } UnturnedChat.Say(sdgPlayer.playerID.steamID, message, @join ? Config.JoinMessage : Config.LeaveMessage); } } } } else { if (!Config.ExtendedMessages) { message = Translate(@join ? "connect_message" : "disconnect_message", player.CharacterName); if (geoip != null && @join) { message = Translate("connect_message_country", player.CharacterName, geoip.Country); } UnturnedChat.Say(message, @join ? Config.JoinMessage : Config.LeaveMessage); } else { foreach (var sdgPlayer in Provider.clients) { if (sdgPlayer != null) { if (R.Permissions.HasPermission(new RocketPlayer(sdgPlayer.playerID.steamID.ToString()), "broadcast.extended") || sdgPlayer.isAdmin) { message = Translate(@join ? "connect_message_extended" : "disconnect_message_extended", player.CharacterName, player.SteamName, player.CSteamID.ToString()); if (geoip != null && @join) { message = Translate("connect_message_country_extended", player.CharacterName, player.SteamName, player.CSteamID.ToString(), geoip.Country); } } else { message = Translate(@join ? "connect_message" : "disconnect_message", player.CharacterName); if (geoip != null && @join) { message = Translate("connect_message_country", player.CharacterName, geoip.Country); } } UnturnedChat.Say(sdgPlayer.playerID.steamID, message, @join ? Config.JoinMessage : Config.LeaveMessage); } } } } } } catch (Exception ex) { Logger.LogException(ex); } }