summaryrefslogtreecommitdiff
path: root/server/lobby.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-11-15 07:02:48 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-11-15 07:02:48 +0100
commit6f51fbfb06767000173647b57d0b755f4d02c247 (patch)
tree18c2f348c0bf0225f5b2e3e5343a4b54a420fbda /server/lobby.cpp
parent174ac25d9788e5604ae37cf9048e307a97bbdff8 (diff)
Added Lobby class to server, serving as the master application class.
Diffstat (limited to 'server/lobby.cpp')
-rw-r--r--server/lobby.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/server/lobby.cpp b/server/lobby.cpp
new file mode 100644
index 0000000..f74a4f2
--- /dev/null
+++ b/server/lobby.cpp
@@ -0,0 +1,48 @@
+#include "lobby.h"
+
+#include <boost/bind.hpp>
+
+#include <iostream>
+
+void Lobby::handle_connect(Connection::p connection) {
+ // Send Hello.
+ connection->send(make_shared<Message::Hello>("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<Message::Login>(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<Message::LoginResponse>(false));
+ connection->recv(boost::bind(&Lobby::handle_login, this, connection, _1));
+ return;
+ }
+
+ connection->send(make_shared<Message::LoginResponse>(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();
+}