From a2d696dea797faaa3157046c8ae89cd70e965bff Mon Sep 17 00:00:00 2001 From: scratko Date: Sat, 10 Aug 2024 02:46:56 +0300 Subject: Prefinal version Added client. Moved files to directories. --- client/verification_client_input.c | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 client/verification_client_input.c (limited to 'client/verification_client_input.c') diff --git a/client/verification_client_input.c b/client/verification_client_input.c new file mode 100644 index 0000000..2134f30 --- /dev/null +++ b/client/verification_client_input.c @@ -0,0 +1,46 @@ +#include "verification_client_input.h" + +#include +#include + +/* + * 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; +} + +int vci_attack_or_tossing(int fd, char *buffer, player_cards deck, + enum client_states state) +{ + int i; + + if(state == tossing && buffer[0] == '\n') /* cancel card tossing */ + return 1; + + for(i = 0; buffer[i] != '\n'; ++i) + if(!card_search_by_letter(deck, buffer[i])) { + printf("incorrect input\n"); + return 0; + } + return 1; +} + +int vci_defense(int fd, char *buffer, player_cards deck) +{ + if(buffer[0] == '\n') /* the player does not want to keep the defense */ + return 1; + if(!card_search_by_letter(deck, buffer[0])) + return 0; + if(buffer[1] != '\n') + return 0; + return 1; +} -- cgit v1.2.3