You should add a $sockerr check to the Sockopen event of SFirc*, to detect whether there was an error connecting the server and either inform the client or disconnect it from your proxy.

Also, add an on Sockclose event for both server and client connections, where you will disconnect the other side as well from your proxy.

If you're interested, here's a similar script I made a while ago. Just type /bnc <port> to listen for incoming connections, and /server <your ip> <port> <server ip>:<port> to use it for a remote connection.