public static void UpdateWeather()
 {
     foreach (Client ThisClient in Clients.AllClients.ToArray())
     {
         ThisClient.SendPacket(Weather);
     }
 }
示例#2
0
 public static bool SendMessage(this List <Client> Clients, string Message, params object[] args)
 {
     if (args == null)
     {
         args = new object[0];
     }
     if (args.Length > 0)
     {
         try
         {
             Message = String.Format(Message, args);
         }
         catch (Exception e)
         {
             Message = e.StackTrace + "\n" + Message;
         }
     }
     _ClientsListLock.EnterReadLock();
     try
     {
         foreach (Client ThisClient in Clients)
         {
             ThisClient.SendMessage(Message);
         }
     }
     finally
     {
         _ClientsListLock.ExitReadLock();
     }
     return(true);
 }
示例#3
0
 public static bool SendPacket(this List <Client> Clients, Packets.GenericPacket InPacket)
 {
     _ClientsListLock.EnterReadLock();
     try
     {
         foreach (Client ThisClient in Clients)
         {
             ThisClient.SendPacket(InPacket);
         }
     }
     finally
     {
         _ClientsListLock.ExitReadLock();
     }
     return(true);
 }
示例#4
0
 public static void Send(this List <NetObject> Clients, Network.Packet ThisPacket)
 {
     foreach (NetObject ThisClient in Clients.ToArray()) //ToArray to make a standalone, uneditable copy to iterate over.
     {
         try
         {
             ThisClient.ClientObject.Send(ThisPacket);
         }
         catch
         {
             //Unable to send, client disconnected?
             if (!(ThisClient.ClientObject.ClientSocket.Connected && ThisClient.HostObject.HostSocket.Connected))
             {
                 ThisClient.Close();
             }
         }
     }
 }
示例#5
0
 public static void SendMessage(this List <NetObject> Clients, String Message)
 {
     foreach (NetObject ThisClient in Clients.ToArray()) //ToArray to make a standalone, uneditable copy to iterate over.
     {
         try
         {
             ThisClient.ClientObject.SendMessage(Message);
         }
         catch
         {
             //Unable to send, client disconnected?
             if (!(ThisClient.ClientObject.ClientSocket.Connected && ThisClient.HostObject.HostSocket.Connected))
             {
                 ThisClient.Close();
             }
         }
     }
     //Logger.Console.WriteLine(Message);
 }
示例#6
0
            public static bool Stop()
            {
                foreach (Client ThisClient in Clients.YSFClients)
                {
                    ThisClient.Disconnect("Server shutting down.");
                }
                DateTime Delay = DateTime.Now;

                while (Clients.YSFClients.Count > 0 & (DateTime.Now - Delay).TotalSeconds < 5)
                {
                    Thread.Sleep(10);
                }
                foreach (Client ThisClient in Clients.YSFClients)
                {
                    Debug.WriteLine("Stray Client" + ThisClient.Username);
                }
                Vehicles.List.Clear();
                ListenerSocket.Close();
                ListenerSocket.Dispose();
                //ServerClosed.WaitOne();
                ServerListenerThread.Abort();
                return(false);
            }
示例#7
0
 public static void DoHeartbeatMonitor()
 {
     Client[] Temp = Clients.YSFClients.ToArray();
     foreach (Client ThisClient in Temp)
     {
         if (ThisClient.IsFakeClient())
         {
             continue;
         }
         if ((DateTime.Now - ThisClient.LastHeartBeat).TotalSeconds >= 60 & (DateTime.Now - ThisClient.LastHeartBeatWarning).TotalSeconds >= 60)
         {
             ThisClient.LastHeartBeatWarning = DateTime.Now + new TimeSpan(0, 0, 1);
             Log.Warning("DoHeartBeat Monitor Warning for " + ThisClient.Username);
             ThisClient.SendMessage("No Activity for 60 Seconds. Please do something or you will be disconnected soon!");
             continue;
         }
         if ((DateTime.Now - ThisClient.LastHeartBeat).TotalSeconds >= 120 & (DateTime.Now - ThisClient.LastHeartBeatWarning).TotalSeconds <= 120)
         {
             ThisClient.SendMessage("You have been disconnected due to inactivity!");
             ThisClient.Disconnect("Disconnected due to inactivity (DoHeartbeatMonitor)");
         }
     }
 }
