changeset 2:8369454d4ec9

with outsourced gamecheck and minor stuff
author meillo@marmaro.de
date Wed, 14 May 2008 21:08:25 +0200
parents 3ff1fbe4693d
children 0c19ad487f02
files clock.c
diffstat 1 files changed, 10 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- 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 <mysql.h>
 
 #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();
 
-	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;
 }