back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/server/server_data_processing.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-08-14 02:35:56 +0300
committerscratko <m@scratko.xyz>2024-08-14 02:35:56 +0300
commit880b8be2c28d761505b2eecc1386919d5add6f2f (patch)
tree63e965c3f82bcd09bb07baf9b669a736293dddc7 /server/server_data_processing.c
parenta2d696dea797faaa3157046c8ae89cd70e965bff (diff)
downloaddurak-880b8be2c28d761505b2eecc1386919d5add6f2f.tar.gz
durak-880b8be2c28d761505b2eecc1386919d5add6f2f.tar.bz2
durak-880b8be2c28d761505b2eecc1386919d5add6f2f.zip
Global fixes v1.0
Defense hint now only takes into account unbeaten cards. The client accounts for sticky data in one packet via TCP. Changed delimiter when sending data related to cards on the table and the queue (from '0' to '='). Accepting cards from a client (verification_client_input.c) is heavily patched. Cards are taken from the stack at the hint's prompt. Added pop_stack(). The trump card is retrieved from the end of the array. Changed the check of the defender's ability to beat all cards.
Diffstat (limited to 'server/server_data_processing.c')
-rw-r--r--server/server_data_processing.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/server/server_data_processing.c b/server/server_data_processing.c
index 30953bf..b7b2374 100644
--- a/server/server_data_processing.c
+++ b/server/server_data_processing.c
@@ -145,12 +145,12 @@ static void copy_base_info(int *free_pos, struct game_info *gi,
if(gi->cot->card_arr_idx != -1)
copy_cards_on_table(free_pos, *gi->cot);
else
- *free_pos += sprintf(output_buffer + *free_pos, "0:");
+ *free_pos += sprintf(output_buffer + *free_pos, "=:");
if(!is_empty_stack(deck))
copy_own_deck(free_pos, deck);
else
- *free_pos += sprintf(output_buffer + *free_pos, "0:");
+ *free_pos += sprintf(output_buffer + *free_pos, "=:");
}
int print_game_part(const struct session *client, struct game_info *gi)
@@ -186,7 +186,7 @@ int print_game_part(const struct session *client, struct game_info *gi)
gi->position_whose_turn);
/* copying card queue */
if(is_empty_queue(gi->cq))
- free_pos += sprintf(output_buffer + free_pos, "0:");
+ free_pos += sprintf(output_buffer + free_pos, "=:");
else
copy_card_queue(&free_pos, gi->cq);
*(output_buffer + free_pos-1) = '\n';
@@ -207,6 +207,10 @@ static int is_receiving_cards_limit(int total_defense_cards, int total_attack_ca
}
#endif
+
+/*
+ * example: 7v\2#\A^\'\n'
+ */
int get_cards_from_attacker(struct session *client,
const struct cards_on_table *cot,
const player_cards defense_deck,
@@ -219,9 +223,13 @@ int get_cards_from_attacker(struct session *client,
const char *stack_card = NULL;
read_result = read_from_client(client->fd, client->buffer, max_buffer_size);
+ printf("%d\n", read_result);
+ for(i = 0; i < read_result; ++i)
+ putchar(client->buffer[i]);
+ putchar('\n');
if(!read_result)
return read_result;
- for(i = 0, j = 0; i < read_result && client->buffer[i] != '\n'; ++i) {
+ for(i = 0, j = 0; i < read_result; ++i) {
if(client->buffer[i] == '\\') {
given_card[j] = '\0';
j = 0;
@@ -249,6 +257,8 @@ int get_cards_from_attacker(struct session *client,
* 1 - card was bited, not bited, or
* defender didn't want to continue defense phase
*
+ * example: 5v'\n'
+ * or: '\n'
*/
int get_card_from_defender(struct session *client, struct cards_on_table *cot,
const char * trump_suit)
@@ -258,12 +268,16 @@ int get_card_from_defender(struct session *client, struct cards_on_table *cot,
const char *stack_card = NULL;
read_result = read_from_client(client->fd, client->buffer, max_buffer_size);
+ printf("%d\n", read_result);
+ for(i = 0; i < read_result; ++i)
+ putchar(client->buffer[i]);
+ putchar('\n');
if(!read_result)
return read_result;
+ if(client->buffer[0] == '\n')
+ return 1;
for(i = 0; i < read_result && client->buffer[i] != '\n'; ++i)
given_card[i] = client->buffer[i];
- if(given_card[0] == '\n')
- return 1;
given_card[i] = '\0';
if(is_card_bit(cot->card_arr[cot->card_arr_idx-2], given_card, trump_suit)){
stack_card = remove_card_from_stack(&client->deck, given_card);
@@ -280,6 +294,7 @@ int get_card_from_defender(struct session *client, struct cards_on_table *cot,
* 3 - player refused to toss the card
*
* example: 10#\A^\7v\'\n'
+ * or: '\n'
*/
int get_cards_from_tossing_player(struct session *client,
const player_cards defense_deck,
@@ -293,14 +308,15 @@ int get_cards_from_tossing_player(struct session *client,
const char *stack_card = NULL;
read_result = read_from_client(client->fd, client->buffer, max_buffer_size);
+ printf("%d\n", read_result);
+ for(i = 0; i < read_result; ++i)
+ putchar(client->buffer[i]);
+ putchar('\n');
if(!read_result)
return read_result;
for(i = 0, j = 0; i < read_result; ++i) {
if(client->buffer[i] == '\\') {
- /* cancellation */
- if(given_card[0] == '\n')
- return 3;
/* tossing limit was set */
if(client->tm == cancel) {
/* it's impossible to accept cards due to tossing limit */
@@ -326,6 +342,10 @@ int get_cards_from_tossing_player(struct session *client,
given_card[j] = client->buffer[i];
++j;
}
+ /* cancellation */
+ if(client->buffer[0] == '\n')
+ return 3;
+
/* 7 -- state for result of received cards */
data_length = sprintf(output_buffer, "%d:%s\n", card_acceptance_status,
all_cards_received_status ? "all" : "not all");