1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#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 = 12, /* it was 32 */
timeout = 30
};
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,
end_round,
end_game
};
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,
spectator,
result,
disconnect
};
enum tossing_mode {
none,
cancel,
answer_wait,
answer_got,
answer_got_with_limit,
};
enum spectator_mode {
spectator_attack,
spectator_defense,
spectator_tossing,
spectator_table
};
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;
const char **shuffled_deck;
int shuffled_deck_size;
const char *trump_suit;
const char *trump_card;
struct game_info *gi;
struct session **turn_queue;
/* changes if the player has discarded all his cards
* (and shuffled_deck_size == 0)
*/
int turn_queue_size;
struct card_count cc;
int position_whose_turn;
struct card_queue cq;
struct cards_on_table cot;
int durak_position;
int tossing_limit;
};
#endif
|