equal
deleted
inserted
replaced
4 ) where |
4 ) where |
5 |
5 |
6 import IO |
6 import IO |
7 import Data.List |
7 import Data.List |
8 import Data.Word |
8 import Data.Word |
|
9 import Data.Sequence(Seq, (|>), empty) |
|
10 import Data.Foldable(toList) |
9 import Miscutils |
11 import Miscutils |
10 import Maybe |
12 import Maybe |
11 import qualified Data.Map as Map |
13 import qualified Data.Map as Map |
12 import Opts |
14 import Opts |
13 |
15 |
243 clRoom = roomByName roomName rooms |
245 clRoom = roomByName roomName rooms |
244 watchRound = if (roomProto clRoom < 20) || (not $ gameinprogress clRoom) then |
246 watchRound = if (roomProto clRoom < 20) || (not $ gameinprogress clRoom) then |
245 [] |
247 [] |
246 else |
248 else |
247 (answerClientOnly ["RUN_GAME"]) ++ |
249 (answerClientOnly ["RUN_GAME"]) ++ |
248 answerClientOnly ("GAMEMSG" : "DGUkc3BlY3RhdGUgMQ==" : roundMsgs clRoom) |
250 answerClientOnly ("GAMEMSG" : "DGUkc3BlY3RhdGUgMQ==" : (toList $ roundMsgs clRoom)) |
249 |
251 |
250 handleCmd_noRoom client clients rooms ["JOIN", roomName] = |
252 handleCmd_noRoom client clients rooms ["JOIN", roomName] = |
251 handleCmd_noRoom client clients rooms ["JOIN", roomName, ""] |
253 handleCmd_noRoom client clients rooms ["JOIN", roomName, ""] |
252 |
254 |
253 handleCmd_noRoom client _ _ ["CHAT_STRING", msg] = |
255 handleCmd_noRoom client _ _ ["CHAT_STRING", msg] = |
366 newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1 |
368 newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1 |
367 |
369 |
368 handleCmd_inRoom client _ rooms ["START_GAME"] = |
370 handleCmd_inRoom client _ rooms ["START_GAME"] = |
369 if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then |
371 if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then |
370 if enoughClans then |
372 if enoughClans then |
371 (noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = []}, answerRunGame) |
373 (noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty}, answerRunGame) |
372 else |
374 else |
373 (noChangeClients, noChangeRooms, answerTooFewClans) |
375 (noChangeClients, noChangeRooms, answerTooFewClans) |
374 else |
376 else |
375 (noChangeClients, noChangeRooms, []) |
377 (noChangeClients, noChangeRooms, []) |
376 where |
378 where |
395 clRoom = roomByName (room client) rooms |
397 clRoom = roomByName (room client) rooms |
396 newStatus = not $ isRestrictedTeams clRoom |
398 newStatus = not $ isRestrictedTeams clRoom |
397 |
399 |
398 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] = |
400 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] = |
399 if isMaster client then |
401 if isMaster client then |
400 (modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = []}, answerAllNotReady) |
402 (modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty}, answerAllNotReady) |
401 else |
403 else |
402 (noChangeClients, noChangeRooms, []) |
404 (noChangeClients, noChangeRooms, []) |
403 where |
405 where |
404 clRoom = roomByName (room client) rooms |
406 clRoom = roomByName (room client) rooms |
405 sameRoomClients = filter (\ci -> room ci == name clRoom) clients |
407 sameRoomClients = filter (\ci -> room ci == name clRoom) clients |
409 (noChangeClients, addMsg, answerOthersRoom ["GAMEMSG", msg]) |
411 (noChangeClients, addMsg, answerOthersRoom ["GAMEMSG", msg]) |
410 where |
412 where |
411 addMsg = if roomProto clRoom < 20 then |
413 addMsg = if roomProto clRoom < 20 then |
412 noChangeRooms |
414 noChangeRooms |
413 else |
415 else |
414 modifyRoom clRoom{roundMsgs = roundMsgs clRoom ++ [msg]} |
416 modifyRoom clRoom{roundMsgs = roundMsgs clRoom |> msg} |
415 clRoom = roomByName (room client) rooms |
417 clRoom = roomByName (room client) rooms |
416 |
418 |
417 handleCmd_inRoom client clients rooms ["KICK", kickNick] = |
419 handleCmd_inRoom client clients rooms ["KICK", kickNick] = |
418 if isMaster client then |
420 if isMaster client then |
419 if noSuchClient || (kickClient == client) then |
421 if noSuchClient || (kickClient == client) then |