示例#8
0
            public bool StopReplay()
            {
                Playing     = false;
                CurrentTime = 0;
                Loaded      = false;
                #region despawn the aircraft
                foreach (uint ThisID in AircraftIDs)
                {
                    Packets.Packet_13_RemoveAirplane ThisRemoveAirplane = new Packets.Packet_13_RemoveAirplane(ThisID);

                    lock (Vehicles.List) Vehicles.List.RemoveAll(x => x.ID == ThisRemoveAirplane.ID);

                    foreach (Client ThisClient in Clients.YSFClients)
                    {
                        Packets.Packet_06_Acknowledgement AcknowledgeLeave = new Packets.Packet_06_Acknowledgement(2, ThisRemoveAirplane.ID);
                        //ThisClient.SendPacketGetPacket(ThisRemoveAirplane, AcknowledgeLeave);
                        ThisClient.SendPacket(ThisRemoveAirplane);
                    }
                    continue;
                }
                #endregion

                return(true);
            }
示例#9
0
文件: Kick.cs 项目: OfficerFlake/Orb
        public static bool Orb_Command_Moderation_User_Kick_Method(Server.NetObject NetObj, CommandReader Command)
        {
            Database.UserDB.User TargetUser = Database.UserDB.Nobody;
            string Reason = "";

            #region FindTargetUser
            if (Command._CmdElements()[1] == "-")
            {
                if (NetObj.CommandHandling.PreviousUser == Database.UserDB.Nobody)
                {
                    NetObj.ClientObject.SendMessage("No previous users iterated over.");
                    return(false);
                }
                else
                {
                    TargetUser = NetObj.CommandHandling.PreviousUser;
                }
            }
            else
            {
                if (Database.UserDB.Find(Command._CmdElements()[1]) != Database.UserDB.Nobody)
                {
                    TargetUser = Database.UserDB.Find(Command._CmdElements()[1]);
                }
                else
                {
                    NetObj.ClientObject.SendMessage("User not found: \"" + Command._CmdElements()[1] + "\".");
                    return(false);
                }
            }
            #endregion
            #region GetKickReason
            if (Command._CmdArguments.Count() < 1)
            {
                //Ban reason not given.
            }
            else
            {
                Reason = Command._CmdRawArguments;
            }
            #endregion
            #region SuperUser Override
            if (NetObj.UserObject == Database.UserDB.SuperUser || NetObj.UserObject.Can(Database.PermissionDB.Strings.Kick))
            {
                //continue
            }
            else
            {
                NetObj.ClientObject.SendMessage("You do not have permission to kick users from the server.");
                return(false);
            }
            #endregion

            if (TargetUser == NetObj.UserObject)
            {
                NetObj.ClientObject.SendMessage("You are not able to kick yourself!");
                return(false);
            }
            if (!Server.ClientList.Select(x => x.UserObject).Contains(TargetUser))
            {
                NetObj.ClientObject.SendMessage("User: \"" + TargetUser.Name + "\" is not online.");
                return(false);
            }
            TargetUser.TimesKicked++;
            TargetUser.KickedBy   = NetObj.UserObject;
            TargetUser.KickReason = Reason;
            TargetUser.SaveAll();
            Server.EmptyClientList.Include(TargetUser).SendMessage("&cYou have been KICKED by \"" + NetObj.UserObject.Name + "\".");
            Server.AllClients.Except(TargetUser).SendMessage("&cUser: \"" + TargetUser.Name + "\" was KICKED by \"" + NetObj.UserObject.Name + "\".");
            if (TargetUser.KickReason != "")
            {
                Server.AllClients.SendMessage("&cKick Reason: \"" + TargetUser.KickReason + "\".");
            }
            foreach (Server.NetObject ThisClient in Server.ClientList.Where(x => x.UserObject == TargetUser).ToArray())
            {
                ThisClient.Close(); //Kicks the target user.
            }
            return(true);
        }
