netserver/HWProto.hs
changeset 902 3cc10f0aae37
parent 901 2f5ce9a584f9
child 903 d4e5d8cbe449
equal deleted inserted replaced
901:2f5ce9a584f9 902:3cc10f0aae37
    35 
    35 
    36 
    36 
    37 -- 'noRoom' clients state command handlers
    37 -- 'noRoom' clients state command handlers
    38 handleCmd_noRoom :: Handle -> [ClientInfo] -> [RoomInfo] -> [String] -> ([ClientInfo], [RoomInfo], [Handle], [String])
    38 handleCmd_noRoom :: Handle -> [ClientInfo] -> [RoomInfo] -> [String] -> ([ClientInfo], [RoomInfo], [Handle], [String])
    39 
    39 
    40 {--handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:roomPassword:[]) =
    40 handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:roomPassword:[]) =
    41 	if haveSameRoom then
    41 	if haveSameRoom then
    42 		(client, rooms, [clhandle], ["WARNING", "There's already a room with that name"])
    42 		(clients, rooms, [clhandle], ["WARNING", "There's already a room with that name"])
    43 	else
    43 	else
    44 		(client{room = newRoom, isMaster = True}, (RoomInfo newRoom roomPassword):rooms, [client], ["JOINS", nick client])
    44 		(modifyClient clhandle clients (\cl -> cl{room = newRoom, isMaster = True}), (RoomInfo newRoom roomPassword):rooms, [clhandle], ["JOINS", nick client])
    45 	where
    45 	where
    46 		haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms
    46 		haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms
       
    47 		client = clientByHandle clhandle clients
    47 
    48 
    48 handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:[]) =
    49 handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:[]) =
    49 	handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""]
    50 	handleCmd_noRoom clhandle clients rooms ["CREATE", newRoom, ""]
    50 
    51 
    51 handleCmd_noRoom clhandle clients rooms ("JOIN":roomName:roomPassword:[]) =
    52 handleCmd_noRoom clhandle clients rooms ("JOIN":roomName:roomPassword:[]) =
    52 	if noRoom then
    53 	if noSuchRoom then
    53 		(client, rooms, [clhandle], ["WARNING", "There's no room with that name"])
    54 		(clients, rooms, [clhandle], ["WARNING", "There's no room with that name"])
    54 	else if roomPassword /= password (getRoom roomName) then
    55 	else if roomPassword /= password (roomByName roomName rooms) then
    55 		(client, rooms, [clhandle], ["WARNING", "Wrong password"])
    56 		(clients, rooms, [clhandle], ["WARNING", "Wrong password"])
    56 	else
    57 	else
    57 		(client{room = roomName}, rooms, client : fromRoom roomName clients, ["JOINS", nick client])
    58 		(modifyClient clhandle clients (\cl -> cl{room = roomName}), rooms, clhandle : (fromRoomHandles roomName clients), ["JOINS", nick client])
    58 	where
    59 	where
    59 		noRoom = null $ filter (\room -> roomName == name room) rooms
    60 		noSuchRoom = null $ filter (\room -> roomName == name room) rooms
    60 		getRoom roomName = fromJust $ find (\room -> roomName == name room) rooms
    61 		client = clientByHandle clhandle clients
    61 
    62 
    62 handleCmd_noRoom clhandle clients rooms ("JOIN":roomName:[]) =
    63 handleCmd_noRoom clhandle clients rooms ("JOIN":roomName:[]) =
    63 	handleCmd_noRoom client clients rooms ["JOIN", ""]--}
    64 	handleCmd_noRoom clhandle clients rooms ["JOIN", roomName, ""]
    64 
    65 
    65 handleCmd_noRoom clhandle clients rooms _ = (clients, rooms, [clhandle], ["ERROR", "Bad command or incorrect parameter"])
    66 handleCmd_noRoom clhandle clients rooms _ = (clients, rooms, [clhandle], ["ERROR", "Bad command or incorrect parameter"])
    66 
    67 
    67 -- 'inRoom' clients state command handlers
    68 -- 'inRoom' clients state command handlers
    68 handleCmd_inRoom :: Handle -> [ClientInfo] -> [RoomInfo] -> [String] -> ([ClientInfo], [RoomInfo], [Handle], [String])
    69 handleCmd_inRoom :: Handle -> [ClientInfo] -> [RoomInfo] -> [String] -> ([ClientInfo], [RoomInfo], [Handle], [String])