--- a/netserver/HWProto.hs Wed Oct 08 13:58:27 2008 +0000
+++ b/netserver/HWProto.hs Wed Oct 08 15:42:09 2008 +0000
@@ -5,8 +5,10 @@
import Data.Word
import Miscutils
import Maybe (fromMaybe, fromJust)
+import qualified Data.Map as Map
answerBadCmd = [(clientOnly, ["ERROR", "Bad command, state or incorrect parameter"])]
+answerNotMaster = [(clientOnly, ["ERROR", "You cannot configure room parameters"])]
answerQuit = [(clientOnly, ["off"])]
answerAbandoned = [(sameRoom, ["BYE"])]
answerQuitInform nick = [(othersInRoom, ["LEFT", nick])]
@@ -22,7 +24,11 @@
answerNoRoom = [(clientOnly, ["WARNING", "There's no room with that name"])]
answerWrongPassword = [(clientOnly, ["WARNING", "Wrong password"])]
answerChatString nick msg = [(othersInRoom, ["CHAT_STRING", nick, msg])]
-
+answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)]
+answerFullConfig room = map toAnswer (Map.toList $ params room)
+ where
+ toAnswer (paramName, paramStrs)=
+ (clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
-- Main state-independent cmd handler
handleCmd :: CmdHandler
@@ -79,7 +85,7 @@
if haveSameRoom then
(noChangeClients, noChangeRooms, answerRoomExists)
else
- (modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword []), answerJoined $ nick client)
+ (modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword (protocol client) [] Map.empty), answerJoined $ nick client)
where
haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms
@@ -89,13 +95,14 @@
handleCmd_noRoom client clients rooms ["JOIN", roomName, roomPassword] =
if noSuchRoom then
(noChangeClients, noChangeRooms, answerNoRoom)
- else if roomPassword /= password (roomByName roomName rooms) then
+ else if roomPassword /= password joinRoom then
(noChangeClients, noChangeRooms, answerWrongPassword)
else
- (modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks)
+ (modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks ++ answerFullConfig joinRoom)
where
noSuchRoom = null $ filter (\room -> roomName == name room) rooms
answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
+ joinRoom = roomByName roomName rooms
handleCmd_noRoom client clients rooms ["JOIN", roomName] =
handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
@@ -105,7 +112,13 @@
-- 'inRoom' clients state command handlers
handleCmd_inRoom :: CmdHandler
+handleCmd_inRoom client _ _ ["CHAT_STRING", _, msg] =
+ (noChangeClients, noChangeRooms, answerChatString (nick client) msg)
-handleCmd_inRoom client _ _ ["CHAT_STRING", _, msg] = (noChangeClients, noChangeRooms, answerChatString (nick client) msg)
+handleCmd_inRoom client _ _ ("CONFIG_PARAM":paramName:paramStrs) =
+ if isMaster client then
+ (noChangeClients, changeRoomConfig (room client) paramName paramStrs, answerConfigParam paramName paramStrs)
+ else
+ (noChangeClients, noChangeRooms, answerNotMaster)
handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)