Skip to content
Snippets Groups Projects
Commit 0687973f authored by Abhisha Nirmalathas's avatar Abhisha Nirmalathas
Browse files

logic errors fixed

parent 671b382f
No related branches found
No related tags found
No related merge requests found
...@@ -323,8 +323,9 @@ static bool handle_http_request(int sockfd, User_list *users) ...@@ -323,8 +323,9 @@ static bool handle_http_request(int sockfd, User_list *users)
// parse the method // parse the method
Request* req = parse_request(curr); Request* req = parse_request(curr);
User* user = get_current_user(users, sockfd); 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){ if(strncmp(req->body, "quit=Quit", 9) == 0){
printf("run\n\n\n\n\\n");
change_player_status(sockfd,users, QUIT); change_player_status(sockfd,users, QUIT);
post_request(buff,sockfd, "7_gameover.html"); post_request(buff,sockfd, "7_gameover.html");
} }
...@@ -332,7 +333,7 @@ static bool handle_http_request(int sockfd, User_list *users) ...@@ -332,7 +333,7 @@ static bool handle_http_request(int sockfd, User_list *users)
// printf("matches start"); // printf("matches start");
if (req->method == GET){ if (req->method == GET){
change_player_status(sockfd, users, READY); 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); // printf("THIS IS ROUND NUMBER %d\n", round);
get_request(buff, sockfd, "3_first_turn.html"); get_request(buff, sockfd, "3_first_turn.html");
// game_change(buff,sockfd, "3_first_turn.html", round); // game_change(buff,sockfd, "3_first_turn.html", round);
...@@ -340,8 +341,8 @@ static bool handle_http_request(int sockfd, User_list *users) ...@@ -340,8 +341,8 @@ static bool handle_http_request(int sockfd, User_list *users)
if (req->method == POST){ if (req->method == POST){
if(strncmp(req->body, "keyword=", 8) == 0){ if(strncmp(req->body, "keyword=", 8) == 0){
if(player_won(users)){ if(player_won(users)){
change_player_status(sockfd, users, COMPLETE);
post_request(buff,sockfd, "6_endgame.html"); post_request(buff,sockfd, "6_endgame.html");
change_all_status(users, RESTART);
} }
else if(should_player_quit(users)){ else if(should_player_quit(users)){
change_player_status(sockfd,users, QUIT); change_player_status(sockfd,users, QUIT);
...@@ -355,7 +356,7 @@ static bool handle_http_request(int sockfd, User_list *users) ...@@ -355,7 +356,7 @@ static bool handle_http_request(int sockfd, User_list *users)
char* keyword = add_keyword(sockfd, users, req->body); char* keyword = add_keyword(sockfd, users, req->body);
if(has_match_ended(users, keyword, sockfd)){ if(has_match_ended(users, keyword, sockfd)){
post_request(buff,sockfd, "6_endgame.html"); post_request(buff,sockfd, "6_endgame.html");
change_player_status(sockfd, users, COMPLETE); change_all_status(users, COMPLETE);
} }
else{ else{
char* keywords = return_all_keywords(user); char* keywords = return_all_keywords(user);
...@@ -412,22 +413,22 @@ static bool handle_http_request(int sockfd, User_list *users) ...@@ -412,22 +413,22 @@ static bool handle_http_request(int sockfd, User_list *users)
perror("write"); perror("write");
return false; return false;
} }
// printf("the numer of users is %d\n", users->n_users); printf("the numer of users is %d\n", users->n_users);
// for(int i=0; i < users->n_users; i++){ for(int i=0; i < users->n_users; i++){
// printf("USER ID %d", users->users[i]->id); printf("USER ID %d", users->users[i]->id);
// if(users->users[i]->status == READY){ if(users->users[i]->status == READY){
// printf("is ready\n"); printf("is ready\n");
// } }
// if(users->users[i]->status == WAIT){ if(users->users[i]->status == WAIT){
// printf("is wait\n"); printf("is wait\n");
// } }
// if(users->users[i]->status == QUIT){ if(users->users[i]->status == QUIT){
// printf("is quit\n"); printf("is quit\n");
// } }
// if(users->users[i]->status == COMPLETE){ if(users->users[i]->status == COMPLETE){
// printf("is complete\n"); printf("is complete\n");
// } }
// } }
free_request(req); free_request(req);
return true; return true;
} }
......
...@@ -109,6 +109,12 @@ void change_player_status(int user_id, User_list* users, STATUS status){ ...@@ -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 change_player_round(int user_id, User_list* users){
int round = 1; int round = 1;
for(int i=0; i < users->n_users; i++){ for(int i=0; i < users->n_users; i++){
......
...@@ -4,7 +4,8 @@ typedef enum ...@@ -4,7 +4,8 @@ typedef enum
READY, READY,
WAIT, WAIT,
QUIT, QUIT,
COMPLETE COMPLETE,
RESTART
} STATUS; } STATUS;
...@@ -43,6 +44,8 @@ bool players_ready(User_list* users); ...@@ -43,6 +44,8 @@ bool players_ready(User_list* users);
void change_player_status(int user_id, User_list* users, STATUS status); 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); int change_player_round(int user_id, User_list* users);
bool keyword_match(User* user, char* keyword); bool keyword_match(User* user, char* keyword);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment