19 |
19 |
20 handleCmd_lobby ["LIST"] = do |
20 handleCmd_lobby ["LIST"] = do |
21 (ci, irnc) <- ask |
21 (ci, irnc) <- ask |
22 let cl = irnc `client` ci |
22 let cl = irnc `client` ci |
23 rooms <- allRoomInfos |
23 rooms <- allRoomInfos |
24 let roomsInfoList = concatMap (\r -> roomInfo (clientProto cl) (nick $ irnc `client` masterID r) r) . filter (\r -> (roomProto r == clientProto cl)) |
24 let roomsInfoList = concatMap (\r -> roomInfo (clientProto cl) (maybeNick . liftM (client irnc) $ masterID r) r) . filter (\r -> (roomProto r == clientProto cl)) |
25 return [AnswerClients [sendChan cl] ("ROOMS" : roomsInfoList rooms)] |
25 return [AnswerClients [sendChan cl] ("ROOMS" : roomsInfoList rooms)] |
26 |
|
27 |
26 |
28 handleCmd_lobby ["CHAT", msg] = do |
27 handleCmd_lobby ["CHAT", msg] = do |
29 n <- clientNick |
28 n <- clientNick |
30 s <- roomOthersChans |
29 s <- roomOthersChans |
31 return [AnswerClients s ["CHAT", n, msg]] |
30 return [AnswerClients s ["CHAT", n, msg]] |
58 let jRI = fromJust maybeRI |
57 let jRI = fromJust maybeRI |
59 let jRoom = irnc `room` jRI |
58 let jRoom = irnc `room` jRI |
60 let sameProto = clientProto cl == roomProto jRoom |
59 let sameProto = clientProto cl == roomProto jRoom |
61 let jRoomClients = map (client irnc) $ roomClients irnc jRI |
60 let jRoomClients = map (client irnc) $ roomClients irnc jRI |
62 let nicks = map nick jRoomClients |
61 let nicks = map nick jRoomClients |
63 let ownerNick = nick . fromJust $ find isMaster jRoomClients |
62 let owner = find isMaster jRoomClients |
64 let chans = map sendChan (cl : jRoomClients) |
63 let chans = map sendChan (cl : jRoomClients) |
65 let isBanned = host cl `elem` roomBansList jRoom |
64 let isBanned = host cl `elem` roomBansList jRoom |
66 return $ |
65 return $ |
67 if isNothing maybeRI then |
66 if isNothing maybeRI then |
68 [Warning $ loc "No such room"] |
67 [Warning $ loc "No such room"] |
69 else if not sameProto then |
68 else if not sameProto then |
70 [Warning $ loc "Room version incompatible to your hedgewars version"] |
69 [Warning $ loc "Room version incompatible to your hedgewars version"] |
71 else if isRestrictedJoins jRoom then |
70 else if isRestrictedJoins jRoom then |
72 [Warning $ loc "Joining restricted"] |
71 [Warning $ loc "Joining restricted"] |
73 else if isRegisteredOnly jRoom && (B.null . webPassword $ cl) then |
72 else if isRegisteredOnly jRoom && (B.null . webPassword $ cl) && not (isAdministrator cl) then |
74 [Warning $ loc "Registered users only"] |
73 [Warning $ loc "Registered users only"] |
75 else if isBanned then |
74 else if isBanned then |
76 [Warning $ loc "You are banned in this room"] |
75 [Warning $ loc "You are banned in this room"] |
77 else if roomPassword /= password jRoom then |
76 else if roomPassword /= password jRoom then |
78 [NoticeMessage WrongPassword] |
77 [NoticeMessage WrongPassword] |
79 else |
78 else |
80 [ |
79 ( |
81 MoveToRoom jRI |
80 MoveToRoom jRI |
82 , ModifyClient (\c -> c{isJoinedMidGame = isJust $ gameInfo jRoom}) |
81 : ModifyClient (\c -> c{isJoinedMidGame = isJust $ gameInfo jRoom}) |
83 , AnswerClients [sendChan cl] $ "JOINED" : nicks |
82 : (AnswerClients [sendChan cl] $ "JOINED" : nicks) |
84 , AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl] |
83 : AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl] |
85 , AnswerClients [sendChan cl] $ ["CLIENT_FLAGS", "+h", ownerNick] |
84 : [AnswerClients [sendChan cl] $ ["CLIENT_FLAGS", "+h", nick $ fromJust owner] | isJust owner] |
86 ] |
85 ) |
87 ++ (if clientProto cl < 38 then map (readynessMessage cl) jRoomClients else [sendStateFlags cl jRoomClients]) |
86 ++ (if clientProto cl < 38 then map (readynessMessage cl) jRoomClients else [sendStateFlags cl jRoomClients]) |
88 ++ answerFullConfig cl jRoom |
87 ++ answerFullConfig cl jRoom |
89 ++ answerTeams cl jRoom |
88 ++ answerTeams cl jRoom |
90 ++ watchRound cl jRoom chans |
89 ++ watchRound cl jRoom chans |
|
90 ++ [] |
91 |
91 |
92 where |
92 where |
93 readynessMessage cl c = AnswerClients [sendChan cl] [if isReady c then "READY" else "NOT_READY", nick c] |
93 readynessMessage cl c = AnswerClients [sendChan cl] [if isReady c then "READY" else "NOT_READY", nick c] |
94 sendStateFlags cl clients = AnswerClients [sendChan cl] . concat . intersperse [""] . filter (not . null) . concat $ |
94 sendStateFlags cl clients = AnswerClients [sendChan cl] . concat . intersperse [""] . filter (not . null) . concat $ |
95 [f "+r" ready, f "-r" unready, f "+g" ingame, f "-g" inroomlobby] |
95 [f "+r" ready, f "-r" unready, f "+g" ingame, f "-g" inroomlobby] |