- if( atoi( Req->argv[1] ) < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+ if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client), Req->command);
+
+ from = Client;
+ target = Client_ThisServer();
+
+ if (Req->argc == 3 || Req->argc == 6) {
+ /* This CONNECT has a target parameter */
+ if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
+ from = Client_Search(Req->prefix);
+ if (! from)
+ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
+ Client_ID(Client), Req->prefix);
+
+ target = (Req->argc == 3) ? Client_Search(Req->argv[2])
+ : Client_Search(Req->argv[5]);
+ if (! target || Client_Type(target) != CLIENT_SERVER)
+ return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
+ Client_ID(from), Req->argv[0]);
+ }