lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
module ServerCore whereimport Networkimport Control.Concurrentimport Control.Concurrent.Chanimport Control.Monadimport qualified Data.IntMap as IntMapimport System.Log.Loggerimport Control.Monad.Readerimport Control.Monad.State.Strictimport Data.Set as Setimport qualified Data.ByteString.Char8 as B--------------------------------------import CoreTypesimport NetRoutinesimport HWProtoCoreimport Actionsimport OfficialServer.DBInteractionimport ServerStatetimerLoop :: Int -> Chan CoreMessage -> IO ()timerLoop tick messagesChan = threadDelay (30 * 10^6) >> writeChan messagesChan (TimerAction tick) >> timerLoop (tick + 1) messagesChanreactCmd :: [B.ByteString] -> StateT ServerState IO ()reactCmd cmd = do (Just ci) <- gets clientIndex rnc <- gets roomsClients actions <- liftIO $ withRoomsAndClients rnc (\irnc -> runReader (handleCmd cmd) (ci, irnc)) forM_ actions processActionmainLoop :: StateT ServerState IO ()mainLoop = forever $ do get >>= \s -> put $! s si <- gets serverInfo r <- liftIO $ readChan $ coreChan si case r of Accept ci -> processAction (AddClient ci) ClientMessage (ci, cmd) -> do liftIO $ debugM "Clients" $ (show ci) ++ ": " ++ (show cmd) removed <- gets removedClients when (not $ ci `Set.member` removed) $ do as <- get put $! as{clientIndex = Just ci} reactCmd cmd Remove ci -> do liftIO $ debugM "Clients" $ "DeleteClient: " ++ show ci processAction (DeleteClient ci) --else --do --debugM "Clients" "Message from dead client" --return (serverInfo, rnc) ClientAccountInfo (ci, info) -> do rnc <- gets roomsClients exists <- liftIO $ clientExists rnc ci when (exists) $ do as <- get put $! as{clientIndex = Just ci} processAction (ProcessAccountInfo info) return () TimerAction tick -> mapM_ processAction $ PingAll : [StatsAction | even tick]startServer :: ServerInfo -> Socket -> IO ()startServer serverInfo serverSocket = do putStrLn $ "Listening on port " ++ show (listenPort serverInfo) forkIO $ acceptLoop serverSocket (coreChan serverInfo) return () --forkIO $ timerLoop 0 $ coreChan serverInfo startDBConnection serverInfo rnc <- newRoomsAndClients newRoom forkIO $ evalStateT mainLoop (ServerState Nothing serverInfo Set.empty rnc) forever $ threadDelay (60 * 60 * 10^6)