- WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,user,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str());
- WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name);
- return;
+ chanrec* c = Srv->FindChannel(parameters[0]);
+
+ if (!c)
+ {
+ user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
+ return;
+ }
+
+ std::string line = "";
+
+ if (c->IsModeSet('K'))
+ {
+ user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
+ return;
+ }
+
+ for (int i = 1; i < pcnt - 1; i++)
+ {
+ line = line + std::string(parameters[i]) + " ";
+ }
+ line = line + std::string(parameters[pcnt-1]);
+
+ if (c->modes[CM_INVITEONLY])
+ {
+ c->WriteChannelWithServ((char*)Srv->GetServerName().c_str(), "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
+ user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
+ return;
+ }
+ else
+ {
+ user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
+ return;
+ }