netserver/HWProto.hs
changeset 1596 4a7b9e451cb4
parent 1592 5ee77ee470a6
child 1598 c853e02ed663
equal deleted inserted replaced
1595:33529f567d2d 1596:4a7b9e451cb4
    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)
    24 answerSameProtoLobby = makeAnswer sameProtoLobbyClients
    25 answerSameProtoLobby = makeAnswer sameProtoLobbyClients
    25 answerAll         = makeAnswer allClients
    26 answerAll         = makeAnswer allClients
    26 
    27 
    27 answerBadCmd            = answerClientOnly ["ERROR", "Bad command, state or incorrect parameter"]
    28 answerBadCmd            = answerClientOnly ["ERROR", "Bad command, state or incorrect parameter"]
    28 answerNotMaster         = answerClientOnly ["ERROR", "You cannot configure room parameters"]
    29 answerNotMaster         = answerClientOnly ["ERROR", "You cannot configure room parameters"]
    67 	if not $ null msg then
    68 	if not $ null msg then
    68 		answerOthersRoom ["LEFT", nick, msg]
    69 		answerOthersRoom ["LEFT", nick, msg]
    69 		else
    70 		else
    70 		answerOthersRoom ["LEFT", nick]
    71 		answerOthersRoom ["LEFT", nick]
    71 
    72 
    72 answerPartInform nick = answerOthersRoom ["LEFT", nick, "bye room"]
    73 answerPartInform nick roomName = answerFromRoom roomName ["LEFT", nick, "bye room"]
    73 answerQuitLobby nick msg =
    74 answerQuitLobby nick msg =
    74 	if not $ null nick then
    75 	if not $ null nick then
    75 		if not $ null msg then
    76 		if not $ null msg then
    76 			answerAll ["LOBBY:LEFT", nick, msg]
    77 			answerAll ["LOBBY:LEFT", nick, msg]
    77 		else
    78 		else
   230 	else if roomPassword /= password clRoom then
   231 	else if roomPassword /= password clRoom then
   231 		(noChangeClients, noChangeRooms, answerWrongPassword)
   232 		(noChangeClients, noChangeRooms, answerWrongPassword)
   232 	else if isRestrictedJoins clRoom then
   233 	else if isRestrictedJoins clRoom then
   233 		(noChangeClients, noChangeRooms, answerRestricted)
   234 		(noChangeClients, noChangeRooms, answerRestricted)
   234 	else
   235 	else
   235 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ answerReady ++ (answerJoined $ nick client) ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom ++ watchRound)
   236 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, (answerJoined $ nick client) ++ answerNicks ++ answerReady ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom ++ watchRound)
   236 	where
   237 	where
   237 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
   238 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
   238 		answerNicks = answerClientOnly $ ["JOINED"] ++ (map nick $ sameRoomClients)
   239 		answerNicks = answerClientOnly $ ["JOINED"] ++ (map nick $ sameRoomClients)
   239 		answerReady = concatMap (\c -> answerClientOnly [if isReady c then "READY" else "NOT_READY", nick c]) sameRoomClients
   240 		answerReady = concatMap (\c -> answerClientOnly [if isReady c then "READY" else "NOT_READY", nick c]) sameRoomClients
   240 		sameRoomClients = filter (\ci -> room ci == roomName) clients
   241 		sameRoomClients = filter (\ci -> room ci == roomName) clients
   269 
   270 
   270 handleCmd_inRoom client _ rooms ["PART"] =
   271 handleCmd_inRoom client _ rooms ["PART"] =
   271 	if isMaster client then
   272 	if isMaster client then
   272 		(modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client))
   273 		(modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client))
   273 	else
   274 	else
   274 		(modifyClient client{room = [], isReady = False}, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerPartInform (nick client)) ++ answerRemoveClientTeams)
   275 		(modifyClient client{room = [], isReady = False}, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerPartInform (room client) (nick client)) ++ answerRemoveClientTeams)
   275 	where
   276 	where
   276 		clRoom = roomByName (room client) rooms
   277 		clRoom = roomByName (room client) rooms
   277 		answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams
   278 		answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams
   278 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
   279 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
   279 		newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom
   280 		newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom