From bcd487e16669cd032184f3577446ecdf79f09c6d Mon Sep 17 00:00:00 2001 From: ChouTatsumi <choutatsumi@gmail.com> Date: Mon, 29 Apr 2019 22:28:08 +1000 Subject: [PATCH] keyword input test --- server.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/server.c b/server.c index 20192ee..de68823 100644 --- a/server.c +++ b/server.c @@ -269,6 +269,10 @@ static bool handle_http_request(int sockfd) { return show_page(sockfd, GAMEOVER_PAGE); } else if (strstr(buff, "keyword=") != NULL) { char* keyword = strstr(buff, "keyword=") + 8; + printf("keyword = %s", keyword); + int keyword_len = strlen(keyword); + keyword[keyword_len - 12] = '\0'; + printf("keyword = %s", keyword); if (p1_is_ready && p2_is_ready) { if (keyword_check(sockfd, keyword)) { // initial players setting @@ -358,8 +362,6 @@ bool show_modified_page(int sockfd, const char* htmldir, char* added, } close(filefd); - print_buff(buff); - // move the trailing part backward int p1, p2; for (p1 = size - 1, p2 = p1 - added_length; p1 >= size - inset_index; @@ -370,8 +372,6 @@ bool show_modified_page(int sockfd, const char* htmldir, char* added, // copy the username strncpy(buff + p2, added, added_length); - print_buff(buff); - if (write(sockfd, buff, size) < 0) { perror("write"); return false; @@ -406,10 +406,10 @@ bool show_accepted_page(int sockfd) { char added[2049]; + // avoid pointer reference error memset(added, 0, sizeof(added)); strcat(added, added_prefix); - printf("added is now %s", added); if (sockfd == p1_sockfd) { for (int i = 0; i < p1_guess_len - 1; i++) { @@ -426,12 +426,8 @@ bool show_accepted_page(int sockfd) { strcat(added, p2_guess[p2_guess_len - 1]); } - printf("added is now %s", added); - strcat(added, added_suffix); - printf("added is now %s", added); - return show_modified_page(sockfd, ACCEPTED_PAGE, added, 264); } -- GitLab