# HG changeset patch # User meillo@marmaro.de # Date 1210792105 -7200 # Node ID 8369454d4ec91bc1b1b25ca86b2996b12968703c # Parent 3ff1fbe4693d1597ad4f7009a646a5f162629972 with outsourced gamecheck and minor stuff diff -r 3ff1fbe4693d -r 8369454d4ec9 clock.c --- a/clock.c Wed May 14 21:07:33 2008 +0200 +++ b/clock.c Wed May 14 21:08:25 2008 +0200 @@ -3,42 +3,29 @@ #include #include "db.h" +#include "game.h" -char query[512]; -int check_game(char* gamename) { - int rows; - - sprintf(query, "select id from simulation where name = '%s' ", gamename); - db_query(query); - result = mysql_store_result(conn); - rows = mysql_num_rows(result); - mysql_free_result(result); - return rows; -} - - -void inc_time(char* gamename) { - int time = 0; +void inc_time() { /* get current time */ - sprintf(query, "select time from simulation where name = '%s' ", gamename); + sprintf(query, "select time from game where name = '%s' ", gamename); db_query(query); result = mysql_store_result(conn); if (mysql_num_rows(result)) { row = mysql_fetch_row(result); - time = atoi(row[0]); + gametime = atoi(row[0]); } mysql_free_result(result); /* increment time */ - sprintf(query, " update simulation set time = '%d' where name = '%s' ", ++time, gamename); + sprintf(query, " update game set time = '%d' where name = '%s' ", ++gametime, gamename); db_query(query); if (mysql_affected_rows(conn) > 0) { printf("time update successful\n"); - printf("simulation time: %d\n", time); + printf("virtual time: %d\n", gametime); } else { printf("E: time update failed\n"); } @@ -47,8 +34,7 @@ int main(int argc, char* argv[]) { - int i; - char* gamename; + printf(" --> clock\n"); /* init */ if (argc != 2) { @@ -57,16 +43,10 @@ } gamename = argv[1]; - printf("gamename: %s\n", gamename); + db_connect(); + check_game(); - db_connect(); - - if (check_game(gamename) != 1) { - printf("game '%s' does not exist\n", gamename); - exit(1); - } - - inc_time(gamename); + inc_time(); /* while ((row = mysql_fetch_row(result)) != NULL) { @@ -82,6 +62,6 @@ db_close(); - printf("the garten program\n"); + printf(" --< clock\n"); return 0; }