示例#10
0
            public bool SendUpdate()
            {
                if (!Loaded)
                {
                    return(false);
                }
                if (Playing)
                {
                    CurrentTime += 0.1;
                }
                #region GetCurrentPackets
                List <Packets.GenericPacket> PacketsToSend =
                    (
                        from ThisPacketEvent in Records
                        where ThisPacketEvent.TimeStamp >= PreviousTime
                        where ThisPacketEvent.TimeStamp < CurrentTime
                        select ThisPacketEvent.Packet
                    ).ToList();
                if (PacketsToSend.Count == 0)
                {
                    return(false);
                }
                List <Packets.Packet_11_FlightData> FlightDataPacketsToSend =
                    (
                        from ThisFlightDataPacket in PacketsToSend
                        where ThisFlightDataPacket.Type == 11
                        select new Packets.Packet_11_FlightData(ThisFlightDataPacket)
                    ).OrderByDescending(x => x.TimeStamp).ToList();
                #endregion

                List <Client> CurrentClients = Clients.LoggedIn;
                foreach (uint ThisACID in AircraftIDs)
                {
                    #region GetFlightDataFromThisAircraft
                    List <Packets.Packet_11_FlightData> ThisAircraftFlightData =
                        (
                            from ThisFlightDataPacket in FlightDataPacketsToSend
                            where ThisFlightDataPacket.ID == ThisACID
                            select ThisFlightDataPacket
                        ).ToList();
                    #endregion
                    if (ThisAircraftFlightData.Count < 1)
                    {
                        continue;
                    }

                    #region GetLatestFlightData
                    Packets.Packet_11_FlightData NewesetFlightData =
                        (from ThisFlightDataPacket in FlightDataPacketsToSend
                         where ThisFlightDataPacket.ID == ThisACID
                         select ThisFlightDataPacket).ToArray().Last();

                    #endregion

                    #region UpdateFlightData
                    foreach (Vehicle ThisVehicle in Vehicles.List.Where(x => x.ID == ThisACID))
                    {
                        ThisVehicle.Update(NewesetFlightData);
                    }
                    #endregion

                    float difference = (float)(NewesetFlightData.TimeStamp - PreviousTime);
                    foreach (Client ThisClient in CurrentClients)
                    {
                        #region SetTimeToNow
                        NewesetFlightData.TimeStamp = (float)((DateTime.Now - OpenYS.TimeStarted).TotalSeconds - (CurrentTime - PreviousTime) + difference);
                        #endregion

                        //Debug.WriteLine(NewesetFlightData.TimeStamp + " Ready to send to " + ThisClient.Username);
                        ThisClient.SendPacket(NewesetFlightData);
                        //Debug.WriteLine(NewesetFlightData.TimeStamp + " Send Flight Data.");
                    }
                    continue;
                }

                foreach (Packets.GenericPacket ThisPacket in PacketsToSend)
                {
                    if (ThisPacket.Type == 11)
                    {
                        continue;
                    }

                    #region Join Data
                    if (ThisPacket.Type == 05)
                    {
                        Packets.Packet_05_EntityJoined ThisJoinData = new Packets.Packet_05_EntityJoined(ThisPacket);

                        #region Create Vehicle
                        Vehicle ThisVehicle = new Vehicle();
                        ThisVehicle.Update(ThisJoinData);
                        //ThisJoinData = ThisVehicle.GetJoinPacket(false);
                        #endregion

                        #region Add Vehicle to Vehicles List
                        Vehicles.List.Add(ThisVehicle);
                        VehiclesHistory.List.Add(ThisVehicle);
                        #endregion

                        foreach (Client ThisClient in CurrentClients)
                        {
                            Packets.Packet_06_Acknowledgement Acknowledgement;
                            if (ThisJoinData.IsAircraft)
                            {
                                Acknowledgement = new Packets.Packet_06_Acknowledgement(0, ThisJoinData.ID);
                            }
                            else
                            {
                                Acknowledgement = new Packets.Packet_06_Acknowledgement(1, 0);
                            }
                            //ThisClient.SendPacketGetPacket(ThisJoinData, Acknowledgement);
                            ThisClient.SendPacket(ThisJoinData);
                        }
                        continue;
                    }
                    #endregion

                    #region Leave Data
                    if (ThisPacket.Type == 13)
                    {
                        Packets.Packet_13_RemoveAirplane ThisRemoveAirplane = new Packets.Packet_13_RemoveAirplane(ThisPacket);

                        lock (Vehicles.List) Vehicles.List.RemoveAll(x => x.ID == ThisRemoveAirplane.ID);

                        foreach (Client ThisClient in CurrentClients)
                        {
                            Packets.Packet_06_Acknowledgement AcknowledgeLeave = new Packets.Packet_06_Acknowledgement(2, ThisRemoveAirplane.ID);
                            //ThisClient.SendPacketGetPacket(ThisRemoveAirplane, AcknowledgeLeave);
                            ThisClient.SendPacket(ThisRemoveAirplane);
                        }
                        continue;
                    }
                    #endregion

                    CurrentClients.SendPacket(ThisPacket);
                }
                if (Playing)
                {
                    PreviousTime = CurrentTime;
                }
                return(true);
            }
