private void OnEnable()
 {
     if (U.Settings.Instance.CommunityBans)
     {
         using (RocketWebClient webClient = new RocketWebClient())
         {
             try
             {
                 webClient.DownloadStringCompleted += (object sender, System.Net.DownloadStringCompletedEventArgs e) =>
                 {
                     if (e.Error == null && e.Result != "false")
                     {
                         Logger.Log("[RocketMod Observatory] Player " + Player.CharacterName + " is banned:" + e.Result);
                         webClientResult = e.Result;
                         requested = DateTime.Now;
                     }
                 };
                 webClient.DownloadStringAsync(new Uri(string.Format("http://banlist.observatory.rocketmod.net/?steamid={0}", Player.CSteamID)));
             }
             catch (Exception)
             {
                 //
             }
         }
     }
 }
예제 #2
0
        public override void Load(AssetLoaded <T> callback = null)
        {
            try
            {
                if (!waiting)
                {
                    Logger.Log(String.Format("Updating WebXMLFileAsset {0} from {1}", typeof(T).Name, url));
                    waiting = true;

                    webclient.DownloadStringCompleted -= handler;
                    handler = (object sender, System.Net.DownloadStringCompletedEventArgs e) =>
                    {
                        if (e.Error != null)
                        {
                            Logger.Log(String.Format("Error retrieving WebXMLFileAsset {0} from {1}: {2}", typeof(T).Name, url, e.Error.Message));
                        }
                        else
                        {
                            try
                            {
                                using (StringReader reader = new StringReader(e.Result))
                                {
                                    XmlSerializer serializer = new XmlSerializer(typeof(T), attr);
                                    T             result     = (T)serializer.Deserialize(reader);
                                    if (result != null)
                                    {
                                        TaskDispatcher.QueueOnMainThread(() =>
                                        {
                                            instance = result;
                                            Logger.Log(String.Format("Successfully updated WebXMLFileAsset {0} from {1}", typeof(T).Name, url));
                                        });
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.Log(String.Format("Error retrieving WebXMLFileAsset {0} from {1}: {2}", typeof(T).Name, url, ex.Message));
                            }
                        }

                        TaskDispatcher.QueueOnMainThread(() =>
                        {
                            callback?.Invoke(this);
                            waiting = false;
                        });
                    };
                    webclient.DownloadStringCompleted += handler;
                    webclient.DownloadStringAsync(url);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(String.Format("Error retrieving WebXMLFileAsset {0} from {1}: {2}", typeof(T).Name, url, ex.Message));
            }
        }
예제 #3
0
 private void OnEnable()
 {
     if (U.Settings.Instance.RocketModObservatory.CommunityBans)
     {
         using (RocketWebClient webClient = new RocketWebClient())
         {
             try
             {
                 webClient.DownloadStringCompleted += (object sender, System.Net.DownloadStringCompletedEventArgs e) =>
                 {
                     if (e.Error == null)
                     {
                         if (e.Result.Contains(","))
                         {
                             string[] result = e.Result.Split(',');
                             long     age;
                             if (result[0] == "true")
                             {
                                 Core.Logging.Logger.Log("[RocketMod Observatory] Kicking Player " + Player.CharacterName + "because he is banned:" + result[1]);
                                 webClientResult = result[1];
                                 requested       = DateTime.Now;
                                 Player.Kick("you are banned from observatory: " + result[1]);
                             }
                             else if (U.Settings.Instance.RocketModObservatory.KickLimitedAccounts && result.Length >= 2 && result[1] == "true")
                             {
                                 Core.Logging.Logger.Log("[RocketMod Observatory] Kicking Player " + Player.CharacterName + " because his account is limited");
                                 Player.Kick("your Steam account is limited");
                             }
                             else if (U.Settings.Instance.RocketModObservatory.KickTooYoungAccounts && result.Length == 3 && long.TryParse(result[2].ToString(), out age))
                             {
                                 long epochTicks = new DateTime(1970, 1, 1).Ticks;
                                 long unixTime   = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);
                                 long d          = (unixTime - age);
                                 if (d < U.Settings.Instance.RocketModObservatory.MinimumAge)
                                 {
                                     Core.Logging.Logger.Log("[RocketMod Observatory] Kicking Player " + Player.CharacterName + " because his account is younger then " + U.Settings.Instance.RocketModObservatory.MinimumAge + " seconds (" + d + " seconds)");
                                     Player.Kick("your Steam account is not old enough");
                                 }
                             }
                         }
                     }
                 };
                 webClient.DownloadStringAsync(new Uri(string.Format("http://banlist.observatory.rocketmod.net/?steamid={0}", Player.CSteamID)));
             }
             catch (Exception)
             {
                 //
             }
         }
     }
 }
 private void OnEnable()
 {
     if (U.Settings.Instance.RocketModObservatory.CommunityBans)
     {
         using (RocketWebClient webClient = new RocketWebClient())
         {
             try
             {
                 webClient.DownloadStringCompleted += (object sender, System.Net.DownloadStringCompletedEventArgs e) =>
                 {
                     if (e.Error == null)
                     {
                         if (e.Result.Contains(",")){
                             string[] result = e.Result.Split(',');
                             long age;
                             if (result[0] == "true")
                             {
                                 Core.Logging.Logger.Log("[RocketMod Observatory] Kicking Player " + Player.CharacterName + "because he is banned:" + result[1]);
                                 webClientResult = result[1];
                                 requested = DateTime.Now;
                                 Player.Kick("you are banned from observatory: " + result[1]);
                             }
                             else if (U.Settings.Instance.RocketModObservatory.KickLimitedAccounts && result.Length >= 2 && result[1] == "true")
                             {
                                 Core.Logging.Logger.Log("[RocketMod Observatory] Kicking Player " + Player.CharacterName + " because his account is limited");
                                 Player.Kick("your Steam account is limited");
                             }
                             else if (U.Settings.Instance.RocketModObservatory.KickTooYoungAccounts && result.Length == 3 && long.TryParse(result[2].ToString(),out age))
                             {
                                 long epochTicks = new DateTime(1970, 1, 1).Ticks;
                                 long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);
                                 long d = (unixTime - age);
                                 if (d < U.Settings.Instance.RocketModObservatory.MinimumAge)
                                 {
                                     Core.Logging.Logger.Log("[RocketMod Observatory] Kicking Player " + Player.CharacterName + " because his account is younger then "+ U.Settings.Instance.RocketModObservatory.MinimumAge+" seconds ("+d+" seconds)");
                                     Player.Kick("your Steam account is not old enough");
                                 } 
                             }
                         }
                     }
                 };
                 webClient.DownloadStringAsync(new Uri(string.Format("http://banlist.observatory.rocketmod.net/?steamid={0}", Player.CSteamID)));
             }
             catch (Exception)
             {
                 //
             }
         }
     }
 }
예제 #5
0
        public override void Load(AssetLoaded <T> callback = null)
        {
            try
            {
                if (!String.IsNullOrEmpty(url) && !waiting)
                {
                    Logger.Log(String.Format("Updating WebXMLFileAsset {0} from {1}", typeof(T).Name, url));
                    waiting = true;
                    webclient.DownloadStringCompleted += (object sender, System.Net.DownloadStringCompletedEventArgs e) =>
                    {
                        TaskDispatcher.QueueOnMainThread(() =>
                        {
                            using (StringReader reader = new StringReader(e.Result))
                            {
                                try
                                {
                                    T result = (T)serializer.Deserialize(reader);

                                    instance = result;

                                    if (callback != null)
                                    {
                                        callback(this);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.LogError("Error retrieving WebXMLFileAsset: " + ex.Message);
                                    callback(this);
                                }
                            }
                            waiting = false;
                        });
                    };
                    webclient.DownloadStringAsync(new Uri(url));
                }
                else
                {
                    throw new ArgumentNullException("WebXMLFileAsset url is blank");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Failed to deserialize WebXMLFileAsset: {0}", url), ex);
            }
        }