disconnecting clients no longer breaks server, fixes #8

This commit is contained in:
Peter Thorson
2011-09-15 06:54:51 -05:00
parent 348214d568
commit e63bb796ca

View File

@@ -72,11 +72,12 @@ void chat_handler::disconnect(session_ptr client,uint16_t status,const std::stri
std::cout << "client " << client << " left the lobby." << std::endl;
const std::string alias = it->second;
m_connections.erase(it);
// send user list and signoff message to all clients
send_to_all(serialize_state());
send_to_all(encode_message("server",m_connections[client]+" has left the chat."));
send_to_all(encode_message("server",alias+" has left the chat."));
}
void chat_handler::message(session_ptr client,const std::string &msg) {
@@ -177,4 +178,4 @@ void chat_handler::send_to_all(std::string data) {
for (it = m_connections.begin(); it != m_connections.end(); it++) {
(*it).first->send(data);
}
}
}