garten

view 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
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <mysql.h>
5 #include "db.h"
6 #include "game.h"
10 void inc_time() {
12 /* get current time */
13 sprintf(query, "select time from game where name = '%s' ", gamename);
14 db_query(query);
15 result = mysql_store_result(conn);
16 if (mysql_num_rows(result)) {
17 row = mysql_fetch_row(result);
18 gametime = atoi(row[0]);
19 }
20 mysql_free_result(result);
23 /* increment time */
24 sprintf(query, " update game set time = '%d' where name = '%s' ", ++gametime, gamename);
25 db_query(query);
26 if (mysql_affected_rows(conn) > 0) {
27 printf("time update successful\n");
28 printf("virtual time: %d\n", gametime);
29 } else {
30 printf("E: time update failed\n");
31 }
33 }
36 int main(int argc, char* argv[]) {
37 printf(" --> clock\n");
39 /* init */
40 if (argc != 2) {
41 printf("usage: %s <game>\n", argv[0]);
42 exit(1);
43 }
44 gamename = argv[1];
46 db_connect();
47 check_game();
49 inc_time();
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 */
63 db_close();
65 printf(" --< clock\n");
66 return 0;
67 }