summaryrefslogtreecommitdiff
path: root/game.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-06-02 00:22:05 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-06-02 00:22:05 +0200
commit6304a3afdcf747468dc125991b3313887c2af941 (patch)
tree807358c0483ef3ea284872ef6f5e7eb77a2e74a2 /game.cpp
parent1d106a249648b2c39c1256c80325b18ffe91f7f3 (diff)
Added a new transparent scheme based on Vanilla and a simple chat window, which displays text strings received from the server.
Diffstat (limited to 'game.cpp')
-rw-r--r--game.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/game.cpp b/game.cpp
index 5bc1a8d..0ebefed 100644
--- a/game.cpp
+++ b/game.cpp
@@ -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();