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 c. ServerInfo c -> IO b |
30 fakeDbConnection :: forall b. ServerInfo -> 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 c) -> IO b |
39 --dbConnectionLoop :: forall b. (ServerInfo c) -> IO b |
40 #if defined(OFFICIAL_SERVER) |
40 #if defined(OFFICIAL_SERVER) |
41 flushRequests :: (ServerInfo c) -> IO () |
41 flushRequests :: ServerInfo -> 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 a c b. |
92 pipeDbConnection :: forall a b. |
93 (Num a, Ord a) => |
93 (Num a, Ord a) => |
94 Map.Map ByteString (UTCTime, AccountInfo) |
94 Map.Map ByteString (UTCTime, AccountInfo) |
95 -> ServerInfo c |
95 -> ServerInfo |
96 -> a |
96 -> a |
97 -> IO b |
97 -> IO b |
98 |
98 |
99 pipeDbConnection accountsCache si errNum = do |
99 pipeDbConnection accountsCache si errNum = do |
100 (updatedCache, newErrNum) <- |
100 (updatedCache, newErrNum) <- |
114 |
114 |
115 when (newErrNum > 1) $ flushRequests si |
115 when (newErrNum > 1) $ flushRequests si |
116 threadDelay (3000000) |
116 threadDelay (3000000) |
117 pipeDbConnection updatedCache si newErrNum |
117 pipeDbConnection updatedCache si newErrNum |
118 |
118 |
119 dbConnectionLoop :: forall c b. ServerInfo c -> IO b |
119 dbConnectionLoop :: forall b. ServerInfo -> IO b |
120 dbConnectionLoop si = |
120 dbConnectionLoop si = |
121 if (not . B.null $ dbHost si) then |
121 if (not . B.null $ dbHost si) then |
122 pipeDbConnection Map.empty si 0 |
122 pipeDbConnection Map.empty si 0 |
123 else |
123 else |
124 fakeDbConnection si |
124 fakeDbConnection si |
125 #else |
125 #else |
126 dbConnectionLoop = fakeDbConnection |
126 dbConnectionLoop = fakeDbConnection |
127 #endif |
127 #endif |
128 |
128 |
129 startDBConnection :: (ServerInfo c) -> IO () |
129 startDBConnection :: ServerInfo -> IO () |
130 startDBConnection serverInfo = |
130 startDBConnection serverInfo = |
131 forkIO (dbConnectionLoop serverInfo) >> return () |
131 forkIO (dbConnectionLoop serverInfo) >> return () |