56 if null (room client) then |
56 if null (room client) then |
57 (noChangeClients, noChangeRooms, answerQuit) |
57 (noChangeClients, noChangeRooms, answerQuit) |
58 else if isMaster client then |
58 else if isMaster client then |
59 (noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer |
59 (noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer |
60 else |
60 else |
61 (noChangeClients, modifyRoom clRoom{teams = othersTeams}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams) |
61 (noChangeClients, modifyRoom clRoom{teams = othersTeams}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams ++ answerLostTeams) |
62 where |
62 where |
63 clRoom = roomByName (room client) rooms |
63 clRoom = roomByName (room client) rooms |
64 answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams |
64 answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams |
65 (clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom |
65 (clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom |
|
66 answerLostTeams = if gameinprogress clRoom then answerInGameLostTeams clientTeams else [] |
|
67 answerInGameLostTeams teams = [] |
|
68 |
66 |
69 |
67 |
70 |
68 -- check state and call state-dependent commmand handlers |
71 -- check state and call state-dependent commmand handlers |
69 handleCmd client clients rooms cmd = |
72 handleCmd client clients rooms cmd = |
70 if null (nick client) || protocol client == 0 then |
73 if null (nick client) || protocol client == 0 then |
107 |
110 |
108 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] = |
111 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] = |
109 if haveSameRoom then |
112 if haveSameRoom then |
110 (noChangeClients, noChangeRooms, answerRoomExists) |
113 (noChangeClients, noChangeRooms, answerRoomExists) |
111 else |
114 else |
112 (modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword (protocol client) [] "+rnd+" Map.empty), answerJoined $ nick client) |
115 (modifyClient client{room = newRoom, isMaster = True}, addRoom createRoom{name = newRoom, password = roomPassword, roomProto = (protocol client)}, answerJoined $ nick client) |
113 where |
116 where |
114 haveSameRoom = isJust $ find (\room -> newRoom == name room) rooms |
117 haveSameRoom = isJust $ find (\room -> newRoom == name room) rooms |
115 |
118 |
116 handleCmd_noRoom client clients rooms ["CREATE", newRoom] = |
119 handleCmd_noRoom client clients rooms ["CREATE", newRoom] = |
117 handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""] |
120 handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""] |
210 noSuchTeam = isNothing findTeam |
213 noSuchTeam = isNothing findTeam |
211 team = fromJust findTeam |
214 team = fromJust findTeam |
212 findTeam = find (\t -> teamName == teamname t) $ teams clRoom |
215 findTeam = find (\t -> teamName == teamname t) $ teams clRoom |
213 clRoom = roomByName (room client) rooms |
216 clRoom = roomByName (room client) rooms |
214 |
217 |
215 handleCmd_inRoom client _ _ ["READY"] = |
218 handleCmd_inRoom client _ rooms ["READY"] = |
216 if not $ isMaster client then |
219 if not $ isMaster client then |
217 (noChangeClients, noChangeRooms, answerNotMaster) |
220 (noChangeClients, noChangeRooms, answerNotMaster) |
218 else |
221 else |
219 (noChangeClients, noChangeRooms, answerRunGame) |
222 (noChangeClients, modifyRoom clRoom{gameinprogress = True}, answerRunGame) |
|
223 where |
|
224 clRoom = roomByName (room client) rooms |
220 |
225 |
221 handleCmd_inRoom client _ rooms ["ROUNDFINISHED"] = |
226 handleCmd_inRoom client _ rooms ["ROUNDFINISHED"] = |
222 if isMaster client then |
227 if isMaster client then |
223 (noChangeClients, modifyRoom clRoom{teams = []}, []) |
228 (noChangeClients, modifyRoom clRoom{teams = [], gameinprogress = False}, []) |
224 else |
229 else |
225 (noChangeClients, noChangeRooms, []) |
230 (noChangeClients, noChangeRooms, []) |
226 where |
231 where |
227 clRoom = roomByName (room client) rooms |
232 clRoom = roomByName (room client) rooms |
228 |
233 |