3 ( |
3 ( |
4 startDBConnection |
4 startDBConnection |
5 ) where |
5 ) where |
6 |
6 |
7 import Prelude hiding (catch); |
7 import Prelude hiding (catch); |
|
8 import Control.Concurrent |
|
9 import Control.Monad |
|
10 import Data.List as L |
|
11 import Data.ByteString.Char8 as B |
|
12 #if defined(OFFICIAL_SERVER) |
8 import System.Process |
13 import System.Process |
9 import System.IO as SIO |
14 import System.IO as SIO |
10 import Control.Concurrent |
|
11 import qualified Control.Exception as Exception |
15 import qualified Control.Exception as Exception |
12 import Control.Monad |
|
13 import qualified Data.Map as Map |
16 import qualified Data.Map as Map |
14 import Data.Maybe |
17 import Data.Maybe |
|
18 import Data.Time |
15 import System.Log.Logger |
19 import System.Log.Logger |
16 import Data.Time |
20 #endif |
17 import Data.ByteString.Char8 as B |
|
18 import Data.List as L |
|
19 ------------------------ |
21 ------------------------ |
20 import CoreTypes |
22 import CoreTypes |
|
23 #if defined(OFFICIAL_SERVER) |
21 import Utils |
24 import Utils |
|
25 #endif |
22 |
26 |
|
27 localAddressList :: [B.ByteString] |
23 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"] |
24 |
29 |
|
30 fakeDbConnection :: forall b. ServerInfo -> IO b |
25 fakeDbConnection serverInfo = forever $ do |
31 fakeDbConnection serverInfo = forever $ do |
26 q <- readChan $ dbQueries serverInfo |
32 q <- readChan $ dbQueries serverInfo |
27 case q of |
33 case q of |
28 CheckAccount clId clUid _ clHost -> do |
34 CheckAccount clId clUid _ clHost -> |
29 writeChan (coreChan serverInfo) $ ClientAccountInfo clId clUid (if clHost `L.elem` localAddressList then Admin else Guest) |
35 writeChan (coreChan serverInfo) $ ClientAccountInfo clId clUid (if clHost `L.elem` localAddressList then Admin else Guest) |
30 ClearCache -> return () |
36 ClearCache -> return () |
31 SendStats {} -> return () |
37 SendStats {} -> return () |
32 |
38 |
33 |
39 dbConnectionLoop :: forall b. ServerInfo -> IO b |
34 #if defined(OFFICIAL_SERVER) |
40 #if defined(OFFICIAL_SERVER) |
35 pipeDbConnectionLoop queries coreChan hIn hOut accountsCache = |
41 pipeDbConnectionLoop queries coreChan hIn hOut accountsCache = |
36 Exception.handle (\(e :: Exception.IOException) -> warningM "Database" (show e) >> return accountsCache) $ |
42 Exception.handle (\(e :: Exception.IOException) -> warningM "Database" (show e) >> return accountsCache) $ |
37 do |
43 do |
38 q <- readChan queries |
44 q <- readChan queries |