A suggestion that you add a little bit of verification to this, to avoid or lessen the possibility that you don't end up connecting to a rogue server. Usually this isn't a problem, but someone could try to mess up your client by SAJOIN'ing you to hundreds of channels or doing something else to make your client slow way down.

This ERROR event isn't a standard message, so it's possible for this to change in the future. If you manually used the /server command to join that server, then $network will be null because the connection hasn't gotten far enough to see how the network identifies itself. If that first server was in your servers list, then it returns the name of the serverlist "group", which is why it's a good idea to always have your groups be named the same way as the network identifies itself. If you ever see $network being "Freenode instead of "freenode", that's because it's using the group name from:

//echo -a $server(chat.freenode.net).group

Perhaps you can add a verification that the server you're being sent to is somewhere in your serverlist. $server($15) will be null if that string isn't in your serverlist.