back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/server/server.h
diff options
context:
space:
mode:
Diffstat (limited to 'server/server.h')
-rw-r--r--server/server.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/server/server.h b/server/server.h
new file mode 100644
index 0000000..46c965b
--- /dev/null
+++ b/server/server.h
@@ -0,0 +1,99 @@
+#ifndef SERVER_H_SENTRY
+#define SERVER_H_SENTRY
+
+#include "card_queue.h"
+#include "card_stack.h"
+
+enum {
+ max_buffer_size = 4096,
+ listen_qlen = 32,
+ init_sess_arr_size = 32
+};
+
+enum {
+ max_shuffled_deck_size = 52,
+ max_card_arr_size = 18
+};
+
+enum server_states {
+ no_players,
+ first_player,
+ confirmation_waiting,
+ start_game,
+ attack_phase_out,
+ attack_phase_in,
+ defense_phase_out,
+ defense_phase_in,
+ tossing_phase_out,
+ tossing_phase_in,
+ table
+};
+
+enum client_game_states {
+ /* in game */
+ display_only_table = 3,
+ attack_expectation,
+ defense_expectation,
+ tossing_expectation,
+ attack,
+ defense,
+ tossing,
+ card_acceptance_status,
+ tossing_limit_status
+};
+
+enum tossing_mode {
+ cancel,
+ answer_wait,
+ answer_got,
+ none
+};
+
+struct session {
+ int fd;
+ enum client_game_states state;
+ /* read data from client */
+ char buffer[max_buffer_size];
+ int buffer_used;
+ int record;
+ player_cards deck;
+ int player_position;
+ enum tossing_mode tm;
+ int defense_lost;
+};
+
+struct cards_on_table {
+ /*
+ * example: 2^ \ - 10# \ K#
+ */
+ const char* card_arr[max_card_arr_size];
+ int card_arr_idx;
+};
+
+struct card_count {
+ int *number_arr;
+ /* will only store the initial number of players (idx) */
+ int number_arr_idx;
+};
+
+struct server {
+ int change_server_state;
+ enum server_states state;
+ int listen_socket;
+ struct session **sess_arr;
+ int max_sess_arr_size;
+ int connected_players_counter;
+ /* TODO: make static allocation memory */
+ const char **shuffled_deck;
+ int shuffled_deck_size;
+ const char *trump_suit;
+ const char *trump_card;
+ struct game_info *gi;
+ struct session **turn_queue;
+ struct card_count cc;
+ int position_whose_turn;
+ struct card_queue cq;
+ struct cards_on_table cot;
+};
+
+#endif