gameServer/OfficialServer/DBInteraction.hs
changeset 1979 912e450d4db2
parent 1970 130e7805d49c
child 2116 dec7ead2d178
equal deleted inserted replaced
1978:8ab9949c8775 1979:912e450d4db2
       
     1 {-# LANGUAGE CPP #-}
     1 module OfficialServer.DBInteraction
     2 module OfficialServer.DBInteraction
     2 (
     3 (
     3 	startDBConnection
     4 	startDBConnection
     4 ) where
     5 ) where
     5 
     6 
     6 import Prelude hiding (catch);
     7 #if defined(OFFICIAL_SERVER)
     7 import Database.HDBC
     8 import Database.HDBC
     8 import Database.HDBC.MySQL
     9 import Database.HDBC.MySQL
       
    10 #endif
       
    11 
       
    12 import Prelude hiding (catch);
     9 import System.IO
    13 import System.IO
    10 import Control.Concurrent
    14 import Control.Concurrent
    11 import Control.Exception
    15 import Control.Exception
    12 import Monad
    16 import Monad
    13 import Maybe
    17 import Maybe
    33 onException io what = io `catch` \e -> do what                   --
    37 onException io what = io `catch` \e -> do what                   --
    34                                           throw (e :: Exception) --
    38                                           throw (e :: Exception) --
    35 -- to be deleted --------------------------------------------------
    39 -- to be deleted --------------------------------------------------
    36 -------------------------------------------------------------------
    40 -------------------------------------------------------------------
    37 
    41 
       
    42 #if defined(OFFICIAL_SERVER)
    38 dbQueryString =
    43 dbQueryString =
    39 	"select users.pass, users_roles.rid from users left join users_roles on users.uid = users_roles.uid where users.name = ?"
    44 	"select users.pass, users_roles.rid from users left join users_roles on users.uid = users_roles.uid where users.name = ?"
    40 
    45 
    41 dbInteractionLoop queries coreChan dbConn = do
    46 dbInteractionLoop queries coreChan dbConn = do
    42 	q <- readChan queries
    47 	q <- readChan queries
    66 			(disconnect)
    71 			(disconnect)
    67 			(dbInteractionLoop (dbQueries serverInfo) (coreChan serverInfo))
    72 			(dbInteractionLoop (dbQueries serverInfo) (coreChan serverInfo))
    68 
    73 
    69 	threadDelay (5 * 10^6)
    74 	threadDelay (5 * 10^6)
    70 	dbConnectionLoop serverInfo
    75 	dbConnectionLoop serverInfo
       
    76 #else
       
    77 dbConnectionLoop = fakeDbConnection
       
    78 #endif
    71 
    79 
    72 startDBConnection serverInfo =
    80 startDBConnection serverInfo =
    73 	if (not . null $ dbHost serverInfo) then
    81 	if (not . null $ dbHost serverInfo) then
    74 		forkIO $ dbConnectionLoop serverInfo
    82 		forkIO $ dbConnectionLoop serverInfo
    75 		else
    83 		else