gameServer/Actions.hs
changeset 9435 59eec19cb31a
parent 9433 f0a8ac191839
child 9437 8d1e9a9dda8e
equal deleted inserted replaced
9433:f0a8ac191839 9435:59eec19cb31a
   419     return ()
   419     return ()
   420 
   420 
   421 
   421 
   422 processAction (ProcessAccountInfo info) = do
   422 processAction (ProcessAccountInfo info) = do
   423     case info of
   423     case info of
   424         HasAccount passwd isAdmin -> do
   424         HasAccount passwd isAdmin isContr -> do
   425             b <- isBanned
   425             b <- isBanned
   426             c <- client's isChecker
   426             c <- client's isChecker
   427             when (not b) $ (if c then checkerLogin else playerLogin) passwd isAdmin
   427             when (not b) $ (if c then checkerLogin else playerLogin) passwd isAdmin isContr
   428         Guest -> do
   428         Guest -> do
   429             b <- isBanned
   429             b <- isBanned
   430             c <- client's isChecker
   430             c <- client's isChecker
   431             when (not b) $
   431             when (not b) $
   432                 if c then
   432                 if c then
   433                     checkerLogin "" False
   433                     checkerLogin "" False False
   434                     else
   434                     else
   435                     processAction JoinLobby
   435                     processAction JoinLobby
   436         Admin -> do
   436         Admin -> do
   437             mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby]
   437             mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby]
   438             chan <- client's sendChan
   438             chan <- client's sendChan
   439             processAction $ AnswerClients [chan] ["ADMIN_ACCESS"]
   439             processAction $ AnswerClients [chan] ["ADMIN_ACCESS"]
   440     where
   440     where
   441     isBanned = do
   441     isBanned = do
   442         processAction $ CheckBanned False
   442         processAction $ CheckBanned False
   443         liftM B.null $ client's nick
   443         liftM B.null $ client's nick
   444     checkerLogin _ False = processAction $ ByeClient $ loc "No checker rights"
   444     checkerLogin _ False _ = processAction $ ByeClient $ loc "No checker rights"
   445     checkerLogin p True = do
   445     checkerLogin p True _ = do
   446         wp <- client's webPassword
   446         wp <- client's webPassword
   447         processAction $
   447         processAction $
   448             if wp == p then ModifyClient $ \c -> c{logonPassed = True} else ByeClient $ loc "Authentication failed"
   448             if wp == p then ModifyClient $ \c -> c{logonPassed = True} else ByeClient $ loc "Authentication failed"
   449     playerLogin p a = do
   449     playerLogin p a contr = do
   450         chan <- client's sendChan
   450         chan <- client's sendChan
   451         mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = p, isAdministrator = a})]
   451         mapM_ processAction [
       
   452             AnswerClients [chan] ["ASKPASSWORD"]
       
   453             , ModifyClient (\c -> c{webPassword = p, isAdministrator = a, isContributor = contr})
       
   454             ]
   452 
   455 
   453 processAction JoinLobby = do
   456 processAction JoinLobby = do
   454     chan <- client's sendChan
   457     chan <- client's sendChan
   455     clientNick <- client's nick
   458     clientNick <- client's nick
   456     isAuthenticated <- liftM (not . B.null) $ client's webPassword
   459     isAuthenticated <- liftM (not . B.null) $ client's webPassword
   457     isAdmin <- client's isAdministrator
   460     isAdmin <- client's isAdministrator
       
   461     isContr <- client's isContributor
   458     loggedInClients <- liftM (Prelude.filter isVisible) $! allClientsS
   462     loggedInClients <- liftM (Prelude.filter isVisible) $! allClientsS
   459     let (lobbyNicks, clientsChans) = unzip . L.map (nick &&& sendChan) $ loggedInClients
   463     let (lobbyNicks, clientsChans) = unzip . L.map (nick &&& sendChan) $ loggedInClients
   460     let authenticatedNicks = L.map nick . L.filter (not . B.null . webPassword) $ loggedInClients
   464     let authenticatedNicks = L.map nick . L.filter (not . B.null . webPassword) $ loggedInClients
   461     let adminsNicks = L.map nick . L.filter isAdministrator $ loggedInClients
   465     let adminsNicks = L.map nick . L.filter isAdministrator $ loggedInClients
   462     let clFlags = B.concat . L.concat $ [["u" | isAuthenticated], ["a" | isAdmin]]
   466     let contrNicks = L.map nick . L.filter isContributor $ loggedInClients
       
   467     let clFlags = B.concat . L.concat $ [["u" | isAuthenticated], ["a" | isAdmin], ["c" | isContr]]
   463     mapM_ processAction . concat $ [
   468     mapM_ processAction . concat $ [
   464         [AnswerClients clientsChans ["LOBBY:JOINED", clientNick]]
   469         [AnswerClients clientsChans ["LOBBY:JOINED", clientNick]]
   465         , [AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks)]
   470         , [AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks)]
   466         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+u" : authenticatedNicks) | not $ null authenticatedNicks]
   471         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+u" : authenticatedNicks) | not $ null authenticatedNicks]
   467         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+a" : adminsNicks) | not $ null adminsNicks]
   472         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+a" : adminsNicks) | not $ null adminsNicks]
       
   473         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+c" : contrNicks) | not $ null contrNicks]
   468         , [AnswerClients (chan : clientsChans) ["CLIENT_FLAGS",  B.concat["+" , clFlags], clientNick] | not $ B.null clFlags]
   474         , [AnswerClients (chan : clientsChans) ["CLIENT_FLAGS",  B.concat["+" , clFlags], clientNick] | not $ B.null clFlags]
   469         , [ModifyClient (\cl -> cl{logonPassed = True, isVisible = True})]
   475         , [ModifyClient (\cl -> cl{logonPassed = True, isVisible = True})]
   470         , [SendServerMessage]
   476         , [SendServerMessage]
   471         ]
   477         ]
   472 
   478 
   608         rnc <- gets roomsClients
   614         rnc <- gets roomsClients
   609         (roomsNum, clientsNum) <- io $ withRoomsAndClients rnc st
   615         (roomsNum, clientsNum) <- io $ withRoomsAndClients rnc st
   610         io $ writeChan (dbQueries si) $ SendStats clientsNum (roomsNum - 1)
   616         io $ writeChan (dbQueries si) $ SendStats clientsNum (roomsNum - 1)
   611     where
   617     where
   612           st irnc = (length $ allRooms irnc, length $ allClients irnc)
   618           st irnc = (length $ allRooms irnc, length $ allClients irnc)
       
   619 
   613 
   620 
   614 processAction RestartServer = do
   621 processAction RestartServer = do
   615     sp <- gets (shutdownPending . serverInfo)
   622     sp <- gets (shutdownPending . serverInfo)
   616     when (not sp) $ do
   623     when (not sp) $ do
   617         sock <- gets (fromJust . serverSocket . serverInfo)
   624         sock <- gets (fromJust . serverSocket . serverInfo)
   621             sClose sock
   628             sClose sock
   622             noticeM "Core" "Spawning new server"
   629             noticeM "Core" "Spawning new server"
   623             _ <- createProcess (proc "./hedgewars-server" args)
   630             _ <- createProcess (proc "./hedgewars-server" args)
   624             return ()
   631             return ()
   625         processAction $ ModifyServerInfo (\s -> s{shutdownPending = True})
   632         processAction $ ModifyServerInfo (\s -> s{shutdownPending = True})
       
   633 
   626 
   634 
   627 processAction Stats = do
   635 processAction Stats = do
   628     cls <- allClientsS
   636     cls <- allClientsS
   629     rms <- allRoomsS
   637     rms <- allRoomsS
   630     let clientsMap = Map.fromListWith (+) . map (\c -> (clientProto c, 1 :: Int)) $ cls
   638     let clientsMap = Map.fromListWith (+) . map (\c -> (clientProto c, 1 :: Int)) $ cls