74 let ris = allRooms irnc |
75 let ris = allRooms irnc |
75 cl <- thisClient |
76 cl <- thisClient |
76 let maybeRI = find (\ri -> roomName == name (irnc `room` ri)) ris |
77 let maybeRI = find (\ri -> roomName == name (irnc `room` ri)) ris |
77 let jRI = fromJust maybeRI |
78 let jRI = fromJust maybeRI |
78 let jRoom = irnc `room` jRI |
79 let jRoom = irnc `room` jRI |
79 let jRoomClients = map (client irnc) $! roomClients irnc jRI -- no lazyness here! |
80 let jRoomClients = map (client irnc) $ roomClients irnc jRI |
|
81 let nicks = map nick jRoomClients |
|
82 let chans = map sendChan (cl : jRoomClients) |
80 return $ |
83 return $ |
81 if isNothing maybeRI then |
84 if isNothing maybeRI then |
82 [Warning "No such rooms"] |
85 [Warning "No such rooms"] |
83 else if isRestrictedJoins jRoom then |
86 else if isRestrictedJoins jRoom then |
84 [Warning "Joining restricted"] |
87 [Warning "Joining restricted"] |
85 else if roomPassword /= password jRoom then |
88 else if roomPassword /= password jRoom then |
86 [Warning "Wrong password"] |
89 [Warning "Wrong password"] |
87 else |
90 else |
88 [ |
91 [ |
89 MoveToRoom jRI, |
92 MoveToRoom jRI, |
90 AnswerClients (map sendChan $ cl : jRoomClients) ["NOT_READY", nick cl], |
93 AnswerClients [sendChan cl] $ "JOINED" : nicks, |
91 AnswerClients [sendChan cl] $ "JOINED" : map nick jRoomClients |
94 AnswerClients chans ["NOT_READY", nick cl] |
92 ] |
95 ] |
93 ++ (map (readynessMessage cl) jRoomClients) |
96 ++ (map (readynessMessage cl) jRoomClients) |
94 ++ (answerFullConfig cl $ params jRoom) |
97 ++ (answerFullConfig cl $ params jRoom) |
95 ++ (answerTeams cl jRoom) |
98 ++ (answerTeams cl jRoom) |
96 ++ (watchRound cl jRoom) |
99 ++ (watchRound cl jRoom) |
110 [] |
113 [] |
111 else |
114 else |
112 [AnswerClients [sendChan cl] ["RUN_GAME"], |
115 [AnswerClients [sendChan cl] ["RUN_GAME"], |
113 AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : Foldable.toList (roundMsgs jRoom)] |
116 AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : Foldable.toList (roundMsgs jRoom)] |
114 |
117 |
115 |
|
116 |
|
117 {- |
|
118 |
|
119 handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, roomPassword] |
|
120 | noSuchRoom = [Warning "No such room"] |
|
121 | isRestrictedJoins jRoom = [Warning "Joining restricted"] |
|
122 | roomPassword /= password jRoom = [Warning "Wrong password"] |
|
123 | otherwise = |
|
124 [RoomRemoveThisClient "", -- leave lobby |
|
125 RoomAddThisClient rID] -- join room |
|
126 ++ answerNicks |
|
127 ++ answerReady |
|
128 ++ [AnswerThisRoom ["NOT_READY", nick client]] |
|
129 ++ answerFullConfig |
|
130 ++ answerTeams |
|
131 ++ watchRound |
|
132 where |
|
133 answerNicks = |
|
134 [AnswerThisClient $ "JOINED" : |
|
135 map (\clID -> nick $ clients IntMap.! clID) roomClientsIDs | playersIn jRoom /= 0] |
|
136 answerReady = map |
|
137 ((\ c -> |
|
138 AnswerThisClient |
|
139 [if isReady c then "READY" else "NOT_READY", nick c]) |
|
140 . (\ clID -> clients IntMap.! clID)) |
|
141 roomClientsIDs |
|
142 |
|
143 toAnswer (paramName, paramStrs) = AnswerThisClient $ "CFG" : paramName : paramStrs |
|
144 |
|
145 answerFullConfig = map toAnswer (leftConfigPart ++ rightConfigPart) |
|
146 (leftConfigPart, rightConfigPart) = partition (\(p, _) -> p /= "MAP") (Map.toList $ params jRoom) |
|
147 |
|
148 watchRound = if not $ gameinprogress jRoom then |
|
149 [] |
|
150 else |
|
151 [AnswerThisClient ["RUN_GAME"], |
|
152 AnswerThisClient $ "EM" : toEngineMsg "e$spectate 1" : Foldable.toList (roundMsgs jRoom)] |
|
153 |
|
154 answerTeams = if gameinprogress jRoom then |
|
155 answerAllTeams (clientProto client) (teamsAtStart jRoom) |
|
156 else |
|
157 answerAllTeams (clientProto client) (teams jRoom) |
|
158 -} |
|
159 |
118 |
160 handleCmd_lobby ["JOIN_ROOM", roomName] = |
119 handleCmd_lobby ["JOIN_ROOM", roomName] = |
161 handleCmd_lobby ["JOIN_ROOM", roomName, ""] |
120 handleCmd_lobby ["JOIN_ROOM", roomName, ""] |
162 |
121 |
163 {- |
122 {- |