28 answerJoined nick = [(sameRoom, ["JOINED", nick])] |
28 answerJoined nick = [(sameRoom, ["JOINED", nick])] |
29 answerNoRoom = [(clientOnly, ["WARNING", "There's no room with that name"])] |
29 answerNoRoom = [(clientOnly, ["WARNING", "There's no room with that name"])] |
30 answerWrongPassword = [(clientOnly, ["WARNING", "Wrong password"])] |
30 answerWrongPassword = [(clientOnly, ["WARNING", "Wrong password"])] |
31 answerChatString nick msg = [(othersInRoom, ["CHAT_STRING", nick, msg])] |
31 answerChatString nick msg = [(othersInRoom, ["CHAT_STRING", nick, msg])] |
32 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)] |
32 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)] |
33 answerFullConfig room = map toAnswer (Map.toList $ params room) |
33 answerFullConfig room = map toAnswer (Map.toList $ params room) ++ [(clientOnly, ["MAP", gamemap room])] |
34 where |
34 where |
35 toAnswer (paramName, paramStrs) = |
35 toAnswer (paramName, paramStrs) = |
36 (clientOnly, "CONFIG_PARAM" : paramName : paramStrs) |
36 (clientOnly, "CONFIG_PARAM" : paramName : paramStrs) |
37 answerCantAdd = [(clientOnly, ["WARNING", "Too many teams or hedgehogs, or same name team"])] |
37 answerCantAdd = [(clientOnly, ["WARNING", "Too many teams or hedgehogs, or same name team"])] |
38 answerTeamAccepted team = [(clientOnly, ["TEAM_ACCEPTED", teamname team])] |
38 answerTeamAccepted team = [(clientOnly, ["TEAM_ACCEPTED", teamname team])] |
45 where |
45 where |
46 toAnswer team = |
46 toAnswer team = |
47 [(clientOnly, teamToNet team), |
47 [(clientOnly, teamToNet team), |
48 (clientOnly, ["TEAM_COLOR", teamname team, teamcolor team]), |
48 (clientOnly, ["TEAM_COLOR", teamname team, teamcolor team]), |
49 (clientOnly, ["HH_NUM", teamname team, show $ hhnum team])] |
49 (clientOnly, ["HH_NUM", teamname team, show $ hhnum team])] |
|
50 answerMap mapName = [(othersInRoom, ["MAP", mapName])] |
50 |
51 |
51 -- Main state-independent cmd handler |
52 -- Main state-independent cmd handler |
52 handleCmd :: CmdHandler |
53 handleCmd :: CmdHandler |
53 handleCmd client _ rooms ("QUIT":xs) = |
54 handleCmd client _ rooms ("QUIT":xs) = |
54 if null (room client) then |
55 if null (room client) then |
101 |
102 |
102 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] = |
103 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] = |
103 if haveSameRoom then |
104 if haveSameRoom then |
104 (noChangeClients, noChangeRooms, answerRoomExists) |
105 (noChangeClients, noChangeRooms, answerRoomExists) |
105 else |
106 else |
106 (modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword (protocol client) [] Map.empty), answerJoined $ nick client) |
107 (modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword (protocol client) [] "+rnd+" Map.empty), answerJoined $ nick client) |
107 where |
108 where |
108 haveSameRoom = isJust $ find (\room -> newRoom == name room) rooms |
109 haveSameRoom = isJust $ find (\room -> newRoom == name room) rooms |
109 |
110 |
110 handleCmd_noRoom client clients rooms ["CREATE", newRoom] = |
111 handleCmd_noRoom client clients rooms ["CREATE", newRoom] = |
111 handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""] |
112 handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""] |
139 else |
140 else |
140 (noChangeClients, noChangeRooms, answerNotMaster) |
141 (noChangeClients, noChangeRooms, answerNotMaster) |
141 where |
142 where |
142 clRoom = roomByName (room client) rooms |
143 clRoom = roomByName (room client) rooms |
143 |
144 |
|
145 handleCmd_inRoom client _ rooms ["MAP", mapName] = |
|
146 if isMaster client then |
|
147 (noChangeClients, modifyRoom clRoom{gamemap = mapName}, answerMap mapName) |
|
148 else |
|
149 (noChangeClients, noChangeRooms, answerNotMaster) |
|
150 where |
|
151 clRoom = roomByName (room client) rooms |
|
152 |
144 handleCmd_inRoom client _ rooms ("ADD_TEAM" : name : color : grave : fort : difStr : hhsInfo) |
153 handleCmd_inRoom client _ rooms ("ADD_TEAM" : name : color : grave : fort : difStr : hhsInfo) |
145 | length hhsInfo == 16 = |
154 | length hhsInfo == 16 = |
146 if length (teams clRoom) == 6 || canAddNumber <= 0 || isJust findTeam then |
155 if length (teams clRoom) == 6 || canAddNumber <= 0 || isJust findTeam then |
147 (noChangeClients, noChangeRooms, answerCantAdd) |
156 (noChangeClients, noChangeRooms, answerCantAdd) |
148 else |
157 else |