From 426cc26db0d38ffe3ee0e667ff6b3436c239c964 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 21 Oct 2012 13:31:52 -0400 Subject: [PATCH] abstract connect() and disconnect() in Client --- src/client/Client.cc | 17 +++++++++++++---- src/client/Client.h | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 5338922..0f06686 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8,8 +8,7 @@ Client::Client() { - m_net_client = new Network(); - m_net_client->Create(59243, "127.0.0.1"); // Just connect to local host for now - testing + connect(59243, "127.0.0.1"); // Just connect to local host for now - testing m_client_has_focus = true; m_players.clear(); m_current_player = 0; @@ -19,6 +18,18 @@ Client::Client() } Client::~Client() +{ + disconnect(); + m_players.clear(); +} + +void Client::connect(int port, const char *host) +{ + m_net_client = new Network(); + m_net_client->Create(port, host); +} + +void Client::disconnect() { // Send disconnect message bool connection_closed = false; @@ -72,10 +83,8 @@ Client::~Client() } m_net_client->Destroy(); - m_players.clear(); } - void Client::run(bool fullscreen, int width, int height, std::string pname) { m_current_player_name = pname; diff --git a/src/client/Client.h b/src/client/Client.h index 82a1a81..4b77503 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -24,6 +24,8 @@ class Client ~Client(); void run(bool fullscreen, int width, int height, std::string pname); protected: + void connect(int port, const char *host); + void disconnect(); bool create_window(bool fullscreen, int width, int height); bool initgl(); void resize_window(int width, int height);