diff options
Diffstat (limited to 'game.cpp')
-rw-r--r-- | game.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -56,10 +56,10 @@ void Game::async_read() { uint8_t *t = new uint8_t; boost::asio::async_read(socket, boost::asio::buffer(t, sizeof(uint8_t)), boost::asio::transfer_all(), - boost::bind(&Game::handle_message, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, t)); + boost::bind(&Game::handle_type, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, t)); } -void Game::handle_message(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type) { +void Game::handle_type(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type) { if(error) { std::cerr << error << std::endl; delete type; @@ -71,6 +71,9 @@ void Game::handle_message(const boost::system::error_code& error, std::size_t by case message::MSG_TYPE_CHUNK: handle_chunk(); break; + case message::MSG_TYPE_MSG: + handle_message(); + break; default: std::cout << "unknown type: " << (int)*type << std::endl; } @@ -101,6 +104,18 @@ void Game::handle_chunk() { scene->terrain->chunks.push_back(chunk); } +void Game::handle_message() { + message::Message m; + + m.read(socket); + m.get_len(); + + m.read(socket); + std::string s = m.get_str(); + + scene->chat->add_line(s); +} + Game& Game::get_instance() { if(!game) game = new Game(); |