From e63bb796ca10938eeea42ceaff5d0c65d2d2bb2b Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 15 Sep 2011 06:54:51 -0500 Subject: [PATCH] disconnecting clients no longer breaks server, fixes #8 --- examples/chat_server/chat.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/chat_server/chat.cpp b/examples/chat_server/chat.cpp index c497224bb0..6cd0fbbebc 100644 --- a/examples/chat_server/chat.cpp +++ b/examples/chat_server/chat.cpp @@ -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); } -} \ No newline at end of file +}