示例#11
0
        public static bool Orb_Command_Moderation_User_Ban_Method(Server.NetObject NetObj, CommandReader Command)
        {
            Database.UserDB.User TargetUser = Database.UserDB.Nobody;
            DateTime             BanEnds    = new DateTime();
            TimeSpan             Duration   = new TimeSpan();
            string Reason = "";

            #region FindTargetUser
            if (Command._CmdElements()[1] == "-")
            {
                if (NetObj.CommandHandling.PreviousUser == Database.UserDB.Nobody)
                {
                    NetObj.ClientObject.SendMessage("No previous users iterated over.");
                    return(false);
                }
                else
                {
                    TargetUser = NetObj.CommandHandling.PreviousUser;
                }
            }
            else
            {
                if (Database.UserDB.Find(Command._CmdElements()[1]) != Database.UserDB.Nobody)
                {
                    TargetUser = Database.UserDB.Find(Command._CmdElements()[1]);
                }
                else
                {
                    NetObj.ClientObject.SendMessage("User not found: \"" + Command._CmdElements()[1] + "\".");
                    return(false);
                }
            }
            #endregion
            #region GetBanExpiry
            if (Command._CmdArguments.Count() < 1)
            {
                //Ban is Permanent by default
            }
            else
            {
                if (Command._CmdArguments[0].ToUpperInvariant() == "INF" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "INFINITE" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "INFINITY" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "0" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "-" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "FOREVER" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "PERMANENT" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "PERM" ||
                    Command._CmdArguments[0].ToUpperInvariant() == "!")
                {
                    //New Date Time == Permanent Ban.
                    //This is already set, we don't need to do anything.
                }
                else
                {
                    if (!Utilities.DateTimeUtilities.TryParseMiniTimespan(Command._CmdArguments[0], out Duration))
                    {
                        NetObj.ClientObject.SendMessage("Ban Duration Format Invalid. Acceptable Format/s: \"*w*d*h*m*s\" eg: \"1w2d5h3m2s\" or \"7w2m\" or even \"5s\".");
                        return(false);
                    }
                    BanEnds = DateTime.Now + Duration;
                }
            }
            #endregion
            #region GetBanReason
            if (Command._CmdArguments.Count() < 2)
            {
                //Ban reason not given.
            }
            else
            {
                Reason = Command._CmdRawArguments.Split(new string[] { " " }, 2, StringSplitOptions.None)[1];
            }
            #endregion
            #region SuperUser Override
            if (NetObj.UserObject == Database.UserDB.SuperUser || NetObj.UserObject.Can(Database.PermissionDB.Strings.Ban))
            {
                //continue
            }
            else
            {
                NetObj.ClientObject.SendMessage("You do not have permission to ban users from the server.");
                return(false);
            }
            #endregion

            if (DateTime.Now - TimeSpan.FromSeconds(30) > BanEnds && BanEnds != new DateTime())
            {
                NetObj.ClientObject.SendMessage("BanTime is in the past! Unable to ban the target!");
                return(false);
            }
            if (TargetUser == NetObj.UserObject)
            {
                NetObj.ClientObject.SendMessage("You are not able to ban yourself!");
                return(false);
            }
            if (TargetUser.Banned)
            {
                NetObj.ClientObject.SendMessage("User: \"" + TargetUser.Name + "\" is already banned.");
                return(false);
            }
            TargetUser.TimesBanned++;
            TargetUser.BanExpires = BanEnds;
            TargetUser.Banned     = true;
            TargetUser.BannedBy   = NetObj.UserObject;
            TargetUser.BanReason  = Reason;
            TargetUser.SaveAll();
            if (TargetUser.BanExpires == new DateTime())
            {
                Server.EmptyClientList.Include(TargetUser).SendMessage("&cYou have been PERMANTENTLY BANNED by \"" + NetObj.UserObject.Name + "\".");
                Server.AllClients.Except(TargetUser).SendMessage("&cUser: \"" + TargetUser.Name + "\" was PERMANTENTLY BANNED by \"" + NetObj.UserObject.Name + "\".");
                if (TargetUser.BanReason != "")
                {
                    Server.AllClients.SendMessage("&cBan Reason: \"" + TargetUser.BanReason + "\".");
                }
            }
            else
            {
                Server.EmptyClientList.Include(TargetUser).SendMessage("&cYou have been BANNED by \"" + NetObj.UserObject.Name + "\" until " + Utilities.DateTimeUtilities.ToYearTimeDescending(Utilities.DateTimeUtilities.FormatDateTime(TargetUser.BanExpires)) + ".");
                Server.AllClients.Except(TargetUser).SendMessage("&cUser: \"" + TargetUser.Name + "\" was BANNED by \"" + NetObj.UserObject.Name + "\" until " + Utilities.DateTimeUtilities.ToYearTimeDescending(Utilities.DateTimeUtilities.FormatDateTime(TargetUser.BanExpires)) + ".");
                if (TargetUser.BanReason != "")
                {
                    Server.AllClients.SendMessage("&cBan Reason: \"" + TargetUser.BanReason + "\".");
                }
            }
            foreach (Server.NetObject ThisClient in Server.ClientList.Where(x => x.UserObject == TargetUser).ToArray())
            {
                ThisClient.Close(); //Kicks the target user.
            }
            return(true);
        }
