--- a/gameServer/CoreTypes.hs Tue Jan 21 21:16:52 2014 +0100
+++ b/gameServer/CoreTypes.hs Wed Jan 22 01:11:13 2014 +0400
@@ -183,6 +183,7 @@
isRegisteredOnly :: Bool,
isSpecial :: Bool,
greeting :: B.ByteString,
+ voting :: Maybe Voting,
roomBansList :: ![B.ByteString],
mapParams :: Map.Map B.ByteString B.ByteString,
params :: Map.Map B.ByteString [B.ByteString]
@@ -204,6 +205,7 @@
False
False
""
+ Nothing
[]
(
Map.fromList $ Prelude.zip
@@ -264,6 +266,21 @@
False
[]
+data Voting = Voting {
+ voteTTL :: Int,
+ entitledToVote :: [Unique],
+ votes :: [(Unique, Bool)],
+ voteType :: VoteType
+ }
+
+
+data VoteType = VoteKick B.ByteString
+
+
+newVote :: VoteType -> Voting
+newVote = Voting 2 [] []
+
+
data AccountInfo =
HasAccount B.ByteString Bool Bool
| Guest
--- a/gameServer/HWProtoCore.hs Tue Jan 21 21:16:52 2014 +0100
+++ b/gameServer/HWProtoCore.hs Wed Jan 22 01:11:13 2014 +0400
@@ -33,10 +33,7 @@
else
return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})]
-handleCmd ["CMD", parameters] = do
- let (cmd, plist) = B.break (== ' ') parameters
- let param = B.dropWhile (== ' ') plist
- h (upperCase cmd) param
+handleCmd ["CMD", parameters] = uncurry h $ extractParameters parameters
where
h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n]
h "STATS" _ = handleCmd ["STATS"]
@@ -54,8 +51,15 @@
h "FIX" _ = handleCmd ["FIX"]
h "UNFIX" _ = handleCmd ["UNFIX"]
h "GREETING" msg = handleCmd ["GREETING", msg]
+ h "CALLVOTE" msg | B.null msg = handleCmd ["CALLVOTE"]
+ | otherwise = let (c, p) = extractParameters msg in
+ if B.null p then handleCmd ["CALLVOTE", c] else handleCmd ["CALLVOTE", c, p]
+ h "VOTE" msg = handleCmd ["VOTE", upperCase msg]
h c p = return [Warning $ B.concat ["Unknown cmd: /", c, p]]
+ extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b)
+
+
handleCmd cmd = do
(ci, irnc) <- ask
let cl = irnc `client` ci
--- a/gameServer/HWProtoInRoomState.hs Tue Jan 21 21:16:52 2014 +0100
+++ b/gameServer/HWProtoInRoomState.hs Wed Jan 22 01:11:13 2014 +0400
@@ -14,7 +14,7 @@
import HandlerUtils
import RoomsAndClients
import EngineInteraction
-
+import Votes
startGame :: Reader (ClientIndex, IRnC) [Action]
startGame = do
@@ -397,6 +397,35 @@
rm <- thisRoom
return [ModifyRoom (\r -> r{greeting = msg}) | isAdministrator cl || (isMaster cl && (not $ isSpecial rm))]
+
+handleCmd_inRoom ["CALLVOTE"] = do
+ cl <- thisClient
+ return [AnswerClients [sendChan cl] ["CHAT", "[server]", "Available callvote commands: kick <nickname>"]]
+
+handleCmd_inRoom ["CALLVOTE", "KICK"] = do
+ cl <- thisClient
+ return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: specify nickname"]]
+
+handleCmd_inRoom ["CALLVOTE", "KICK", nickname] = do
+ (thisClientId, rnc) <- ask
+ cl <- thisClient
+ maybeClientId <- clientByNick nickname
+ let kickId = fromJust maybeClientId
+ let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
+
+ if isJust maybeClientId && sameRoom then
+ startVote $ VoteKick nickname
+ else
+ return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: no such user"]]
+
+handleCmd_inRoom ["VOTE", m] = do
+ cl <- thisClient
+ let b = if m == "YES" then Just True else if m == "NO" then Just False else Nothing
+ if isJust b then
+ voted (clUID cl) (fromJust b)
+ else
+ return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]]
+
handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17)
handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"]