diff --git a/http-server.c b/http-server.c index adfda964781e5313459bb92f158a3e31c068b0d7..83a414b9096ba455002a3f6212d4438bd28af89f 100644 --- a/http-server.c +++ b/http-server.c @@ -323,8 +323,9 @@ static bool handle_http_request(int sockfd, User_list *users) // parse the method Request* req = parse_request(curr); User* user = get_current_user(users, sockfd); - // printf("REQUEST BODY IS \n\n%s\n", req->body); + printf("REQUEST BODY IS \n\n%s\n", req->body); if(strncmp(req->body, "quit=Quit", 9) == 0){ + printf("run\n\n\n\n\\n"); change_player_status(sockfd,users, QUIT); post_request(buff,sockfd, "7_gameover.html"); } @@ -332,7 +333,7 @@ static bool handle_http_request(int sockfd, User_list *users) // printf("matches start"); if (req->method == GET){ change_player_status(sockfd, users, READY); - // int round = change_player_round(sockfd, users); + int round = change_player_round(sockfd, users); // printf("THIS IS ROUND NUMBER %d\n", round); get_request(buff, sockfd, "3_first_turn.html"); // game_change(buff,sockfd, "3_first_turn.html", round); @@ -340,8 +341,8 @@ static bool handle_http_request(int sockfd, User_list *users) if (req->method == POST){ if(strncmp(req->body, "keyword=", 8) == 0){ if(player_won(users)){ - change_player_status(sockfd, users, COMPLETE); post_request(buff,sockfd, "6_endgame.html"); + change_all_status(users, RESTART); } else if(should_player_quit(users)){ change_player_status(sockfd,users, QUIT); @@ -355,7 +356,7 @@ static bool handle_http_request(int sockfd, User_list *users) char* keyword = add_keyword(sockfd, users, req->body); if(has_match_ended(users, keyword, sockfd)){ post_request(buff,sockfd, "6_endgame.html"); - change_player_status(sockfd, users, COMPLETE); + change_all_status(users, COMPLETE); } else{ char* keywords = return_all_keywords(user); @@ -412,22 +413,22 @@ static bool handle_http_request(int sockfd, User_list *users) perror("write"); return false; } - // printf("the numer of users is %d\n", users->n_users); - // for(int i=0; i < users->n_users; i++){ - // printf("USER ID %d", users->users[i]->id); - // if(users->users[i]->status == READY){ - // printf("is ready\n"); - // } - // if(users->users[i]->status == WAIT){ - // printf("is wait\n"); - // } - // if(users->users[i]->status == QUIT){ - // printf("is quit\n"); - // } - // if(users->users[i]->status == COMPLETE){ - // printf("is complete\n"); - // } - // } + printf("the numer of users is %d\n", users->n_users); + for(int i=0; i < users->n_users; i++){ + printf("USER ID %d", users->users[i]->id); + if(users->users[i]->status == READY){ + printf("is ready\n"); + } + if(users->users[i]->status == WAIT){ + printf("is wait\n"); + } + if(users->users[i]->status == QUIT){ + printf("is quit\n"); + } + if(users->users[i]->status == COMPLETE){ + printf("is complete\n"); + } + } free_request(req); return true; } diff --git a/user.c b/user.c index 42a7f74bba59e31a454f6d56eff1c8d104f68957..d30b057da7f26c49a4b884e6bfb5377c2aec58e6 100644 --- a/user.c +++ b/user.c @@ -109,6 +109,12 @@ void change_player_status(int user_id, User_list* users, STATUS status){ } } +void change_all_status(User_list* users, STATUS status){ + for(int i=0; i < users->n_users; i++){ + users->users[i]->status = status; + } +} + int change_player_round(int user_id, User_list* users){ int round = 1; for(int i=0; i < users->n_users; i++){ diff --git a/user.h b/user.h index 404d0b584a76ba1ef1f70616f42d6bdfdd7a61cb..7a1ebd9ae505df6b4e35c82d4ce471a3665c88d8 100644 --- a/user.h +++ b/user.h @@ -4,7 +4,8 @@ typedef enum READY, WAIT, QUIT, - COMPLETE + COMPLETE, + RESTART } STATUS; @@ -43,6 +44,8 @@ bool players_ready(User_list* users); void change_player_status(int user_id, User_list* users, STATUS status); +void change_all_status(User_list* users, STATUS status); + int change_player_round(int user_id, User_list* users); bool keyword_match(User* user, char* keyword);