comparison clock.c @ 18:5937504619f2

rename game.h -> modules.h; added some error handling; and more
author meillo@marmaro.de
date Wed, 23 Jul 2008 17:40:55 +0200
parents 5e6c9260913a
children
comparison
equal deleted inserted replaced
17:5e6c9260913a 18:5937504619f2
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include "db.h" 3 #include "db.h"
4 #include "game.h"
5 4
6 5
7 void inc_time() { 6 int inc_time() {
8 /* get current time */ 7 /* get current time */
9 sprintf(query, "select time from game;"); 8 sprintf(query, "select time from game;");
10 stmt = db_query(query); 9 stmt = db_query(query);
11 if (sqlite3_step(stmt) == SQLITE_ROW) { 10 if (sqlite3_step(stmt) == SQLITE_ROW) {
12 gametime = sqlite3_column_int(stmt, 0); 11 gametime = sqlite3_column_int(stmt, 0);
13 } else { 12 } else {
14 db_error("get current time"); 13 db_error("get current time");
14 return 0;
15 } 15 }
16 sqlite3_finalize(stmt); 16 sqlite3_finalize(stmt);
17 17
18 /* increment time */ 18 /* increment time */
19 sprintf(query, 19 sprintf(query,
20 "update game" 20 "update game "
21 "set time = '%d';" 21 "set time = '%d';"
22 , ++gametime 22 , ++gametime
23 ); 23 );
24 if (!db_update(query)) { 24 if (!db_update(query)) {
25 db_error("time update"); 25 db_error("time update");
26 return 0;
26 } 27 }
28 return 1;
27 } 29 }
28 30
29 31
30 void worldclock(void) { 32 int worldclock(void) {
31 inc_time(); 33 int ret;
34
35 ret = inc_time();
32 printf("gametime: %d\n", gametime); 36 printf("gametime: %d\n", gametime);
37
38 return ret;
33 } 39 }