Oooookkayyyy, first off the code is for a server, but the problem is with me trying to remove a client from the list of connected clients.
Problematic code:
sf::Socket::Status status = clients.receive(buffer, sizeof(buffer), received);
if (status == sf::Socket::Disconnected)
{
std::cout << "\nUser #" << i << " has discconected and has been removed from the user list" << std::endl;
clients.disconnect();
iter_swap(clients.begin() + i, clients.begin() + maxClients); //Swap indexs of disconnected user with client at end of list
numClients--;
continue;
}
Now wtf i'm trying to do:
When a client disconnects, I want to remove them from the list of clients (as said above), but the way I have set up the server makes this really annoying bug, basically if a client disconnects, it kicks the person that joined last.
The way I am trying to fix this is by moving the disconnected clients vector entry thingy to the back of the vector, so that it would continue server-ing normally.
Now the error I end up with by using the above code:
'sf::TcpSocket::TcpSocket(const sf::TcpSocket &)': attemtping to referance a deleted function
What I've tried:
- Using a deque instead of a vector to remove elements from the list, and move the ones above to it's place (Same error)
- (Probs a dumb idea kek) Using a second vector to represent the other one, filled with ints that represent indexes in the client vector, allowing my to do clients[indexs].blah_blah
Extra notes:
- Clients is a vector of sf::TcpSockets
- The disconnect check thing is in a for loop iterating though each client connected
- numClients is how many people are connected
Please don't treat me like people on stack overflow do xD