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 |