summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client_game_states.c3
-rw-r--r--src/game.c14
-rw-r--r--src/net/server.c6
-rw-r--r--src/server_game_states.c63
-rw-r--r--src/ui.c9
-rw-r--r--src/ui.h2
6 files changed, 78 insertions, 19 deletions
diff --git a/src/client_game_states.c b/src/client_game_states.c
index b327855..4ffd50b 100644
--- a/src/client_game_states.c
+++ b/src/client_game_states.c
@@ -209,4 +209,7 @@ void state_client_game_finished(void)
player_list_sort_by_score(&d->player_list, d->player_list.count); // Sort player list by scores in ascending ordner
ui_display_wnd_final_scores(&d->player_list, d->player_list.count, d->own_player_id);
ui_update();
+#ifdef OXEN_DGLSERVER
+ sleep(5);
+#endif // OXEN_DGLSERVER
}
diff --git a/src/game.c b/src/game.c
index efe65db..a7fef5a 100644
--- a/src/game.c
+++ b/src/game.c
@@ -150,7 +150,7 @@ void start_game(const bool servermode, const char* addr, const char* port, const
{
#ifdef OXEN_DGLSERVER
#ifdef OXEN_DEBUG
- printf("Running server in dgamelaunch mode\n");
+ fprintf(stderr, "Running server in dgamelaunch mode\n");
#endif // OXEN_DEBUG
#else // No forking needed when running as dedicated server
pid_t child = fork();
@@ -187,11 +187,21 @@ void start_game(const bool servermode, const char* addr, const char* port, const
net_send(client_socks.sockets[i], msg_type_start_game, NULL);
}
+#ifdef OXEN_DGLSERVER
+ ui_init();
+ // Display all windows
+ ui_display_wnd_table_cards(&data->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&data->table_stacks, false, 0);
+ ui_display_wnd_current_state(&data->player_list, data->player_list.count, false, 0, -1);
+#endif // OXEN_DGLSERVER
+
main_loop_server(&client_socks);
#ifdef OXEN_DGLSERVER
+ ui_fini();
+
#ifdef OXEN_DEBUG
- printf("Server in dgamelaunch mode finished.\n");
+ fprintf(stderr, "Server in dgamelaunch mode finished.\n");
#endif // OXEN_DEBUG
#endif // OXEN_DGLSERVER
}
diff --git a/src/net/server.c b/src/net/server.c
index a37c17c..9658e20 100644
--- a/src/net/server.c
+++ b/src/net/server.c
@@ -130,7 +130,7 @@ void server_get_players(int serversock, socket_list_t* client_socks, const uint8
assert(count <= MAX_PLAYERS && count > 0);
- printf("Waiting for %d players to connect ...\n", count);
+ fprintf(stderr, "Waiting for %d players to connect ...\n", count);
// accept connections
for(i=0; i<count; i++)
@@ -140,14 +140,14 @@ void server_get_players(int serversock, socket_list_t* client_socks, const uint8
client_socks->sockets[i] = accept(serversock, (struct sockaddr*) &addr, &addrlen);
if(client_socks->sockets[i] == -1)
{
- printf("accept: %s\n", strerror(client_socks->sockets[i]));
+ fprintf(stderr, "accept: %s\n", strerror(client_socks->sockets[i]));
exit(EXIT_FAILURE);
}
//printf("new client connected: %s\n", inet_ntop(sock.ss_family, get_in_addr((struct sockaddr*)&sock), INET6_ADDRSTRLEN));
}
client_socks->count = count;
- printf("All players connected. Starting game!\n");
+ fprintf(stderr, "All players connected. Starting game!\n");
}
/**
diff --git a/src/server_game_states.c b/src/server_game_states.c
index f3089fc..4ec7154 100644
--- a/src/server_game_states.c
+++ b/src/server_game_states.c
@@ -28,7 +28,9 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
#include "data_store.h"
+#include "ui.h"
/**
* Game state handler. If it is the first round, the server takes cards from the main stack and places them onto the table, as table stacks. The server then sends the table stacks to all players. After this, the hands for the players will be drawn from the main stack and sent to the players. On returning from the function, a state transition occurs.
@@ -49,6 +51,12 @@ game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, con
d->table_stacks.stacks[2].cards[0] = main_stack_remove_card(m);
d->table_stacks.stacks[3].cards[0] = main_stack_remove_card(m);
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_table_cards(&d->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&d->table_stacks, false, 0);
+ ui_update();
+#endif // OXEN_DGLSERVER
+
for(int i = 0; i < d->player_list.count; i++)
{
net_send(client_socks->sockets[i], msg_type_initial_stacks, NULL);
@@ -90,6 +98,11 @@ game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks)
{
data_store_t *d = data_store();
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Waiting for the players to pick their cards", false); // The two spaces between 'their' and 'cards' are intentionally and used for poor man's word wrap
+ ui_update();
+#endif // OXEN_DGLSERVER
+
// Receive open cards from clients
for(int i = 0; i < d->player_list.count; i++)
{
@@ -134,15 +147,32 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma
card c = d->player_list.players[i].open_card;
uint8_t stack_idx = get_stack_idx_for_card(&d->table_stacks, c);
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Placing cards ...", false);
+ ui_display_wnd_current_state(&d->player_list, d->player_list.count, true, i, -1);
+ ui_update();
+#endif // OXEN_DGLSERVER
+
if(stack_idx >= NUM_TABLE_STACKS) // card does not fit on any stack
{
int cur_sock = socket_for_player_id(client_socks, d->player_list.players[i].player_id);
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Waiting for player to choose stack", false);
+ ui_update();
+#endif // OXEN_DGLSERVER
+
net_recv(cur_sock, msg_type_selected_stack_c);
for(int j=0; j<client_socks->count; j++) // send received stack to all clients (including the one who sent it)
net_send(client_socks->sockets[j], msg_type_selected_stack_s, NULL);
d->player_list.players[i].score += card_stack_get_points(&d->table_stacks.stacks[d->stack_index]);
card_stack_replace(&d->table_stacks.stacks[d->stack_index], c);
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_table_cards(&d->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&d->table_stacks, false, 0);
+#endif // OXEN_DGLSERVER
}
else // card fits on a stack -> place it
{
@@ -153,17 +183,22 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma
card_stack_replace(cs, c);
}
else
- {
- // put open card on top of stack
- for(int j=0; j<MAX_CARD_STACK_SIZE; j++)
- {
- if(cs->cards[j] != 0)
- continue;
- cs->cards[j] = c;
- break;
- }
- }
+ card_stack_push(cs, c);
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_table_cards(&d->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&d->table_stacks, false, 0);
+#endif // OXEN_DGLSERVER
}
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Placing cards ...", false); // may have been overwritten by "Waiting .. stack" message. Rewrite it.
+ ui_update();
+
+ // Wait between player turns, but not after the last one
+ if (i != d->player_list.count - 1)
+ sleep(2);
+#endif // OXEN_DGLSERVER
}
if(hand_count_cards(&d->hand) > 0) // still cards in hand?
@@ -198,4 +233,12 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma
*/
void state_server_game_finished(void)
{
+#ifdef OXEN_DGLSERVER
+ data_store_t *d = data_store();
+
+ player_list_sort_by_score(&d->player_list, d->player_list.count); // Sort player list by scores in ascending ordner
+ ui_display_wnd_final_scores(&d->player_list, d->player_list.count, d->own_player_id);
+ ui_update();
+ sleep(5);
+#endif // OXEN_DGLSERVER
}
diff --git a/src/ui.c b/src/ui.c
index 735621f..3537c1b 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -256,9 +256,9 @@ void ui_display_wnd_stack_points(const table_stacks_t *ts, const bool highlight,
* @param[in] num_players The number of players to show a player name and open card for
* @param[in] highlight If true, a player in the player table will be highlighted
* @param[in] highlighted_player The player to highlight
- * @param[in] score The players score
+ * @param[in] score The players score. Will be displayed if >= 0.
*/
-void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const player_id_t highlighted_player, const uint32_t score)
+void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const player_id_t highlighted_player, const int32_t score)
{
assert(pl != NULL);
uint8_t pos = 0;
@@ -266,7 +266,8 @@ void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_pla
werase(w_current_state);
wattron(w_current_state, A_BOLD);
mvwprintw(w_current_state, 0, 0, "Current state:");
- mvwprintw(w_current_state, 0, 22, "Your Score: %3d", score);
+ if (score >= 0)
+ mvwprintw(w_current_state, 0, 22, "Your Score: %3d", score);
wattroff(w_current_state, A_BOLD);
mvwprintw(w_current_state, 1, 1, "Player Card");
mvwprintw(w_current_state, 1, 22, "Player Card");
@@ -435,10 +436,12 @@ void ui_display_wnd_final_scores(const player_list_t *pl, const uint8_t num_play
wrefresh(w_final_scores);
+#ifndef OXEN_DGLSERVER
int key;
do {
key = wgetch(w_final_scores);
} while (KEY_RETURN != key && KEY_ESCAPE != key);
+#endif // !OXEN_DGLSERVER
}
/**
diff --git a/src/ui.h b/src/ui.h
index d19839a..a56871c 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -35,7 +35,7 @@
void ui_display_wnd_table_cards(const table_stacks_t *ts, const bool highlight, const uint8_t highlighted_stack);
void ui_display_wnd_stack_points(const table_stacks_t *ts, const bool highlight, const uint8_t highlighted_points);
-void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const player_id_t highlighted_player, const uint32_t score);
+void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const player_id_t highlighted_player, const int32_t score);
void ui_display_wnd_messages(const char *message, const bool highlight);
void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint8_t highlighted_card);
void ui_display_wnd_final_scores(const player_list_t *pl, const uint8_t num_players, const player_id_t highlighted_player);