unc0rr's patch from
issue #144 - prevent spectators from ruining the game
--- a/gameServer/Actions.hs Thu Jul 09 00:56:26 2009 +0000
+++ b/gameServer/Actions.hs Thu Jul 09 14:36:41 2009 +0000
@@ -178,7 +178,7 @@
processAction (
clID,
serverInfo,
- adjust (\cl -> cl{roomID = rID}) clID clients,
+ adjust (\cl -> cl{roomID = rID, teamsInGame = if rID == 0 then teamsInGame cl else 0}) clID clients,
adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r), playersIn = (playersIn r) + 1}) rID $
adjust (\r -> r{playersIDs = IntSet.delete clID (playersIDs r)}) 0 rooms
) joinMsg
@@ -204,7 +204,7 @@
return (
clID,
serverInfo,
- adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False}) clID newClients,
+ adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined}) clID newClients,
adjust (\r -> r{
playersIDs = IntSet.delete clID (playersIDs r),
playersIn = (playersIn r) - 1,
@@ -244,7 +244,7 @@
processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["ROOMABANDONED", name room]
return (clID,
serverInfo,
- Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False, isReady = False} else cl) clients,
+ Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined} else cl) clients,
delete rID $ adjust (\r -> r{playersIDs = IntSet.union (playersIDs room) (playersIDs r)}) 0 rooms
)
where
--- a/gameServer/CoreTypes.hs Thu Jul 09 00:56:26 2009 +0000
+++ b/gameServer/CoreTypes.hs Thu Jul 09 14:36:41 2009 +0000
@@ -28,7 +28,8 @@
pingsQueue :: !Word,
isMaster :: Bool,
isReady :: Bool,
- isAdministrator :: Bool
+ isAdministrator :: Bool,
+ teamsInGame :: Word
}
instance Show ClientInfo where
--- a/gameServer/HWProtoInRoomState.hs Thu Jul 09 00:56:26 2009 +0000
+++ b/gameServer/HWProtoInRoomState.hs Thu Jul 09 14:36:41 2009 +0000
@@ -58,6 +58,7 @@
[Warning "restricted"]
else
[ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}),
+ ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1}),
AnswerThisClient ["TEAM_ACCEPTED", name],
AnswerOthersInRoom $ teamToNet newTeam,
AnswerOthersInRoom ["TEAM_COLOR", name, color]
@@ -81,7 +82,9 @@
if not $ nick client == teamowner team then
[ProtocolError "Not team owner!"]
else
- [RemoveTeam teamName]
+ [RemoveTeam teamName,
+ ModifyClient (\c -> c{teamsInGame = teamsInGame c - 1})
+ ]
where
client = clients IntMap.! clID
room = rooms IntMap.! (roomID client)
@@ -155,10 +158,14 @@
enoughClans = not $ null $ drop 1 $ group $ map teamcolor $ teams room
-handleCmd_inRoom _ _ rooms ["EM", msg] =
- [ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}),
- AnswerOthersInRoom ["EM", msg]]
-
+handleCmd_inRoom clID clients rooms ["EM", msg] =
+ if teamsInGame client > 0 then
+ [ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}),
+ AnswerOthersInRoom ["EM", msg]]
+ else
+ []
+ where
+ client = clients IntMap.! clID
handleCmd_inRoom clID clients rooms ["ROUNDFINISHED"] =
if isMaster client then
--- a/gameServer/NetRoutines.hs Thu Jul 09 00:56:26 2009 +0000
+++ b/gameServer/NetRoutines.hs Thu Jul 09 14:36:41 2009 +0000
@@ -45,6 +45,7 @@
False
False
False
+ undefined
)
writeChan coreChan $ Accept newClient
--- a/gameServer/OfficialServer/DBInteraction.hs Thu Jul 09 00:56:26 2009 +0000
+++ b/gameServer/OfficialServer/DBInteraction.hs Thu Jul 09 14:36:41 2009 +0000
@@ -28,6 +28,7 @@
writeChan (coreChan serverInfo) $ ClientAccountInfo (clUid,
if clHost `elem` localAddressList then Admin else Guest)
ClearCache -> return ()
+ SendStats {} -> return ()
fakeDbConnection serverInfo