示例#12
0
        public static bool UpdateTimeOfDay()
        {
            while ((DateTime.Now - AdvancedWeatherOptions._LastDayNightCycleRestart).TotalMinutes > AdvancedWeatherOptions._DayNightCycleLength & AdvancedWeatherOptions._DayNightCycleLength > 0)
            {
                AdvancedWeatherOptions._LastDayNightCycleRestart += new TimeSpan(0, AdvancedWeatherOptions._DayNightCycleLength, 0);
            }
            CurrentTick = GetServerTimeTicks();
            if (AdvancedWeatherOptions._DayNightCycleLength <= 0)
            {
                CurrentTick = PreviousTick;
                //return false;
            }

            //These packets ultimately sent to the clients.
            Packets.Packet_49_SkyColor SkyColorUpdate = new Packets.Packet_49_SkyColor(Settings.Weather.Advanced.SkyColor);
            Packets.Packet_48_FogColor FogColorUpdate = new Packets.Packet_48_FogColor(Settings.Weather.Advanced.FogColor);

            Colors.XRGBColor BlendedSkyColor = Settings.Weather.Advanced.SkyColor;
            Colors.XRGBColor BlendedFogColor = Settings.Weather.Advanced.FogColor;
            #region TimeOfDayBlending
            //Night 1
            if (CurrentTick < 6000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.NightSkyColor;
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor;
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            //Dawn 1
            if (CurrentTick >= 6000 && CurrentTick < 7000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.NightSkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DawnSkyColor, (CurrentTick - 6000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DawnHorizonColor, (CurrentTick - 6000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            //Dawn 2
            if (CurrentTick >= 7000 && CurrentTick < 8000)
            {
                if (PreviousTick < 7000)
                {
                    Weather = new Packets.Packet_33_Weather(_Weather)
                    {
                        Lighting = 0
                    };                                                                  //Set To Day
                    Clients.AllClients.SendPacket(Weather);
                }
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DawnSkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(new Colors.XRGBColor(255, 255, 255), (CurrentTick - 7000) / 1000d);
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DaySkyColor, (CurrentTick - 7000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DawnHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(new Colors.XRGBColor(255, 255, 255), (CurrentTick - 7000) / 1000d);
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DayHorizonColor, (CurrentTick - 7000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
            }
            //Day
            if (CurrentTick >= 8000 && CurrentTick < 18000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DaySkyColor;
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DayHorizonColor;
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
            }
            //Dusk 1
            if (CurrentTick >= 18000 && CurrentTick < 19000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DaySkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DuskSkyColor, (CurrentTick - 18000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DayHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DuskHorizonColor, (CurrentTick - 18000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
            }
            //Dusk 2
            if (CurrentTick >= 19000 && CurrentTick < 20000)
            {
                if (PreviousTick < 19000)
                {
                    Weather = new Packets.Packet_33_Weather(_Weather)
                    {
                        Lighting = 65537
                    };                                                                      //Set To Night
                    Clients.AllClients.SendPacket(Weather);
                }
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DuskSkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NightSkyColor, (CurrentTick - 19000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DuskHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor, (CurrentTick - 19000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            //Night 2
            if (CurrentTick >= 20000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.NightSkyColor;
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor;
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            #endregion

            #region Fog Distance Blending
            BlendedFogColor      = FogColorUpdate.Color;
            BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.WhiteFogColor, 1 - (OpenYS.Weather.Fog / 20000));
            FogColorUpdate.Color = BlendedFogColor;
            #endregion

            foreach (Client ThisClient in Clients.LoggedIn)
            {
                #region Altitude Blending
                //Now filter the sky and fog based on altitude.
                Packets.Packet_48_FogColor ThisClientFogUpdate = FogColorUpdate;
                Packets.Packet_49_SkyColor ThisClientSkyUpdate = SkyColorUpdate;

                Vehicle ThisVehicle = ThisClient.Vehicle;
                if (ThisVehicle != Vehicles.NoVehicle)
                {
                    if (ThisVehicle.PosY >= Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters) //Above 100,000ft
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereSkyColor, 1.0);
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereHorizonColor, 1.0);
                        //ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - NightFogFilter);
                    }
                    if (ThisVehicle.PosY >= Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters && ThisVehicle.PosY < Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters) //Roughly 40,000ft to 100,000ft
                    {
                        BlendedSkyColor           = ThisClientSkyUpdate.Color;
                        BlendedSkyColor           = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.MaxAltitudeSkyColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters));  //fade to the sky color.
                        BlendedSkyColor           = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereSkyColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters)); //fade to the noatmosphere color.
                        ThisClientSkyUpdate.Color = BlendedSkyColor;

                        BlendedFogColor           = ThisClientFogUpdate.Color;
                        BlendedFogColor           = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.MaxAltitudeHorizonColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters));  //fade to the Fog color.
                        BlendedFogColor           = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereHorizonColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters)); //fade to the noatmosphere color.
                        ThisClientFogUpdate.Color = BlendedFogColor;
                        //ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - NightFogFilter);
                    }
                    if (ThisVehicle.PosY < Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) //Less then 40,000 ft.
                    {
                        //Do nothing.
                    }
                    #region SetNightColors
                    if (CurrentTick < 6000 | CurrentTick >= 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor);                                            //7000 = 0, 6000 = 1
                    }
                    if (CurrentTick >= 6000 & CurrentTick < 7000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 6000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 7000 & CurrentTick < 8000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 7000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 18000 & CurrentTick < 19000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 18000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 19000 & CurrentTick < 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 19000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    #endregion
                }
                else
                {
                    #region SetNightColors
                    if (CurrentTick < 6000 | CurrentTick >= 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor);                                            //7000 = 0, 6000 = 1
                    }
                    if (CurrentTick >= 6000 & CurrentTick < 7000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 6000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 7000 & CurrentTick < 8000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 7000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 18000 & CurrentTick < 19000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 18000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 19000 & CurrentTick < 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 19000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    #endregion
                }
                #endregion

                #region Set Definied Colors
                if (ThisClient.Version > 20110207)
                {
                    if (!Settings.Weather.Advanced.EnableSkyColor)
                    {
                        ThisClient.SendPacket(ThisClientSkyUpdate);
                    }
                    if (!Settings.Weather.Advanced.EnableFogColor)
                    {
                        ThisClient.SendPacket(ThisClientFogUpdate);
                    }
                }
                #endregion
            }
            PreviousTick = CurrentTick;
            return(true);
        }