summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.c8
-rw-r--r--src/main.c2
2 files changed, 7 insertions, 3 deletions
diff --git a/src/game.c b/src/game.c
index 9c0f353..9087832 100644
--- a/src/game.c
+++ b/src/game.c
@@ -7,8 +7,8 @@
#include <time.h>
#include <unistd.h>
#include <assert.h>
-#include <curses.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include "ui.h"
#include "data_store.h"
#include "net/comm.h"
@@ -99,7 +99,7 @@ void start_game(const bool servermode, const char* addr, const char* port, const
if(servermode)
{
pid_t child = fork();
- server_process = (child == 0);
+ server_process = (child == 0); // start server as child
}
if(server_process) // Start server and connect to localhost
@@ -138,6 +138,7 @@ void start_game(const bool servermode, const char* addr, const char* port, const
int sock;
sleep(1); // TODO make sure server process is listening
+
sock = client_connect_server(addr, port);
data_store_t *data = data_store();
@@ -164,6 +165,9 @@ void start_game(const bool servermode, const char* addr, const char* port, const
ple = &data->player_list.players[i];
printf("%s: %d\n", ple->player_name, ple->score);
}
+
+ if(servermode) // wait until server (child) has exited
+ wait(NULL);
}
destroy_data_store();
diff --git a/src/main.c b/src/main.c
index 8ab12f3..71beb56 100644
--- a/src/main.c
+++ b/src/main.c
@@ -65,5 +65,5 @@ int main(int argc, char *argv[])
start_game(servermode, addr, port, num_players);
- return EXIT_SUCCESS;
+ exit(EXIT_SUCCESS);
}