private static bool YSFHandle_12_Unjoin(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    //ThisClient.YSFServer.SendPacket(InPacket);

                    //Re-Synchronise...
                    OpenYS_Link.OYS_Link_Response Response = OpenYS_Link.Get(OpenYS_Link.Stats._id, "stats_total_flight_seconds");
                    double OldTime = 0;
                    bool   Failed  = !Double.TryParse(Response.Response, out OldTime);

                    if (!Response.Success | Failed)
                    {
                        ThisClient.SendMessage("Failed to update your flight time due to a server error! Sorry about that!");
                        return(true);
                    }



                    //Update OYS_LINK...
                    double difference = OpenYS_Link.Stats.total_flight_seconds - OldTime;

                    Response = OpenYS_Link.Set(OpenYS_Link.Stats._id, "stats_total_flight_seconds", OpenYS_Link.Stats.total_flight_seconds);
                    if (Response.Success)
                    {
                        ThisClient.SendMessage("Successfully updated your flight time by " + Math.Round(difference.AsSeconds().TotalHours, 2).ToString() + " hours.");
                        ThisClient.SendMessage("Your new total flight time is " + Math.Round(OpenYS_Link.Stats.total_flight_seconds.AsSeconds().TotalHours, 2).ToString() + " hours.");

                        return(true);
                    }
                    else
                    {
                        ThisClient.SendMessage("Failed to update your flight time due to a server error! Sorry about that!");
                        return(true);
                    }
                }
