gameServer/OfficialServer/DBInteraction.hs
changeset 1804 4e78ad846fb6
child 1833 e901ec5644b4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer/OfficialServer/DBInteraction.hs	Wed Feb 18 15:04:40 2009 +0000
@@ -0,0 +1,37 @@
+module OfficialServer.DBInteraction
+(
+	startDBConnection,
+	DBQuery(HasRegistered, CheckPassword)
+) where
+
+import Database.HDBC
+import Database.HDBC.MySQL
+
+import System.IO
+import Control.Concurrent
+import Control.Concurrent.STM
+import Control.Exception
+
+data DBQuery =
+	HasRegistered String
+	| CheckPassword String
+
+dbInteractionLoop queries dbConn = do
+	q <- atomically $ readTChan queries
+	case q of
+		HasRegistered queryStr -> putStrLn queryStr
+		CheckPassword queryStr -> putStrLn queryStr
+
+	dbInteractionLoop queries dbConn
+
+dbConnectionLoop queries = do
+	Control.Exception.handle (\e -> print e) $ handleSqlError $
+		bracket
+			(connectMySQL defaultMySQLConnectInfo { mysqlHost = "192.168.50.5", mysqlDatabase = "glpi" })
+			(disconnect)
+			(dbInteractionLoop queries)
+
+	threadDelay (15 * 10^6)
+	dbConnectionLoop queries
+
+startDBConnection queries = forkIO $ dbConnectionLoop queries