-
Notifications
You must be signed in to change notification settings - Fork 0
/
answer.c
executable file
·67 lines (50 loc) · 2.31 KB
/
answer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Student Name : Yordan Radev
// Student ID : 260 744 314
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void main() {
// Payload Get
char *data = getenv("QUERY_STRING");
// Tokenize
char *tokOne;
int goldCoins;
char *command;
tokOne = strtok( data, "=" );
if( strcmp(tokOne,"answer") == 0 ){
command = strtok( NULL, "&" );
if( strtok( NULL, "=" ) == NULL ) goldCoins = 10;
else goldCoins = atoi( strtok( NULL, "" ) );
} else {
goldCoins = atoi( strtok( NULL, "&" ) );
if( strtok( NULL, "=" ) != NULL ) command = strtok( NULL, "" );
}
printf("Content-Type:text/html\n\n");
printf("<html>");
printf("<body>");
if ( strcmp( command , "NORTH" ) == 0 ) {
printf("<a href=\"http://cs.mcgill.ca/~anikul3/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go NORTH</a>", goldCoins );
} else if ( strcmp( command , "SOUTH" ) == 0 ) {
printf("<a href=\"http://cs.mcgill.ca/~aduboi8/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go SOUTH</a>",goldCoins);
} else if ( strcmp( command , "EAST" ) == 0 ) {
printf("<a href=\"http://cs.mcgill.ca/~ywang498/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go EAST</a>",goldCoins);
} else if ( strcmp( command , "WEST" ) == 0 ) {
printf("<a href=\"http://cs.mcgill.ca/~ldesch11/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go WEST</a>",goldCoins);
} else if ( strcmp( command , "GOLD" ) == 0 ) {
printf("You have %d gold coins.<br /> <a href=\"http://cs.mcgill.ca/~yradev/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go back.</a>",goldCoins,goldCoins);
} else if ( strcmp( command , "5" ) == 0 ) {
goldCoins += 10;
printf("Right answer, now you have %d gold coins. <br /><a href=\"http://cs.mcgill.ca/~yradev/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go back. </a>", goldCoins, goldCoins);
if ( goldCoins >= 100 ) {
printf("Victory!!! <br /> <a href=\"http://cs.mcgill.ca/~yradev\">Press HERE to start a new game</a>");
}
} else {
goldCoins -= 5;
printf("Neither a direction nor a right answer. You have %d gold coins left. <br /> <a href=\"http://cs.mcgill.ca/~yradev/cgi-bin/addgold.cgi?gold=%d\">Press HERE to go back.</a>", goldCoins, goldCoins);
if(goldCoins <= 0) {
printf("Defeat! <br /> <a href=\"https://www.cs.mcgill.ca/~yradev\">Press HERE to start over</a>");
}
}
printf("</body>");
printf("</html>");
}