diff --git a/.gitignore b/.gitignore index a478da1ac5..1051289658 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ examples/chat_client/chat_client examples/chat_client/chat_client test/basic/tests + +examples/chat_client/chat_client diff --git a/examples/chat_client/chat_client b/examples/chat_client/chat_client index 9dce4933e5..84a2d40930 100755 Binary files a/examples/chat_client/chat_client and b/examples/chat_client/chat_client differ diff --git a/examples/chat_client/chat_client_handler.cpp b/examples/chat_client/chat_client_handler.cpp index 94d2c71f15..38f8ff80ee 100644 --- a/examples/chat_client/chat_client_handler.cpp +++ b/examples/chat_client/chat_client_handler.cpp @@ -48,7 +48,7 @@ void chat_client_handler::on_close(session_ptr s,uint16_t status,const std::stri } void chat_client_handler::on_message(session_ptr s,const std::string &msg) { - std::cout << "message from server: " << msg << std::endl; + //std::cout << "message from server: " << msg << std::endl; decode_server_msg(msg); } @@ -82,9 +82,9 @@ void chat_client_handler::do_send(const std::string &msg) { } // check for local commands - if (msg == "list") { + if (msg == "/list") { std::cout << "list all participants" << std::endl; - } else if (msg == "close") { + } else if (msg == "/close") { do_close(); } else { m_session->send(msg); diff --git a/examples/chat_server/chat.cpp b/examples/chat_server/chat.cpp index 4db52eaeb1..d346281f99 100644 --- a/examples/chat_server/chat.cpp +++ b/examples/chat_server/chat.cpp @@ -104,8 +104,19 @@ void chat_server_handler::on_message(session_ptr client,const std::string &msg) alias = msg.substr(7); } - // store alias response = m_connections[client] + " is now known as "+alias; + + // store alias pre-escaped so we don't have to do this replacing every time this + // user sends a message + + // escape JSON characters + boost::algorithm::replace_all(alias,"\\","\\\\"); + boost::algorithm::replace_all(alias,"\"","\\\""); + + // escape HTML characters + boost::algorithm::replace_all(alias,"&","&"); + boost::algorithm::replace_all(alias,"<","<"); + boost::algorithm::replace_all(alias,">",">"); m_connections[client] = alias;