48 answerCannotCreateRoom = answerClientOnly ["WARNING", "Cannot create more rooms"] |
48 answerCannotCreateRoom = answerClientOnly ["WARNING", "Cannot create more rooms"] |
49 answerInfo client = answerClientOnly ["INFO", nick client, host client, proto2ver $ protocol client, roomInfo] |
49 answerInfo client = answerClientOnly ["INFO", nick client, host client, proto2ver $ protocol client, roomInfo] |
50 where |
50 where |
51 roomInfo = if not $ null $ room client then "room " ++ (room client) else "lobby" |
51 roomInfo = if not $ null $ room client then "room " ++ (room client) else "lobby" |
52 |
52 |
53 answerAbandoned = answerOthersRoom ["BYE", "Room abandoned"] |
53 answerAbandoned protocol = |
|
54 if protocol < 20 then |
|
55 answerOthersRoom ["BYE", "Room abandoned"] |
|
56 else |
|
57 answerOthersRoom ["ROOMABANDONED"] |
|
58 |
54 answerChatString nick msg = answerOthersRoom ["CHAT_STRING", nick, msg] |
59 answerChatString nick msg = answerOthersRoom ["CHAT_STRING", nick, msg] |
55 answerAddTeam team = answerOthersRoom $ teamToNet team |
60 answerAddTeam team = answerOthersRoom $ teamToNet team |
56 answerRemoveTeam teamName = answerOthersRoom ["REMOVE_TEAM", teamName] |
61 answerRemoveTeam teamName = answerOthersRoom ["REMOVE_TEAM", teamName] |
57 answerMap mapName = answerOthersRoom ["MAP", mapName] |
62 answerMap mapName = answerOthersRoom ["MAP", mapName] |
58 answerHHNum teamName hhNumber = answerOthersRoom ["HH_NUM", teamName, show hhNumber] |
63 answerHHNum teamName hhNumber = answerOthersRoom ["HH_NUM", teamName, show hhNumber] |
61 answerQuitInform nick msg = |
66 answerQuitInform nick msg = |
62 if not $ null msg then |
67 if not $ null msg then |
63 answerOthersRoom ["LEFT", nick, msg] |
68 answerOthersRoom ["LEFT", nick, msg] |
64 else |
69 else |
65 answerOthersRoom ["LEFT", nick] |
70 answerOthersRoom ["LEFT", nick] |
|
71 |
|
72 answerPartInform nick = answerOthersRoom ["LEFT", nick, "bye room"] |
66 answerQuitLobby nick msg = |
73 answerQuitLobby nick msg = |
67 if not $ null nick then |
74 if not $ null nick then |
68 if not $ null msg then |
75 if not $ null msg then |
69 answerAll ["LOBBY:LEFT", nick, msg] |
76 answerAll ["LOBBY:LEFT", nick, msg] |
70 else |
77 else |
116 handleCmd :: CmdHandler |
123 handleCmd :: CmdHandler |
117 handleCmd client _ rooms ("QUIT" : xs) = |
124 handleCmd client _ rooms ("QUIT" : xs) = |
118 if null (room client) then |
125 if null (room client) then |
119 (noChangeClients, noChangeRooms, answerQuit msg ++ (answerQuitLobby (nick client) msg) ) |
126 (noChangeClients, noChangeRooms, answerQuit msg ++ (answerQuitLobby (nick client) msg) ) |
120 else if isMaster client then |
127 else if isMaster client then |
121 (noChangeClients, removeRoom (room client), (answerQuit msg) ++ (answerQuitLobby (nick client) msg) ++ answerAbandoned ++ (answerRoomDeleted $ room client)) -- core disconnects clients on ROOMABANDONED answer |
128 (modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerQuit msg) ++ (answerQuitLobby (nick client) msg) ++ (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client)) -- core disconnects clients on ROOMABANDONED answer |
122 else |
129 else |
123 (noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform (nick client) msg) ++ (answerQuitLobby (nick client) msg) ++ answerRemoveClientTeams) |
130 (noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform (nick client) msg) ++ (answerQuitLobby (nick client) msg) ++ answerRemoveClientTeams) |
124 where |
131 where |
125 clRoom = roomByName (room client) rooms |
132 clRoom = roomByName (room client) rooms |
126 answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams |
133 answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams |
257 (noChangeClients, modifyRoom clRoom{params = Map.insert paramName paramStrs (params clRoom)}, answerConfigParam paramName paramStrs) |
264 (noChangeClients, modifyRoom clRoom{params = Map.insert paramName paramStrs (params clRoom)}, answerConfigParam paramName paramStrs) |
258 else |
265 else |
259 (noChangeClients, noChangeRooms, answerNotMaster) |
266 (noChangeClients, noChangeRooms, answerNotMaster) |
260 where |
267 where |
261 clRoom = roomByName (room client) rooms |
268 clRoom = roomByName (room client) rooms |
|
269 |
|
270 handleCmd_inRoom client _ rooms ["PART"] = |
|
271 if isMaster client then |
|
272 (modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client)) |
|
273 else |
|
274 (modifyClient client{room = [], isReady = False}, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerPartInform (nick client)) ++ answerRemoveClientTeams) |
|
275 where |
|
276 clRoom = roomByName (room client) rooms |
|
277 answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams |
|
278 (clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom |
|
279 newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom |
262 |
280 |
263 handleCmd_inRoom client _ rooms ["MAP", mapName] = |
281 handleCmd_inRoom client _ rooms ["MAP", mapName] = |
264 if isMaster client then |
282 if isMaster client then |
265 (noChangeClients, modifyRoom clRoom{gamemap = mapName}, answerMap mapName) |
283 (noChangeClients, modifyRoom clRoom{gamemap = mapName}, answerMap mapName) |
266 else |
284 else |