summary refs log tree commit diff stats
path: root/server_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server_main.cpp')
-rw-r--r--server_main.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/server_main.cpp b/server_main.cpp index 8da6477..145f8a2 100644 --- a/server_main.cpp +++ b/server_main.cpp
@@ -22,8 +22,9 @@ using socket_type = websocketpp::server<websocketpp::config::asio>;
22 22
23class server { 23class server {
24 public: 24 public:
25 server(const cardset& cards, const imagestore& images, std::mt19937& rng) 25 server(const cardset& cards, const imagestore& images, int port,
26 : cards_(cards), images_(images), rng_(rng) { 26 std::mt19937& rng)
27 : cards_(cards), images_(images), port_(port), rng_(rng) {
27 socket_.init_asio(); 28 socket_.init_asio();
28 29
29 socket_.set_message_handler([this](websocketpp::connection_hdl connection, 30 socket_.set_message_handler([this](websocketpp::connection_hdl connection,
@@ -33,11 +34,13 @@ class server {
33 } 34 }
34 35
35 void run() { 36 void run() {
36 socket_.listen(9002); 37 socket_.listen(port_);
37 socket_.start_accept(); 38 socket_.start_accept();
38 39
39 asio::post(std::bind(&server::cleanup_thread, this)); 40 asio::post(std::bind(&server::cleanup_thread, this));
40 41
42 std::cout << "Listening on port " << port_ << "..." << std::endl;
43
41 socket_.run(); 44 socket_.run();
42 } 45 }
43 46
@@ -198,6 +201,7 @@ class server {
198 201
199 const cardset& cards_; 202 const cardset& cards_;
200 const imagestore& images_; 203 const imagestore& images_;
204 const int port_;
201 205
202 std::mutex rng_mutex_; 206 std::mutex rng_mutex_;
203 std::mt19937& rng_; 207 std::mt19937& rng_;
@@ -224,7 +228,8 @@ int main(int argc, char** argv) {
224 228
225 cardset cards(config_data["cards_path"]); 229 cardset cards(config_data["cards_path"]);
226 imagestore images(config_data["cache_path"]); 230 imagestore images(config_data["cache_path"]);
231 int port = config_data["port"];
227 232
228 server app(cards, images, rng); 233 server app(cards, images, port, rng);
229 app.run(); 234 app.run();
230} 235}