gameServer/ServerCore.hs
changeset 2173 98cde8645e21
parent 2172 80d34c0b9dfe
child 2184 f59f80e034b1
equal deleted inserted replaced
2172:80d34c0b9dfe 2173:98cde8645e21
    14 import HWProtoCore
    14 import HWProtoCore
    15 import Actions
    15 import Actions
    16 import OfficialServer.DBInteraction
    16 import OfficialServer.DBInteraction
    17 
    17 
    18 
    18 
    19 timerLoop :: Chan CoreMessage -> IO()
    19 timerLoop :: Int -> Chan CoreMessage -> IO()
    20 timerLoop messagesChan = forever $ do
    20 timerLoop tick messagesChan = do
    21 	threadDelay (30 * 10^6) -- 30 seconds
    21 	threadDelay (30 * 10^6) -- 30 seconds
    22 	writeChan messagesChan TimerAction
    22 	writeChan messagesChan $ TimerAction tick
       
    23 	timerLoop (tick + 1) messagesChan
    23 
    24 
    24 firstAway (_, a, b, c) = (a, b, c)
    25 firstAway (_, a, b, c) = (a, b, c)
    25 
    26 
    26 reactCmd :: ServerInfo -> Int -> [String] -> Clients -> Rooms -> IO (ServerInfo, Clients, Rooms)
    27 reactCmd :: ServerInfo -> Int -> [String] -> Clients -> Rooms -> IO (ServerInfo, Clients, Rooms)
    27 reactCmd serverInfo clID cmd clients rooms =
    28 reactCmd serverInfo clID cmd clients rooms =
    54 					else
    55 					else
    55 					do
    56 					do
    56 					debugM "Clients" "Got info for dead client"
    57 					debugM "Clients" "Got info for dead client"
    57 					return (serverInfo, clients, rooms)
    58 					return (serverInfo, clients, rooms)
    58 
    59 
    59 			TimerAction ->
    60 			TimerAction tick ->
    60 				liftM firstAway $
    61 				liftM firstAway $
    61 					foldM processAction (0, serverInfo, clients, rooms)
    62 					foldM processAction (0, serverInfo, clients, rooms) $
    62 						[PingAll, StatsAction]
    63 						PingAll : if even tick then [StatsAction] else []
    63 
    64 
    64 
    65 
    65 	{-			let hadRooms = (not $ null rooms) && (null mrooms)
    66 	{-			let hadRooms = (not $ null rooms) && (null mrooms)
    66 					in unless ((not $ isDedicated serverInfo) && ((null clientsIn) || hadRooms)) $
    67 					in unless ((not $ isDedicated serverInfo) && ((null clientsIn) || hadRooms)) $
    67 						mainLoop serverInfo acceptChan messagesChan clientsIn mrooms -}
    68 						mainLoop serverInfo acceptChan messagesChan clientsIn mrooms -}
    78 			(coreChan serverInfo)
    79 			(coreChan serverInfo)
    79 			0
    80 			0
    80 
    81 
    81 	return ()
    82 	return ()
    82 	
    83 	
    83 	forkIO $ timerLoop $ coreChan serverInfo
    84 	forkIO $ timerLoop 0 $ coreChan serverInfo
    84 
    85 
    85 	startDBConnection $ serverInfo
    86 	startDBConnection $ serverInfo
    86 
    87 
    87 	mainLoop serverInfo IntMap.empty (IntMap.singleton 0 newRoom)
    88 	mainLoop serverInfo IntMap.empty (IntMap.singleton 0 newRoom)