As the OP, I'm making an update on this post as I never went back on here since 2019 (sorry for all the missed messages!). In 2023, I am now a postgrad. If any lonely student finds this post, I have advice to give you as someone who's been through a rather tough period of loneliness, only to come out of it just fine later.
First of all, we all experience ups and downs in social life, mood, ambition and love life at uni. It tends to be a transient experience that ranges in length from person to person. I was pretty lonely in my second year to the point where I believe I may have been depressed. At the time, I felt like I was the only one in this position. One day, I saw a post for year abroad registration and decided to sign myself up for one. The year abroad was truly the best decision for me! It completely spiced up my student experience and gave me a fresh start when I came back in the final year. My biggest advice is to be proactive when you are lonely. Try to foster a sense of positivity even when the times get rough. For me, a year abroad was a way to step away for a bit whilst I reconnected with myself. For someone else, that may be societies or sports clubs. Even if you are a shy person, you can easily make friends at the right societies where you'll meet the personalities that you click with! Above all, try to work on mental wellbeing by meditating, reading helpful books and listening to meaningful podcasts. You need to address the dependency on people first, before you're faced with potential friendships around you.