gameServer/HandlerUtils.hs
branchsdl2transition
changeset 11362 ed5a6478e710
parent 11046 47a8c19ecb60
child 15878 fc3cb23fd26f
--- a/gameServer/HandlerUtils.hs	Tue Nov 10 18:16:35 2015 +0100
+++ b/gameServer/HandlerUtils.hs	Tue Nov 10 20:43:13 2015 +0100
@@ -1,3 +1,21 @@
+{-
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ \-}
+
 module HandlerUtils where
 
 import Control.Monad.Reader
@@ -8,6 +26,8 @@
 import CoreTypes
 
 
+type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
+
 thisClient :: Reader (ClientIndex, IRnC) ClientInfo
 thisClient = do
     (ci, rnc) <- ask
@@ -66,3 +86,10 @@
     let allClientIDs = allClients rnc
     return $ find (\clId -> let cl = client rnc clId in n == nick cl && not (isChecker cl)) allClientIDs
 
+
+roomAdminOnly :: Reader (ClientIndex, IRnC) [Action] -> Reader (ClientIndex, IRnC) [Action]
+roomAdminOnly h = thisClient >>= \cl -> if isMaster cl then h else return []
+
+
+serverAdminOnly :: Reader (ClientIndex, IRnC) [Action] -> Reader (ClientIndex, IRnC) [Action]
+serverAdminOnly h = thisClient >>= \cl -> if isAdministrator cl then h else return []