annotate clock.c @ 2:8369454d4ec9

with outsourced gamecheck and minor stuff
author meillo@marmaro.de
date Wed, 14 May 2008 21:08:25 +0200
parents 831599184108
children 176ee28e7464
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
1 #include <stdio.h>
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
2 #include <stdlib.h>
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
3 #include <mysql.h>
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
4
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
5 #include "db.h"
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
6 #include "game.h"
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
7
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
8
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
9
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
10 void inc_time() {
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
11
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
12 /* get current time */
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
13 sprintf(query, "select time from game where name = '%s' ", gamename);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
14 db_query(query);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
15 result = mysql_store_result(conn);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
16 if (mysql_num_rows(result)) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
17 row = mysql_fetch_row(result);
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
18 gametime = atoi(row[0]);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
19 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
20 mysql_free_result(result);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
21
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
22
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
23 /* increment time */
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
24 sprintf(query, " update game set time = '%d' where name = '%s' ", ++gametime, gamename);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
25 db_query(query);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
26 if (mysql_affected_rows(conn) > 0) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
27 printf("time update successful\n");
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
28 printf("virtual time: %d\n", gametime);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
29 } else {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
30 printf("E: time update failed\n");
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
31 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
32
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
33 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
34
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
35
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
36 int main(int argc, char* argv[]) {
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
37 printf(" --> clock\n");
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
38
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
39 /* init */
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
40 if (argc != 2) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
41 printf("usage: %s <game>\n", argv[0]);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
42 exit(1);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
43 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
44 gamename = argv[1];
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
45
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
46 db_connect();
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
47 check_game();
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
48
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
49 inc_time();
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
50
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
51 /*
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
52 while ((row = mysql_fetch_row(result)) != NULL) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
53 for (i = 0; i < mysql_num_fields(result); i++) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
54 printf("%10s ", row[i]);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
55 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
56 printf("\n");
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
57 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
58 */
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
59
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
60
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
61
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
62
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
63 db_close();
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
64
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
65 printf(" --< clock\n");
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
66 return 0;
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
67 }