0
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <mysql.h>
|
|
4
|
|
5 #include "db.h"
|
2
|
6 #include "game.h"
|
0
|
7
|
|
8
|
|
9
|
2
|
10 void inc_time() {
|
0
|
11
|
|
12 /* get current time */
|
2
|
13 sprintf(query, "select time from game where name = '%s' ", gamename);
|
0
|
14 db_query(query);
|
|
15 result = mysql_store_result(conn);
|
|
16 if (mysql_num_rows(result)) {
|
|
17 row = mysql_fetch_row(result);
|
2
|
18 gametime = atoi(row[0]);
|
0
|
19 }
|
|
20 mysql_free_result(result);
|
|
21
|
|
22
|
|
23 /* increment time */
|
2
|
24 sprintf(query, " update game set time = '%d' where name = '%s' ", ++gametime, gamename);
|
0
|
25 db_query(query);
|
|
26 if (mysql_affected_rows(conn) > 0) {
|
|
27 printf("time update successful\n");
|
2
|
28 printf("virtual time: %d\n", gametime);
|
0
|
29 } else {
|
|
30 printf("E: time update failed\n");
|
|
31 }
|
|
32
|
|
33 }
|
|
34
|
|
35
|
|
36 int main(int argc, char* argv[]) {
|
2
|
37 printf(" --> clock\n");
|
0
|
38
|
|
39 /* init */
|
|
40 if (argc != 2) {
|
|
41 printf("usage: %s <game>\n", argv[0]);
|
|
42 exit(1);
|
|
43 }
|
|
44 gamename = argv[1];
|
|
45
|
|
46 db_connect();
|
2
|
47 check_game();
|
0
|
48
|
2
|
49 inc_time();
|
0
|
50
|
|
51 /*
|
|
52 while ((row = mysql_fetch_row(result)) != NULL) {
|
|
53 for (i = 0; i < mysql_num_fields(result); i++) {
|
|
54 printf("%10s ", row[i]);
|
|
55 }
|
|
56 printf("\n");
|
|
57 }
|
|
58 */
|
|
59
|
|
60
|
|
61
|
|
62
|
|
63 db_close();
|
|
64
|
2
|
65 printf(" --< clock\n");
|
0
|
66 return 0;
|
|
67 }
|