From ab6a569afd9dffc45fac0d0ef92063d6b55904df Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 1 Dec 2010 14:07:20 +0100 Subject: Added game mode selection, with 1p and 4p testing modes. --- server/lobby.cpp | 33 ++++++++++++++++++++++++++------- server/lobby.h | 5 ++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/server/lobby.cpp b/server/lobby.cpp index 79c207b..667d68e 100644 --- a/server/lobby.cpp +++ b/server/lobby.cpp @@ -8,20 +8,39 @@ void Lobby::handle_connect(Connection::p connection) { // Create player. - Client::create(connection, boost::bind(&Lobby::handle_action, this, _1)); + Client::create(connection, boost::bind(&Lobby::handle_login, this, _1)); // Get another connection. server.get_connection(boost::bind(&Lobby::handle_connect, this, _1)); } -void Lobby::handle_action(Client::p client) { +void Lobby::handle_login(Client::p client) { std::cout << "Client " << client->nick() << " entered the lobby." << std::endl; - if(waiting.size() >= 3) { - Game::create(waiting[0], waiting[1], waiting[2], client); - waiting.clear(); - } else { - waiting.push_back(client); + std::vector game_modes; + + game_modes.push_back("1p test mode"); + game_modes.push_back("4p test mode"); + + client->lobby_status(game_modes, boost::bind(&Lobby::handle_action, this, client, _1)); +} + +void Lobby::handle_action(Client::p client, int game_mode) { + std::cout << "Client " << client->nick() << " joined a game." << std::endl; + + switch(game_mode) { + case 0: { + Game::create(client, make_shared(), make_shared(), make_shared()); + } + + case 1: { + if(waiting.size() >= 3) { + Game::create(waiting[0], waiting[1], waiting[2], client); + waiting.clear(); + } else { + waiting.push_back(client); + } + } break; } } diff --git a/server/lobby.h b/server/lobby.h index 0e25975..fa0e5fe 100644 --- a/server/lobby.h +++ b/server/lobby.h @@ -18,8 +18,11 @@ class Lobby { //! Handle new connection. void handle_connect(Connection::p connection); + //! Handle login. + void handle_login(Client::p client); + //! Handle action. - void handle_action(Client::p client); + void handle_action(Client::p client, int game_mode); public: Lobby(); -- cgit v1.2.3