Beispiel #1
0
        public static void Vote(UnturnedPlayer caller, bool giveItemDirectly = true)
        {
            try
            {
                if (Instance.Configuration.Instance.Services.Where(s => !String.IsNullOrEmpty(s.APIKey)).FirstOrDefault() == null)
                {
                    Logger.Log(Instance.Translations.Instance.Translate("no_apikeys_message")); return;
                }

                List <Service> services = Instance.Configuration.Instance.Services.Where(s => !String.IsNullOrEmpty(s.APIKey)).ToList();


                foreach (Service service in services)
                {
                    ServiceDefinition apidefinition = Instance.Configuration.Instance.ServiceDefinitions.Where(s => s.Name == service.Name).FirstOrDefault();
                    if (apidefinition == null)
                    {
                        Logger.Log(Instance.Translations.Instance.Translate("api_unknown_message", service.Name)); return;
                    }
                    try
                    {
                        VotifierWebclient wc = new VotifierWebclient();
                        wc.DownloadStringCompleted += (sender, e) => wc_DownloadStringCompleted(e, caller, service, apidefinition, giveItemDirectly);
                        wc.DownloadStringAsync(new Uri(String.Format(apidefinition.CheckHasVoted, service.APIKey, caller.ToString())));
                    }
                    catch (TimeoutException)
                    {
                        Logger.Log(Instance.Translations.Instance.Translate("api_down_message", service.Name));
                        UnturnedChat.Say(caller, Instance.Translations.Instance.Translate("api_down_message", service.Name));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
Beispiel #2
0
        public void Vote(UnturnedPlayer caller, bool giveItemDirectly = true)
        {
            try
            {
                if (ConfigurationInstance.Services.FirstOrDefault(s => !String.IsNullOrEmpty(s.APIKey)) == null)
                {
                    Logger.LogError(Translations.Get("no_apikeys_message")); return;
                }

                List <Service> services = ConfigurationInstance.Services.Where(s => !String.IsNullOrEmpty(s.APIKey)).ToList();


                foreach (Service service in services)
                {
                    ServiceDefinition apiDefinition = ConfigurationInstance.ServiceDefinitions.FirstOrDefault(s => s.Name == service.Name);
                    if (apiDefinition == null)
                    {
                        Logger.LogWarning(Translations.Get("api_unknown_message", service.Name)); return;
                    }
                    try
                    {
                        VotifierWebclient wc = new VotifierWebclient();
                        wc.DownloadStringCompleted += (sender, e) => OnDownloadStringCompleted(e, caller, service, apiDefinition, giveItemDirectly);
                        wc.DownloadStringAsync(new Uri(String.Format(apiDefinition.CheckHasVoted, service.APIKey, caller.ToString())));
                    }
                    catch (TimeoutException)
                    {
                        Logger.LogError(Translations.Get("api_down_message", service.Name));
                        caller.User.SendLocalizedMessage(Translations, "api_down_message", service.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(null, ex);
            }
        }