public void HandleConnectionData(HandshakeMessage type, ByteStreamReader stream, IPEndPoint endpoint)
    {
        Console.WriteLine(type);
        if (type == HandshakeMessage.SYN)
        {
            PendingConnectionEntity ce = new PendingConnectionEntity();
            ce.m_connectionId = m_connectionId.Allocate();
            ce.m_sender       = new Connection();
            int port = stream.ReadInt();
            ce.m_pendingStartTime = DateTime.Now;
            ce.m_sender.Connect(new IPEndPoint(endpoint.Address, port));
            m_pending.Add(ce);

            HandshakeStepTwo(ce);
        }
        else if (type == HandshakeMessage.ACK)
        {
            int id = stream.ReadInt();
            PendingConnectionEntity chosen = m_pending.FirstOrDefault(x => x.m_connectionId == id);
            if (chosen != null)
            {
                m_pending.Remove(chosen);
                m_entities[chosen.m_connectionId] = new ConnectionEntity(chosen);
                Network.Server.World.AddPlayer(chosen.m_connectionId);
            }
        }
        else if (type == HandshakeMessage.Disconnect)
        {
            int id = stream.ReadInt();
            Disconnect(id, false);
        }
    }
 public ConnectionEntity(PendingConnectionEntity pending)
 {
     m_sender       = pending.m_sender;
     m_connectionId = pending.m_connectionId;
 }