netserver/HWProto.hs
changeset 899 36f91881e83f
parent 898 344ba7dba23d
child 901 2f5ce9a584f9
equal deleted inserted replaced
898:344ba7dba23d 899:36f91881e83f
    41 
    41 
    42 handleCmd_noRoom client clients rooms ("CREATE":newRoom:roomPassword:[]) =
    42 handleCmd_noRoom client clients rooms ("CREATE":newRoom:roomPassword:[]) =
    43 	if haveSameRoom then
    43 	if haveSameRoom then
    44 		(client, rooms, [client], ["WARNING", "There's already a room with that name"])
    44 		(client, rooms, [client], ["WARNING", "There's already a room with that name"])
    45 	else
    45 	else
    46 		(client{room = newRoom, isMaster = True}, (RoomInfo newRoom roomPassword):rooms, [client], ["JOIN", newRoom, nick client])
    46 		(client{room = newRoom, isMaster = True}, (RoomInfo newRoom roomPassword):rooms, [client], ["JOINS", nick client])
    47 	where
    47 	where
    48 		haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms
    48 		haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms
    49 
    49 
    50 handleCmd_noRoom client clients rooms ("CREATE":newRoom:[]) =
    50 handleCmd_noRoom client clients rooms ("CREATE":newRoom:[]) =
    51 	handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""]
    51 	handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""]
    54 	if noRoom then
    54 	if noRoom then
    55 		(client, rooms, [client], ["WARNING", "There's no room with that name"])
    55 		(client, rooms, [client], ["WARNING", "There's no room with that name"])
    56 	else if roomPassword /= password (getRoom roomName) then
    56 	else if roomPassword /= password (getRoom roomName) then
    57 		(client, rooms, [client], ["WARNING", "Wrong password"])
    57 		(client, rooms, [client], ["WARNING", "Wrong password"])
    58 	else
    58 	else
    59 		(client{room = roomName}, rooms, client : fromRoom roomName clients, ["JOIN", roomName, nick client])
    59 		(client{room = roomName}, rooms, client : fromRoom roomName clients, ["JOINS", nick client])
    60 	where
    60 	where
    61 		noRoom = null $ filter (\room -> roomName == name room) rooms
    61 		noRoom = null $ filter (\room -> roomName == name room) rooms
    62 		getRoom roomName = fromJust $ find (\room -> roomName == name room) rooms
    62 		getRoom roomName = fromJust $ find (\room -> roomName == name room) rooms
    63 
    63 
    64 handleCmd_noRoom client clients rooms ("JOIN":roomName:[]) =
    64 handleCmd_noRoom client clients rooms ("JOIN":roomName:[]) =
    65 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
    65 	handleCmd_noRoom client clients rooms ["JOIN", ""]
    66 
    66 
    67 handleCmd_noRoom client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command or incorrect parameter"])
    67 handleCmd_noRoom client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command or incorrect parameter"])
    68 
    68 
    69 -- 'inRoom' clients state command handlers
    69 -- 'inRoom' clients state command handlers
    70 handleCmd_inRoom :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String])
    70 handleCmd_inRoom :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String])
    76 
    76 
    77 handleCmd client clients rooms ("QUIT":xs) =
    77 handleCmd client clients rooms ("QUIT":xs) =
    78 	if null (room client) then
    78 	if null (room client) then
    79 		(client, rooms, [client], ["QUIT"])
    79 		(client, rooms, [client], ["QUIT"])
    80 	else if isMaster client then
    80 	else if isMaster client then
    81 		(client, filter (\rm -> room client /= name rm) rooms, fromRoom (room client) clients, ["ROOMABANDONED"])
    81 		(client, filter (\rm -> room client /= name rm) rooms, fromRoom (room client) clients, ["ROOMABANDONED"]) -- core disconnect clients on ROOMABANDONED command
    82 	else
    82 	else
    83 		(client, rooms, fromRoom (room client) clients, ["QUIT", nick client])
    83 		(client, rooms, fromRoom (room client) clients, ["QUIT", nick client])
    84 
    84 
    85 -- check state and call state-dependent commmand handlers
    85 -- check state and call state-dependent commmand handlers
    86 handleCmd client clients rooms cmd =
    86 handleCmd client clients rooms cmd =