gameServer/OfficialServer/DBInteraction.hs
changeset 4975 31da8979e5b1
parent 4944 e43a3da2fc22
child 4982 3572eaf14340
equal deleted inserted replaced
4974:078cd026a7b1 4975:31da8979e5b1
    25 #endif
    25 #endif
    26 
    26 
    27 localAddressList :: [B.ByteString]
    27 localAddressList :: [B.ByteString]
    28 localAddressList = ["127.0.0.1", "0:0:0:0:0:0:0:1", "0:0:0:0:0:ffff:7f00:1"]
    28 localAddressList = ["127.0.0.1", "0:0:0:0:0:0:0:1", "0:0:0:0:0:ffff:7f00:1"]
    29 
    29 
    30 fakeDbConnection :: forall b. ServerInfo -> IO b
    30 --fakeDbConnection :: forall b. (ServerInfo c)-> IO b
    31 fakeDbConnection si = forever $ do
    31 fakeDbConnection si = forever $ do
    32     q <- readChan $ dbQueries si
    32     q <- readChan $ dbQueries si
    33     case q of
    33     case q of
    34         CheckAccount clId clUid _ clHost ->
    34         CheckAccount clId clUid _ clHost ->
    35             writeChan (coreChan si) $ ClientAccountInfo clId clUid (if clHost `L.elem` localAddressList then Admin else Guest)
    35             writeChan (coreChan si) $ ClientAccountInfo clId clUid (if clHost `L.elem` localAddressList then Admin else Guest)
    36         ClearCache -> return ()
    36         ClearCache -> return ()
    37         SendStats {} -> return ()
    37         SendStats {} -> return ()
    38 
    38 
    39 dbConnectionLoop :: forall b. ServerInfo -> IO b
    39 --dbConnectionLoop :: forall b. (ServerInfo c) -> IO b
    40 #if defined(OFFICIAL_SERVER)
    40 #if defined(OFFICIAL_SERVER)
    41 flushRequests :: ServerInfo -> IO ()
    41 flushRequests :: (ServerInfo c) -> IO ()
    42 flushRequests si = do
    42 flushRequests si = do
    43     e <- isEmptyChan $ dbQueries si
    43     e <- isEmptyChan $ dbQueries si
    44     unless e $ do
    44     unless e $ do
    45         q <- readChan $ dbQueries si
    45         q <- readChan $ dbQueries si
    46         case q of
    46         case q of
    87     pipeDbConnectionLoop queries cChan hIn hOut updatedCache newReq
    87     pipeDbConnectionLoop queries cChan hIn hOut updatedCache newReq
    88     where
    88     where
    89         maybeException (Just a) = return a
    89         maybeException (Just a) = return a
    90         maybeException Nothing = ioError (userError "Can't read")
    90         maybeException Nothing = ioError (userError "Can't read")
    91 
    91 
    92 pipeDbConnection :: forall b. Map.Map ByteString (UTCTime, AccountInfo) -> ServerInfo -> Int -> IO b
    92 --pipeDbConnection :: forall b. Map.Map ByteString (UTCTime, AccountInfo) -> (ServerInfo c) -> Int -> IO b
    93 pipeDbConnection accountsCache si errNum = do
    93 pipeDbConnection accountsCache si errNum = do
    94     (updatedCache, newErrNum) <-
    94     (updatedCache, newErrNum) <-
    95         Exception.handle (\(e :: Exception.IOException) -> warningM "Database" (show e) >> return (accountsCache, errNum + 1)) $ do
    95         Exception.handle (\(e :: Exception.IOException) -> warningM "Database" (show e) >> return (accountsCache, errNum + 1)) $ do
    96             (Just hIn, Just hOut, _, _) <- createProcess (proc "./OfficialServer/extdbinterface" [])
    96             (Just hIn, Just hOut, _, _) <- createProcess (proc "./OfficialServer/extdbinterface" [])
    97                     {std_in = CreatePipe,
    97                     {std_in = CreatePipe,
   116             fakeDbConnection si
   116             fakeDbConnection si
   117 #else
   117 #else
   118 dbConnectionLoop = fakeDbConnection
   118 dbConnectionLoop = fakeDbConnection
   119 #endif
   119 #endif
   120 
   120 
   121 startDBConnection :: ServerInfo -> IO ()
   121 startDBConnection :: (ServerInfo c) -> IO ()
   122 startDBConnection serverInfo =
   122 startDBConnection serverInfo =
   123     forkIO (dbConnectionLoop serverInfo) >> return ()
   123     forkIO (dbConnectionLoop serverInfo) >> return ()