Exemple #2
0
                public static bool OYSHandle(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region SWITCH
                    if (InPacket == null | InPacket == Packets.NoPacket)
                    {
                        return(false);
                    }
                    switch (InPacket.Type)
                    {
                    case 11:
                        OYSHandle_11_FlightData(ThisClient, InPacket);
                        break;

                    case 29:
                        OYSHandle_29_HandShake(ThisClient, InPacket);
                        break;

                    default:
#if DEBUG
                        //Console.WriteLine("Unknown Custom Packet From Host " + ThisClient.Username);
                        //Console.WriteLine("-Type: " +  InPacket.Type.ToString());
                        //Console.WriteLine("-Data: " +  InPacket.Data.ToString());
#endif
                        break;
                    }
                    #endregion
                    return(true);
                }
        static void OnMessageReceived(ClientContext context)
        {
            // process the message here

            Packets.GenericPacket ThisPacket = new Packets.GenericPacket(context.Message.ToArray());
            System.Console.WriteLine(ThisPacket.Type);
        }
 public void ProcessPacket(Packets.GenericPacket Output)
 {
     ReceiveHeader(); //Start on the next packet immediately!
     //Debug.WriteLine("Start Processing");
     _ProcessPacket(Output);
     //Debug.WriteLine("End Processing");
 }
        public void Send(Packets.GenericPacket Output)
        {
            try
            {
                if (ConnectionContext == ConnectionContexts.Connectionless)
                {
                    return;
                }
                if (Client.IsDisconnecting())
                {
                    return;
                }
                if (Client.IsDisconnected())
                {
                    return;
                }
                // Begin sending the data to the remote device.

                SocketSendObject SendOp = new SocketSendObject();
                SendOp.outpacket = Output;
                Socket.BeginSend(Output.GetRawBytes(), 0, (int)Output.Size + 4, SocketFlags.None,
                                 new AsyncCallback(SendCallback), SendOp);
            }
            catch (SocketException e)
            {
                Client.Disconnect("Remote client forcibly closed the connection.");
                return;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
            public ClientIO Parent = null; //ERROR POINT! BE CAREFUL HERE!

            public WaitForPacketObject(ClientIO ThisClientIO, Packets.GenericPacket InPacket)
            {
                Packet = InPacket;
                Parent = ThisClientIO; //ERROR POINT RESOLVED.
                ThisClientIO.WaitForPacketList.Add(this);
                Debug.TestPoint();
            }
 public bool Send(Packets.GenericPacket Output)
 {
     return(false);
     //try
     //{
     //    if (Client.ClientType.HasFlag(Client.FlagsClientType.FakeClient))
     //    {
     //        return true;
     //    }
     //    if (!Client.Disconnecting.WaitOne(0)) Socket.Send(Output.GetRawBytes());
     //    return true;
     //}
     //catch (SocketException)
     //{
     //    Connection.Client.Disconnect("Failed to send data - Socket Closed Exception.");
     //    return false;
     //}
     //catch (ObjectDisposedException)
     //{
     //    Connection.Client.Disconnect("Failed to send data - Socket Disposed Exception.");
     //    return false;
     //}
     //catch (Exception e)
     //{
     //    if (Client.IsBot())
     //    {
     //        Client.Disconnect("Bot Disconnected.");
     //        return false; //Don't care if bots get errors...
     //    }
     //    Log.Error(e);
     //    Client.Disconnect("Data Send Failure.");
     //    return false;
     //}
 }
 private static bool YSFHandle_11_FlightData(Client ThisClient, Packets.GenericPacket InPacket)
 {
     #region Prepare Flight Data
     //Prepare FlightData Packet
     //Check if the server has the vehicle specified.
     //Deny old flightdatapackets.
     Packets.Packet_11_FlightData FlightData = new Packets.Packet_11_FlightData(InPacket);
     Vehicle SenderVehicle;
     lock (Vehicles.List)
     {
         if (Vehicles.List.ToArray().Where(x => x.ID == FlightData.ID).Count() <= 0)
         {
             //Console.WriteLine("Missing Aircraft ID: " + FlightData.ID + " for client " + ThisConnection.ThisClient.Info.Username);
             return(false);
         }
         SenderVehicle = Vehicles.List.ToArray().Where(x => x.ID == FlightData.ID).ToArray()[0];
     }
     #endregion
     #region ValidateFlightData
     if (SenderVehicle.TimeStamp > FlightData.TimeStamp)
     {
         return(false);
     }
     SenderVehicle.Update(FlightData);
     #endregion
     ThisClient.SendPacket(InPacket);
     return(true);
 }
 public bool _ProcessPacket(Packets.GenericPacket NewPacket)
 {
     try
     {
         if (NewPacket == null | NewPacket == Packets.NoPacket)
         {
             Debug.WriteLine("&eGot a \"NULL\" Packet from " + Client.Username + ". Terminating the connection.");
             return(false);
         }
         else
         {
             ProcessorRecursionDepth++;
             #region Recursion Depth Test - Abort if too deep!
             if (ProcessorRecursionDepth > 20)
             {
                 Console.WriteLine("&c" + Client.Username + " recursion depth > 20. For OYS safety, connection terminated!");
                 Client.Disconnect("Data Recusrion Depth > 20.");
                 return(false);
             }
             #endregion
             PacketHandler(Client, NewPacket);
             ProcessorRecursionDepth--;
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return(false);
     }
 }
                private static bool YSFHandle_05_EntityJoined(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    if (InPacket.Data.Length < 171)
                    {
                        ThisClient.SendPacket(InPacket);
                        return(true);
                    }

                    Packets.Packet_05_EntityJoined EntityJoined = new Packets.Packet_05_EntityJoined(InPacket);
                    Vehicle ThisVehicle = new Vehicle();

                    ThisVehicle.Update(EntityJoined);
                    ThisVehicle.TimeStamp = 0; //So the client can have immediate control of the flight data!
                    #region Add Vehicle to Vehicles List
                    lock (Vehicles.List)
                    {
                        Vehicles.List.RemoveAll(x => x == ThisVehicle);
                        Vehicles.List.Add(ThisVehicle);
                        VehiclesHistory.List.Add(ThisVehicle);
                    }
                    //ThisClient.CurrentAircraftJoinPacket = new Packets.Packet_05_EntityJoined(EntityJoined);
                    #endregion

                    if (EntityJoined.IsGround)
                    {
                        ThisClient.SendPacket(InPacket);
                        return(true);
                    }
                    if (Clients.YSFClients[0] == ThisClient)
                    {
                        Console.WriteLine("&b" + "Aircraft ID " + EntityJoined.ID + " Created");
                    }
                    if (EntityJoined.OwnerType == 3)
                    {
                        //Console.WriteLine(EntityJoined.Data.ToDebugHexString());
                        //Console.WriteLine(ThisConnection.ThisClient.Info.Username);
                        //Console.WriteLine(EntityJoined.ID);
                        ThisClient.Vehicle = ThisVehicle;
                        ThisClient.SendPacket(InPacket);

                        /*
                         *
                         * Client.Listener AckCreation = ThisConnection.ThisClient.YSFClient.ThisConnection.SocketDescriptor.SubscribeAcknowledgement(0, EntityJoined.ID);
                         * ThisConnection.SocketDescriptor.SendPacket(InPacket);
                         * ThisConnection.ThisClient.YSFClient.WaitListener(AckCreation);
                         *
                         * Packet_09_JoinApproved JoinApproved = new Packets.Packet_09_JoinApproved(new Packets.GenericPacket() { Type = 09 });
                         * Client.Listener WaitJoinApproval = ThisConnection.ThisClient.YSFServer.ThisConnection.Subscribe(JoinApproved);
                         * ThisConnection.ThisClient.YSFServer.WaitListener(WaitJoinApproval);
                         *
                         * Client.Listener AcknowledgeJoinApproval = ThisConnection.ThisClient.YSFClient.ThisConnection.SocketDescriptor.SubscribeAcknowledgement(6, 0);
                         * ThisConnection.ThisClient.YSFClient.WaitListener(AcknowledgeJoinApproval);
                         *
                         * Console.WriteLine("ADDED VEHICLE. TOTAL VEHICLES IS NOW: " + Server.Info.Vehicles.Count.ToString());
                         */
                        return(true);
                    }
                    ThisClient.SendPacket(InPacket);
                    return(true);
                }
                private static bool YSFHandle_13_RemoveAircraft(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    //ThisClient.YSFServer.SendPacket(InPacket);

                    //Update OYS_LINK...
                    //OpenYS_Link.Set(OpenYS_Link.Stats._id, "stats_total_flight_seconds", OpenYS_Link.Stats.total_flight_seconds);
                    return(true);
                }
        private static void Send(ClientContext context, Packets.GenericPacket OutPacket)
        {
            // Convert the string data to byte data using ASCII encoding.
            byte[] byteData = OutPacket.GetRawBytes();

            // Begin sending the data to the remote device.
            context.Stream.BeginWrite(byteData, 0, byteData.Length, new AsyncCallback(SendCallback), context.Client);
        }
Exemple #13
0
 public static bool OpenYS_Command_Administration_Password_Method(Client ThisClient, CommandReader Command)
 {
     Console.WriteLine("&c" + ThisClient.Username + " is trying to log in to the server as an administrator...");
     if (Settings.Administration.AdminPassword == "")
     {
         ThisClient.SendMessage("&cNo Admin Password is set for the server, cannot log you in!");
         return(false);
     }
     ThisClient.SendMessage("&9OpenYS Server Authentication System");
     ThisClient.SendMessage("&f===================================");
     ThisClient.SendMessage("");
     ThisClient.SendMessage("&9Ready to log you in to the server. All messages are now being securely caught, and will not be passed onto the server.");
     ThisClient.SendMessage("&9Please also note that you are deaf to all messages while you you are in this interface!");
     ThisClient.SendMessage("");
     ThisClient.SendMessage("Please enter the admin password.");
     Console.WriteLine("&e" + ThisClient.Username + " temporarily deafened as part of the authentication process...");
     ThisClient.IsDeaf = true;
     while (true)
     {
         Packets.GenericPacket InPacket = ThisClient.YSFClient.ReceivePacket();
         if (InPacket.Type == 32)
         {
             ThisClient.IsDeaf = false;
             Packets.Packet_32_ChatMessage ChatMessage = new Packets.Packet_32_ChatMessage(InPacket, ThisClient.Username);
             if (ChatMessage.Message == Settings.Administration.AdminPassword)
             {
                 Console.WriteLine("&a" + ThisClient.Username + " has successfully authenticated as a server administrator.");
                 ThisClient.SendMessage("&aSuccessfully logged in as an administrator... Returning you back to the server.");
                 Clients.YSFClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " has successfully authenticated as a server administrator.");
                 ThisClient.OP();
                 break;
             }
             else
             {
                 Console.WriteLine("&c" + ThisClient.Username + " failed to authenticate as an administrator.");
                 ThisClient.SendMessage("&cAdmin Password Incorrect... Returning you back to the server.");
                 break;
             }
         }
         else
         {
             if (InPacket.Type == 08)
             {
                 ThisClient.IsDeaf = false;
                 ThisClient.SendMessage("&cJoin Requested Detected... Returning you back to the server.");
                 ThisClient.YSFClient.ProcessPacket(InPacket);
                 break;
             }
             ThisClient.YSFClient.ProcessPacket(InPacket);
         }
     }
     return(true);
 }
Exemple #14
0
 public static bool OYSHandle_29_HandShake(Client ThisClient, Packets.GenericPacket InPacket)
 {
     Packets.Packet_64_29_OpenYS_Handshake HandShake = new Packets.Packet_64_29_OpenYS_Handshake(InPacket);
     if (HandShake.Version == Settings.Loading.OYSNetcodeVersion)
     {
         ThisClient.YSFServer.OpenYSSupport = true;
         Console.WriteLine(ConsoleColor.Green, ThisClient.Username + " - Server Supports Extended OpenYS Protocal Version: " + HandShake.Version.ToString());
     }
     else
     {
         Console.WriteLine(ConsoleColor.Red, ThisClient.Username + " - Different Server Extended OpenYS Protocal Version: " + HandShake.Version.ToString());
     }
     return(true);
 }
 private static bool YSFHandle_13_RemoveAircraft(Client ThisClient, Packets.GenericPacket InPacket)
 {
     ThisClient.SendPacket(InPacket);
     Packets.Packet_13_RemoveAirplane RemoveAirplane = new Packets.Packet_13_RemoveAirplane(InPacket);
     lock (Vehicles.List) Vehicles.List.RemoveAll(x => x.ID == RemoveAirplane.ID);
     if (Clients.YSFClients[0] == ThisClient)
     {
         if (Settings.Flight.LeaveFlightNotification)
         {
             Console.WriteLine("&3" + "Aircraft ID " + RemoveAirplane.ID + " Removed");
         }
     }
     //Console.WriteLine("REMOVED VEHICLE. TOTAL VEHICLES IS NOW: " + Server.Info.Vehicles.Count.ToString());
     return(true);
 }
 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);
 }
                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);
                }
 private static bool YSFHandle_32_ChatMessage(Client ThisClient, Packets.GenericPacket InPacket)
 {
     Packets.Packet_32_ChatMessage ChatMessage = new Packets.Packet_32_ChatMessage(InPacket, ThisClient.Username);
     lock (ThisClient.MessagesTyped)
     {
         if ((ChatMessage.Message) == "/" & ThisClient.MessagesTyped.Count == 0)
         {
             ThisClient.SendMessage("No previously typed commands...");
             return(false);
         }
         if ((ChatMessage.Message) != "/")
         {
             ThisClient.MessagesTyped.Add(new Client.MessageTypedInfo(ChatMessage.Message));
         }
     }
     CommandManager.Process(ThisClient, ChatMessage.Message);
     return(true);
 }
                public static bool YSFHandle(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region SWITCH
                    if (InPacket == null | InPacket == Packets.NoPacket)
                    {
                        return(false);
                    }
                    switch (InPacket.Type)
                    {
                    case 05:
                        YSFHandle_05_EntityJoined(ThisClient, InPacket);
                        break;

                    case 11:
                        YSFHandle_11_FlightData(ThisClient, InPacket);
                        break;

                    case 13:
                        YSFHandle_13_RemoveAircraft(ThisClient, InPacket);
                        break;

                    case 16:
                        YSFHandle_16_PrepareSimulation(ThisClient, InPacket);
                        break;

                    case 29:
                        //When the Server sends the client the version number, tell the server that this client supports the OpenYS Protocal.
                        //ThisClient.YSFServer.SendPacket(new Packets.Packet_64_29_OpenYS_Handshake(Settings.Loading.OYSNetcodeVersion).ToCustomPacket());

                        ThisClient.SendPacket(InPacket);
                        break;

                    case 64:
                        //OpenYS User Data Packet
                        YSFHandle_64_UserPacket(ThisClient, InPacket);
                        break;

                    default:
                        ThisClient.SendPacket(InPacket);
                        break;
                    }
                    #endregion
                    return(true);
                }
                public static bool OYSHandle(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region PacketSwitch
                    if (InPacket == null | InPacket == Packets.NoPacket)
                    {
                        return(false);
                    }
                    switch (InPacket.Type)
                    {
                    default:
#if DEBUG
                        //Console.WriteLine("Unknown Custom Packet From " + ThisClient.Username);
                        //Console.WriteLine("-Type: " +  InPacket.Type.ToString());
                        //Console.WriteLine("-Data: " +  InPacket.Data.ToString());
#endif
                        break;
                    }
                    #endregion
                    return(true);
                }
                public static bool YSFHandle(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region SWITCH
                    if (InPacket == null | InPacket == Packets.NoPacket)
                    {
                        return(false);
                    }
                    switch (InPacket.Type)
                    {
                    case 1:
                        YSFHandle_01_Login(ThisClient, InPacket);
                        break;

                    case 11:
                        YSFHandle_11_FlightData(ThisClient, InPacket);
                        break;

                    case 12:
                        YSFHandle_12_Unjoin(ThisClient, InPacket);
                        break;

                    case 13:
                        YSFHandle_13_RemoveAircraft(ThisClient, InPacket);
                        break;

                    case 32:
                        YSFHandle_32_ChatMessage(ThisClient, InPacket);
                        break;

                    default:
                        //ThisClient.YSFServer.SendPacket(InPacket);
                        break;
                    }
                    #endregion
                    return(true);
                }
 public DataEvent(bool _IsSend, Client _Client, Packets.GenericPacket _Packet)
 {
     IsSend = _IsSend;
     Client = _Client;
     Packet = _Packet;
 }
