30 import ServerState |
30 import ServerState |
31 import Consts |
31 import Consts |
32 import ConfigFile |
32 import ConfigFile |
33 import EngineInteraction |
33 import EngineInteraction |
34 |
34 |
35 data Action = |
|
36 AnswerClients ![ClientChan] ![B.ByteString] |
|
37 | SendServerMessage |
|
38 | SendServerVars |
|
39 | MoveToRoom RoomIndex |
|
40 | MoveToLobby B.ByteString |
|
41 | RemoveTeam B.ByteString |
|
42 | SendTeamRemovalMessage B.ByteString |
|
43 | RemoveRoom |
|
44 | FinishGame |
|
45 | UnreadyRoomClients |
|
46 | JoinLobby |
|
47 | ProtocolError B.ByteString |
|
48 | Warning B.ByteString |
|
49 | NoticeMessage Notice |
|
50 | ByeClient B.ByteString |
|
51 | KickClient ClientIndex |
|
52 | KickRoomClient ClientIndex |
|
53 | BanClient NominalDiffTime B.ByteString ClientIndex |
|
54 | BanIP B.ByteString NominalDiffTime B.ByteString |
|
55 | BanNick B.ByteString NominalDiffTime B.ByteString |
|
56 | BanList |
|
57 | Unban B.ByteString |
|
58 | ChangeMaster (Maybe ClientIndex) |
|
59 | RemoveClientTeams |
|
60 | ModifyClient (ClientInfo -> ClientInfo) |
|
61 | ModifyClient2 ClientIndex (ClientInfo -> ClientInfo) |
|
62 | ModifyRoomClients (ClientInfo -> ClientInfo) |
|
63 | ModifyRoom (RoomInfo -> RoomInfo) |
|
64 | ModifyServerInfo (ServerInfo -> ServerInfo) |
|
65 | AddRoom B.ByteString B.ByteString |
|
66 | SendUpdateOnThisRoom |
|
67 | CheckRegistered |
|
68 | ClearAccountsCache |
|
69 | ProcessAccountInfo AccountInfo |
|
70 | AddClient ClientInfo |
|
71 | DeleteClient ClientIndex |
|
72 | PingAll |
|
73 | StatsAction |
|
74 | RestartServer |
|
75 | AddNick2Bans B.ByteString B.ByteString UTCTime |
|
76 | AddIP2Bans B.ByteString B.ByteString UTCTime |
|
77 | CheckBanned Bool |
|
78 | SaveReplay |
|
79 | Stats |
|
80 | CheckRecord |
|
81 | CheckFailed B.ByteString |
|
82 | CheckSuccess [B.ByteString] |
|
83 |
|
84 |
35 |
85 type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action] |
36 type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action] |
86 |
|
87 instance NFData Action where |
|
88 rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` () |
|
89 rnf a = a `seq` () |
|
90 |
|
91 #if __GLASGOW_HASKELL__ < 706 |
|
92 instance NFData B.ByteString |
|
93 #endif |
|
94 |
|
95 instance NFData (Chan a) |
|
96 |
37 |
97 |
38 |
98 othersChans :: StateT ServerState IO [ClientChan] |
39 othersChans :: StateT ServerState IO [ClientChan] |
99 othersChans = do |
40 othersChans = do |
100 cl <- client's id |
41 cl <- client's id |
592 (Just ci) <- gets clientIndex |
533 (Just ci) <- gets clientIndex |
593 rc <- gets removedClients |
534 rc <- gets removedClients |
594 when (not $ ci `Set.member` rc) |
535 when (not $ ci `Set.member` rc) |
595 $ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
536 $ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
596 |
537 |
|
538 |
597 processAction (CheckBanned byIP) = do |
539 processAction (CheckBanned byIP) = do |
598 clTime <- client's connectTime |
540 clTime <- client's connectTime |
599 clNick <- client's nick |
541 clNick <- client's nick |
600 clHost <- client's host |
542 clHost <- client's host |
601 si <- gets serverInfo |
543 si <- gets serverInfo |
610 checkBan True ip _ (BanByIP bip _ _) = bip `B.isPrefixOf` ip |
552 checkBan True ip _ (BanByIP bip _ _) = bip `B.isPrefixOf` ip |
611 checkBan False _ n (BanByNick bn _ _) = caseInsensitiveCompare bn n |
553 checkBan False _ n (BanByNick bn _ _) = caseInsensitiveCompare bn n |
612 checkBan _ _ _ _ = False |
554 checkBan _ _ _ _ = False |
613 getBanReason (BanByIP _ msg _) = msg |
555 getBanReason (BanByIP _ msg _) = msg |
614 getBanReason (BanByNick _ msg _) = msg |
556 getBanReason (BanByNick _ msg _) = msg |
|
557 |
615 |
558 |
616 processAction PingAll = do |
559 processAction PingAll = do |
617 rnc <- gets roomsClients |
560 rnc <- gets roomsClients |
618 io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
561 io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
619 cis <- io $ allClientsM rnc |
562 cis <- io $ allClientsM rnc |