|
1 {- |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 \-} |
|
18 |
1 module HandlerUtils where |
19 module HandlerUtils where |
2 |
20 |
3 import Control.Monad.Reader |
21 import Control.Monad.Reader |
4 import qualified Data.ByteString.Char8 as B |
22 import qualified Data.ByteString.Char8 as B |
5 import Data.List |
23 import Data.List |
6 |
24 |
7 import RoomsAndClients |
25 import RoomsAndClients |
8 import CoreTypes |
26 import CoreTypes |
9 |
27 |
|
28 |
|
29 type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action] |
10 |
30 |
11 thisClient :: Reader (ClientIndex, IRnC) ClientInfo |
31 thisClient :: Reader (ClientIndex, IRnC) ClientInfo |
12 thisClient = do |
32 thisClient = do |
13 (ci, rnc) <- ask |
33 (ci, rnc) <- ask |
14 return $ rnc `client` ci |
34 return $ rnc `client` ci |
64 clientByNick n = do |
84 clientByNick n = do |
65 (_, rnc) <- ask |
85 (_, rnc) <- ask |
66 let allClientIDs = allClients rnc |
86 let allClientIDs = allClients rnc |
67 return $ find (\clId -> let cl = client rnc clId in n == nick cl && not (isChecker cl)) allClientIDs |
87 return $ find (\clId -> let cl = client rnc clId in n == nick cl && not (isChecker cl)) allClientIDs |
68 |
88 |
|
89 |
|
90 roomAdminOnly :: Reader (ClientIndex, IRnC) [Action] -> Reader (ClientIndex, IRnC) [Action] |
|
91 roomAdminOnly h = thisClient >>= \cl -> if isMaster cl then h else return [] |
|
92 |
|
93 |
|
94 serverAdminOnly :: Reader (ClientIndex, IRnC) [Action] -> Reader (ClientIndex, IRnC) [Action] |
|
95 serverAdminOnly h = thisClient >>= \cl -> if isAdministrator cl then h else return [] |