Exemple #23
0
 public PacketEvent(float _TimeStamp, Packets.GenericPacket _Packet)
 {
     TimeStamp = _TimeStamp;
     Packet    = _Packet;
 }
 private static bool YSFHandle_64_UserPacket(Client ThisClient, Packets.GenericPacket InPacket)
 {
     Packets.Packet_64_UserPacket UserPacket = new Packets.Packet_64_UserPacket(InPacket);
     PacketHandler.ClientMode.FromServerToClient.OYSHandle(ThisClient, UserPacket.ToYSFPacket());
     return(true);
 }
        private void ReceiveDataCallback(IAsyncResult ar)
        {
            Packets.GenericPacket NewPacket = Packets.NoPacket;
            lock (Client)
            {
                try
                {
                    if (ConnectionContext == ConnectionContexts.Connectionless)
                    {
                        return;
                    }
                    if (Client.IsDisconnecting())
                    {
                        return;
                    }
                    if (Client.IsDisconnected())
                    {
                        return;
                    }

                    // Retrieve the state object and the client socket
                    // from the asynchronous state object.
                    SocketReadObject state = (SocketReadObject)ar.AsyncState;
                    // Read data from the remote device.
                    int bytesRead = Socket.EndReceive(ar);
                    if (bytesRead == 0)
                    {
                        //End Of Stream
                        //Debug.WriteLine("End of DataStream");
                        Client.Disconnect("Recv'd 0 data when trying to receive packet body.");
                    }
                    state.bytesreceivedsofar += bytesRead;
                    if (state.bytesreceivedsofar < state.size)
                    {
                        Socket.BeginReceive(state.databuffer, state.bytesreceivedsofar, state.size - state.bytesreceivedsofar, SocketFlags.None,
                                            new AsyncCallback(ReceiveDataCallback), state);
                        return;
                    }
                    else
                    {
                        //Debug.WriteLine(state.sizebuffer.ToDebugHexString() + state.databuffer.ToDebugHexString());
                        //Debug.TestPoint();

                        // All bytes have been received.
                        NewPacket = new Packets.GenericPacket(state.sizebuffer.Concat(state.databuffer).ToArray());
                        //Debug.WriteLine("End Receiving");
                    }
                }
                catch (SocketException e)
                {
                    Client.Disconnect("Remote client forcibly closed the connection.");
                    return;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Client.Disconnect("Generic Error when trying to receive packet body.");
                    return;
                }
            }

            //Outside of lock now, let another receive process begin!
            foreach (WaitForPacketObject ThisWaitForPacketObject in WaitForPacketList.ToArray())
            {
                if (NewPacket == null)
                {
                    break;
                }
                if (NewPacket == Packets.NoPacket)
                {
                    break;
                }
                if (NewPacket.GetRawString() == ThisWaitForPacketObject.Packet.GetRawString()) //Must match based on strings, not bytes...
                {
                    //Packets match.
                    ThisWaitForPacketObject.Trigger.Set();             //Set the trigger...
                    WaitForPacketList.Remove(ThisWaitForPacketObject); //Remove self.
                    //ThisWaitForPacketObject.Trigger.Dispose(); //Remove the trigger once set.
                    //Debug.WriteLine(Client.Username + " End Wait");
                }
            }
            ProcessPacket(NewPacket);
            //Thread.Sleep(500);
        }
 private static bool YSFHandle_16_PrepareSimulation(Client ThisClient, Packets.GenericPacket InPacket)
 {
     Console.WriteLine(ConsoleColor.Green, ThisClient.Username + " Login Complete!");
     ThisClient.SendPacket(InPacket);
     return(true);
 }
 public static bool DummyPacketHandler(Client ThisClient, Packets.GenericPacket ReceivedPacket)
 {
     Debug.WriteLine("&cPacket sent from " + Thread.CurrentThread.Name + " went to dummy handler... Nothing happened!");
     return(false);
 }
        public Packets.GenericPacket ReceivePacket()
        {
            if (ConnectionContext == ConnectionContexts.Connectionless)
            {
                return(Packets.NoPacket);
            }
            lock (Client) //only can be called one at a time per client!
            {
                try
                {
RESTART:
                    byte[] Size          = new byte[4];
                    byte[] _Buffer       = new byte[4];
                    int    ReceivedBytes = 0;
                    while (ReceivedBytes < 4)
                    {
                        int ThisReceivedBytes = Socket.Receive(_Buffer, 4 - ReceivedBytes, SocketFlags.None);
                        if (ThisReceivedBytes == 0)
                        {
                            Client.Disconnect("SocketDataReceiver Not able to get the Size of the Packet? (Received 0 Data.)");                         //Will never return 0 unless shutdown!
                        }
                        System.Buffer.BlockCopy(_Buffer, 0, Size, ReceivedBytes, ThisReceivedBytes);
                        ReceivedBytes += ThisReceivedBytes;
                    }

                    int RecvAmmt = (int)BitConverter.ToUInt32(Size, 0);
                    if (RecvAmmt > 8192 | RecvAmmt < 0)
                    {
                        //critical error in data receipt on the socket, flush it!
                        int    Available = Socket.Available;
                        byte[] Garbage   = new byte[Available];
                        Socket.Receive(Garbage, Available, SocketFlags.None);
                        Log.Warning("Flushed Socket for Client " + Client.Username + " as data size was corrupted!");
                        Debug.WriteLine("Flushed Socket for Client " + Client.Username + " as data size was corrupted!");
                        Log.Packets(new List <string>()
                        {
                            new Packets.GenericPacket(Garbage).GetRawBytes().ToDebugHexString()
                        });
                        //flushed the socket, start again!
                        goto RESTART;
                    }
                    _Buffer       = new byte[RecvAmmt];
                    ReceivedBytes = 0;
                    byte[] Data = new byte[RecvAmmt];
                    while (ReceivedBytes < RecvAmmt)
                    {
                        int ThisReceivedBytes = Socket.Receive(_Buffer, RecvAmmt - ReceivedBytes, SocketFlags.None);
                        if (ThisReceivedBytes == 0)
                        {
                            Client.Disconnect("SocketDataReceiver Not able to get the Remaining Data of the Packet? (Received 0 Data.)");                         //Will never return 0 unless shutdown!
                        }
                        System.Buffer.BlockCopy(_Buffer, 0, Data, ReceivedBytes, ThisReceivedBytes);
                        ReceivedBytes += ThisReceivedBytes;
                    }

                    Packets.GenericPacket Output = new Packets.GenericPacket(Size.Concat(Data).ToArray());
                    //OnPacketReceivedEvent(Output);
                    return(Output);
                }
                catch (SocketException)
                {
                    Client.Disconnect("Failed to receive data - Socket Closed Exception.");
                    return(Packets.NoPacket);
                }
                catch (ObjectDisposedException)
                {
                    Client.Disconnect("Failed to receive data - Socket Disposed Exception.");
                    return(Packets.NoPacket);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Client.Disconnect("SocketDataReceiver Generic Error - See the Error Log for Details!");
                    return(Packets.NoPacket);
                }
            }
        }
 public bool WaitFor(int Timeout, Packets.GenericPacket Packet)
 {
     return(BeginWait(Packet).EndWait(Timeout));
 }
 public WaitForPacketObject BeginWait(Packets.GenericPacket InPacket)
 {
     //Debug.WriteLine(Client.Username + " Start Wait");
     return(new WaitForPacketObject(this, InPacket));
 }