netserver/HWProto.hs
changeset 1478 8bfb417d165e
parent 1473 60e1fad78d58
child 1483 89e24edb6020
--- a/netserver/HWProto.hs	Wed Nov 05 08:02:12 2008 +0000
+++ b/netserver/HWProto.hs	Fri Nov 07 15:58:36 2008 +0000
@@ -25,8 +25,8 @@
 answerBadCmd = [(clientOnly, ["ERROR", "Bad command, state or incorrect parameter"])]
 answerNotMaster = [(clientOnly, ["ERROR", "You cannot configure room parameters"])]
 answerBadParam = [(clientOnly, ["ERROR", "Bad parameter"])]
-answerQuit = [(clientOnly, ["BYE"])]
-answerAbandoned = [(othersInRoom, ["BYE"])]
+answerQuit msg = [(clientOnly, ["BYE", msg])]
+answerAbandoned = [(othersInRoom, ["BYE", "Room abandoned"])]
 answerQuitInform nick = [(othersInRoom, ["LEFT", nick])]
 answerNickChosen = [(clientOnly, ["ERROR", "The nick already chosen"])]
 answerNickChooseAnother = [(clientOnly, ["WARNING", "Choose another nick"])]
@@ -70,18 +70,19 @@
 
 -- Main state-independent cmd handler
 handleCmd :: CmdHandler
-handleCmd client _ rooms ("QUIT":xs) =
+handleCmd client _ rooms ("QUIT" : xs) =
 	if null (room client) then
-		(noChangeClients, noChangeRooms, answerQuit)
+		(noChangeClients, noChangeRooms, answerQuit msg)
 	else if isMaster client then
-		(noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
+		(noChangeClients, removeRoom (room client), (answerQuit msg) ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
 	else
-		(noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
+		(noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
 	where
 		clRoom = roomByName (room client) rooms
 		answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams
 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
 		newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom
+		msg = if not $ null xs then head xs else ""
 
 handleCmd _ _ _ ["PING"] = -- core requsted
 	(noChangeClients, noChangeRooms, answerPing)