netserver/HWProto.hs
changeset 1598 c853e02ed663
parent 1596 4a7b9e451cb4
child 1599 65b5d3cd3e01
equal deleted inserted replaced
1597:24f2f9fa0160 1598:c853e02ed663
    19 makeAnswer func msg = [\_ -> (func, msg)]
    19 makeAnswer func msg = [\_ -> (func, msg)]
    20 answerClientOnly, answerOthersRoom, answerSameRoom :: [String] -> [Answer]
    20 answerClientOnly, answerOthersRoom, answerSameRoom :: [String] -> [Answer]
    21 answerClientOnly  = makeAnswer clientOnly
    21 answerClientOnly  = makeAnswer clientOnly
    22 answerOthersRoom  = makeAnswer othersInRoom
    22 answerOthersRoom  = makeAnswer othersInRoom
    23 answerSameRoom    = makeAnswer sameRoom
    23 answerSameRoom    = makeAnswer sameRoom
    24 answerFromRoom roomName = makeAnswer (fromRoom roomName)
       
    25 answerSameProtoLobby = makeAnswer sameProtoLobbyClients
    24 answerSameProtoLobby = makeAnswer sameProtoLobbyClients
    26 answerAll         = makeAnswer allClients
    25 answerAll         = makeAnswer allClients
    27 
    26 
    28 answerBadCmd            = answerClientOnly ["ERROR", "Bad command, state or incorrect parameter"]
    27 answerBadCmd            = answerClientOnly ["ERROR", "Bad command, state or incorrect parameter"]
    29 answerNotMaster         = answerClientOnly ["ERROR", "You cannot configure room parameters"]
    28 answerNotMaster         = answerClientOnly ["ERROR", "You cannot configure room parameters"]
    68 	if not $ null msg then
    67 	if not $ null msg then
    69 		answerOthersRoom ["LEFT", nick, msg]
    68 		answerOthersRoom ["LEFT", nick, msg]
    70 		else
    69 		else
    71 		answerOthersRoom ["LEFT", nick]
    70 		answerOthersRoom ["LEFT", nick]
    72 
    71 
    73 answerPartInform nick roomName = answerFromRoom roomName ["LEFT", nick, "bye room"]
    72 answerPartInform nick = answerOthersRoom ["LEFT", nick, "bye room"]
    74 answerQuitLobby nick msg =
    73 answerQuitLobby nick msg =
    75 	if not $ null nick then
    74 	if not $ null nick then
    76 		if not $ null msg then
    75 		if not $ null msg then
    77 			answerAll ["LOBBY:LEFT", nick, msg]
    76 			answerAll ["LOBBY:LEFT", nick, msg]
    78 		else
    77 		else
   268 	where
   267 	where
   269 		clRoom = roomByName (room client) rooms
   268 		clRoom = roomByName (room client) rooms
   270 
   269 
   271 handleCmd_inRoom client _ rooms ["PART"] =
   270 handleCmd_inRoom client _ rooms ["PART"] =
   272 	if isMaster client then
   271 	if isMaster client then
   273 		(modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client))
   272 		(modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False, isMaster = False}), removeRoom (room client), (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client))
   274 	else
   273 	else
   275 		(modifyClient client{room = [], isReady = False}, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerPartInform (room client) (nick client)) ++ answerRemoveClientTeams)
   274 		(modifyClient client{isReady = False, partRoom = True}, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerPartInform (nick client)) ++ answerRemoveClientTeams)
   276 	where
   275 	where
   277 		clRoom = roomByName (room client) rooms
   276 		clRoom = roomByName (room client) rooms
   278 		answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams
   277 		answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams
   279 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
   278 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
   280 		newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom
   279 		newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom