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