Fixes minor chat client issues

This commit is contained in:
Peter Thorson
2011-09-29 07:47:19 -05:00
parent d650d68551
commit 5adb5cdfbe
4 changed files with 17 additions and 4 deletions

2
.gitignore vendored
View File

@@ -23,3 +23,5 @@ examples/chat_client/chat_client
examples/chat_client/chat_client
test/basic/tests
examples/chat_client/chat_client

Binary file not shown.

View File

@@ -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);

View File

@@ -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,"&","&amp;");
boost::algorithm::replace_all(alias,"<","&lt;");
boost::algorithm::replace_all(alias,">","&gt;");
m_connections[client] = alias;