From 4b2fdc91d42a438193d15840e10851c3847fbe80 Mon Sep 17 00:00:00 2001 From: scratko Date: Sat, 17 Aug 2024 02:42:19 +0300 Subject: Global fixes v3.0 Fixed bug when entering cards incorrectly. Added recognition of disconnection from the server. Added welcome screen and update screen. --- client/client.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'client/client.c') diff --git a/client/client.c b/client/client.c index a5b3daf..5d49e1a 100644 --- a/client/client.c +++ b/client/client.c @@ -24,10 +24,15 @@ static void get_data_from_server(struct client *cl, fd_set *readfds) if(FD_ISSET(cl->fd, readfds)) { if(!cl->data_left_in_buffer) { cl->data_left_in_buffer = read(cl->fd, cl->buffer, max_buffer_size); + /* end of file -- closed connection */ + if(!cl->data_left_in_buffer) + exit(0); +#ifdef DEBUG printf("%d\n", cl->data_left_in_buffer); for(i = 0; i < cl->data_left_in_buffer; ++i) putchar(cl->buffer[i]); putchar('\n'); +#endif } decrypt_set_state(cl, &end_p); update_info = 1; @@ -69,6 +74,7 @@ static void get_data_from_server(struct client *cl, fd_set *readfds) break; /* no data to extract */ case tossing_limit_status: + case disconnect: default: {} } @@ -147,6 +153,9 @@ static void change_client_frame(struct client *cl) case result: pgf_game_result(cl->durak_position); break; + case disconnect: + pgf_disconnect(); + break; case none: {} } @@ -160,6 +169,11 @@ static void send_data_to_server(struct client *cl, fd_set *readfds) if(FD_ISSET(0, readfds)) { /* 0 - stdin */ read(0, cl->buffer, max_buffer_size); + if(cl->buffer[0] == 'q' && cl->buffer[1] == 'q') { + close(cl->fd); + exit(0); + } + switch(cl->state) { case confirmation_waiting: input_result = vci_confirmation_waiting(cl->fd, cl->buffer); @@ -274,8 +288,16 @@ int main() { struct client cl; + pgf_new_frame(); + pgf_welcome(); + sleep(2); init_client(&cl); - if(!connect_to_server(&cl)) + if(!connect_to_server(&cl)) { + pgf_new_frame(); + pgf_connection(0); return 1; + } + pgf_new_frame(); + pgf_connection(1); return main_loop(&cl); } -- cgit v1.2.3