private static bool YSFHandle_01_Login(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region Get Login(01)
                    Packets.Packet_01_Login LoginPacket = new Packets.Packet_01_Login(InPacket);
                    ThisClient.Username = LoginPacket.Username;
                    ThisClient.Version  = LoginPacket.Version;
                    #endregion

                    bool isBot = (ThisClient.Username.ToUpperInvariant() == "PHP_BOT");
                    if (!isBot)
                    {
                        Console.WriteLine(ConsoleColor.Yellow, ThisClient.Username + " Logging in...");
                    }

                    Clients.AllClients.SendMessage("&a" + ThisClient.Username + " Joined the server.");
                    //ThisClient.YSFServer.SendPacket(InPacket);
                    return(true);
                }
        public bool ConnectTray(Socket ConnectingClientSocket, bool IsClientMode)
        {
            lock (this)
            {
                if (this == Clients.NoClient)
                {
                    return(false);
                }
                YSFClient.Socket = ConnectingClientSocket;
                #region Sneak the username in so we can name the receiver thread!
                Packets.Packet_01_Login LoginPacket = new Packets.Packet_01_Login("nameless", 20110207);
                try
                {
                    byte[] Size = new byte[4];
                    YSFClient.Socket.Receive(Size, 4, SocketFlags.Peek);
                    byte[] Full = new byte[BitConverter.ToUInt32(Size, 0) + 4];
                    YSFClient.Socket.Receive(Full, Full.Length, SocketFlags.Peek);
                    if (Full.Length > 28)
                    {
                        Username = Full.ToDataString().Substring(28).Split('\0')[0];
                    }
                    else
                    {
                        Username = Full.Skip(8).Take(16).ToArray().ToDataString().Split('\0')[0];
                    }
                    Version     = BitConverter.ToUInt32(Full, 24);
                    LoginPacket = new Packets.Packet_01_Login(Username, Version);
                    Packets.Packet_29_VersionNotify VersionPacket = new Packets.Packet_29_VersionNotify(Version);
                    //YSFClient.SendPacketNow(VersionPacket);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                #endregion
                #region OYS Tray Mode - Select Server!
                //string ServerListFile = System.Environment.ExpandEnvironmentVariables("%USERPROFILE%/Documents/YSFLIGHT.COM/YSFLIGHT/config/serverhistory.txt");
                //if (!Files.FileExists(ServerListFile))
                //{
                //    SendMessage("Could not load ServerHistory.txt from YSFlight settings folder.");
                //    Disconnect("No Host Server");
                //    return false;
                //}
                //string[] ServersList = Files.FileReadAllLines(ServerListFile);
                //List<ServerAddress> Processed = new List<ServerAddress>();
                //foreach (string ThisLine in ServersList)
                //{
                //    if (ThisLine.CountOccurances("(") < 1) continue;
                //    string Address = ThisLine.Split('(')[0];
                //    int Port = 0;
                //    bool Failed = !Int32.TryParse(ThisLine.Split('(')[1].Split(')')[0], out Port);
                //    if (!Failed) Processed.Add(new ServerAddress(Address, Port));
                //}
                ////Now show the server list!
                //SendMessage("Welcome to OpenYS-Tray! Please select your desired server:");
                //SendMessage("==========================================================");
                //int Offset = 0;
                //IPAddress TargetAddress = IPAddress.Parse("127.0.0.1");
                //int TargetPort = 7915;
                //while (true)
                //{
                //    ListServers:
                //    for (int i = 0; (i + Offset) < Processed.Count & i < 9; i++)
                //    {
                //        SendMessage("[" + i.ToString() +"] " + Processed[i + Offset].Address.Resize(64).Split('\0')[0] + ":" + Processed[i + Offset].Port.ToString());
                //    }
                //    SendMessage("[M] More Servers");
                //    SendMessage("[X] Quit");

                //    int Number = -1;
                //    while (true)
                //    {
                //        Packets.GenericPacket InPacket = YSFClient.ReceivePacket();
                //        if (InPacket.Type == 32)
                //        {
                //            Packets.Packet_32_ChatMessage ChatMessage = new Packets.Packet_32_ChatMessage(InPacket, Username);
                //            bool Failed = !Int32.TryParse(ChatMessage.Message.Substring(0,1), out Number);
                //            if (Failed)
                //            {
                //                char Upper = ChatMessage.Message.ToUpperInvariant()[0];
                //                if (Upper == 'M')
                //                {
                //                    Offset += 10;
                //                    if (Offset >= Processed.Count) Offset = 0;
                //                    SendMessage("Please select your desired server:");
                //                    SendMessage("==================================");
                //                    goto ListServers;
                //                }
                //                if (Upper == 'X')
                //                {
                //                    Disconnect("Quit");
                //                    return false;
                //                }
                //            }
                //            else
                //            {
                //                TargetAddress = Dns.GetHostAddresses(Processed[Offset + Number].Address)[0];
                //                TargetPort = Processed[Offset + Number].Port;
                //                break;
                //            }
                //        }
                //    }

                //    SendMessage("You Chose: " + Processed[Offset + Number].Address + ":" + Processed[Offset + Number].Port);
                //    SendMessage("    ");
                //    SendMessage("Logging in now...");
                //    SendMessage("=================");

                //    try
                //    {
                //        YSFServer.Socket.Connect(new IPEndPoint(TargetAddress, TargetPort));
                //    }
                //    catch (Exception e)
                //    {
                //        Log.Error(e);
                //        Console.WriteLine(ConsoleColor.Yellow, "Connecting client \"" + Username + "\" was unable to reach the host YSF Server - is it down?");
                //        SendMessage("Unable to reach the host YSF Server - is it down?");
                //        Disconnect("No Host Socket to connect to. (Failed to redirect client to host)");
                //        return false;
                //    }
                //    //Set the Server Packet Handler Here.
                //    YSFServer.Connect(YSFServer.Socket);
                //    //YSFServer.SendPacket(LoginPacket);
                //    break;
                //}

                #endregion
                #region OYS Server Mode - Start Receiver
                YSFClient.ConnectionContext = ClientIO.ConnectionContexts.Client;
                #endregion
                #region OYS Client Mode - Start Receiver
                if (IsClientMode)
                {
                    YSFServer.ConnectionContext = ClientIO.ConnectionContexts.Server;
                }
                #endregion
                StateConnection = Client.FlagsStateConnection.Connecting;
                return(true);
            }
        }