netserver/HWProto.hs
changeset 1321 d7dc4e86201e
parent 1320 bffc7262e25e
child 1322 c624b04699fb
equal deleted inserted replaced
1320:bffc7262e25e 1321:d7dc4e86201e
    25 answerWrongPassword = [(clientOnly, ["WARNING", "Wrong password"])]
    25 answerWrongPassword = [(clientOnly, ["WARNING", "Wrong password"])]
    26 answerChatString nick msg = [(othersInRoom, ["CHAT_STRING", nick, msg])]
    26 answerChatString nick msg = [(othersInRoom, ["CHAT_STRING", nick, msg])]
    27 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)]
    27 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)]
    28 answerFullConfig room = map toAnswer (Map.toList $ params room)
    28 answerFullConfig room = map toAnswer (Map.toList $ params room)
    29 	where
    29 	where
    30 		toAnswer (paramName, paramStrs)=
    30 		toAnswer (paramName, paramStrs) =
    31 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
    31 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
    32 
    32 
    33 -- Main state-independent cmd handler
    33 -- Main state-independent cmd handler
    34 handleCmd :: CmdHandler
    34 handleCmd :: CmdHandler
    35 handleCmd client _ rooms ("QUIT":xs) =
    35 handleCmd client _ rooms ("QUIT":xs) =
    93 	handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""]
    93 	handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""]
    94 	
    94 	
    95 handleCmd_noRoom client clients rooms ["JOIN", roomName, roomPassword] =
    95 handleCmd_noRoom client clients rooms ["JOIN", roomName, roomPassword] =
    96 	if noSuchRoom then
    96 	if noSuchRoom then
    97 		(noChangeClients, noChangeRooms, answerNoRoom)
    97 		(noChangeClients, noChangeRooms, answerNoRoom)
    98 	else if roomPassword /= password joinRoom then
    98 	else if roomPassword /= password clRoom then
    99 		(noChangeClients, noChangeRooms, answerWrongPassword)
    99 		(noChangeClients, noChangeRooms, answerWrongPassword)
   100 	else
   100 	else
   101 		(modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks ++ answerFullConfig joinRoom)
   101 		(modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks ++ answerFullConfig clRoom)
   102 	where
   102 	where
   103 		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
   103 		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
   104 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
   104 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
   105 		joinRoom = roomByName roomName rooms
   105 		clRoom = roomByName roomName rooms
   106 
   106 
   107 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   107 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
   108 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   108 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
   109 
   109 
   110 handleCmd_noRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)
   110 handleCmd_noRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)
   113 -- 'inRoom' clients state command handlers
   113 -- 'inRoom' clients state command handlers
   114 handleCmd_inRoom :: CmdHandler
   114 handleCmd_inRoom :: CmdHandler
   115 handleCmd_inRoom client _ _ ["CHAT_STRING", _, msg] =
   115 handleCmd_inRoom client _ _ ["CHAT_STRING", _, msg] =
   116 	(noChangeClients, noChangeRooms, answerChatString (nick client) msg)
   116 	(noChangeClients, noChangeRooms, answerChatString (nick client) msg)
   117 
   117 
   118 handleCmd_inRoom client _ _ ("CONFIG_PARAM":paramName:paramStrs) =
   118 handleCmd_inRoom client _ rooms ("CONFIG_PARAM":paramName:paramStrs) =
   119 	if isMaster client then
   119 	if isMaster client then
   120 		(noChangeClients, changeRoomConfig (room client) paramName paramStrs, answerConfigParam paramName paramStrs)
   120 		(noChangeClients, modifyRoom clRoom{params = Map.insert paramName paramStrs (params room)}, answerConfigParam paramName paramStrs)
   121 	else
   121 	else
   122 		(noChangeClients, noChangeRooms, answerNotMaster)
   122 		(noChangeClients, noChangeRooms, answerNotMaster)
       
   123 	where
       
   124 		clRoom = roomByName (room client) rooms
       
   125 
       
   126 
       
   127 handleCmd_inRoom client _ _ ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
       
   128 	| length hhsInfo == 16 = (noChangeClients, noChangeRooms, answerBadCmd)
   123 
   129 
   124 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)
   130 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)