netserver/HWProto.hs
changeset 1406 08b9c28419f1
parent 1404 2b6b6809c2e4
child 1407 b44fbb630fb6
equal deleted inserted replaced
1405:ee4b28a1861d 1406:08b9c28419f1
    52 			(clientOnly, ["TEAM_COLOR", teamname team, teamcolor team]),
    52 			(clientOnly, ["TEAM_COLOR", teamname team, teamcolor team]),
    53 			(clientOnly, ["HH_NUM", teamname team, show $ hhnum team])]
    53 			(clientOnly, ["HH_NUM", teamname team, show $ hhnum team])]
    54 answerMap mapName = [(othersInRoom, ["MAP", mapName])]
    54 answerMap mapName = [(othersInRoom, ["MAP", mapName])]
    55 answerRunGame = [(sameRoom, ["RUN_GAME"])]
    55 answerRunGame = [(sameRoom, ["RUN_GAME"])]
    56 answerCannotCreateRoom = [(clientOnly, ["WARNING", "Cannot create more rooms"])]
    56 answerCannotCreateRoom = [(clientOnly, ["WARNING", "Cannot create more rooms"])]
    57 answerReady nick = [(sameRoom, ["READY", nick])]
    57 answerIsReady nick = [(sameRoom, ["READY", nick])]
    58 answerNotReady nick = [(sameRoom, ["NOT_READY", nick])]
    58 answerNotReady nick = [(sameRoom, ["NOT_READY", nick])]
    59 
    59 
    60 
    60 
    61 -- Main state-independent cmd handler
    61 -- Main state-independent cmd handler
    62 handleCmd :: CmdHandler
    62 handleCmd :: CmdHandler
   139 	if noSuchRoom then
   139 	if noSuchRoom then
   140 		(noChangeClients, noChangeRooms, answerNoRoom)
   140 		(noChangeClients, noChangeRooms, answerNoRoom)
   141 	else if roomPassword /= password clRoom then
   141 	else if roomPassword /= password clRoom then
   142 		(noChangeClients, noChangeRooms, answerWrongPassword)
   142 		(noChangeClients, noChangeRooms, answerWrongPassword)
   143 	else
   143 	else
   144 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ (answerJoined $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
   144 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ answerReady ++ (answerJoined $ nick client) ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
   145 	where
   145 	where
   146 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
   146 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
   147 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
   147 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ sameRoomClients))]
       
   148 		answerReady = map (\c -> (clientOnly, [if isReady c then "READY" else "NOT_READY", nick c])) sameRoomClients
       
   149 		sameRoomClients = filter (\ci -> room ci == roomName) clients
   148 		clRoom = roomByName roomName rooms
   150 		clRoom = roomByName roomName rooms
   149 
   151 
   150 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   152 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   151 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   153 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   152 
   154 
   234 handleCmd_inRoom client _ rooms ["TOGGLE_READY"] =
   236 handleCmd_inRoom client _ rooms ["TOGGLE_READY"] =
   235 	if isReady client then
   237 	if isReady client then
   236 		(modifyClient client{isReady = False}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, (answerNotReady $ nick client))
   238 		(modifyClient client{isReady = False}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, (answerNotReady $ nick client))
   237 	else
   239 	else
   238 		if (playersIn clRoom) == newReadyPlayers then
   240 		if (playersIn clRoom) == newReadyPlayers then
   239 			(modifyClient client{isReady = True}, modifyRoom clRoom{gameinprogress = True, readyPlayers = newReadyPlayers}, (answerReady $ nick client) ++ answerRunGame)
   241 			(modifyClient client{isReady = True}, modifyRoom clRoom{gameinprogress = True, readyPlayers = newReadyPlayers}, (answerIsReady $ nick client) ++ answerRunGame)
   240 		else
   242 		else
   241 			(modifyClient client{isReady = True}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerReady $ nick client)
   243 			(modifyClient client{isReady = True}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerIsReady $ nick client)
   242 	where
   244 	where
   243 		clRoom = roomByName (room client) rooms
   245 		clRoom = roomByName (room client) rooms
   244 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1
   246 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1
   245 
   247 
   246 handleCmd_inRoom client _ rooms ["ROUNDFINISHED"] =
   248 handleCmd_inRoom client _ rooms ["ROUNDFINISHED"] =