92 [] |
93 [] |
93 ) |
94 ) |
94 |
95 |
95 type ClientsTransform = [ClientInfo] -> [ClientInfo] |
96 type ClientsTransform = [ClientInfo] -> [ClientInfo] |
96 type RoomsTransform = [RoomInfo] -> [RoomInfo] |
97 type RoomsTransform = [RoomInfo] -> [RoomInfo] |
97 type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [Handle] |
98 type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [ClientInfo] |
98 type Answer = ServerInfo -> (HandlesSelector, [String]) |
99 type Answer = ServerInfo -> (HandlesSelector, [String]) |
99 type CmdHandler = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientsTransform, RoomsTransform, [Answer]) |
100 type CmdHandler = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientsTransform, RoomsTransform, [Answer]) |
100 |
101 |
101 |
102 |
102 roomByName :: String -> [RoomInfo] -> RoomInfo |
103 roomByName :: String -> [RoomInfo] -> RoomInfo |
115 deleteBy2t eq x (y:ys) = if y `eq` x then ys else y : deleteBy2t eq x ys |
116 deleteBy2t eq x (y:ys) = if y `eq` x then ys else y : deleteBy2t eq x ys |
116 |
117 |
117 deleteFirstsBy2t :: (a -> b -> Bool) -> [a] -> [b] -> [a] |
118 deleteFirstsBy2t :: (a -> b -> Bool) -> [a] -> [b] -> [a] |
118 deleteFirstsBy2t eq = foldl (flip (deleteBy2t eq)) |
119 deleteFirstsBy2t eq = foldl (flip (deleteBy2t eq)) |
119 |
120 |
120 clientByHandle :: Handle -> [ClientInfo] -> Maybe ClientInfo |
121 --clientByHandle :: Handle -> [ClientInfo] -> Maybe ClientInfo |
121 clientByHandle chandle clients = find (\c -> handle c == chandle) clients |
122 --clientByHandle chandle clients = find (\c -> handle c == chandle) clients |
122 |
123 |
123 sameRoom :: HandlesSelector |
124 sameRoom :: HandlesSelector |
124 sameRoom client clients rooms = map handle $ filter (\ci -> room ci == room client) clients |
125 sameRoom client clients rooms = filter (\ci -> room ci == room client) clients |
125 |
126 |
126 noRoomSameProto :: HandlesSelector |
127 noRoomSameProto :: HandlesSelector |
127 noRoomSameProto client clients _ = map handle $ filter (null . room) $ filter (\ci -> protocol client == protocol ci) clients |
128 noRoomSameProto client clients _ = filter (null . room) $ filter (\ci -> protocol client == protocol ci) clients |
128 |
129 |
129 othersInRoom :: HandlesSelector |
130 othersInRoom :: HandlesSelector |
130 othersInRoom client clients rooms = map handle $ filter (client /=) $ filter (\ci -> room ci == room client) clients |
131 othersInRoom client clients rooms = filter (client /=) $ filter (\ci -> room ci == room client) clients |
131 |
132 |
132 fromRoom :: String -> HandlesSelector |
133 fromRoom :: String -> HandlesSelector |
133 fromRoom roomName _ clients _ = map handle $ filter (\ci -> room ci == roomName) clients |
134 fromRoom roomName _ clients _ = filter (\ci -> room ci == roomName) clients |
134 |
135 |
135 allClients :: HandlesSelector |
136 allClients :: HandlesSelector |
136 allClients _ clients _ = map handle $ clients |
137 allClients _ clients _ = clients |
137 |
138 |
138 clientOnly :: HandlesSelector |
139 clientOnly :: HandlesSelector |
139 clientOnly client _ _ = [handle client] |
140 clientOnly client _ _ = [client] |
140 |
141 |
141 noChangeClients :: ClientsTransform |
142 noChangeClients :: ClientsTransform |
142 noChangeClients a = a |
143 noChangeClients a = a |
143 |
144 |
144 modifyClient :: ClientInfo -> ClientsTransform |
145 modifyClient :: ClientInfo -> ClientsTransform |