netserver/HWProto.hs
changeset 1742 cf97d1eecb12
parent 1725 38a074db049c
child 1748 27dd2967fc65
equal deleted inserted replaced
1741:1bec3a7bca37 1742:cf97d1eecb12
   258 		clRoom = roomByName roomName rooms
   258 		clRoom = roomByName roomName rooms
   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" : "DGUkc3BlY3RhdGUgMQ==" : (toList $ roundMsgs clRoom))
   263 					answerClientOnly ("GAMEMSG" : toEngineMsg "e$spectate 1" : (toList $ roundMsgs clRoom))
   264 
   264 
   265 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   265 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   266 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   266 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   267 
   267 
   268 handleCmd_noRoom client _ _ ["CHAT_STRING", msg] =
   268 handleCmd_noRoom client _ _ ["CHAT_STRING", msg] =
   366 		(noChangeClients, noChangeRooms, [])
   366 		(noChangeClients, noChangeRooms, [])
   367 	else
   367 	else
   368 		if not $ nick client == teamowner team then
   368 		if not $ nick client == teamowner team then
   369 			(noChangeClients, noChangeRooms, answerNotOwner)
   369 			(noChangeClients, noChangeRooms, answerNotOwner)
   370 		else
   370 		else
   371 			(noChangeClients, modifyRoom clRoom{teams = filter (\t -> teamName /= teamname t) $ teams clRoom}, answerRemoveTeam teamName)
   371 			if not $ gameinprogress clRoom then
       
   372 				(noChangeClients, modifyRoom clRoom{teams = filter (\t -> teamName /= teamname t) $ teams clRoom}, answerRemoveTeam teamName)
       
   373 			else
       
   374 				(noChangeClients, modifyRoom clRoom{leftTeams = teamName : leftTeams clRoom, roundMsgs = roundMsgs clRoom |> rmTeamMsg}, answerOthersRoom ["GAMEMSG", rmTeamMsg])
   372 	where
   375 	where
   373 		noSuchTeam = isNothing findTeam
   376 		noSuchTeam = isNothing findTeam
   374 		team = fromJust findTeam
   377 		team = fromJust findTeam
   375 		findTeam = find (\t -> teamName == teamname t) $ teams clRoom
   378 		findTeam = find (\t -> teamName == teamname t) $ teams clRoom
   376 		clRoom = roomByName (room client) rooms
   379 		clRoom = roomByName (room client) rooms
       
   380 		rmTeamMsg = toEngineMsg $ 'F' : teamName
   377 
   381 
   378 handleCmd_inRoom client _ rooms ["TOGGLE_READY"] =
   382 handleCmd_inRoom client _ rooms ["TOGGLE_READY"] =
   379 	if isReady client then
   383 	if isReady client then
   380 		(modifyClient client{isReady = False}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerNotReady $ nick client)
   384 		(modifyClient client{isReady = False}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerNotReady $ nick client)
   381 	else
   385 	else
   385 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1
   389 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1
   386 
   390 
   387 handleCmd_inRoom client _ rooms ["START_GAME"] =
   391 handleCmd_inRoom client _ rooms ["START_GAME"] =
   388 	if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then
   392 	if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then
   389 		if enoughClans then
   393 		if enoughClans then
   390 			(noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty}, answerRunGame)
   394 			(noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty, leftTeams = []}, answerRunGame)
   391 		else
   395 		else
   392 			(noChangeClients, noChangeRooms, answerTooFewClans)
   396 			(noChangeClients, noChangeRooms, answerTooFewClans)
   393 	else
   397 	else
   394 		(noChangeClients, noChangeRooms, [])
   398 		(noChangeClients, noChangeRooms, [])
   395 	where
   399 	where
   414 		clRoom = roomByName (room client) rooms
   418 		clRoom = roomByName (room client) rooms
   415 		newStatus = not $ isRestrictedTeams clRoom
   419 		newStatus = not $ isRestrictedTeams clRoom
   416 
   420 
   417 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] =
   421 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] =
   418 	if isMaster client then
   422 	if isMaster client then
   419 		(modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty}, answerAllNotReady)
   423 		(modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty, leftTeams = []}, answerAllNotReady ++ answerRemovedTeams)
   420 	else
   424 	else
   421 		(noChangeClients, noChangeRooms, [])
   425 		(noChangeClients, noChangeRooms, [])
   422 	where
   426 	where
   423 		clRoom = roomByName (room client) rooms
   427 		clRoom = roomByName (room client) rooms
   424 		sameRoomClients = filter (\ci -> room ci == name clRoom) clients
   428 		sameRoomClients = filter (\ci -> room ci == name clRoom) clients
   425 		answerAllNotReady = concatMap (\cl -> answerSameRoom ["NOT_READY", nick cl]) sameRoomClients
   429 		answerAllNotReady = concatMap (\cl -> answerSameRoom ["NOT_READY", nick cl]) sameRoomClients
       
   430 		answerRemovedTeams = concatMap answerRemoveTeam $ leftTeams clRoom
   426 
   431 
   427 handleCmd_inRoom client _ rooms ["GAMEMSG", msg] =
   432 handleCmd_inRoom client _ rooms ["GAMEMSG", msg] =
   428 	(noChangeClients, addMsg, answerOthersRoom ["GAMEMSG", msg])
   433 	(noChangeClients, addMsg, answerOthersRoom ["GAMEMSG", msg])
   429 	where
   434 	where
   430 		addMsg = if roomProto clRoom < 20 then
   435 		addMsg = if roomProto clRoom < 20 then