#include "lobby.h" #include #include void Lobby::handle_connect(Connection::p connection) { // Send Hello. connection->send(make_shared("aotenjoud git")); // Wait for Login. connection->recv(boost::bind(&Lobby::handle_login, this, connection, _1)); // Get another connection. server.get_connection(boost::bind(&Lobby::handle_connect, this, _1)); } void Lobby::handle_login(Connection::p connection, Message::p msg) { if(msg->type != Message::Types::Login) { return; } Message::Login::p login_msg = dynamic_pointer_cast(msg); std::cout << "Player " << login_msg->nick << " entered the lobby." << std::endl; // Check if nick is invalid. if(login_msg->nick.size() == 0) { connection->send(make_shared(false)); connection->recv(boost::bind(&Lobby::handle_login, this, connection, _1)); return; } connection->send(make_shared(true)); // Do something with the connection to keep it around. } Lobby::Lobby() : server(io_service) { } void Lobby::run() { // Get a connection. server.get_connection(boost::bind(&Lobby::handle_connect, this, _1)); io_service.run(); }