- Room save/load into/from file
- Vote on map (not complete implementation, also voting itself is still buggy)
--- a/gameServer/Actions.hs Thu Mar 13 23:25:31 2014 +0400
+++ b/gameServer/Actions.hs Fri Mar 14 00:42:04 2014 +0400
@@ -777,6 +777,15 @@
, [AnswerClients [c] ["KICKED"]]
]
+processAction (SaveRoom rname) = do
+ rnc <- gets roomsClients
+ ri <- clientRoomA
+ rm <- io $ room'sM rnc id ri
+ liftIO $ writeFile (B.unpack rname) $ show (greeting rm, roomSaves rm)
+
+processAction (LoadRoom rname) = do
+ (g, rs) <- liftIO $ liftM read $ readFile (B.unpack rname)
+ processAction $ ModifyRoom $ \r -> r{greeting = g, roomSaves = rs}
processAction Cleanup = do
jm <- gets joinsMonitor
--- a/gameServer/CoreTypes.hs Thu Mar 13 23:25:31 2014 +0400
+++ b/gameServer/CoreTypes.hs Fri Mar 14 00:42:04 2014 +0400
@@ -79,6 +79,8 @@
| ShowReplay B.ByteString
| Cleanup
| RegisterEvent Event
+ | SaveRoom B.ByteString
+ | LoadRoom B.ByteString
data Event = LobbyChatMessage
@@ -293,6 +295,7 @@
data VoteType = VoteKick B.ByteString
+ | VoteMap B.ByteString
newVoting :: VoteType -> Voting
--- a/gameServer/HWProtoCore.hs Thu Mar 13 23:25:31 2014 +0400
+++ b/gameServer/HWProtoCore.hs Fri Mar 14 00:42:04 2014 +0400
@@ -36,6 +36,8 @@
handleCmd ["CMD", parameters] = uncurry h $ extractParameters parameters
where
h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n]
+ h "SAVEROOM" n | not $ B.null n = handleCmd ["SAVEROOM", n]
+ h "LOADROOM" n | not $ B.null n = handleCmd ["LOADROOM", n]
h "SAVE" n | not $ B.null n = handleCmd ["SAVE", n]
h "DELETE" n | not $ B.null n = handleCmd ["DELETE", n]
h "STATS" _ = handleCmd ["STATS"]
@@ -57,7 +59,7 @@
| 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]]
+ 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)
--- a/gameServer/HWProtoInRoomState.hs Thu Mar 13 23:25:31 2014 +0400
+++ b/gameServer/HWProtoInRoomState.hs Fri Mar 14 00:42:04 2014 +0400
@@ -375,7 +375,7 @@
handleCmd_inRoom ["CALLVOTE"] = do
cl <- thisClient
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", "Available callvote commands: kick <nickname>"]]
+ return [AnswerClients [sendChan cl] ["CHAT", "[server]", "Available callvote commands: kick <nickname>, map <name>"]]
handleCmd_inRoom ["CALLVOTE", "KICK"] = do
cl <- thisClient
@@ -397,6 +397,17 @@
else
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: no such user"]]
+
+handleCmd_inRoom ["CALLVOTE", "MAP", roomSave] = do
+ cl <- thisClient
+ rm <- thisRoom
+
+ if Map.member roomSave $ roomSaves rm then
+ startVote $ VoteMap roomSave
+ else
+ return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote map: no such map"]]
+
+
handleCmd_inRoom ["VOTE", m] = do
cl <- thisClient
let b = if m == "YES" then Just True else if m == "NO" then Just False else Nothing
@@ -412,7 +423,13 @@
handleCmd_inRoom ["DELETE", stateName] = serverAdminOnly $ do
return [ModifyRoom $ \r -> r{roomSaves = Map.delete stateName (roomSaves r)}]
+handleCmd_inRoom ["SAVEROOM", fileName] = serverAdminOnly $ do
+ return [SaveRoom fileName]
+handleCmd_inRoom ["LOADROOM", fileName] = serverAdminOnly $ do
+ return [LoadRoom fileName]
+
+
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)"]
--- a/gameServer/Votes.hs Thu Mar 13 23:25:31 2014 +0400
+++ b/gameServer/Votes.hs Fri Mar 14 00:42:04 2014 +0400
@@ -6,6 +6,7 @@
import ServerState
import qualified Data.ByteString.Char8 as B
import qualified Data.List as L
+import qualified Data.Map as Map
import Data.Maybe
-------------------
import Utils
@@ -61,6 +62,12 @@
&& sameRoom
&& ((isNothing $ gameInfo rm) || teamsInGame kickCl == 0)
]
+ act (VoteMap roomSave) = do
+ rm <- thisRoom
+ let rs = Map.lookup roomSave (roomSaves rm)
+ case rs of
+ Nothing -> return []
+ Just (mp, p) -> return [ModifyRoom $ \r -> r{params = p, mapParams = mp}]
startVote :: VoteType -> Reader (ClientIndex, IRnC) [Action]
@@ -86,4 +93,4 @@
voteInfo :: VoteType -> B.ByteString
voteInfo (VoteKick n) = B.concat [loc "kick", " ", n]
-
+voteInfo (VoteMap n) = B.concat [loc "map", " ", n]