diff options
author | scratko <m@scratko.xyz> | 2024-08-30 12:46:56 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-08-30 14:59:44 +0300 |
commit | 831f9f01fbe4088eb6bd378c0e417d9996b676fd (patch) | |
tree | 53297459d35ad795618c351a79b1829776e5e1f4 /client/verification_client_input.c | |
parent | 4b6c15f780d59895f067383a5041edcfe86f504e (diff) | |
download | durak-831f9f01fbe4088eb6bd378c0e417d9996b676fd.tar.gz durak-831f9f01fbe4088eb6bd378c0e417d9996b676fd.tar.bz2 durak-831f9f01fbe4088eb6bd378c0e417d9996b676fd.zip |
Final version v2.0
Added windows client.
SIGPIPE signal was being sent to the server when the client was disconnected.
Now there is handling of this signal.
Added a delay when displaying some informational messages.
Diffstat (limited to 'client/verification_client_input.c')
-rw-r--r-- | client/verification_client_input.c | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/client/verification_client_input.c b/client/verification_client_input.c deleted file mode 100644 index fa88b54..0000000 --- a/client/verification_client_input.c +++ /dev/null @@ -1,115 +0,0 @@ -#include "verification_client_input.h" -#include "card_handling.h" -#include "printing_game_frames.h" - -#include <stdio.h> -#include <unistd.h> -#include <string.h> - -enum { - output_buffer_size = 1024 -}; - -static char output_buffer[output_buffer_size]; - -/* - * 1 - response received - * 0 - waiting for re-entry of data - */ -int vci_confirmation_waiting(int fd, char *buffer) -{ - if(buffer[0] == '\n') { - write(fd, buffer, 1); - return 1; - } - else - printf("please press enter\n"); - return 0; -} - -/* - * example: A#\A^\Av\'\n' - * or (while tossing): '\n' - */ -int vci_attack_or_tossing(int fd, char *buffer, player_cards deck, - enum client_states state) -{ - int rank = 0, i, free_pos = 0; - char * card = NULL; - - if(state == tossing && buffer[0] == '\n') { /* cancel card tossing */ - write(fd, buffer, 1); - printf("skipping the card toss\n"); - return 1; - } - - for(i = 0; buffer[i] != '\n'; ++i) { - /* some symbols */ - if(state == attack && buffer[1] != '\n') { - card = card_search_by_marked_letter(deck, buffer[i]); - if(card) { - if(!rank) - rank = convert_rank_to_int(card); - if(rank != convert_rank_to_int(card)) { - printf("incorrect input\n> "); - fflush(stdout); - return 0; - } - } - /* one symbol inputed? */ - } else if(state == attack && buffer[1] == '\n') - card = card_search_by_unmarked_letter(deck, buffer[i]); - else if(state == tossing) - card = card_search_by_marked_letter(deck, buffer[i]); - - if(!card) { - printf("incorrect input\n> "); - fflush(stdout); - return 0; - } - strncpy(output_buffer + free_pos, card, strlen(card)); - free_pos += strlen(card); - output_buffer[free_pos] = '\\'; - ++free_pos; - } - if(state == attack && buffer[0] == '\n') { - printf("incorrect input\n> "); - fflush(stdout); - return 0; - } - output_buffer[free_pos] = '\n'; - write(fd, output_buffer, free_pos+1); - return 1; -} - -/* - * example: 5v'\n' - * or: '\n' - */ -int vci_defense(int fd, char *buffer, player_cards deck) -{ - int last_idx; - char *card = NULL; - - if(buffer[0] == '\n') { /* the player does not want to keep the defense */ - write(fd, buffer, 1); - printf("accepting cards\n"); - return 1; - } - if(buffer[1] != '\n') { - printf("incorrect input\n> "); - fflush(stdout); - return 0; - } - if((card = card_search_by_marked_letter(deck, buffer[0])) != NULL) { - strcpy(output_buffer, card); - last_idx = strlen(card); - output_buffer[last_idx] = '\n'; - write(fd, output_buffer, last_idx+1); - return 1; - } - /* card is not found in the deck or cannot be used */ - printf("incorrect input\n> "); - fflush(stdout); - return 0; -} |