back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/client/client.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-08-17 02:42:19 +0300
committerscratko <m@scratko.xyz>2024-08-17 02:42:19 +0300
commit4b2fdc91d42a438193d15840e10851c3847fbe80 (patch)
tree08c3de6e851ee07463beae6d0a2fbd9e74202662 /client/client.c
parenteb90648bdad1443c9cfc72e903a93642e10a0ab7 (diff)
downloaddurak-4b2fdc91d42a438193d15840e10851c3847fbe80.tar.gz
durak-4b2fdc91d42a438193d15840e10851c3847fbe80.tar.bz2
durak-4b2fdc91d42a438193d15840e10851c3847fbe80.zip
Global fixes v3.0
Fixed bug when entering cards incorrectly. Added recognition of disconnection from the server. Added welcome screen and update screen.
Diffstat (limited to 'client/client.c')
-rw-r--r--client/client.c24
1 files changed, 23 insertions, 1 deletions
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);
}