back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/server.h
diff options
context:
space:
mode:
Diffstat (limited to 'server.h')
-rw-r--r--server.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/server.h b/server.h
new file mode 100644
index 0000000..787d767
--- /dev/null
+++ b/server.h
@@ -0,0 +1,80 @@
+#ifndef SERVER_H_SENTRY
+#define SERVER_H_SENTRY
+
+#include "card_qeueu.h"
+
+enum {
+ max_buffer_size = 4096,
+ listen_qlen = 32,
+ init_sess_arr_size = 32
+};
+
+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 {
+ display_only_table,
+ attack_expectation,
+ defense_expectation,
+ tossing_expectation,
+ attack,
+ defense,
+ tossing
+};
+
+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 server {
+ int change_server_state;
+ int listen_socket;
+ struct session **sess_arr;
+ int max_sess_arr_size;
+ int connected_players_counter;
+ char **shuffled_deck;
+ int shuffled_deck_size;
+ struct game_info *gi;
+ struct session **turn_queue;
+ int *card_quantity_arr;
+ int number_whose_turn;
+ struct card_queue *cq;
+ struct cards_on_table *cot;
+};
+
+#endif