63 else |
63 else |
64 handleCmd_loggedin cmd |
64 handleCmd_loggedin cmd |
65 else |
65 else |
66 handleCmd_NotEntered cmd |
66 handleCmd_NotEntered cmd |
67 |
67 |
|
68 handleCmd_lobbyOnly cmd = do |
|
69 (ci, rnc) <- ask |
|
70 if (clientRoom rnc ci) == lobbyId then |
|
71 handleCmd cmd |
|
72 else |
|
73 return [Warning $ loc "This command is only available in the lobby."] |
|
74 |
|
75 handleCmd_roomOnly cmd = do |
|
76 (ci, rnc) <- ask |
|
77 if (clientRoom rnc ci) == lobbyId then |
|
78 return [Warning $ loc "This command is only available in rooms."] |
|
79 else |
|
80 handleCmd cmd |
|
81 |
|
82 -- Chat command handling |
68 unknownCmdWarningText :: B.ByteString |
83 unknownCmdWarningText :: B.ByteString |
69 unknownCmdWarningText = loc "Unknown command or invalid parameters. Say '/help' in chat for a list of commands." |
84 unknownCmdWarningText = loc "Unknown command or invalid parameters. Say '/help' in chat for a list of commands." |
70 |
85 |
71 handleCmd_loggedin ["CMD"] = return [Warning unknownCmdWarningText] |
86 handleCmd_loggedin ["CMD"] = return [Warning unknownCmdWarningText] |
72 |
87 |
73 handleCmd_loggedin ["CMD", parameters] = uncurry h $ extractParameters parameters |
88 handleCmd_loggedin ["CMD", parameters] = uncurry h $ extractParameters parameters |
74 where |
89 where |
75 h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n] |
90 -- room-only commands |
76 h "SAVEROOM" n | not $ B.null n = handleCmd ["SAVEROOM", n] |
91 h "DELEGATE" n | not $ B.null n = handleCmd_roomOnly ["DELEGATE", n] |
77 h "LOADROOM" n | not $ B.null n = handleCmd ["LOADROOM", n] |
92 h "SAVEROOM" n | not $ B.null n = handleCmd_roomOnly ["SAVEROOM", n] |
78 h "SAVE" n | not $ B.null n = let (sn, ln) = B.break (== ' ') n in if B.null ln then return [] else handleCmd ["SAVE", sn, B.tail ln] |
93 h "LOADROOM" n | not $ B.null n = handleCmd_roomOnly ["LOADROOM", n] |
79 h "DELETE" n | not $ B.null n = handleCmd ["DELETE", n] |
94 h "SAVE" n | not $ B.null n = let (sn, ln) = B.break (== ' ') n in if B.null ln then return [Warning unknownCmdWarningText] else handleCmd_roomOnly ["SAVE", sn, B.tail ln] |
80 h "STATS" _ = handleCmd ["STATS"] |
95 h "DELETE" n | not $ B.null n = handleCmd_roomOnly ["DELETE", n] |
|
96 h "FIX" _ = handleCmd_roomOnly ["FIX"] |
|
97 h "UNFIX" _ = handleCmd_roomOnly ["UNFIX"] |
|
98 h "GREETING" msg = handleCmd_roomOnly ["GREETING", msg] |
|
99 h "CALLVOTE" msg | B.null msg = handleCmd_roomOnly ["CALLVOTE"] |
|
100 | otherwise = let (c, p) = extractParameters msg in |
|
101 if B.null p then handleCmd_roomOnly ["CALLVOTE", c] else handleCmd_roomOnly ["CALLVOTE", c, p] |
|
102 h "VOTE" msg | not $ B.null msg = handleCmd_roomOnly ["VOTE", upperCase msg] |
|
103 | otherwise = handleCmd_roomOnly ["VOTE", ""] |
|
104 h "FORCE" msg | not $ B.null msg = handleCmd_roomOnly ["VOTE", upperCase msg, "FORCE"] |
|
105 | otherwise = handleCmd_roomOnly ["VOTE", "", "FORCE"] |
|
106 h "MAXTEAMS" n | not $ B.null n = handleCmd_roomOnly ["MAXTEAMS", n] |
|
107 |
|
108 -- lobby-only commands |
|
109 h "STATS" _ = handleCmd_lobbyOnly ["STATS"] |
|
110 h "RESTART_SERVER" "YES" = handleCmd_lobbyOnly ["RESTART_SERVER"] |
|
111 |
|
112 -- room and lobby commands |
81 h "QUIT" m | not $ B.null m = handleCmd ["QUIT", m] |
113 h "QUIT" m | not $ B.null m = handleCmd ["QUIT", m] |
82 | otherwise = handleCmd ["QUIT"] |
114 | otherwise = handleCmd ["QUIT"] |
83 h "RND" p = handleCmd ("RND" : B.words p) |
115 h "RND" p = handleCmd ("RND" : B.words p) |
84 h "GLOBAL" p = serverAdminOnly $ do |
116 h "GLOBAL" p = serverAdminOnly $ do |
85 rnc <- liftM snd ask |
117 rnc <- liftM snd ask |
86 let chans = map (sendChan . client rnc) $ allClients rnc |
118 let chans = map (sendChan . client rnc) $ allClients rnc |
87 return [AnswerClients chans ["CHAT", nickGlobal, p]] |
119 return [AnswerClients chans ["CHAT", nickGlobal, p]] |
88 h "WATCH" f = return [QueryReplay f] |
120 h "WATCH" f = return [QueryReplay f] |
89 h "FIX" _ = handleCmd ["FIX"] |
|
90 h "UNFIX" _ = handleCmd ["UNFIX"] |
|
91 h "GREETING" msg = handleCmd ["GREETING", msg] |
|
92 h "CALLVOTE" msg | B.null msg = handleCmd ["CALLVOTE"] |
|
93 | otherwise = let (c, p) = extractParameters msg in |
|
94 if B.null p then handleCmd ["CALLVOTE", c] else handleCmd ["CALLVOTE", c, p] |
|
95 h "VOTE" msg | not $ B.null msg = handleCmd ["VOTE", upperCase msg] |
|
96 | otherwise = handleCmd ["VOTE", ""] |
|
97 h "FORCE" msg | not $ B.null msg = handleCmd ["VOTE", upperCase msg, "FORCE"] |
|
98 | otherwise = handleCmd ["VOTE", "", "FORCE"] |
|
99 h "MAXTEAMS" n | not $ B.null n = handleCmd ["MAXTEAMS", n] |
|
100 h "INFO" n | not $ B.null n = handleCmd ["INFO", n] |
121 h "INFO" n | not $ B.null n = handleCmd ["INFO", n] |
101 h "HELP" _ = handleCmd ["HELP"] |
122 h "HELP" _ = handleCmd ["HELP"] |
102 h "RESTART_SERVER" "YES" = handleCmd ["RESTART_SERVER"] |
|
103 h "REGISTERED_ONLY" _ = serverAdminOnly $ do |
123 h "REGISTERED_ONLY" _ = serverAdminOnly $ do |
104 cl <- thisClient |
124 cl <- thisClient |
105 return |
125 return |
106 [ModifyServerInfo(\s -> s{isRegisteredUsersOnly = not $ isRegisteredUsersOnly s}) |
126 [ModifyServerInfo(\s -> s{isRegisteredUsersOnly = not $ isRegisteredUsersOnly s}) |
107 -- TODO: Say whether 'registered only' state is on or off |
127 -- TODO: Say whether 'registered only' state is on or off |