gameServer/Actions.hs
branchwebgl
changeset 9127 e350500c4edb
parent 8833 c13ebed437cb
parent 9062 a65492ca1587
child 9160 fc46e75f6b72
--- a/gameServer/Actions.hs	Thu Apr 04 14:37:19 2013 +0200
+++ b/gameServer/Actions.hs	Tue Jun 04 22:28:12 2013 +0200
@@ -20,6 +20,7 @@
 import Control.Exception
 import System.Process
 import Network.Socket
+import System.Random
 -----------------------------
 #if defined(OFFICIAL_SERVER)
 import OfficialServer.GameReplayStore
@@ -206,8 +207,9 @@
     rnc <- gets roomsClients
     newMasterId <- liftM (\ids -> fromMaybe (last . filter (/= ci) $ ids) delegateId) . io $ roomClientsIndicesM rnc ri
     newMaster <- io $ client'sM rnc id newMasterId
+    oldMasterId <- io $ room'sM rnc masterID ri
+    oldMaster <- io $ client'sM rnc id oldMasterId
     oldRoomName <- io $ room'sM rnc name ri
-    oldMaster <- client's nick
     kicked <- client's isKickedFromServer
     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
     let newRoomName = if (proto < 42) || kicked then nick newMaster else oldRoomName
@@ -216,12 +218,13 @@
                 , name = newRoomName
                 , isRestrictedJoins = False
                 , isRestrictedTeams = False
-                , isRegisteredOnly = False
-                , readyPlayers = if isReady newMaster then readyPlayers r else readyPlayers r + 1})
-        , ModifyClient2 newMasterId (\c -> c{isMaster = True, isReady = True})
+                , isRegisteredOnly = False}
+                )
+        , ModifyClient2 newMasterId (\c -> c{isMaster = True})
+        , ModifyClient2 oldMasterId (\c -> c{isMaster = False})
         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
-        , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster]
-        , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+hr", nick newMaster]
+        , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", nick oldMaster]
+        , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+h", nick newMaster]
         ]
 
     newRoom' <- io $ room'sM rnc id ri
@@ -381,7 +384,7 @@
         if p < 38 then
             processAction $ ByeClient $ loc "Nickname is already in use"
             else
-            processAction $ NoticeMessage NickAlreadyInUse
+            mapM_ processAction [NoticeMessage NickAlreadyInUse, ModifyClient $ \c -> c{nick = B.empty}]
         else
         do
         db <- gets (dbQueries . serverInfo)
@@ -615,6 +618,12 @@
     processAction $ Warning versionsStats
 
 
+processAction (Random chans items) = do
+    let i = if null items then ["heads", "tails"] else items
+    n <- io $ randomRIO (0, length i - 1)
+    processAction $ AnswerClients chans ["CHAT", "[random]", i !! n]
+
+
 #if defined(OFFICIAL_SERVER)
 processAction SaveReplay = do
     ri <- clientRoomA