From 7c624f27af52dcaa2a64d9c6c098873e747ac279 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Tue, 5 Feb 2013 23:46:11 +0100 Subject: add system clock check --- src/db.vala | 12 ++++++++++-- src/main.vala | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/db.vala b/src/db.vala index 344aa85..1e81aad 100644 --- a/src/db.vala +++ b/src/db.vala @@ -197,8 +197,9 @@ public class Database { queries["total_profit"] = "SELECT SUM(price - (SELECT price FROM purchaseprices WHERE product = productid)) FROM invoice WHERE user >= 0 AND timestamp >= ?"; queries["user_get_ids"] = "SELECT id FROM users WHERE id > 0"; queries["user_replace"] = "INSERT OR REPLACE INTO users ('id', 'email', 'firstname', 'lastname', 'gender', 'street', 'plz', 'city', 'pgp') VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - queries["user_auth_create"] = "INSERT OR IGNORE INTO authentication (user) VALUES (?)"; - queries["user_disable"] = "UPDATE authentication SET disabled = ? WHERE user = ?"; + queries["user_auth_create"] = "INSERT OR IGNORE INTO authentication (user) VALUES (?)"; + queries["user_disable"] = "UPDATE authentication SET disabled = ? WHERE user = ?"; + queries["last_timestamp"] = "SELECT timestamp FROM sales ORDER BY timestamp DESC LIMIT 1"; /* compile queries into statements */ foreach(var entry in queries.entries) { @@ -813,4 +814,11 @@ public class Database { public bool user_is_disabled(int user) { return get_user_auth(user).disabled; } + + public int64 get_timestamp_of_last_purchase() { + statements["last_timestamp"].reset(); + if(statements["last_timestamp"].step() != Sqlite.ROW) + return 0; + return statements["last_timestamp"].column_int64(0); + } } diff --git a/src/main.vala b/src/main.vala index 81f006d..82fe238 100644 --- a/src/main.vala +++ b/src/main.vala @@ -80,6 +80,11 @@ public static int main(string[] args) { dev.blink(10); }); + while(!check_valid_time()) { + write_to_log("Invalid System Time! Retry in 1 minute..."); + Posix.sleep(60); + } + write_to_log("KtT Shop System has been started"); audio.play_system("startup.ogg"); @@ -104,6 +109,10 @@ public static int main(string[] args) { return 0; } +public bool check_valid_time() { + return time_t() > db.get_timestamp_of_last_purchase(); +} + public void write_to_log(string format, ...) { var arguments = va_list(); var message = format.vprintf(arguments); -- cgit v1.2.3