gameServer/Actions.hs
changeset 8372 3c193ec03e09
parent 8371 0551b5c3de9a
child 8396 5123eac2f9d6
equal deleted inserted replaced
8371:0551b5c3de9a 8372:3c193ec03e09
   140     (Just ci) <- gets clientIndex
   140     (Just ci) <- gets clientIndex
   141     ri <- clientRoomA
   141     ri <- clientRoomA
   142 
   142 
   143     chan <- client's sendChan
   143     chan <- client's sendChan
   144     clNick <- client's nick
   144     clNick <- client's nick
   145     loggedIn <- client's logonPassed
   145     loggedIn <- client's isVisible
   146 
   146 
   147     when (ri /= lobbyId) $ do
   147     when (ri /= lobbyId) $ do
   148         processAction $ MoveToLobby ("quit: " `B.append` msg)
   148         processAction $ MoveToLobby ("quit: " `B.append` msg)
   149         return ()
   149         return ()
   150 
   150 
   151     clientsChans <- liftM (Prelude.map sendChan . Prelude.filter logonPassed) $! allClientsS
   151     clientsChans <- liftM (Prelude.map sendChan . Prelude.filter isVisible) $! allClientsS
   152     io $
   152     io $
   153         infoM "Clients" (show ci ++ " quits: " ++ B.unpack msg)
   153         infoM "Clients" (show ci ++ " quits: " ++ B.unpack msg)
   154 
   154 
   155     when loggedIn $ processAction $ AnswerClients clientsChans ["LOBBY:LEFT", clNick, msg]
   155     when loggedIn $ processAction $ AnswerClients clientsChans ["LOBBY:LEFT", clNick, msg]
   156 
   156 
   157     mapM_ processAction
   157     mapM_ processAction
   158         [
   158         [
   159         AnswerClients [chan] ["BYE", msg]
   159         AnswerClients [chan] ["BYE", msg]
   160         , ModifyClient (\c -> c{nick = "", logonPassed = False}) -- this will effectively hide client from others while he isn't deleted from list
   160         , ModifyClient (\c -> c{nick = "", isVisible = False}) -- this will effectively hide client from others while he isn't deleted from list
   161         ]
   161         ]
   162 
   162 
   163     s <- get
   163     s <- get
   164     put $! s{removedClients = ci `Set.insert` removedClients s}
   164     put $! s{removedClients = ci `Set.insert` removedClients s}
   165 
   165 
   443 
   443 
   444 processAction (ProcessAccountInfo info) = do
   444 processAction (ProcessAccountInfo info) = do
   445     case info of
   445     case info of
   446         HasAccount passwd isAdmin -> do
   446         HasAccount passwd isAdmin -> do
   447             b <- isBanned
   447             b <- isBanned
   448             when (not b) $ do
   448             c <- client's isChecker
   449                 chan <- client's sendChan
   449             when (not b) $ (if c then checkerLogin else playerLogin) passwd isAdmin
   450                 mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = passwd, isAdministrator = isAdmin})]
       
   451         Guest -> do
   450         Guest -> do
   452             b <- isBanned
   451             b <- isBanned
   453             when (not b) $
   452             when (not b) $
   454                 processAction JoinLobby
   453                 processAction JoinLobby
   455         Admin -> do
   454         Admin -> do
   458             processAction $ AnswerClients [chan] ["ADMIN_ACCESS"]
   457             processAction $ AnswerClients [chan] ["ADMIN_ACCESS"]
   459     where
   458     where
   460     isBanned = do
   459     isBanned = do
   461         processAction $ CheckBanned False
   460         processAction $ CheckBanned False
   462         liftM B.null $ client's nick
   461         liftM B.null $ client's nick
   463 
   462     checkerLogin p False = processAction $ ByeClient "No checker rights"
       
   463     checkerLogin p True = do
       
   464         wp <- client's webPassword
       
   465         processAction $
       
   466             if wp == p then ModifyClient $ \c -> c{logonPassed = True} else ByeClient "Authentication failed"
       
   467     playerLogin p a = do
       
   468         chan <- client's sendChan
       
   469         mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = p, isAdministrator = a})]
   464 
   470 
   465 processAction JoinLobby = do
   471 processAction JoinLobby = do
   466     chan <- client's sendChan
   472     chan <- client's sendChan
   467     clientNick <- client's nick
   473     clientNick <- client's nick
   468     isAuthenticated <- liftM (not . B.null) $ client's webPassword
   474     isAuthenticated <- liftM (not . B.null) $ client's webPassword
   469     isAdmin <- client's isAdministrator
   475     isAdmin <- client's isAdministrator
   470     loggedInClients <- liftM (Prelude.filter logonPassed) $! allClientsS
   476     loggedInClients <- liftM (Prelude.filter isVisible) $! allClientsS
   471     let (lobbyNicks, clientsChans) = unzip . L.map (nick &&& sendChan) $ loggedInClients
   477     let (lobbyNicks, clientsChans) = unzip . L.map (nick &&& sendChan) $ loggedInClients
   472     let authenticatedNicks = L.map nick . L.filter (not . B.null . webPassword) $ loggedInClients
   478     let authenticatedNicks = L.map nick . L.filter (not . B.null . webPassword) $ loggedInClients
   473     let adminsNicks = L.map nick . L.filter isAdministrator $ loggedInClients
   479     let adminsNicks = L.map nick . L.filter isAdministrator $ loggedInClients
   474     let clFlags = B.concat . L.concat $ [["u" | isAuthenticated], ["a" | isAdmin]]
   480     let clFlags = B.concat . L.concat $ [["u" | isAuthenticated], ["a" | isAdmin]]
   475     mapM_ processAction . concat $ [
   481     mapM_ processAction . concat $ [
   476         [AnswerClients clientsChans ["LOBBY:JOINED", clientNick]]
   482         [AnswerClients clientsChans ["LOBBY:JOINED", clientNick]]
   477         , [AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks)]
   483         , [AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks)]
   478         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+u" : authenticatedNicks) | not $ null authenticatedNicks]
   484         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+u" : authenticatedNicks) | not $ null authenticatedNicks]
   479         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+a" : adminsNicks) | not $ null adminsNicks]
   485         , [AnswerClients [chan] ("CLIENT_FLAGS" : "+a" : adminsNicks) | not $ null adminsNicks]
   480         , [AnswerClients (chan : clientsChans) ["CLIENT_FLAGS",  B.concat["+" , clFlags], clientNick] | not $ B.null clFlags]
   486         , [AnswerClients (chan : clientsChans) ["CLIENT_FLAGS",  B.concat["+" , clFlags], clientNick] | not $ B.null clFlags]
   481         , [ModifyClient (\cl -> cl{logonPassed = True})]
   487         , [ModifyClient (\cl -> cl{logonPassed = True, isVisible = True})]
   482         , [SendServerMessage]
   488         , [SendServerMessage]
   483         ]
   489         ]
   484 
   490 
   485 
   491 
   486 processAction (KickClient kickId) = do
   492 processAction (KickClient kickId) = do