422 p <- client's clientProto |
422 p <- client's clientProto |
423 uid <- client's clUID |
423 uid <- client's clUID |
424 haveSameNick <- liftM (not . null . tail . filter (\c -> caseInsensitiveCompare (nick c) n)) allClientsS |
424 haveSameNick <- liftM (not . null . tail . filter (\c -> caseInsensitiveCompare (nick c) n)) allClientsS |
425 if haveSameNick then |
425 if haveSameNick then |
426 if p < 38 then |
426 if p < 38 then |
427 mapM_ processAction [ByeClient "Nickname is already in use", removeNick] |
427 processAction $ ByeClient "Nickname is already in use" |
428 else |
428 else |
429 mapM_ processAction [NoticeMessage NickAlreadyInUse, removeNick] |
429 processAction $ NoticeMessage NickAlreadyInUse |
430 else |
430 else |
431 do |
431 do |
432 db <- gets (dbQueries . serverInfo) |
432 db <- gets (dbQueries . serverInfo) |
433 io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
433 io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
434 return () |
434 return () |
435 where |
|
436 removeNick = ModifyClient (\c -> c{nick = ""}) |
|
437 |
|
438 |
435 |
439 processAction ClearAccountsCache = do |
436 processAction ClearAccountsCache = do |
440 dbq <- gets (dbQueries . serverInfo) |
437 dbq <- gets (dbQueries . serverInfo) |
441 io $ writeChan dbq ClearCache |
438 io $ writeChan dbq ClearCache |
442 return () |
439 return () |
457 mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby] |
454 mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby] |
458 chan <- client's sendChan |
455 chan <- client's sendChan |
459 processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
456 processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
460 where |
457 where |
461 isBanned = do |
458 isBanned = do |
462 processAction CheckBanned |
459 processAction $ CheckBanned False |
463 liftM B.null $ client's nick |
460 liftM B.null $ client's nick |
464 |
461 |
465 |
462 |
466 processAction JoinLobby = do |
463 processAction JoinLobby = do |
467 chan <- client's sendChan |
464 chan <- client's sendChan |
555 |
552 |
556 modify (\s -> s{clientIndex = Just newClId}) |
553 modify (\s -> s{clientIndex = Just newClId}) |
557 mapM_ processAction |
554 mapM_ processAction |
558 [ |
555 [ |
559 AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
556 AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
560 , CheckBanned |
557 , CheckBanned True |
561 , AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl) |
558 , AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl) |
562 ] |
559 ] |
563 |
560 |
564 |
561 |
565 processAction (AddNick2Bans n reason expiring) = do |
562 processAction (AddNick2Bans n reason expiring) = do |
569 (Just ci) <- gets clientIndex |
566 (Just ci) <- gets clientIndex |
570 rc <- gets removedClients |
567 rc <- gets removedClients |
571 when (not $ ci `Set.member` rc) |
568 when (not $ ci `Set.member` rc) |
572 $ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
569 $ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
573 |
570 |
574 processAction CheckBanned = do |
571 processAction (CheckBanned byIP) = do |
575 clTime <- client's connectTime |
572 clTime <- client's connectTime |
576 clNick <- client's nick |
573 clNick <- client's nick |
577 clHost <- client's host |
574 clHost <- client's host |
578 si <- gets serverInfo |
575 si <- gets serverInfo |
579 let validBans = filter (checkNotExpired clTime) $ bans si |
576 let validBans = filter (checkNotExpired clTime) $ bans si |
580 let ban = L.find (checkBan clHost clNick) $ validBans |
577 let ban = L.find (checkBan byIP clHost clNick) $ validBans |
581 mapM_ processAction $ |
578 mapM_ processAction $ |
582 ModifyServerInfo (\s -> s{bans = validBans}) |
579 ModifyServerInfo (\s -> s{bans = validBans}) |
583 : [ByeClient (getBanReason $ fromJust ban) | isJust ban] |
580 : [ByeClient (getBanReason $ fromJust ban) | isJust ban] |
584 where |
581 where |
585 checkNotExpired testTime (BanByIP _ _ time) = testTime `diffUTCTime` time <= 0 |
582 checkNotExpired testTime (BanByIP _ _ time) = testTime `diffUTCTime` time <= 0 |
586 checkNotExpired testTime (BanByNick _ _ time) = testTime `diffUTCTime` time <= 0 |
583 checkNotExpired testTime (BanByNick _ _ time) = testTime `diffUTCTime` time <= 0 |
587 checkBan ip _ (BanByIP bip _ _) = bip `B.isPrefixOf` ip |
584 checkBan True ip _ (BanByIP bip _ _) = bip `B.isPrefixOf` ip |
588 checkBan _ n (BanByNick bn _ _) = caseInsensitiveCompare bn n |
585 checkBan False _ n (BanByNick bn _ _) = caseInsensitiveCompare bn n |
|
586 checkBan _ _ _ _ = False |
589 getBanReason (BanByIP _ msg _) = msg |
587 getBanReason (BanByIP _ msg _) = msg |
590 getBanReason (BanByNick _ msg _) = msg |
588 getBanReason (BanByNick _ msg _) = msg |
591 |
589 |
592 processAction PingAll = do |
590 processAction PingAll = do |
593 rnc <- gets roomsClients |
591 rnc <- gets roomsClients |