Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
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
Xun Zhang
comp30023-2019-project-1
Commits
343b2aa9
Commit
343b2aa9
authored
Apr 29, 2019
by
ChouTatsumi
Browse files
Options
Downloads
Patches
Plain Diff
end_game quit_game test
parent
41d1a024
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.c
+19
-19
19 additions, 19 deletions
server.c
with
19 additions
and
19 deletions
server.c
+
19
−
19
View file @
343b2aa9
...
...
@@ -44,6 +44,7 @@ static char const* const DISCARDED_PAGE = "./views/5_discarded.html";
static
char
const
*
const
ENDGAME_PAGE
=
"./views/6_endgame.html"
;
static
char
const
*
const
GAMEOVER_PAGE
=
"./views/7_gameover.html"
;
bool
is_end_game
,
is_quit_game
;
bool
p1_is_ready
,
p2_is_ready
;
int
p1_sockfd
,
p2_sockfd
;
// assume we can save 2000 keywords from each player,
...
...
@@ -62,7 +63,7 @@ bool show_page(int sockfd, const char* htmldir);
bool
show_start_page
(
int
sockfd
,
char
*
username
);
void
print_html_request
(
char
*
request
,
int
sockfd
);
bool
keyword_check
(
int
sockfd
,
char
*
keyword
);
void
player_init
(
int
sockfd
);
void
player_init
();
int
main
(
int
argc
,
char
**
argv
)
{
int
port
;
...
...
@@ -98,9 +99,8 @@ void run_server(const char* ip, const int port) {
port
);
// Initialise
p1_sockfd
=
p2_sockfd
=
-
1
;
p1_is_ready
=
p2_is_ready
=
false
;
p1_guess_len
=
p2_guess_len
=
0
;
player_init
();
is_end_game
=
is_quit_game
=
false
;
// initialise an active file descriptors set
fd_set
masterfds
;
...
...
@@ -243,7 +243,8 @@ static bool handle_http_request(int sockfd) {
char
*
username
=
strstr
(
buff
,
"user="
)
+
5
;
return
show_start_page
(
sockfd
,
username
);
}
else
if
(
strstr
(
buff
,
"quit="
)
!=
NULL
)
{
player_init
(
sockfd
);
player_init
();
is_quit_game
=
true
;
return
show_page
(
sockfd
,
GAMEOVER_PAGE
);
}
}
else
...
...
@@ -263,15 +264,20 @@ static bool handle_http_request(int sockfd) {
return
show_page
(
sockfd
,
FIRST_TURN_PAGE
);
}
else
if
(
method
==
POST
)
{
if
(
strstr
(
buff
,
"quit="
)
!=
NULL
)
{
player_init
(
sockfd
);
player_init
();
is_quit_game
=
true
;
return
show_page
(
sockfd
,
GAMEOVER_PAGE
);
}
else
if
(
strstr
(
buff
,
"keyword="
)
!=
NULL
)
{
char
*
keyword
=
strstr
(
buff
,
"keyword="
)
+
8
;
if
(
p1_is_ready
&&
p2_is_ready
)
{
if
(
keyword_check
(
sockfd
,
keyword
))
{
if
(
is_end_game
)
return
show_page
(
sockfd
,
ENDGAME_PAGE
);
else
if
(
is_quit_game
)
return
show_page
(
sockfd
,
GAMEOVER_PAGE
);
else
if
(
keyword_check
(
sockfd
,
keyword
))
{
// initial players setting
p
1_is_ready
=
p2_is_ready
=
false
;
p1_gues
s_
l
en
=
p2_guess_len
=
0
;
p
layer_init
()
;
i
s_en
d_game
=
true
;
return
show_page
(
sockfd
,
ENDGAME_PAGE
);
}
else
return
show_page
(
sockfd
,
ACCEPTED_PAGE
);
...
...
@@ -405,14 +411,8 @@ bool keyword_check(int sockfd, char* keyword) {
return
false
;
}
void
player_init
(
int
sockfd
)
{
if
(
sockfd
==
p1_sockfd
)
{
p1_is_ready
=
false
;
p1_sockfd
=
-
1
;
p1_guess_len
=
0
;
}
else
if
(
sockfd
==
p2_sockfd
)
{
p2_is_ready
=
false
;
p2_sockfd
=
-
1
;
p2_guess_len
=
0
;
}
void
player_init
()
{
p1_is_ready
=
p2_is_ready
=
false
;
p1_sockfd
=
p2_sockfd
=
-
1
;
p1_guess_len
=
p2_guess_len
=
0
;
}
\ No newline at end of file
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