--- a/gameServer/HWProtoInRoomState.hs Sun Oct 21 01:28:33 2012 +0400
+++ b/gameServer/HWProtoInRoomState.hs Sat Nov 03 00:34:35 2012 +0400
@@ -3,7 +3,7 @@
import qualified Data.Map as Map
import Data.Sequence((|>))
-import Data.List
+import Data.List as L
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import Control.Monad
@@ -52,6 +52,13 @@
clNick <- clientNick
clChan <- thisClientChans
othChans <- roomOthersChans
+ roomChans <- roomClientsChans
+ cl <- thisClient
+ teamColor <-
+ if clientProto cl < 42 then
+ return color
+ else
+ liftM (head . (L.\\) (map B.singleton ['0'..]) . map teamcolor . teams) thisRoom
return $
if not . null . drop (maxTeams rm - 1) $ teams rm then
[Warning "too many teams"]
@@ -64,16 +71,17 @@
else if isRestrictedTeams rm then
[Warning "restricted"]
else
- [ModifyRoom (\r -> r{teams = teams r ++ [newTeam ci clNick r]}),
- ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just color}),
+ [ModifyRoom (\r -> r{teams = teams r ++ [newTeam ci clNick r teamColor]}),
+ SendUpdateOnThisRoom,
+ ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just teamColor}),
AnswerClients clChan ["TEAM_ACCEPTED", tName],
- AnswerClients othChans $ teamToNet $ newTeam ci clNick rm,
- AnswerClients othChans ["TEAM_COLOR", tName, color]
+ AnswerClients othChans $ teamToNet $ newTeam ci clNick rm teamColor,
+ AnswerClients roomChans ["TEAM_COLOR", tName, teamColor]
]
where
canAddNumber r = 48 - (sum . map hhnum $ teams r)
findTeam = find (\t -> tName == teamname t) . teams
- newTeam ci clNick r = TeamInfo ci clNick tName color grave fort voicepack flag dif (newTeamHHNum r) (hhsList hhsInfo)
+ newTeam ci clNick r tColor = TeamInfo ci clNick tName tColor grave fort voicepack flag dif (newTeamHHNum r) (hhsList hhsInfo)
dif = readInt_ difStr
hhsList [] = []
hhsList [_] = error "Hedgehogs list with odd elements number"
@@ -99,6 +107,7 @@
[ProtocolError "Not team owner!"]
else
[RemoveTeam tName,
+ SendUpdateOnThisRoom,
ModifyClient
(\c -> c{
teamsInGame = teamsInGame c - 1,
@@ -157,14 +166,17 @@
handleCmd_inRoom ["TOGGLE_READY"] = do
cl <- thisClient
chans <- roomClientsChans
- return [
- ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}),
- ModifyClient (\c -> c{isReady = not $ isReady cl}),
- AnswerClients chans $ if clientProto cl < 38 then
- [if isReady cl then "NOT_READY" else "READY", nick cl]
- else
- ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl]
- ]
+ if isMaster cl then
+ return []
+ else
+ return [
+ ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}),
+ ModifyClient (\c -> c{isReady = not $ isReady cl}),
+ AnswerClients chans $ if clientProto cl < 38 then
+ [if isReady cl then "NOT_READY" else "READY", nick cl]
+ else
+ ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl]
+ ]
handleCmd_inRoom ["START_GAME"] = do
(ci, rnc) <- ask
@@ -184,6 +196,7 @@
}
)
, AnswerClients chans ["RUN_GAME"]
+ , SendUpdateOnThisRoom
, AnswerClients chans $ "CLIENT_FLAGS" : "+g" : nicks
, ModifyRoomClients (\c -> c{isInGame = True})
]