Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nirmalathasa_comp30023_2019_project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abhisha Nirmalathas
nirmalathasa_comp30023_2019_project-1
Commits
0687973f
Commit
0687973f
authored
Apr 19, 2019
by
Abhisha Nirmalathas
Browse files
Options
Downloads
Patches
Plain Diff
logic errors fixed
parent
671b382f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
http-server.c
+21
-20
21 additions, 20 deletions
http-server.c
user.c
+6
-0
6 additions, 0 deletions
user.c
user.h
+4
-1
4 additions, 1 deletion
user.h
with
31 additions
and
21 deletions
http-server.c
+
21
−
20
View file @
0687973f
...
@@ -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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
user.c
+
6
−
0
View file @
0687973f
...
@@ -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
++
){
...
...
This diff is collapsed.
Click to expand it.
user.h
+
4
−
1
View file @
0687973f
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment