netserver/hwserv.hs
changeset 852 f756a1d3324c
parent 851 8ffa4ad0d8ea
equal deleted inserted replaced
851:8ffa4ad0d8ea 852:f756a1d3324c
    14 		ls <- atomically(readTVar clientsList)
    14 		ls <- atomically(readTVar clientsList)
    15 		sendOthers (map (\x -> handle x) ls) clientHandle (concat param)
    15 		sendOthers (map (\x -> handle x) ls) clientHandle (concat param)
    16 		return ()
    16 		return ()
    17 
    17 
    18 handleCmd clientHandle clientsList roomsList ("CREATE", [roomname]) = do
    18 handleCmd clientHandle clientsList roomsList ("CREATE", [roomname]) = do
    19 		manipState2 clientsList roomsList (hcCreate)
    19 		res <- manipState2 clientsList roomsList (hcCreate)
    20 		sendMsg clientHandle ("JOINED " ++ roomname)
    20 		if res then sendMsg clientHandle ("JOINED " ++ roomname) else sendMsg clientHandle "Already exists"
    21 		where
    21 		where
    22 			hcCreate ci ri = if (null $ filter (\ xr -> roomname == name xr) ri) then
    22 			hcCreate ci ri = if (null $ filter (\ xr -> roomname == name xr) ri) then
    23 				(map
    23 				(map
    24 					(\ xc
    24 					(\ xc
    25 						-> if (clientHandle == handle xc) then
    25 						-> if (clientHandle == handle xc) then
    26 								xc {isMaster = True, room = roomname}
    26 								xc {isMaster = True, room = roomname}
    27 							else
    27 							else
    28 								xc)
    28 								xc)
    29 					ci,
    29 					ci,
    30 					(RoomInfo roomname "") : ri)
    30 					(RoomInfo roomname "") : ri, True)
    31 				else
    31 				else
    32 					(ci, ri)
    32 					(ci, ri, False)
    33 
    33 
    34 handleCmd clientHandle clientsList roomsList ("LIST", []) = do
    34 handleCmd clientHandle clientsList roomsList ("LIST", []) = do
    35 		rl <- atomically $ readTVar roomsList
    35 		rl <- atomically $ readTVar roomsList
    36 		sendMsg clientHandle (unlines $ map (\x -> name x) rl)
    36 		sendMsg clientHandle (unlines $ map (\x -> name x) rl)
    37 
    37