summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/lobby.cpp33
-rw-r--r--server/lobby.h5
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<std::string> 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<ClientDumb>(), make_shared<ClientDumb>(), make_shared<ClientDumb>());
+ }
+
+ 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();