netserver/HWProto.hs
changeset 1748 27dd2967fc65
parent 1742 cf97d1eecb12
child 1751 b67a124afe53
equal deleted inserted replaced
1747:44a6a9924c6d 1748:27dd2967fc65
    97 answerFullConfig room = concatMap toAnswer (Map.toList $ params room) ++ (answerClientOnly ["MAP", gamemap room])
    97 answerFullConfig room = concatMap toAnswer (Map.toList $ params room) ++ (answerClientOnly ["MAP", gamemap room])
    98 	where
    98 	where
    99 		toAnswer (paramName, paramStrs) =
    99 		toAnswer (paramName, paramStrs) =
   100 			answerClientOnly $ "CONFIG_PARAM" : paramName : paramStrs
   100 			answerClientOnly $ "CONFIG_PARAM" : paramName : paramStrs
   101 
   101 
   102 answerAllTeams protocol room = concatMap toAnswer (teams room)
   102 answerAllTeams protocol teams = concatMap toAnswer teams
   103 	where
   103 	where
   104 		toAnswer team =
   104 		toAnswer team =
   105 			(answerClientOnly $ teamToNet protocol team) ++
   105 			(answerClientOnly $ teamToNet protocol team) ++
   106 			(answerClientOnly ["TEAM_COLOR", teamname team, teamcolor team]) ++
   106 			(answerClientOnly ["TEAM_COLOR", teamname team, teamcolor team]) ++
   107 			(answerClientOnly ["HH_NUM", teamname team, show $ hhnum team])
   107 			(answerClientOnly ["HH_NUM", teamname team, show $ hhnum team])
   244 	else if roomPassword /= password clRoom then
   244 	else if roomPassword /= password clRoom then
   245 		(noChangeClients, noChangeRooms, answerWrongPassword)
   245 		(noChangeClients, noChangeRooms, answerWrongPassword)
   246 	else if isRestrictedJoins clRoom then
   246 	else if isRestrictedJoins clRoom then
   247 		(noChangeClients, noChangeRooms, answerRestricted)
   247 		(noChangeClients, noChangeRooms, answerRestricted)
   248 	else
   248 	else
   249 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, (answerJoined $ nick client) ++ answerNicks ++ answerReady ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams (protocol client) clRoom ++ watchRound)
   249 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, (answerJoined $ nick client) ++ answerNicks ++ answerReady ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerTeams ++ watchRound)
   250 	where
   250 	where
   251 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
   251 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
   252 		answerNicks = if not $ null sameRoomClients then
   252 		answerNicks = if not $ null sameRoomClients then
   253 					answerClientOnly $ ["JOINED"] ++ (map nick $ sameRoomClients)
   253 					answerClientOnly $ ["JOINED"] ++ (map nick $ sameRoomClients)
   254 				else
   254 				else
   259 		watchRound = if (roomProto clRoom < 20) || (not $ gameinprogress clRoom) then
   259 		watchRound = if (roomProto clRoom < 20) || (not $ gameinprogress clRoom) then
   260 					[]
   260 					[]
   261 				else
   261 				else
   262 					(answerClientOnly  ["RUN_GAME"]) ++
   262 					(answerClientOnly  ["RUN_GAME"]) ++
   263 					answerClientOnly ("GAMEMSG" : toEngineMsg "e$spectate 1" : (toList $ roundMsgs clRoom))
   263 					answerClientOnly ("GAMEMSG" : toEngineMsg "e$spectate 1" : (toList $ roundMsgs clRoom))
       
   264 		answerTeams = if gameinprogress clRoom then
       
   265 				answerAllTeams (protocol client) (teamsAtStart clRoom)
       
   266 			else
       
   267 				answerAllTeams (protocol client) (teams clRoom)
   264 
   268 
   265 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   269 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   266 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   270 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   267 
   271 
   268 handleCmd_noRoom client _ _ ["CHAT_STRING", msg] =
   272 handleCmd_noRoom client _ _ ["CHAT_STRING", msg] =
   369 			(noChangeClients, noChangeRooms, answerNotOwner)
   373 			(noChangeClients, noChangeRooms, answerNotOwner)
   370 		else
   374 		else
   371 			if not $ gameinprogress clRoom then
   375 			if not $ gameinprogress clRoom then
   372 				(noChangeClients, modifyRoom clRoom{teams = filter (\t -> teamName /= teamname t) $ teams clRoom}, answerRemoveTeam teamName)
   376 				(noChangeClients, modifyRoom clRoom{teams = filter (\t -> teamName /= teamname t) $ teams clRoom}, answerRemoveTeam teamName)
   373 			else
   377 			else
   374 				(noChangeClients, modifyRoom clRoom{leftTeams = teamName : leftTeams clRoom, roundMsgs = roundMsgs clRoom |> rmTeamMsg}, answerOthersRoom ["GAMEMSG", rmTeamMsg])
   378 				(noChangeClients,
       
   379 				modifyRoom clRoom{
       
   380 					teams = filter (\t -> teamName /= teamname t) $ teams clRoom,
       
   381 					leftTeams = teamName : leftTeams clRoom,
       
   382 					roundMsgs = roundMsgs clRoom |> rmTeamMsg
       
   383 					},
       
   384 				answerOthersRoom ["GAMEMSG", rmTeamMsg])
   375 	where
   385 	where
   376 		noSuchTeam = isNothing findTeam
   386 		noSuchTeam = isNothing findTeam
   377 		team = fromJust findTeam
   387 		team = fromJust findTeam
   378 		findTeam = find (\t -> teamName == teamname t) $ teams clRoom
   388 		findTeam = find (\t -> teamName == teamname t) $ teams clRoom
   379 		clRoom = roomByName (room client) rooms
   389 		clRoom = roomByName (room client) rooms
   389 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1
   399 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1
   390 
   400 
   391 handleCmd_inRoom client _ rooms ["START_GAME"] =
   401 handleCmd_inRoom client _ rooms ["START_GAME"] =
   392 	if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then
   402 	if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then
   393 		if enoughClans then
   403 		if enoughClans then
   394 			(noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty, leftTeams = []}, answerRunGame)
   404 			(noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty, leftTeams = [], teamsAtStart = teams clRoom}, answerRunGame)
   395 		else
   405 		else
   396 			(noChangeClients, noChangeRooms, answerTooFewClans)
   406 			(noChangeClients, noChangeRooms, answerTooFewClans)
   397 	else
   407 	else
   398 		(noChangeClients, noChangeRooms, [])
   408 		(noChangeClients, noChangeRooms, [])
   399 	where
   409 	where
   418 		clRoom = roomByName (room client) rooms
   428 		clRoom = roomByName (room client) rooms
   419 		newStatus = not $ isRestrictedTeams clRoom
   429 		newStatus = not $ isRestrictedTeams clRoom
   420 
   430 
   421 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] =
   431 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] =
   422 	if isMaster client then
   432 	if isMaster client then
   423 		(modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty, leftTeams = []}, answerAllNotReady ++ answerRemovedTeams)
   433 		(modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty, leftTeams = [], teamsAtStart = []}, answerAllNotReady ++ answerRemovedTeams)
   424 	else
   434 	else
   425 		(noChangeClients, noChangeRooms, [])
   435 		(noChangeClients, noChangeRooms, [])
   426 	where
   436 	where
   427 		clRoom = roomByName (room client) rooms
   437 		clRoom = roomByName (room client) rooms
   428 		sameRoomClients = filter (\ci -> room ci == name clRoom) clients
   438 		sameRoomClients = filter (\ci -> room ci == name clRoom) clients