Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tdenning_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
Terence Denning
tdenning_comp30023_2019_project-1
Commits
3d2172cc
Commit
3d2172cc
authored
6 years ago
by
Terence Denning
Browse files
Options
Downloads
Patches
Plain Diff
fixed user bug
parent
66c02bd0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
http-server.c
+26
-10
26 additions, 10 deletions
http-server.c
image_tagger
+0
-0
0 additions, 0 deletions
image_tagger
with
26 additions
and
10 deletions
http-server.c
+
26
−
10
View file @
3d2172cc
...
@@ -29,6 +29,7 @@ void reset_game();
...
@@ -29,6 +29,7 @@ void reset_game();
void
reset_user
(
int
sockfd
);
void
reset_user
(
int
sockfd
);
void
set_user
(
int
sockfd
);
void
set_user
(
int
sockfd
);
void
user_ready
(
int
sockfd
);
void
user_ready
(
int
sockfd
);
void
print_details
();
// constants
// constants
static
char
const
*
const
HTTP_200_FORMAT
=
"HTTP/1.1 200 OK
\r\n
\
static
char
const
*
const
HTTP_200_FORMAT
=
"HTTP/1.1 200 OK
\r\n
\
...
@@ -114,7 +115,11 @@ static bool handle_http_request(int sockfd)
...
@@ -114,7 +115,11 @@ static bool handle_http_request(int sockfd)
if
(
method
==
GET
)
if
(
method
==
GET
)
{
{
if
(
strstr
(
buff
,
"?start=Start"
)
!=
NULL
){
if
(
strstr
(
buff
,
"start=Start"
)
!=
NULL
){
if
(
strcmp
(
webpage
,
"html/2_start.html"
)
){
user_ready
(
sockfd
);
}
/* Handle resetting users when starting a new game */
/* Handle resetting users when starting a new game */
printf
(
"gameover: %d
\n
"
,
gameover
);
printf
(
"gameover: %d
\n
"
,
gameover
);
if
(
gameover
==
0
){
if
(
gameover
==
0
){
...
@@ -123,8 +128,6 @@ static bool handle_http_request(int sockfd)
...
@@ -123,8 +128,6 @@ static bool handle_http_request(int sockfd)
printf
(
"Restarting game, user1: %d, user2: %d
\n
"
,
user1
,
user2
);
printf
(
"Restarting game, user1: %d, user2: %d
\n
"
,
user1
,
user2
);
gameover
=
0
;
gameover
=
0
;
}
}
user_ready
(
sockfd
);
webpage
=
"html/3_first_turn.html"
;
webpage
=
"html/3_first_turn.html"
;
}
else
if
(
strstr
(
buff
,
"Cookie:"
)
!=
NULL
)
{
}
else
if
(
strstr
(
buff
,
"Cookie:"
)
!=
NULL
)
{
webpage
=
"html/1_intro.html"
;
webpage
=
"html/1_intro.html"
;
...
@@ -161,6 +164,7 @@ static bool handle_http_request(int sockfd)
...
@@ -161,6 +164,7 @@ static bool handle_http_request(int sockfd)
return
false
;
return
false
;
}
}
close
(
filefd
);
close
(
filefd
);
}
}
else
if
(
method
==
POST
)
else
if
(
method
==
POST
)
{
{
...
@@ -207,7 +211,7 @@ static bool handle_http_request(int sockfd)
...
@@ -207,7 +211,7 @@ static bool handle_http_request(int sockfd)
stat
(
webpage
,
&
st
);
stat
(
webpage
,
&
st
);
username
=
strstr
(
buff
,
"user="
)
+
5
;
username
=
strstr
(
buff
,
"user="
)
+
5
;
set_user
(
sockfd
);
//
set_user(sockfd);
username_length
=
strlen
(
username
);
username_length
=
strlen
(
username
);
added_length
=
username_length
+
2
;
added_length
=
username_length
+
2
;
...
@@ -215,12 +219,11 @@ static bool handle_http_request(int sockfd)
...
@@ -215,12 +219,11 @@ static bool handle_http_request(int sockfd)
n
=
sprintf
(
buff
,
HTTP_200_FORMAT_WITH_COOKIE
,
username
,
size
);
n
=
sprintf
(
buff
,
HTTP_200_FORMAT_WITH_COOKIE
,
username
,
size
);
}
}
else
if
(
strstr
(
buff
,
"guess=Guess"
)
!=
NULL
)
{
else
if
(
strstr
(
buff
,
"guess=Guess"
)
!=
NULL
)
{
char
*
keyword
=
strstr
(
buff
,
"keyword="
)
+
8
;
char
*
keyword
=
strstr
(
buff
,
"keyword="
)
+
8
;
int
keyword_length
=
strlen
(
keyword
);
int
keyword_length
=
strlen
(
keyword
);
keyword
[
keyword_length
-
12
]
=
'\0'
;
keyword
[
keyword_length
-
12
]
=
'\0'
;
if
(
sockfd
==
user1
){
if
(
sockfd
==
user1
){
/* if other player is ready then accept guesses */
/* if other player is ready then accept guesses */
if
(
user2_start
==
1
){
if
(
user2_start
==
1
){
...
@@ -268,6 +271,13 @@ static bool handle_http_request(int sockfd)
...
@@ -268,6 +271,13 @@ static bool handle_http_request(int sockfd)
stat
(
webpage
,
&
st
);
stat
(
webpage
,
&
st
);
n
=
sprintf
(
buff
,
HTTP_200_FORMAT
,
st
.
st_size
);
n
=
sprintf
(
buff
,
HTTP_200_FORMAT
,
st
.
st_size
);
if
(
sockfd
==
user1
){
printf
(
"I AM USER1"
);
}
else
if
(
sockfd
==
user2
){
printf
(
"I AM USER2"
);
}
print_details
();
}
else
{
}
else
{
printf
(
"
\n\n\n
error reading html...
\n\n\n
"
);
printf
(
"
\n\n\n
error reading html...
\n\n\n
"
);
}
}
...
@@ -299,6 +309,7 @@ static bool handle_http_request(int sockfd)
...
@@ -299,6 +309,7 @@ static bool handle_http_request(int sockfd)
// put the separator
// put the separator
buff
[
p2
++
]
=
' '
;
buff
[
p2
++
]
=
' '
;
buff
[
p2
++
]
=
' '
;
buff
[
p2
++
]
=
' '
;
// copy the username
// copy the username
strncpy
(
buff
+
p2
,
username
,
username_length
);
strncpy
(
buff
+
p2
,
username
,
username_length
);
if
(
write
(
sockfd
,
buff
,
size
)
<
0
)
if
(
write
(
sockfd
,
buff
,
size
)
<
0
)
...
@@ -434,6 +445,8 @@ int main(int argc, char * argv[])
...
@@ -434,6 +445,8 @@ int main(int argc, char * argv[])
void
reset_game
(){
void
reset_game
(){
gameover
=
1
;
gameover
=
1
;
user1
=
-
1
;
user2
=
-
1
;
user1_guess_number
=
0
;
user1_guess_number
=
0
;
user2_guess_number
=
0
;
user2_guess_number
=
0
;
user1_start
=
0
;
user1_start
=
0
;
...
@@ -486,3 +499,6 @@ void user_ready(int sockfd){
...
@@ -486,3 +499,6 @@ void user_ready(int sockfd){
}
}
}
}
void
print_details
(){
printf
(
"User1: %d, User2: %d, User1_start: %d, User2_start: %d
\n\n
"
,
user1
,
user2
,
user1_start
,
user2_start
);
}
This diff is collapsed.
Click to expand it.
image_tagger
+
0
−
0
View file @
3d2172cc
No preview for this file type
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