From bf72e0303daed5363fdac236644170df710c9f12 Mon Sep 17 00:00:00 2001
From: Anqi Chen <a.chen49@student.unimelb.edu.au>
Date: Mon, 29 Apr 2019 17:33:40 +1000
Subject: [PATCH] logic redo upload

---
 img.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/img.c b/img.c
index 82530cd..2fcedd3 100644
--- a/img.c
+++ b/img.c
@@ -333,7 +333,7 @@ static bool handle_http_request(int sockfd, struct User* user_arr[])
         }
         else if (method == POST){
 
-            if(strstr(buff, "quit=Quit") != NULL)
+            if(strstr(buff, "quit=") != NULL)
             {
             
                 simple_load_html("7_gameover.html",sockfd,buff,n,curr_user);
@@ -341,7 +341,40 @@ static bool handle_http_request(int sockfd, struct User* user_arr[])
             }
             else if(curr_user->isOnline == 0) 
             {
-                
+                char* username = strstr(buff, "user=")+5;
+                char u[MAX_BUFF];
+                strcpy(u,"<br>");
+                strcat(u, username);
+                u[strlen(username)]='\0';
+                curr_user->isOnline = 1;
+
+                edit_load_html("2_start.html", sockfd,buff,username,curr_user);
+            }
+
+            else if (curr_user->isOnline == 2 ||curr_user->isOnline == 1 ) {
+                curr_user->isOnline = 2;
+                if (the_other_user(curr_user, user_arr)->stage==0 || the_other_user(curr_user, user_arr)->stage == 4)
+                {
+                    simple_load_html("5_discarded.html",sockfd,buff,n,curr_user);
+                }
+                else if (the_other_user(curr_user, user_arr)->stage==3){
+                    simple_load_html("7_gameover.html",sockfd,buff,n,curr_user);
+                    curr_user->stage = 3;
+                }
+                else if (curr_user->stage == 2|| curr_user->stage == 4){
+                    simple_load_html("6_endgame.html",sockfd,buff,n,curr_user);
+                    if (curr_user->stage == 4){
+                        curr_user->stage = 1;
+                        curr_user->isOnline = 1;
+                    }
+                    else{
+                        curr_user->stage = 2;
+                    } 
+                }
+
+                else {
+                    
+                }
             }
 
         }
-- 
GitLab