/* Now with added unF! ;) */
+using namespace std;
+
#include "inspircd.h"
#include "inspircd_io.h"
#include "inspircd_util.h"
#include <vector>
#include <errno.h>
#include <deque>
+#include <errno.h>
#include "connection.h"
#include "users.h"
#include "servers.h"
#include "dynamic.h"
#include "wildcard.h"
-using namespace std;
-
#ifdef GCC3
#define nspace __gnu_cxx
#else
int WHOWAS_MAX = 100; // default 100 people maximum in the WHOWAS list
int DieDelay = 5;
time_t startup_time = time(NULL);
+int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops
+time_t nb_start = time(NULL);
extern vector<Module*> modules;
-vector<string> module_names;
+std::vector<std::string> module_names;
extern vector<ircd_module*> factory;
-vector<int> fd_reap;
+std::vector<int> fd_reap;
extern int MODCOUNT;
bool IsDenied(userrec *user);
void AddWhoWas(userrec* u);
+std::stringstream config_f(stringstream::in | stringstream::out);
void safedelete(userrec *p)
{
log(DEBUG,"deleting %s %s %s %s",p->nick,p->ident,p->dhost,p->fullname);
log(DEBUG,"safedelete(userrec*): pointer is safe to delete");
delete p;
+ p = NULL;
}
else
{
if (p)
{
delete p;
+ p = NULL;
log(DEBUG,"safedelete(chanrec*): pointer is safe to delete");
}
else
void chop(char* str)
{
-
+ if (!str)
+ {
+ log(DEBUG,"ERROR! Null string passed to chop()!");
+ return;
+ }
string temp = str;
FOREACH_MOD OnServerRaw(temp,false);
const char* str2 = temp.c_str();
void ReadConfig(void)
{
- char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF];
+ char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF];
ConnectClass c;
- ConfValue("server","name",0,ServerName);
- ConfValue("server","description",0,ServerDesc);
- ConfValue("server","network",0,Network);
- ConfValue("admin","name",0,AdminName);
- ConfValue("admin","email",0,AdminEmail);
- ConfValue("admin","nick",0,AdminNick);
- ConfValue("files","motd",0,motd);
- ConfValue("files","rules",0,rules);
- ConfValue("power","diepass",0,diepass);
- ConfValue("power","pause",0,pauseval);
- ConfValue("power","restartpass",0,restartpass);
- ConfValue("options","prefixquit",0,PrefixQuit);
- ConfValue("die","value",0,DieValue);
- ConfValue("options","loglevel",0,dbg);
+ LoadConf(CONFIG_FILE,&config_f);
+
+ ConfValue("server","name",0,ServerName,&config_f);
+ ConfValue("server","description",0,ServerDesc,&config_f);
+ ConfValue("server","network",0,Network,&config_f);
+ ConfValue("admin","name",0,AdminName,&config_f);
+ ConfValue("admin","email",0,AdminEmail,&config_f);
+ ConfValue("admin","nick",0,AdminNick,&config_f);
+ ConfValue("files","motd",0,motd,&config_f);
+ ConfValue("files","rules",0,rules,&config_f);
+ ConfValue("power","diepass",0,diepass,&config_f);
+ ConfValue("power","pause",0,pauseval,&config_f);
+ ConfValue("power","restartpass",0,restartpass,&config_f);
+ ConfValue("options","prefixquit",0,PrefixQuit,&config_f);
+ ConfValue("die","value",0,DieValue,&config_f);
+ ConfValue("options","loglevel",0,dbg,&config_f);
+ ConfValue("options","netbuffersize",0,NB,&config_f);
+ NetBufferSize = atoi(NB);
+ if ((!NetBufferSize) || (NetBufferSize > 65535) || (NetBufferSize < 1024))
+ {
+ log(DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
+ NetBufferSize = 10240;
+ }
if (!strcmp(dbg,"debug"))
LogLevel = DEBUG;
if (!strcmp(dbg,"verbose"))
LogLevel = SPARSE;
if (!strcmp(dbg,"none"))
LogLevel = NONE;
+ readfile(MOTD,motd);
+ log(DEBUG,"Reading message of the day");
readfile(RULES,rules);
log(DEBUG,"Reading connect classes");
Classes.clear();
- for (int i = 0; i < ConfValueEnum("connect"); i++)
+ for (int i = 0; i < ConfValueEnum("connect",&config_f); i++)
{
strcpy(Value,"");
- ConfValue("connect","allow",i,Value);
+ ConfValue("connect","allow",i,Value,&config_f);
+ ConfValue("connect","timeout",i,timeout,&config_f);
+ ConfValue("connect","flood",i,flood,&config_f);
if (strcmp(Value,""))
{
strcpy(c.host,Value);
c.type = CC_ALLOW;
strcpy(Value,"");
- ConfValue("connect","password",i,Value);
+ ConfValue("connect","password",i,Value,&config_f);
strcpy(c.pass,Value);
+ c.registration_timeout = 90; // default is 2 minutes
+ c.flood = atoi(flood);
+ if (atoi(timeout)>0)
+ {
+ c.registration_timeout = atoi(timeout);
+ }
Classes.push_back(c);
- log(DEBUG,"Read connect class type ALLOW, host=%s password=%s",c.host,c.pass);
+ log(DEBUG,"Read connect class type ALLOW, host=%s password=%s timeout=%d flood=%d",c.host,c.pass,c.registration_timeout,c.flood);
}
else
{
- ConfValue("connect","deny",i,Value);
+ ConfValue("connect","deny",i,Value,&config_f);
strcpy(c.host,Value);
c.type = CC_DENY;
Classes.push_back(c);
int flags;
log(DEBUG,"NonBlocking: %d",s);
flags = fcntl(s, F_GETFL, 0);
+ //fcntl(s, F_SETFL, O_NONBLOCK);
fcntl(s, F_SETFL, flags | O_NONBLOCK);
}
va_end(argsPtr);
sprintf(tb,"%s\r\n",textbuffer);
chop(tb);
- write(sock,tb,strlen(tb));
- update_stats_l(sock,strlen(tb)); /* add one line-out to stats L for this fd */
+ if (sock != -1)
+ {
+ write(sock,tb,strlen(tb));
+ update_stats_l(sock,strlen(tb)); /* add one line-out to stats L for this fd */
+ }
}
/* write a server formatted numeric response to a single socket */
va_end(argsPtr);
sprintf(tb,":%s %s\r\n",ServerName,textbuffer);
chop(tb);
- write(sock,tb,strlen(tb));
- update_stats_l(sock,strlen(tb)); /* add one line-out to stats L for this fd */
+ if (sock != -1)
+ {
+ write(sock,tb,strlen(tb));
+ update_stats_l(sock,strlen(tb)); /* add one line-out to stats L for this fd */
+ }
}
/* write text from an originating user to originating user */
va_end(argsPtr);
sprintf(tb,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
chop(tb);
- write(sock,tb,strlen(tb));
- update_stats_l(sock,strlen(tb)); /* add one line-out to stats L for this fd */
+ if (sock != -1)
+ {
+ write(sock,tb,strlen(tb));
+ update_stats_l(sock,strlen(tb)); /* add one line-out to stats L for this fd */
+ }
}
/* write text to an destination user from a source user (e.g. user privmsg) */
void WriteTo(userrec *source, userrec *dest,char *data, ...)
{
- if ((!source) || (!dest) || (!data))
+ if ((!dest) || (!data))
{
log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
return;
vsnprintf(textbuffer, MAXBUF, data, argsPtr);
va_end(argsPtr);
chop(tb);
- WriteFrom(dest->fd,source,"%s",textbuffer);
+
+ // if no source given send it from the server.
+ if (!source)
+ {
+ WriteServ(dest->fd,":%s %s",ServerName,textbuffer);
+ }
+ else
+ {
+ WriteFrom(dest->fd,source,"%s",textbuffer);
+ }
}
/* write formatted text from a source user to all users on a channel
}
}
+/* write formatted text from a source user to all users on a channel
+ * including the sender (NOT for privmsg, notice etc!) doesnt send to
+ * users on remote servers */
+
+void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
+{
+ if ((!Ptr) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
+ return;
+ }
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+ va_start (argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+ for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+ {
+ if (has_channel(i->second,Ptr))
+ {
+ if (i->second->fd != -1)
+ {
+ if (!user)
+ {
+ WriteServ(i->second->fd,"%s",textbuffer);
+ }
+ else
+ {
+ WriteTo(user,i->second,"%s",textbuffer);
+ }
+ }
+ }
+ }
+}
+
+
void WriteChannelWithServ(char* ServerName, chanrec* Ptr, userrec* user, char* text, ...)
{
if ((!Ptr) || (!user) || (!text))
log(DEFAULT,"*** BUG *** common_channels was given an invalid parameter");
return 0;
}
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
for (z = 0; z != MAXCHANS; z++)
{
}
}
+// returns TRUE of any users on channel C occupy server 'servername'.
+
+bool ChanAnyOnThisServer(chanrec *c,char* servername)
+{
+ log(DEBUG,"ChanAnyOnThisServer");
+ for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
+ {
+ if (has_channel(i->second,c))
+ {
+ if (!strcasecmp(i->second->server,servername))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+// returns true if user 'u' shares any common channels with any users on server 'servername'
+
+bool CommonOnThisServer(userrec* u,char* servername)
+{
+ log(DEBUG,"ChanAnyOnThisServer");
+ for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
+ {
+ if ((common_channels(u,i->second)) && (u != i->second))
+ {
+ if (!strcasecmp(i->second->server,servername))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+
+bool hasumode(userrec* user, char mode)
+{
+ if (user)
+ {
+ return (strchr(user->modes,mode)>0);
+ }
+ else return false;
+}
+
+void WriteMode(const char* modes, int flags, const char* text, ...)
+{
+ if ((!text) || (!modes) || (!flags))
+ {
+ log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
+ return;
+ }
+
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+ va_start (argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+ {
+ if (i->second)
+ {
+ bool send_to_user = false;
+
+ if (flags == WM_AND)
+ {
+ send_to_user = true;
+ for (int n = 0; n < strlen(modes); n++)
+ {
+ if (!hasumode(i->second,modes[n]))
+ {
+ send_to_user = false;
+ break;
+ }
+ }
+ }
+ else if (flags == WM_OR)
+ {
+ send_to_user = false;
+ for (int n = 0; n < strlen(modes); n++)
+ {
+ if (hasumode(i->second,modes[n]))
+ {
+ send_to_user = true;
+ break;
+ }
+ }
+ }
+
+ if (send_to_user)
+ {
+ WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
+ }
+ }
+ }
+}
+
void WriteWallOps(userrec *source, char* text, ...)
{
if ((!text) || (!source))
int isident(const char* n)
{
- int i = 0;
char v[MAXBUF];
if (!n)
{
return 0;
}
- for (i = 0; i != strlen(n); i++)
+ for (int i = 0; i != strlen(n); i++)
{
if ((n[i] < 33) || (n[i] > 125))
{
{
return 0;
}
- for (i = 0; i != strlen(n); i++)
+ for (int i = 0; i != strlen(n); i++)
{
if ((n[i] < 33) || (n[i] > 125))
{
}
int i;
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
if ((user->chans[i].channel == chan) && (chan != NULL))
{
}
}
-char scratch[MAXMODES];
-char sparam[MAXMODES];
+char scratch[MAXBUF];
+char sparam[MAXBUF];
char* chanmodes(chanrec *chan)
{
strcpy(sparam,"");
if (chan->noexternal)
{
- strcat(scratch,"n");
+ strncat(scratch,"n",MAXMODES);
}
if (chan->topiclock)
{
- strcat(scratch,"t");
+ strncat(scratch,"t",MAXMODES);
}
if (strcmp(chan->key,""))
{
- strcat(scratch,"k");
+ strncat(scratch,"k",MAXMODES);
}
if (chan->limit)
{
- strcat(scratch,"l");
+ strncat(scratch,"l",MAXMODES);
}
if (chan->inviteonly)
{
- strcat(scratch,"i");
+ strncat(scratch,"i",MAXMODES);
}
if (chan->moderated)
{
- strcat(scratch,"m");
+ strncat(scratch,"m",MAXMODES);
}
if (chan->secret)
{
- strcat(scratch,"s");
+ strncat(scratch,"s",MAXMODES);
}
if (chan->c_private)
{
- strcat(scratch,"p");
+ strncat(scratch,"p",MAXMODES);
}
if (strcmp(chan->key,""))
{
- strcat(sparam,chan->key);
+ strncat(sparam,chan->key,MAXBUF);
}
if (chan->limit)
{
char foo[24];
sprintf(foo," %d",chan->limit);
- strcat(sparam,foo);
+ strncat(sparam,foo,MAXBUF);
}
if (strlen(chan->custom_modes))
{
std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
if (extparam != "")
{
- strcat(sparam," ");
- strcat(sparam,extparam.c_str());
+ strncat(sparam," ",MAXBUF);
+ strncat(sparam,extparam.c_str(),MAXBUF);
}
}
}
return 0;
}
- int i;
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
if ((user->chans[i].channel == chan) && (chan != NULL))
{
/* add a channel to a user, creating the record for it if needed and linking
* it to the user record */
-chanrec* add_channel(userrec *user, char* cname, char* key)
+chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override)
{
-
- if ((!user) || (!cname))
+ if ((!user) || (!cn))
{
log(DEFAULT,"*** BUG *** add_channel was given an invalid parameter");
return 0;
int i = 0;
chanrec* Ptr;
int created = 0;
+ char cname[MAXBUF];
+
+ strncpy(cname,cn,MAXBUF);
// we MUST declare this wherever we use FOREACH_RESULT
int MOD_RESULT = 0;
- if ((!cname) || (!user))
- {
- return NULL;
- }
if (strlen(cname) > CHANMAX-1)
{
cname[CHANMAX-1] = '\0';
Ptr = FindChan(cname);
if (Ptr)
{
- FOREACH_RESULT(OnUserPreJoin(user,Ptr,cname));
- if (MOD_RESULT) {
- return NULL;
- }
-
log(DEBUG,"add_channel: joining to: %s",Ptr->name);
- if (strcmp(Ptr->key,""))
+
+ // the override flag allows us to bypass channel modes
+ // and bans (used by servers)
+ if (!override)
{
- log(DEBUG,"add_channel: %s has key %s",Ptr->name,Ptr->key);
- if (!key)
- {
- log(DEBUG,"add_channel: no key given in JOIN");
- WriteServ(user->fd,"475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
+ FOREACH_RESULT(OnUserPreJoin(user,Ptr,cname));
+ if (MOD_RESULT) {
return NULL;
}
- else
+
+ if (strcmp(Ptr->key,""))
{
- log(DEBUG,"key at %p is %s",key,key);
- if (strcasecmp(key,Ptr->key))
+ log(DEBUG,"add_channel: %s has key %s",Ptr->name,Ptr->key);
+ if (!key)
{
- log(DEBUG,"add_channel: bad key given in JOIN");
- WriteServ(user->fd,"475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
+ log(DEBUG,"add_channel: no key given in JOIN");
+ WriteServ(user->fd,"475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
return NULL;
}
+ else
+ {
+ log(DEBUG,"key at %p is %s",key,key);
+ if (strcasecmp(key,Ptr->key))
+ {
+ log(DEBUG,"add_channel: bad key given in JOIN");
+ WriteServ(user->fd,"475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
+ return NULL;
+ }
+ }
}
- }
- log(DEBUG,"add_channel: no key");
-
- if (Ptr->inviteonly)
- {
- log(DEBUG,"add_channel: channel is +i");
- if (user->IsInvited(Ptr->name))
+ log(DEBUG,"add_channel: no key");
+
+ if (Ptr->inviteonly)
{
- /* user was invited to channel */
- /* there may be an optional channel NOTICE here */
+ log(DEBUG,"add_channel: channel is +i");
+ if (user->IsInvited(Ptr->name))
+ {
+ /* user was invited to channel */
+ /* there may be an optional channel NOTICE here */
+ }
+ else
+ {
+ WriteServ(user->fd,"473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
+ return NULL;
+ }
}
- else
+ log(DEBUG,"add_channel: channel is not +i");
+
+ if (Ptr->limit)
{
- WriteServ(user->fd,"473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
- return NULL;
+ if (usercount(Ptr) == Ptr->limit)
+ {
+ WriteServ(user->fd,"471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
+ return NULL;
+ }
}
- }
- log(DEBUG,"add_channel: channel is not +i");
-
- if (Ptr->limit)
- {
- if (usercount(Ptr) == Ptr->limit)
+
+ log(DEBUG,"add_channel: about to walk banlist");
+
+ /* check user against the channel banlist */
+ if (Ptr)
{
- WriteServ(user->fd,"471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
- return NULL;
+ if (Ptr->bans.size())
+ {
+ for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
+ {
+ if (match(user->GetFullHost(),i->data))
+ {
+ WriteServ(user->fd,"474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
+ return NULL;
+ }
+ }
+ }
}
- }
-
- log(DEBUG,"add_channel: about to walk banlist");
+
+ log(DEBUG,"add_channel: bans checked");
+
- /* check user against the channel banlist */
- for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
- {
- if (match(user->GetFullHost(),i->data))
+ if ((Ptr) && (user))
{
- WriteServ(user->fd,"474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
- return NULL;
+ user->RemoveInvite(Ptr->name);
}
- }
-
- log(DEBUG,"add_channel: bans checked");
+
+ log(DEBUG,"add_channel: invites removed");
- user->RemoveInvite(Ptr->name);
+ }
+ else
+ {
+ log(DEBUG,"Overridden checks");
+ }
- log(DEBUG,"add_channel: invites removed");
}
created = 1;
log(DEBUG,"Passed channel checks");
- for (i =0; i != MAXCHANS; i++)
+ for (int i =0; i != MAXCHANS; i++)
{
+ log(DEBUG,"Check location %d",i);
if (user->chans[i].channel == NULL)
{
- log(DEBUG,"Adding into their channel list");
+ log(DEBUG,"Adding into their channel list at location %d",i);
if (created == 2)
{
}
user->chans[i].channel = Ptr;
WriteChannel(Ptr,user,"JOIN :%s",Ptr->name);
+
+ if (!override) // we're not overriding... so this isnt part of a netburst, broadcast it.
+ {
+ // use the stamdard J token with no privilages.
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"J %s :%s",user->nick,Ptr->name);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent J token");
+ }
+ }
+ }
log(DEBUG,"Sent JOIN to client");
/* remove a channel from a users record, and remove the record from memory
* if the channel has become empty */
-chanrec* del_channel(userrec *user, char* cname, char* reason)
+chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local)
{
if ((!user) || (!cname))
{
return NULL;
}
- int i = 0;
chanrec* Ptr;
int created = 0;
FOREACH_MOD OnUserPart(user,Ptr);
log(DEBUG,"del_channel: removing: %s %s",user->nick,Ptr->name);
- for (i =0; i != MAXCHANS; i++)
+ for (int i =0; i != MAXCHANS; i++)
{
/* zap it from the channel list of the user */
if (user->chans[i].channel == Ptr)
if (reason)
{
WriteChannel(Ptr,user,"PART %s :%s",Ptr->name, reason);
+
+ if (!local)
+ {
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"L %s %s :%s",user->nick,Ptr->name,reason);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent L token (with reason)");
+ }
+ }
+ }
+
+
}
else
{
+ if (!local)
+ {
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"L %s %s :",user->nick,Ptr->name);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent L token (no reason)");
+ }
+ }
+ }
+
WriteChannel(Ptr,user,"PART :%s",Ptr->name);
}
user->chans[i].uc_modes = 0;
}
else
{
- WriteServ(src->fd,"482 %s %s :You must be at least a half-operator",src->nick, Ptr->name);
+ WriteServ(src->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",src->nick, Ptr->name);
}
return;
}
- for (i =0; i != MAXCHANS; i++)
+ for (int i =0; i != MAXCHANS; i++)
{
/* zap it from the channel list of the user */
- if (user->chans[i].channel == Ptr)
+ if (user->chans[i].channel)
+ if (!strcasecmp(user->chans[i].channel->name,Ptr->name))
{
WriteChannel(Ptr,src,"KICK %s %s :%s",Ptr->name, user->nick, reason);
user->chans[i].uc_modes = 0;
int has_channel(userrec *u, chanrec *c)
{
- int i = 0;
-
if ((!u) || (!c))
{
log(DEFAULT,"*** BUG *** has_channel was given an invalid parameter");
return 0;
}
- for (i =0; i != MAXCHANS; i++)
+ for (int i =0; i != MAXCHANS; i++)
{
if (u->chans[i].channel == c)
{
log(DEFAULT,"*** BUG *** give_ops was given an invalid parameter");
return 0;
}
- if (status != STATUS_OP)
+ if (status < STATUS_OP)
{
+ log(DEBUG,"%s cant give ops to %s because they nave status %d and needs %d",user->nick,dest,status,STATUS_OP);
WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
return 0;
}
{
if (!isnick(dest))
{
+ log(DEFAULT,"the target nickname given to give_ops was invalid");
WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
return 0;
}
d = Find(dest);
if (!d)
{
+ log(DEFAULT,"the target nickname given to give_ops couldnt be found");
WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
return 0;
}
else
{
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
- if ((d->chans[i].channel == chan) && (chan != NULL))
+ if ((d->chans[i].channel != NULL) && (chan != NULL))
+ if (!strcasecmp(d->chans[i].channel->name,chan->name))
{
if (d->chans[i].uc_modes & UCMODE_OP)
{
/* mode already set on user, dont allow multiple */
+ log(DEFAULT,"The target user given to give_ops was already opped on the channel");
return 0;
}
d->chans[i].uc_modes = d->chans[i].uc_modes | UCMODE_OP;
log(DEBUG,"gave ops: %s %s",d->chans[i].channel->name,d->nick);
+ return 1;
}
}
+ log(DEFAULT,"The target channel given to give_ops was not in the users mode list");
}
}
return 1;
}
else
{
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
- if ((d->chans[i].channel == chan) && (chan != NULL))
+ if ((d->chans[i].channel != NULL) && (chan != NULL))
+ if (!strcasecmp(d->chans[i].channel->name,chan->name))
{
if (d->chans[i].uc_modes & UCMODE_HOP)
{
}
d->chans[i].uc_modes = d->chans[i].uc_modes | UCMODE_HOP;
log(DEBUG,"gave h-ops: %s %s",d->chans[i].channel->name,d->nick);
+ return 1;
}
}
}
}
if (status < STATUS_HOP)
{
- WriteServ(user->fd,"482 %s %s :You must be at least a half-operator",user->nick, chan->name);
+ WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
return 0;
}
else
}
else
{
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
- if ((d->chans[i].channel == chan) && (chan != NULL))
+ if ((d->chans[i].channel != NULL) && (chan != NULL))
+ if (!strcasecmp(d->chans[i].channel->name,chan->name))
{
if (d->chans[i].uc_modes & UCMODE_VOICE)
{
}
d->chans[i].uc_modes = d->chans[i].uc_modes | UCMODE_VOICE;
log(DEBUG,"gave voice: %s %s",d->chans[i].channel->name,d->nick);
+ return 1;
}
}
}
log(DEFAULT,"*** BUG *** take_ops was given an invalid parameter");
return 0;
}
- if (status != STATUS_OP)
+ if (status < STATUS_OP)
{
+ log(DEBUG,"%s cant give ops to %s because they have status %d and needs %d",user->nick,dest,status,STATUS_OP);
WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
return 0;
}
d = Find(dest);
if (!isnick(dest))
{
+ log(DEBUG,"take_ops was given an invalid target nickname of %s",dest);
WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
return 0;
}
if (!d)
{
+ log(DEBUG,"take_ops couldnt resolve the target nickname: %s",dest);
WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
return 0;
}
else
{
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
- if ((d->chans[i].channel == chan) && (chan != NULL))
+ if ((d->chans[i].channel != NULL) && (chan != NULL))
+ if (!strcasecmp(d->chans[i].channel->name,chan->name))
{
if ((d->chans[i].uc_modes & UCMODE_OP) == 0)
{
}
d->chans[i].uc_modes ^= UCMODE_OP;
log(DEBUG,"took ops: %s %s",d->chans[i].channel->name,d->nick);
+ return 1;
}
}
+ log(DEBUG,"take_ops couldnt locate the target channel in the target users list");
}
}
return 1;
}
else
{
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
- if ((d->chans[i].channel == chan) && (chan != NULL))
+ if ((d->chans[i].channel != NULL) && (chan != NULL))
+ if (!strcasecmp(d->chans[i].channel->name,chan->name))
{
if ((d->chans[i].uc_modes & UCMODE_HOP) == 0)
{
}
d->chans[i].uc_modes ^= UCMODE_HOP;
log(DEBUG,"took h-ops: %s %s",d->chans[i].channel->name,d->nick);
+ return 1;
}
}
}
}
if (status < STATUS_HOP)
{
- WriteServ(user->fd,"482 %s %s :You must be at least a half-operator",user->nick, chan->name);
+ WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
return 0;
}
else
}
else
{
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
- if ((d->chans[i].channel == chan) && (chan != NULL))
+ if ((d->chans[i].channel != NULL) && (chan != NULL))
+ if (!strcasecmp(d->chans[i].channel->name,chan->name))
{
if ((d->chans[i].uc_modes & UCMODE_VOICE) == 0)
{
}
d->chans[i].uc_modes ^= UCMODE_VOICE;
log(DEBUG,"took voice: %s %s",d->chans[i].channel->name,d->nick);
+ return 1;
}
}
}
return 0;
}
-void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode)
+void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
{
- if ((!parameters) || (!user)) {
+ if (!parameters) {
log(DEFAULT,"*** BUG *** process_modes was given an invalid parameter");
return;
}
-
char modelist[MAXBUF];
char outlist[MAXBUF];
char outstr[MAXBUF];
return;
}
- log(DEBUG,"process_modes: start");
+ log(DEBUG,"process_modes: start: parameters=%d",pcnt);
strcpy(modelist,parameters[1]); /* mode list, e.g. +oo-o */
/* parameters[2] onwards are parameters for
break;
case 'o':
+ log(DEBUG,"Ops");
if ((param >= pcnt)) break;
+ log(DEBUG,"Enough parameters left");
if (mdir == 1)
{
+ log(DEBUG,"calling give_ops");
r = give_ops(user,parameters[param++],chan,status);
}
else
{
+ log(DEBUG,"calling take_ops");
r = take_ops(user,parameters[param++],chan,status);
}
if (r)
strcat(outstr," ");
strcat(outstr,outpars[ptr]);
}
- if (servermode)
+ if (local)
{
- WriteChannelWithServ(ServerName,chan,user,"MODE %s %s",chan->name,outstr);
+ log(DEBUG,"Local mode change");
+ WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outstr);
}
else
{
- WriteChannel(chan,user,"MODE %s %s",chan->name,outstr);
+ if (servermode)
+ {
+ if (!silent)
+ {
+ WriteChannelWithServ(ServerName,chan,user,"MODE %s %s",chan->name,outstr);
+ // M token for a usermode must go to all servers
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"M %s %s",chan->name, outstr);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent M token");
+ }
+ }
+ }
+ }
+
+ }
+ else
+ {
+ if (!silent)
+ {
+ WriteChannel(chan,user,"MODE %s %s",chan->name,outstr);
+ // M token for a usermode must go to all servers
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"m %s %s %s",user->nick,chan->name, outstr);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent m token");
+ }
+ }
+ }
+ }
+ }
}
}
}
-void handle_mode(char **parameters, int pcnt, userrec *user)
-{
- chanrec* Ptr;
- userrec* dest;
- int can_change,i;
- int direction = 1;
- char outpars[MAXBUF];
-
- dest = Find(parameters[0]);
+// based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
- if ((dest) && (pcnt == 1))
+bool allowed_umode(char umode, char* sourcemodes,bool adding)
+{
+ log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
+ // RFC1459 specified modes
+ if ((umode == 'w') || (umode == 's') || (umode == 'i'))
{
- WriteServ(user->fd,"221 %s :+%s",user->nick,user->modes);
- return;
+ log(DEBUG,"umode %c allowed by RFC1459 scemantics",umode);
+ return true;
}
- if ((dest) && (pcnt > 1))
+
+ // user may not +o themselves or others, but an oper may de-oper other opers or themselves
+ if ((strchr(sourcemodes,'o')) && (!adding))
{
- can_change = 0;
- if (user != dest)
+ log(DEBUG,"umode %c allowed by RFC1459 scemantics",umode);
+ return true;
+ }
+ else if (umode == 'o')
+ {
+ log(DEBUG,"umode %c allowed by RFC1459 scemantics",umode);
+ return false;
+ }
+
+ // process any module-defined modes that need oper
+ if ((ModeDefinedOper(umode,MT_CLIENT)) && (strchr(sourcemodes,'o')))
+ {
+ log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
+ return true;
+ }
+ else
+ if (ModeDefined(umode,MT_CLIENT))
+ {
+ // process any module-defined modes that don't need oper
+ log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
+ if ((ModeDefinedOper(umode,MT_CLIENT)) && (!strchr(sourcemodes,'o')))
+ {
+ // no, this mode needs oper, and this user 'aint got what it takes!
+ return false;
+ }
+ return true;
+ }
+
+ // anything else - return false.
+ log(DEBUG,"umode %c not known by any ruleset",umode);
+ return false;
+}
+
+bool process_module_umode(char umode, userrec* source, void* dest, bool adding)
+{
+ userrec* s2;
+ bool faked = false;
+ if (!source)
+ {
+ s2 = new userrec;
+ strncpy(s2->nick,ServerName,NICKMAX);
+ strcpy(s2->modes,"o");
+ s2->fd = -1;
+ source = s2;
+ faked = true;
+ }
+ string_list p;
+ p.clear();
+ if (ModeDefined(umode,MT_CLIENT))
+ {
+ for (int i = 0; i <= MODCOUNT; i++)
+ {
+ if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
+ {
+ log(DEBUG,"Module claims umode %c",umode);
+ return true;
+ }
+ }
+ log(DEBUG,"No module claims umode %c",umode);
+ if (faked)
+ {
+ delete s2;
+ source = NULL;
+ }
+ return false;
+ }
+ else
+ {
+ log(DEBUG,"*** BUG *** Non-module umode passed to process_module_umode!");
+ if (faked)
+ {
+ delete s2;
+ source = NULL;
+ }
+ return false;
+ }
+}
+
+void handle_mode(char **parameters, int pcnt, userrec *user)
+{
+ chanrec* Ptr;
+ userrec* dest;
+ int can_change,i;
+ int direction = 1;
+ char outpars[MAXBUF];
+
+ dest = Find(parameters[0]);
+
+ if (!user)
+ {
+ return;
+ }
+
+ if ((dest) && (pcnt == 1))
+ {
+ WriteServ(user->fd,"221 %s :+%s",user->nick,user->modes);
+ return;
+ }
+
+ if ((dest) && (pcnt > 1))
+ {
+ char dmodes[MAXBUF];
+ strncpy(dmodes,dest->modes,MAXBUF);
+ log(DEBUG,"pulled up dest user modes: %s",dmodes);
+
+ can_change = 0;
+ if (user != dest)
{
if (strchr(user->modes,'o'))
{
if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
return;
- for (i = 0; i < strlen(parameters[1]); i++)
+ for (int i = 0; i < strlen(parameters[1]); i++)
{
if (parameters[1][i] == '+')
{
}
else
{
- if ((parameters[1][i] == 'i') || (parameters[1][i] == 'w') || (parameters[1][i] == 's'))
+ if ((parameters[1][i] == 'i') || (parameters[1][i] == 'w') || (parameters[1][i] == 's') || (allowed_umode(parameters[1][i],user->modes,direction)))
{
can_change = 1;
}
{
if (direction == 1)
{
- if (!strchr(dest->modes,parameters[1][i]))
+ if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],user->modes,true)))
{
- dest->modes[strlen(dest->modes)+1]='\0';
- dest->modes[strlen(dest->modes)] = parameters[1][i];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ char umode = parameters[1][i];
+ if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
+ {
+ dmodes[strlen(dmodes)+1]='\0';
+ dmodes[strlen(dmodes)] = parameters[1][i];
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+ }
}
}
else
{
- int q = 0;
- char temp[MAXBUF];
- char moo[MAXBUF];
-
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
-
- strcpy(temp,"");
- for (q = 0; q < strlen(user->modes); q++)
+ if ((allowed_umode(parameters[1][i],user->modes,false)) && (strchr(dmodes,parameters[1][i])))
{
- if (user->modes[q] != parameters[1][i])
+ char umode = parameters[1][i];
+ if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
{
- moo[0] = user->modes[q];
- moo[1] = '\0';
- strcat(temp,moo);
+ int q = 0;
+ char temp[MAXBUF];
+ char moo[MAXBUF];
+
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+
+ strcpy(temp,"");
+ for (q = 0; q < strlen(dmodes); q++)
+ {
+ if (dmodes[q] != parameters[1][i])
+ {
+ moo[0] = dmodes[q];
+ moo[1] = '\0';
+ strcat(temp,moo);
+ }
+ }
+ strcpy(dmodes,temp);
}
}
- strcpy(user->modes,temp);
}
}
}
return;
WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
+
+ // M token for a usermode must go to all servers
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent m token");
+ }
+ }
+ }
+
+ if (strlen(dmodes)>MAXMODES)
+ {
+ dmodes[MAXMODES-1] = '\0';
+ }
+ log(DEBUG,"Stripped mode line");
+ log(DEBUG,"Line dest is now %s",dmodes);
+ strncpy(dest->modes,dmodes,MAXMODES);
+
}
+
return;
}
WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
}
WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
+ return;
}
}
if ((cstatus(user,Ptr) < STATUS_HOP) && (Ptr))
{
- WriteServ(user->fd,"482 %s %s :You must be at least a half-operator",user->nick, Ptr->name);
+ WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
return;
}
- process_modes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false);
+ process_modes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
}
else
{
char outpars[MAXBUF];
dest = Find(parameters[0]);
+
+ // fix: ChroNiCk found this - we cant use this as debug if its null!
+ if (dest)
+ {
+ log(DEBUG,"server_mode on %s",dest->nick);
+ }
if ((dest) && (pcnt > 1))
{
+ log(DEBUG,"params > 1");
+
+ char dmodes[MAXBUF];
+ strncpy(dmodes,dest->modes,MAXBUF);
+
strcpy(outpars,"+");
direction = 1;
if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
return;
- for (i = 0; i < strlen(parameters[1]); i++)
+ for (int i = 0; i < strlen(parameters[1]); i++)
{
if (parameters[1][i] == '+')
{
}
else
{
- can_change = 0;
- if (strchr(user->modes,'o'))
- {
- can_change = 1;
- }
- else
- {
- if ((parameters[1][i] == 'i') || (parameters[1][i] == 'w') || (parameters[1][i] == 's'))
- {
- can_change = 1;
- }
- }
+ log(DEBUG,"begin mode processing entry");
+ can_change = 1;
if (can_change)
{
if (direction == 1)
{
- if (!strchr(dest->modes,parameters[1][i]))
+ log(DEBUG,"umode %c being added",parameters[1][i]);
+ if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],user->modes,true)))
{
- dest->modes[strlen(dest->modes)+1]='\0';
- dest->modes[strlen(dest->modes)] = parameters[1][i];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ char umode = parameters[1][i];
+ log(DEBUG,"umode %c is an allowed umode",umode);
+ if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
+ {
+ dmodes[strlen(dmodes)+1]='\0';
+ dmodes[strlen(dmodes)] = parameters[1][i];
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+ }
}
}
else
{
- int q = 0;
- char temp[MAXBUF];
- char moo[MAXBUF];
-
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
-
- strcpy(temp,"");
- for (q = 0; q < strlen(user->modes); q++)
+ // can only remove a mode they already have
+ log(DEBUG,"umode %c being removed",parameters[1][i]);
+ if ((allowed_umode(parameters[1][i],user->modes,false)) && (strchr(dmodes,parameters[1][i])))
{
- if (user->modes[q] != parameters[1][i])
+ char umode = parameters[1][i];
+ log(DEBUG,"umode %c is an allowed umode",umode);
+ if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
{
- moo[0] = user->modes[q];
- moo[1] = '\0';
- strcat(temp,moo);
+ int q = 0;
+ char temp[MAXBUF];
+ char moo[MAXBUF];
+
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+
+ strcpy(temp,"");
+ for (q = 0; q < strlen(dmodes); q++)
+ {
+ if (dmodes[q] != parameters[1][i])
+ {
+ moo[0] = dmodes[q];
+ moo[1] = '\0';
+ strcat(temp,moo);
+ }
+ }
+ strcpy(dmodes,temp);
}
}
- strcpy(user->modes,temp);
}
}
}
return;
WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
+
+ // M token for a usermode must go to all servers
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent m token");
+ }
+ }
+ }
+
+ if (strlen(dmodes)>MAXMODES)
+ {
+ dmodes[MAXMODES-1] = '\0';
+ }
+ log(DEBUG,"Stripped mode line");
+ log(DEBUG,"Line dest is now %s",dmodes);
+ strncpy(dest->modes,dmodes,MAXMODES);
+
}
+
return;
}
Ptr = FindChan(parameters[0]);
if (Ptr)
{
- process_modes(parameters,user,Ptr,STATUS_OP,pcnt,true);
+ process_modes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
}
else
{
}
-/* This function pokes and hacks at a parameter list like the following:
- *
- * PART #winbot, #darkgalaxy :m00!
- *
- * to turn it into a series of individual calls like this:
- *
- * PART #winbot :m00!
- * PART #darkgalaxy :m00!
- *
- * The seperate calls are sent to a callback function provided by the caller
- * (the caller will usually call itself recursively). The callback function
- * must be a command handler. Calling this function on a line with no list causes
- * no action to be taken. You must provide a starting and ending parameter number
- * where the range of the list can be found, useful if you have a terminating
- * parameter as above which is actually not part of the list, or parameters
- * before the actual list as well. This code is used by many functions which
- * can function as "one to list" (see the RFC) */
-int loop_call(handlerfunc fn, char **parameters, int pcnt, userrec *u, int start, int end, int joins)
+void merge_mode(char **parameters, int pcnt)
{
- char plist[MAXBUF];
- char *param;
- char *pars[32];
- char blog[32][MAXBUF];
- char blog2[32][MAXBUF];
- int i = 0, j = 0, q = 0, total = 0, t = 0, t2 = 0, total2 = 0;
- char keystr[MAXBUF];
- char moo[MAXBUF];
-
- for (i = 0; i <32; i++)
- strcpy(blog[i],"");
-
- for (i = 0; i <32; i++)
- strcpy(blog2[i],"");
+ chanrec* Ptr;
+ userrec* dest;
+ int can_change,i;
+ int direction = 1;
+ char outpars[MAXBUF];
- strcpy(moo,"");
- for (i = 0; i <10; i++)
- {
- if (!parameters[i])
- {
- parameters[i] = moo;
- }
- }
- if (joins)
+ dest = Find(parameters[0]);
+
+ // fix: ChroNiCk found this - we cant use this as debug if its null!
+ if (dest)
{
- if (pcnt > 1) /* we have a key to copy */
- {
- strcpy(keystr,parameters[1]);
- }
+ log(DEBUG,"merge_mode on %s",dest->nick);
}
- if (!parameters[start])
- {
- return 0;
- }
- if (!strchr(parameters[start],','))
- {
- return 0;
- }
- strcpy(plist,"");
- for (i = start; i <= end; i++)
+ if ((dest) && (pcnt > 1))
{
- if (parameters[i])
- {
- strcat(plist,parameters[i]);
- }
- }
-
- j = 0;
- param = plist;
+ log(DEBUG,"params > 1");
- t = strlen(plist);
- for (i = 0; i < t; i++)
- {
- if (plist[i] == ',')
- {
- plist[i] = '\0';
- strcpy(blog[j++],param);
- param = plist+i+1;
- }
- }
- strcpy(blog[j++],param);
- total = j;
+ char dmodes[MAXBUF];
+ strncpy(dmodes,dest->modes,MAXBUF);
- if ((joins) && (keystr) && (total>0)) // more than one channel and is joining
- {
- strcat(keystr,",");
- }
-
- if ((joins) && (keystr))
- {
- if (strchr(keystr,','))
+ strcpy(outpars,"+");
+ direction = 1;
+
+ if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
+ return;
+
+ for (int i = 0; i < strlen(parameters[1]); i++)
{
- j = 0;
- param = keystr;
- t2 = strlen(keystr);
- for (i = 0; i < t2; i++)
+ if (parameters[1][i] == '+')
{
- if (keystr[i] == ',')
+ if (direction != 1)
{
- keystr[i] = '\0';
- strcpy(blog2[j++],param);
- param = keystr+i+1;
+ if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ {
+ outpars[strlen(outpars)-1] = '+';
+ }
+ else
+ {
+ strcat(outpars,"+");
+ }
}
- }
- strcpy(blog2[j++],param);
- total2 = j;
- }
- }
-
- for (j = 0; j < total; j++)
- {
- if (blog[j])
- {
- pars[0] = blog[j];
- }
- for (q = end; q < pcnt-1; q++)
- {
- if (parameters[q+1])
- {
- pars[q-end+1] = parameters[q+1];
- }
- }
- if ((joins) && (parameters[1]))
- {
- if (pcnt > 1)
- {
- pars[1] = blog2[j];
+ direction = 1;
}
else
+ if (parameters[1][i] == '-')
{
- pars[1] = NULL;
- }
+ if (direction != 0)
+ {
+ if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ {
+ outpars[strlen(outpars)-1] = '-';
+ }
+ else
+ {
+ strcat(outpars,"-");
+ }
+ }
+ direction = 0;
+ }
+ else
+ {
+ log(DEBUG,"begin mode processing entry");
+ can_change = 1;
+ if (can_change)
+ {
+ if (direction == 1)
+ {
+ log(DEBUG,"umode %c being added",parameters[1][i]);
+ if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],"o",true)))
+ {
+ char umode = parameters[1][i];
+ log(DEBUG,"umode %c is an allowed umode",umode);
+ if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
+ {
+ dmodes[strlen(dmodes)+1]='\0';
+ dmodes[strlen(dmodes)] = parameters[1][i];
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+ }
+ }
+ }
+ else
+ {
+ // can only remove a mode they already have
+ log(DEBUG,"umode %c being removed",parameters[1][i]);
+ if ((allowed_umode(parameters[1][i],"o",false)) && (strchr(dmodes,parameters[1][i])))
+ {
+ char umode = parameters[1][i];
+ log(DEBUG,"umode %c is an allowed umode",umode);
+ if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
+ {
+ int q = 0;
+ char temp[MAXBUF];
+ char moo[MAXBUF];
+
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+
+ strcpy(temp,"");
+ for (q = 0; q < strlen(dmodes); q++)
+ {
+ if (dmodes[q] != parameters[1][i])
+ {
+ moo[0] = dmodes[q];
+ moo[1] = '\0';
+ strcat(temp,moo);
+ }
+ }
+ strcpy(dmodes,temp);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (strlen(outpars))
+ {
+ char b[MAXBUF];
+ strcpy(b,"");
+ int z = 0;
+ int i = 0;
+ while (i < strlen (outpars))
+ {
+ b[z++] = outpars[i++];
+ b[z] = '\0';
+ if (i<strlen(outpars)-1)
+ {
+ if (((outpars[i] == '-') || (outpars[i] == '+')) && ((outpars[i+1] == '-') || (outpars[i+1] == '+')))
+ {
+ // someones playing silly buggers and trying
+ // to put a +- or -+ into the line...
+ i++;
+ }
+ }
+ if (i == strlen(outpars)-1)
+ {
+ if ((outpars[i] == '-') || (outpars[i] == '+'))
+ {
+ i++;
+ }
+ }
+ }
+
+ z = strlen(b)-1;
+ if ((b[z] == '-') || (b[z] == '+'))
+ b[z] == '\0';
+
+ if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
+ return;
+
+ if (strlen(dmodes)>MAXMODES)
+ {
+ dmodes[MAXMODES-1] = '\0';
+ }
+ log(DEBUG,"Stripped mode line");
+ log(DEBUG,"Line dest is now %s",dmodes);
+ strncpy(dest->modes,dmodes,MAXMODES);
+
+ }
+
+ return;
+ }
+
+ Ptr = FindChan(parameters[0]);
+ if (Ptr)
+ {
+ userrec s2;
+ strncpy(s2.nick,ServerName,NICKMAX);
+ strcpy(s2.modes,"o");
+ s2.fd = -1;
+ process_modes(parameters,&s2,Ptr,STATUS_OP,pcnt,true,true,false);
+ }
+}
+
+
+void merge_mode2(char **parameters, int pcnt, userrec* user)
+{
+ chanrec* Ptr;
+ userrec* dest;
+ int can_change,i;
+ int direction = 1;
+ char outpars[MAXBUF];
+
+ dest = Find(parameters[0]);
+
+ // fix: ChroNiCk found this - we cant use this as debug if its null!
+ if (dest)
+ {
+ log(DEBUG,"merge_mode on %s",dest->nick);
+ }
+
+ if ((dest) && (pcnt > 1))
+ {
+ log(DEBUG,"params > 1");
+
+ char dmodes[MAXBUF];
+ strncpy(dmodes,dest->modes,MAXBUF);
+
+ strcpy(outpars,"+");
+ direction = 1;
+
+ if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
+ return;
+
+ for (int i = 0; i < strlen(parameters[1]); i++)
+ {
+ if (parameters[1][i] == '+')
+ {
+ if (direction != 1)
+ {
+ if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ {
+ outpars[strlen(outpars)-1] = '+';
+ }
+ else
+ {
+ strcat(outpars,"+");
+ }
+ }
+ direction = 1;
+ }
+ else
+ if (parameters[1][i] == '-')
+ {
+ if (direction != 0)
+ {
+ if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ {
+ outpars[strlen(outpars)-1] = '-';
+ }
+ else
+ {
+ strcat(outpars,"-");
+ }
+ }
+ direction = 0;
+ }
+ else
+ {
+ log(DEBUG,"begin mode processing entry");
+ can_change = 1;
+ if (can_change)
+ {
+ if (direction == 1)
+ {
+ log(DEBUG,"umode %c being added",parameters[1][i]);
+ if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],user->modes,true)))
+ {
+ char umode = parameters[1][i];
+ log(DEBUG,"umode %c is an allowed umode",umode);
+ if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
+ {
+ dmodes[strlen(dmodes)+1]='\0';
+ dmodes[strlen(dmodes)] = parameters[1][i];
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+ }
+ }
+ }
+ else
+ {
+ // can only remove a mode they already have
+ log(DEBUG,"umode %c being removed",parameters[1][i]);
+ if ((allowed_umode(parameters[1][i],user->modes,false)) && (strchr(dmodes,parameters[1][i])))
+ {
+ char umode = parameters[1][i];
+ log(DEBUG,"umode %c is an allowed umode",umode);
+ if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
+ {
+ int q = 0;
+ char temp[MAXBUF];
+ char moo[MAXBUF];
+
+ outpars[strlen(outpars)+1]='\0';
+ outpars[strlen(outpars)] = parameters[1][i];
+
+ strcpy(temp,"");
+ for (q = 0; q < strlen(dmodes); q++)
+ {
+ if (dmodes[q] != parameters[1][i])
+ {
+ moo[0] = dmodes[q];
+ moo[1] = '\0';
+ strcat(temp,moo);
+ }
+ }
+ strcpy(dmodes,temp);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (strlen(outpars))
+ {
+ char b[MAXBUF];
+ strcpy(b,"");
+ int z = 0;
+ int i = 0;
+ while (i < strlen (outpars))
+ {
+ b[z++] = outpars[i++];
+ b[z] = '\0';
+ if (i<strlen(outpars)-1)
+ {
+ if (((outpars[i] == '-') || (outpars[i] == '+')) && ((outpars[i+1] == '-') || (outpars[i+1] == '+')))
+ {
+ // someones playing silly buggers and trying
+ // to put a +- or -+ into the line...
+ i++;
+ }
+ }
+ if (i == strlen(outpars)-1)
+ {
+ if ((outpars[i] == '-') || (outpars[i] == '+'))
+ {
+ i++;
+ }
+ }
+ }
+
+ z = strlen(b)-1;
+ if ((b[z] == '-') || (b[z] == '+'))
+ b[z] == '\0';
+
+ if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
+ return;
+
+ WriteTo(user,dest,"MODE :%s",b);
+
+ if (strlen(dmodes)>MAXMODES)
+ {
+ dmodes[MAXMODES-1] = '\0';
+ }
+ log(DEBUG,"Stripped mode line");
+ log(DEBUG,"Line dest is now %s",dmodes);
+ strncpy(dest->modes,dmodes,MAXMODES);
+
+ }
+
+ return;
+ }
+
+ Ptr = FindChan(parameters[0]);
+ if (Ptr)
+ {
+ if ((cstatus(user,Ptr) < STATUS_HOP) && (Ptr))
+ {
+ return;
+ }
+
+ process_modes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,true);
+ }
+}
+
+
+
+/* This function pokes and hacks at a parameter list like the following:
+ *
+ * PART #winbot, #darkgalaxy :m00!
+ *
+ * to turn it into a series of individual calls like this:
+ *
+ * PART #winbot :m00!
+ * PART #darkgalaxy :m00!
+ *
+ * The seperate calls are sent to a callback function provided by the caller
+ * (the caller will usually call itself recursively). The callback function
+ * must be a command handler. Calling this function on a line with no list causes
+ * no action to be taken. You must provide a starting and ending parameter number
+ * where the range of the list can be found, useful if you have a terminating
+ * parameter as above which is actually not part of the list, or parameters
+ * before the actual list as well. This code is used by many functions which
+ * can function as "one to list" (see the RFC) */
+
+int loop_call(handlerfunc fn, char **parameters, int pcnt, userrec *u, int start, int end, int joins)
+{
+ char plist[MAXBUF];
+ char *param;
+ char *pars[32];
+ char blog[32][MAXBUF];
+ char blog2[32][MAXBUF];
+ int i = 0, j = 0, q = 0, total = 0, t = 0, t2 = 0, total2 = 0;
+ char keystr[MAXBUF];
+ char moo[MAXBUF];
+
+ for (int i = 0; i <32; i++)
+ strcpy(blog[i],"");
+
+ for (int i = 0; i <32; i++)
+ strcpy(blog2[i],"");
+
+ strcpy(moo,"");
+ for (int i = 0; i <10; i++)
+ {
+ if (!parameters[i])
+ {
+ parameters[i] = moo;
+ }
+ }
+ if (joins)
+ {
+ if (pcnt > 1) /* we have a key to copy */
+ {
+ strcpy(keystr,parameters[1]);
+ }
+ }
+
+ if (!parameters[start])
+ {
+ return 0;
+ }
+ if (!strchr(parameters[start],','))
+ {
+ return 0;
+ }
+ strcpy(plist,"");
+ for (int i = start; i <= end; i++)
+ {
+ if (parameters[i])
+ {
+ strcat(plist,parameters[i]);
+ }
+ }
+
+ j = 0;
+ param = plist;
+
+ t = strlen(plist);
+ for (int i = 0; i < t; i++)
+ {
+ if (plist[i] == ',')
+ {
+ plist[i] = '\0';
+ strcpy(blog[j++],param);
+ param = plist+i+1;
+ if (j>20)
+ {
+ WriteServ(u->fd,"407 %s %s :Too many targets in list, message not delivered.",u->nick,blog[j-1]);
+ return 1;
+ }
+ }
+ }
+ strcpy(blog[j++],param);
+ total = j;
+
+ if ((joins) && (keystr) && (total>0)) // more than one channel and is joining
+ {
+ strcat(keystr,",");
+ }
+
+ if ((joins) && (keystr))
+ {
+ if (strchr(keystr,','))
+ {
+ j = 0;
+ param = keystr;
+ t2 = strlen(keystr);
+ for (int i = 0; i < t2; i++)
+ {
+ if (keystr[i] == ',')
+ {
+ keystr[i] = '\0';
+ strcpy(blog2[j++],param);
+ param = keystr+i+1;
+ }
+ }
+ strcpy(blog2[j++],param);
+ total2 = j;
+ }
+ }
+
+ for (j = 0; j < total; j++)
+ {
+ if (blog[j])
+ {
+ pars[0] = blog[j];
+ }
+ for (q = end; q < pcnt-1; q++)
+ {
+ if (parameters[q+1])
+ {
+ pars[q-end+1] = parameters[q+1];
+ }
+ }
+ if ((joins) && (parameters[1]))
+ {
+ if (pcnt > 1)
+ {
+ pars[1] = blog2[j];
+ }
+ else
+ {
+ pars[1] = NULL;
+ }
}
/* repeatedly call the function with the hacked parameter list */
if ((joins) && (pcnt > 1))
return;
if (parameters[0][0] == '#')
{
- Ptr = add_channel(user,parameters[0],parameters[1]);
+ Ptr = add_channel(user,parameters[0],parameters[1],false);
}
}
{
if (loop_call(handle_part,parameters,pcnt,user,0,pcnt-2,0))
return;
- del_channel(user,parameters[0],parameters[1]);
+ del_channel(user,parameters[0],parameters[1],false);
}
else
{
if (loop_call(handle_part,parameters,pcnt,user,0,pcnt-1,0))
return;
- del_channel(user,parameters[0],NULL);
+ del_channel(user,parameters[0],NULL,false);
}
}
WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, parameters[0]);
return;
}
+
+ char reason[MAXBUF];
if (pcnt > 2)
{
- char reason[MAXBUF];
strncpy(reason,parameters[2],MAXBUF);
if (strlen(reason)>MAXKICK)
{
}
else
{
- kick_channel(user,u,Ptr,user->nick);
+ strcpy(reason,user->nick);
+ kick_channel(user,u,Ptr,reason);
+ }
+
+ // this must be propogated so that channel membership is kept in step network-wide
+
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"k %s %s %s :%s",user->nick,u->nick,Ptr->name,reason);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent k token");
+ }
}
+
}
}
-void kill_link(userrec *user,char* reason)
+void kill_link(userrec *user,const char* r)
{
user_hash::iterator iter = clientlist.find(user->nick);
+
+ char reason[MAXBUF];
+
+ strncpy(reason,r,MAXBUF);
if (strlen(reason)>MAXQUIT)
{
if (user->registered == 7) {
FOREACH_MOD OnUserQuit(user);
WriteCommonExcept(user,"QUIT :%s",reason);
+
+ // Q token must go to ALL servers!!!
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"Q %s :%s",user->nick,reason);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent Q token");
+ }
+ }
+ }
}
- /* push the socket on a stack of sockets due to be closed at the next opportunity */
+ /* push the socket on a stack of sockets due to be closed at the next opportunity
+ * 'Client exited' is an exception to this as it means the client side has already
+ * closed the socket, we don't need to do it.
+ */
fd_reap.push_back(user->fd);
bool do_purge = false;
}
+
void handle_pass(char **parameters, int pcnt, userrec *user)
{
+ // Check to make sure they havnt registered -- Fix by FCS
+ if (user->registered == 7)
+ {
+ WriteServ(user->fd,"462 %s :You may not reregister",user->nick);
+ return;
+ }
if (!strcasecmp(parameters[0],Passwd(user)))
{
user->haspassed = true;
{
if (!c)
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[1]);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[1]);
}
else
{
{
if (cstatus(user,c) < STATUS_HOP)
{
- WriteServ(user->fd,"482 %s %s :You must be at least a half-operator",user->nick, c->name);
+ WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
return;
}
-
- u->InviteTo(c->name);
- WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name);
- WriteServ(user->fd,"341 %s %s %s",user->nick,u->nick,c->name);
+ }
+ if (has_channel(u,c))
+ {
+ WriteServ(user->fd,"443 %s %s %s :Is already on channel %s",user->nick,u->nick,c->name,c->name);
+ return;
+ }
+ if (!has_channel(user,c))
+ {
+ WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name);
+ return;
+ }
+ u->InviteTo(c->name);
+ WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name);
+ WriteServ(user->fd,"341 %s %s %s",user->nick,u->nick,c->name);
+
+ // i token must go to ALL servers!!!
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"i %s %s %s",u->nick,user->nick,c->name);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent i token");
+ }
+ }
}
}
{
if ((Ptr->topiclock) && (cstatus(user,Ptr)<STATUS_HOP))
{
- WriteServ(user->fd,"482 %s %s :You must be at least a half-operator", user->nick, Ptr->name);
+ WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
return;
}
strcpy(Ptr->setby,user->nick);
Ptr->topicset = time(NULL);
WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic);
+
+ // t token must go to ALL servers!!!
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"t %s %s :%s",user->nick,Ptr->name,topic);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent t token");
+ }
+ }
+ }
}
else
{
log(DEBUG,"send_error: %s",s);
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
+ if (isnick(i->second->nick))
+ {
+ WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
+ }
+ else
+ {
+ // fix - unregistered connections receive ERROR, not NOTICE
+ Write(i->second->fd,"ERROR :%s",s);
+ }
}
}
exit(status);
}
+
int main (int argc, char *argv[])
{
Start();
NonBlocking(socket);
log(DEBUG,"AddClient: %d %s %d",socket,host,port);
-
clientlist[tempnick]->fd = socket;
strncpy(clientlist[tempnick]->nick, tn2,NICKMAX);
strncpy(clientlist[tempnick]->host, host,160);
strncpy(clientlist[tempnick]->dhost, host,160);
strncpy(clientlist[tempnick]->server, ServerName,256);
+ strncpy(clientlist[tempnick]->ident, "unknown",9);
clientlist[tempnick]->registered = 0;
clientlist[tempnick]->signon = time(NULL);
clientlist[tempnick]->nping = time(NULL)+240;
WriteServ(socket,"NOTICE Auth :Looking up your hostname...");
}
+ // set the registration timeout for this user
+ unsigned long class_regtimeout = 90;
+ for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
+ {
+ if (match(clientlist[tempnick]->host,i->host) && (i->type == CC_ALLOW))
+ {
+ class_regtimeout = (unsigned long)i->registration_timeout;
+ break;
+ }
+ }
+
+ int class_flood = 0;
+ for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
+ {
+ if (match(clientlist[tempnick]->host,i->host) && (i->type == CC_ALLOW))
+ {
+ class_flood = i->flood;
+ break;
+ }
+ }
+
+ clientlist[tempnick]->timeout = time(NULL)+class_regtimeout;
+ clientlist[tempnick]->flood = class_flood;
+
+ for (int i = 0; i < MAXCHANS; i++)
+ {
+ clientlist[tempnick]->chans[i].channel = NULL;
+ clientlist[tempnick]->chans[i].uc_modes = 0;
+ }
+
if (clientlist.size() == MAXCLIENTS)
kill_link(clientlist[tempnick],"No more connections allowed in this class");
}
}
}
-
void handle_privmsg(char **parameters, int pcnt, userrec *user)
{
userrec *dest;
WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
}
+
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreMessage(user,chan,TYPE_CHANNEL,std::string(parameters[1])));
+ if (MOD_RESULT) {
+ return;
+ }
+
ChanExceptSender(chan, user, "PRIVMSG %s :%s", chan->name, parameters[1]);
+
+ // if any users of this channel are on remote servers, broadcast the packet
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"P %s %s :%s",user->nick,chan->name,parameters[1]);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (ChanAnyOnThisServer(chan,servers[j]->name))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ }
+ }
+ }
}
else
{
/* auto respond with aweh msg */
WriteServ(user->fd,"301 %s %s :%s",user->nick,dest->nick,dest->awaymsg);
}
- WriteTo(user, dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
+
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreMessage(user,dest,TYPE_USER,std::string(parameters[1])));
+ if (MOD_RESULT) {
+ return;
+ }
+
+
+
+ if (!strcmp(dest->server,user->server))
+ {
+ // direct write, same server
+ WriteTo(user, dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
+ }
+ else
+ {
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (!strcasecmp(servers[j]->name,dest->server))
+ {
+ // direct write, same server
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"P %s %s :%s",user->nick,dest->nick,parameters[1]);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ }
+ }
+ }
+ }
}
else
{
WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
}
- WriteChannel(chan, user, "NOTICE %s :%s", chan->name, parameters[1]);
+
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreNotice(user,chan,TYPE_CHANNEL,std::string(parameters[1])));
+ if (MOD_RESULT) {
+ return;
+ }
+
+ ChanExceptSender(chan, user, "NOTICE %s :%s", chan->name, parameters[1]);
+
+ // if any users of this channel are on remote servers, broadcast the packet
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"V %s %s :%s",user->nick,chan->name,parameters[1]);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (ChanAnyOnThisServer(chan,servers[j]->name))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ }
+ }
+ }
}
else
{
dest = Find(parameters[0]);
if (dest)
{
- WriteTo(user, dest, "NOTICE %s :%s", dest->nick, parameters[1]);
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreNotice(user,dest,TYPE_USER,std::string(parameters[1])));
+ if (MOD_RESULT) {
+ return;
+ }
+
+ if (!strcmp(dest->server,user->server))
+ {
+ // direct write, same server
+ WriteTo(user, dest, "NOTICE %s :%s", dest->nick, parameters[1]);
+ }
+ else
+ {
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (!strcasecmp(servers[j]->name,dest->server))
+ {
+ // direct write, same server
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"V %s %s :%s",user->nick,dest->nick,parameters[1]);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ }
+ }
+ }
+ }
}
else
{
{
return lst;
}
- for (i = 0; i != MAXCHANS; i++)
+ for (int i = 0; i != MAXCHANS; i++)
{
if (user->chans[i].channel != NULL)
{
}
}
}
+ if (strlen(lst))
+ {
+ lst[strlen(lst)-1] = '\0'; // chop trailing space
+ }
return lst;
}
WriteServ(user->fd,"371 %s :The Inspire IRCd Project Has been brought to you by the following people..",user->nick);
WriteServ(user->fd,"371 %s :Craig Edwards, Craig McLure, and Others..",user->nick);
WriteServ(user->fd,"371 %s :Will finish this later when i can be arsed :p",user->nick);
+ FOREACH_MOD OnInfo(user);
WriteServ(user->fd,"374 %s :End of /INFO list",user->nick);
}
dest = Find(parameters[0]);
if (dest)
{
- WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
- if ((user == dest) || (strchr(user->modes,'o')))
- {
- WriteServ(user->fd,"378 %s %s :is connecting from *@%s",user->nick, dest->nick, dest->host);
- }
- if (strcmp(chlist(dest),""))
- {
- WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, chlist(dest));
- }
- WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, dest->server, ServerDesc);
- if (strcmp(dest->awaymsg,""))
+ // bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
+ if (dest->registered == 7)
{
- WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
+ WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
+ if ((user == dest) || (strchr(user->modes,'o')))
+ {
+ WriteServ(user->fd,"378 %s %s :is connecting from *@%s",user->nick, dest->nick, dest->host);
+ }
+ if (strcmp(chlist(dest),""))
+ {
+ WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, chlist(dest));
+ }
+ WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, dest->server, ServerDesc);
+ if (strcmp(dest->awaymsg,""))
+ {
+ WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
+ }
+ if (strchr(dest->modes,'o'))
+ {
+ WriteServ(user->fd,"313 %s %s :is an IRC operator",user->nick, dest->nick);
+ }
+ FOREACH_MOD OnWhois(user,dest);
+ //WriteServ(user->fd,"310 %s %s :is available for help.",user->nick, dest->nick);
+ WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-time(NULL)), dest->signon);
+
+ WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
}
- if (strchr(dest->modes,'o'))
+ else
{
- WriteServ(user->fd,"313 %s %s :is an IRC operator",user->nick, dest->nick);
+ WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
}
- //WriteServ(user->fd,"310 %s %s :is available for help.",user->nick, dest->nick);
- WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-time(NULL)), dest->signon);
-
- WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
}
else
{
}
}
+void send_network_quit(const char* nick, const char* reason)
+{
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"Q %s :%s",nick,reason);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent Q token");
+ }
+ }
+}
+
void handle_quit(char **parameters, int pcnt, userrec *user)
{
user_hash::iterator iter = clientlist.find(user->nick);
Write(user->fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,parameters[0]);
WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,parameters[0]);
WriteCommonExcept(user,"QUIT :%s%s",PrefixQuit,parameters[0]);
+
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"Q %s :%s%s",user->nick,PrefixQuit,parameters[0]);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent Q token");
+ }
+ }
}
else
{
Write(user->fd,"ERROR :Closing link (%s@%s) [QUIT]",user->ident,user->host);
WriteOpers("*** Client exiting: %s!%s@%s [Client exited]",user->nick,user->ident,user->host);
WriteCommonExcept(user,"QUIT :Client exited");
+
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"Q %s :Client exited",user->nick);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent Q token");
+ }
+ }
}
FOREACH_MOD OnUserQuit(user);
AddWhoWas(user);
if (iter != clientlist.end())
{
- log(DEBUG,"deleting user hash value %d",iter->second);
- if ((iter->second) && (user->registered == 7)) {
- delete iter->second;
- }
clientlist.erase(iter);
+ log(DEBUG,"deleting user hash value %d",iter->second);
+ //if ((user) && (user->registered == 7)) {
+ //delete user;
+ //}
}
if (user->registered == 7) {
{
if ((common_channels(user,i->second)) && (isnick(i->second->nick)))
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, ServerName, i->second->nick, i->second->fullname);
+ WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
}
}
}
}
return;
}
- if (parameters[0][0] = '#')
+ if (parameters[0][0] == '#')
{
Ptr = FindChan(parameters[0]);
if (Ptr)
{
if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, ServerName, i->second->nick, i->second->fullname);
+ WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
}
}
WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name);
WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
}
}
+ else
+ {
+ userrec* u = Find(parameters[0]);
+ WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, u->nick, u->ident, u->dhost, u->server, u->nick, u->fullname);
+ }
}
if (pcnt == 2)
{
if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
{
Ptr = user->chans[0].channel;
- printf(user->chans[0].channel->name);
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
if ((common_channels(user,i->second)) && (isnick(i->second->nick)))
{
if (strchr(i->second->modes,'o'))
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, ServerName, i->second->nick, i->second->fullname);
+ WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
}
}
}
void handle_rehash(char **parameters, int pcnt, userrec *user)
{
- WriteServ(user->fd,"382 %s %s :Rehashing",user->nick,CONFIG_FILE);
+ WriteServ(user->fd,"382 %s %s :Rehashing",user->nick,CleanFilename(CONFIG_FILE));
ReadConfig();
FOREACH_MOD OnRehash();
- WriteOpers("%s is rehashing config file %s",user->nick,CONFIG_FILE);
+ WriteOpers("%s is rehashing config file %s",user->nick,CleanFilename(CONFIG_FILE));
}
return clientlist.size();
}
+
int usercount_invisible(void)
{
int c = 0;
if (strcmp(Passwd(user),"") && (!user->haspassed))
{
- Write(user->fd,"ERROR :Closing link: Invalid password");
kill_link(user,"Invalid password");
return;
}
if (IsDenied(user))
{
- Write(user->fd,"ERROR :Closing link: Unauthorized connection");
kill_link(user,"Unauthorised connection");
+ return;
}
WriteServ(user->fd,"NOTICE Auth :Welcome to \002%s\002!",Network);
ShowMOTD(user);
FOREACH_MOD OnUserConnect(user);
WriteOpers("*** Client connecting on port %d: %s!%s@%s",user->port,user->nick,user->ident,user->host);
+
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"N %d %s %s %s %s +%s %s :%s",user->age,user->nick,user->host,user->dhost,user->ident,user->modes,ServerName,user->fullname);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent N token");
+ }
+ }
+ }
+
}
void handle_version(char **parameters, int pcnt, userrec *user)
{
- WriteServ(user->fd,"351 %s :%s %s %s :%s",user->nick,VERSION,"$Id$",ServerName,SYSTEM);
+ WriteServ(user->fd,"351 %s :%s %s %s :%s",user->nick,VERSION,"$Revision$ $Date$",ServerName,SYSTEM);
}
void handle_ping(char **parameters, int pcnt, userrec *user)
void handle_trace(char **parameters, int pcnt, userrec *user)
{
- for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
+ for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
if (i->second)
{
for (int i = 0; i < module_names.size(); i++)
{
Version V = modules[i]->GetVersion();
- WriteServ(user->fd,"900 0x%08lx %d.%d.%d.%d :%s",modules[i],V.Major,V.Minor,V.Revision,V.Build,module_names[i].c_str());
+ char modulename[MAXBUF];
+ strncpy(modulename,module_names[i].c_str(),256);
+ WriteServ(user->fd,"900 %s :0x%08lx %d.%d.%d.%d %s",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename));
}
}
+// calls a handler function for a command
+
+void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user)
+{
+ for (int i = 0; i < cmdlist.size(); i++)
+ {
+ if (!strcasecmp(cmdlist[i].command,commandname))
+ {
+ if (cmdlist[i].handler_function)
+ {
+ if (pcnt>=cmdlist[i].min_params)
+ {
+ if (strchr(user->modes,cmdlist[i].flags_needed))
+ {
+ cmdlist[i].handler_function(parameters,pcnt,user);
+ }
+ }
+ }
+ }
+ }
+}
+
void handle_stats(char **parameters, int pcnt, userrec *user)
{
if (pcnt != 1)
/* stats o */
if (!strcasecmp(parameters[0],"o"))
{
- for (int i = 0; i < ConfValueEnum("oper"); i++)
+ for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
{
char LoginName[MAXBUF];
char HostName[MAXBUF];
char OperType[MAXBUF];
- ConfValue("oper","name",i,LoginName);
- ConfValue("oper","host",i,HostName);
- ConfValue("oper","type",i,OperType);
+ ConfValue("oper","name",i,LoginName,&config_f);
+ ConfValue("oper","host",i,HostName,&config_f);
+ ConfValue("oper","type",i,OperType,&config_f);
WriteServ(user->fd,"243 %s O %s * %s %s 0",user->nick,HostName,LoginName,OperType);
}
}
int LinkPort;
bool found = false;
- for (int i = 0; i < ConfValueEnum("link"); i++)
+ for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
{
- ConfValue("link","name",i,Link_ServerName);
- ConfValue("link","ipaddr",i,Link_IPAddr);
- ConfValue("link","port",i,Link_Port);
- ConfValue("link","sendpass",i,Link_Pass);
+ ConfValue("link","name",i,Link_ServerName,&config_f);
+ ConfValue("link","ipaddr",i,Link_IPAddr,&config_f);
+ ConfValue("link","port",i,Link_Port,&config_f);
+ ConfValue("link","sendpass",i,Link_Pass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
if (match(Link_ServerName,parameters[0])) {
if (servers[j] == NULL) {
servers[j] = new serverrec;
strcpy(servers[j]->internal_addr,Link_IPAddr);
+ servers[j]->internal_port = LinkPort;
strcpy(servers[j]->name,Link_ServerName);
log(DEBUG,"Allocated new serverrec");
if (!me[defaultRoute]->BeginLink(Link_IPAddr,LinkPort,Link_Pass))
}
}
-void handle_squit(char **parameters, int pcnt, userrec *user)
+void handle_squit(char **parameters, int pcnt, userrec *user)
+{
+ // send out an squit across the mesh and then clear the server list (for local squit)
+}
+
+char islast(serverrec* s)
+{
+ char c = '`';
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ c = '|';
+ }
+ if (servers[j] == s)
+ {
+ c = '`';
+ }
+ }
+ return c;
+}
+
+void handle_links(char **parameters, int pcnt, userrec *user)
+{
+ WriteServ(user->fd,"364 %s %s %s :0 %s",user->nick,ServerName,ServerName,ServerDesc);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ WriteServ(user->fd,"364 %s %s %s :1 %s",user->nick,servers[j]->name,ServerName,servers[j]->description);
+ }
+ }
+ WriteServ(user->fd,"365 %s * :End of /LINKS list.",user->nick);
+}
+
+void handle_map(char **parameters, int pcnt, userrec *user)
{
- // send out an squit across the mesh and then clear the server list (for local squit)
+ WriteServ(user->fd,"006 %s :%s",user->nick,ServerName);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ WriteServ(user->fd,"006 %s :%c-%s",user->nick,islast(servers[j]),servers[j]->name);
+ }
+ }
+ WriteServ(user->fd,"007 %s :End of /MAP",user->nick);
}
+
void handle_oper(char **parameters, int pcnt, userrec *user)
{
char LoginName[MAXBUF];
char Hostname[MAXBUF];
int i,j;
- for (i = 0; i < ConfValueEnum("oper"); i++)
+ for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
{
- ConfValue("oper","name",i,LoginName);
- ConfValue("oper","password",i,Password);
+ ConfValue("oper","name",i,LoginName,&config_f);
+ ConfValue("oper","password",i,Password,&config_f);
if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1])))
{
/* correct oper credentials */
- ConfValue("oper","type",i,OperType);
+ ConfValue("oper","type",i,OperType,&config_f);
WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
WriteServ(user->fd,"MODE %s :+o",user->nick);
- for (j =0; j < ConfValueEnum("type"); j++)
+ for (j =0; j < ConfValueEnum("type",&config_f); j++)
{
- ConfValue("type","name",j,TypeName);
+ ConfValue("type","name",j,TypeName,&config_f);
if (!strcmp(TypeName,OperType))
{
/* found this oper's opertype */
- ConfValue("type","host",j,Hostname);
+ ConfValue("type","host",j,Hostname,&config_f);
strncpy(user->dhost,Hostname,256);
}
}
{
strcat(user->modes,"o");
}
+ FOREACH_MOD OnOper(user);
return;
}
}
WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
}
-
+
void handle_nick(char **parameters, int pcnt, userrec *user)
{
if (pcnt < 1)
if (user->registered == 7)
{
WriteCommon(user,"NICK %s",parameters[0]);
+
+ // Q token must go to ALL servers!!!
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"n %s %s",user->nick,parameters[0]);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] != NULL)
+ {
+ if (strcmp(servers[j]->name,ServerName))
+ {
+ me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ log(DEBUG,"Sent n token");
+ }
+ }
+ }
+
}
/* change the nick of the user in the users_hash */
log(DEBUG,"exit nickchange: %s",user->nick);
}
+void force_nickchange(userrec* user,const char* newnick)
+{
+ char nick[MAXBUF];
+ strcpy(nick,"");
+
+ if (user)
+ {
+ if (newnick)
+ {
+ strncpy(nick,newnick,MAXBUF);
+ }
+ if (user->registered == 7)
+ {
+ char* pars[1];
+ pars[0] = nick;
+ handle_nick(pars,1,user);
+ }
+ }
+}
+
+
int process_parameters(char **command_p,char *parameters)
{
int i = 0;
}
}
command_p[j++] = parameters;
- for (i = 0; i <= q; i++)
+ for (int i = 0; i <= q; i++)
{
if (parameters[i] == ' ')
{
{
return;
}
+
+ int total_params = 0;
+ if (strlen(cmd)>2)
+ {
+ for (int q = 0; q < strlen(cmd)-1; q++)
+ {
+ if ((cmd[q] == ' ') && (cmd[q+1] == ':'))
+ {
+ total_params++;
+ // found a 'trailing', we dont count them after this.
+ break;
+ }
+ if (cmd[q] == ' ')
+ total_params++;
+ }
+ }
+
+ // another phidjit bug...
+ if (total_params > 126)
+ {
+ kill_link(user,"Protocol violation (1)");
+ return;
+ }
+
strcpy(temp,cmd);
string tmp = cmd;
{
/* no parameters, lets skip the formalities and not chop up
* the string */
+ log(DEBUG,"About to preprocess command with no params");
items = 0;
command_p[0] = NULL;
parameters = NULL;
{
cmd[i] = toupper(cmd[i]);
}
+ log(DEBUG,"Preprocess done length=%d",strlen(cmd));
+ command = cmd;
}
else
{
strcpy(cmd,"");
j = 0;
/* strip out extraneous linefeeds through mirc's crappy pasting (thanks Craig) */
- for (i = 0; i < strlen(temp); i++)
+ for (int i = 0; i < strlen(temp); i++)
{
if ((temp[i] != 10) && (temp[i] != 13) && (temp[i] != 0) && (temp[i] != 7))
{
command = cmd;
if (strchr(cmd,' '))
{
- for (i = 0; i <= strlen(cmd); i++)
+ for (int i = 0; i <= strlen(cmd); i++)
{
/* capitalise the command ONLY, leave params intact */
cmd[i] = toupper(cmd[i]);
}
else
{
- for (i = 0; i <= strlen(cmd); i++)
+ for (int i = 0; i <= strlen(cmd); i++)
{
cmd[i] = toupper(cmd[i]);
}
}
}
-
cmd_found = 0;
-
+
if (strlen(command)>MAXCOMMAND)
{
- command[MAXCOMMAND-1] = '\0';
- WriteOpers("Possible command-flood from %s, sending excessively long commands.",user->nick);
+ kill_link(user,"Protocol violation (2)");
+ return;
+ }
+
+ for (int x = 0; x < strlen(command); x++)
+ {
+ if (((command[x] < 'A') || (command[x] > 'Z')) && (command[x] != '.'))
+ {
+ if (((command[x] < '0') || (command[x]> '9')) && (command[x] != '-'))
+ {
+ if (strchr("@!\"$%^&*(){}[]_-=+;:'#~,.<>/?\\|`",command[x]))
+ {
+ kill_link(user,"Protocol violation (3)");
+ return;
+ }
+ }
+ }
}
- for (i = 0; i != cmdlist.size(); i++)
+ for (int i = 0; i != cmdlist.size(); i++)
{
if (strcmp(cmdlist[i].command,""))
{
- if (!strcmp(command, cmdlist[i].command))
+ if (strlen(command)>=(strlen(cmdlist[i].command))) if (!strncmp(command, cmdlist[i].command,MAXCOMMAND))
{
+ log(DEBUG,"Found matching command");
+
if (parameters)
{
if (strcmp(parameters,""))
if (user)
{
+ log(DEBUG,"Processing command");
+
/* activity resets the ping pending timer */
user->nping = time(NULL) + 120;
if ((items) < cmdlist[i].min_params)
cmd_found = 1;
return;
}
- /* if the command isnt USER, PASS, or NICK, and nick is empty,
- * deny command! */
- if ((strcmp(command,"USER")) && (strcmp(command,"NICK")) && (strcmp(command,"PASS")))
+ /* if the command isnt USER, PASS, or NICK, and nick is empty,
+ * deny command! */
+ if ((strncmp(command,"USER",4)) && (strncmp(command,"NICK",4)) && (strncmp(command,"PASS",4)))
{
if ((!isnick(user->nick)) || (user->registered != 7))
{
}
if ((!cmd_found) && (user))
{
- log(DEBUG,"process_command: not in table: %s %s",user->nick,command);
- WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
+ log(DEBUG,"process_command: not in table: %s %s",user->nick,command);
+ WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
+ }
+}
+
+
+void createcommand(char* cmd, handlerfunc f, char flags, int minparams)
+{
+ command_t comm;
+ /* create the command and push it onto the table */
+ strcpy(comm.command,cmd);
+ comm.handler_function = f;
+ comm.flags_needed = flags;
+ comm.min_params = minparams;
+ comm.use_count = 0;
+ comm.total_bytes = 0;
+ cmdlist.push_back(comm);
+ log(DEBUG,"Added command %s (%d parameters)",cmd,minparams);
+}
+
+void SetupCommandTable(void)
+{
+ createcommand("USER",handle_user,0,4);
+ createcommand("NICK",handle_nick,0,1);
+ createcommand("QUIT",handle_quit,0,0);
+ createcommand("VERSION",handle_version,0,0);
+ createcommand("PING",handle_ping,0,1);
+ createcommand("PONG",handle_pong,0,1);
+ createcommand("ADMIN",handle_admin,0,0);
+ createcommand("PRIVMSG",handle_privmsg,0,2);
+ createcommand("INFO",handle_info,0,0);
+ createcommand("TIME",handle_time,0,0);
+ createcommand("WHOIS",handle_whois,0,1);
+ createcommand("WALLOPS",handle_wallops,'o',1);
+ createcommand("NOTICE",handle_notice,0,2);
+ createcommand("JOIN",handle_join,0,1);
+ createcommand("NAMES",handle_names,0,1);
+ createcommand("PART",handle_part,0,1);
+ createcommand("KICK",handle_kick,0,2);
+ createcommand("MODE",handle_mode,0,1);
+ createcommand("TOPIC",handle_topic,0,1);
+ createcommand("WHO",handle_who,0,1);
+ createcommand("MOTD",handle_motd,0,0);
+ createcommand("RULES",handle_rules,0,0);
+ createcommand("OPER",handle_oper,0,2);
+ createcommand("LIST",handle_list,0,0);
+ createcommand("DIE",handle_die,'o',1);
+ createcommand("RESTART",handle_restart,'o',1);
+ createcommand("KILL",handle_kill,'o',2);
+ createcommand("REHASH",handle_rehash,'o',0);
+ createcommand("LUSERS",handle_lusers,0,0);
+ createcommand("STATS",handle_stats,0,1);
+ createcommand("USERHOST",handle_userhost,0,1);
+ createcommand("AWAY",handle_away,0,0);
+ createcommand("ISON",handle_ison,0,0);
+ createcommand("SUMMON",handle_summon,0,0);
+ createcommand("USERS",handle_users,0,0);
+ createcommand("INVITE",handle_invite,0,2);
+ createcommand("PASS",handle_pass,0,1);
+ createcommand("TRACE",handle_trace,'o',0);
+ createcommand("WHOWAS",handle_whowas,0,1);
+ createcommand("CONNECT",handle_connect,'o',1);
+ createcommand("SQUIT",handle_squit,'o',1);
+ createcommand("MODULES",handle_modules,'o',0);
+ createcommand("LINKS",handle_links,0,0);
+ createcommand("MAP",handle_map,0,0);
+}
+
+void process_buffer(const char* cmdbuf,userrec *user)
+{
+ if (!user)
+ {
+ log(DEFAULT,"*** BUG *** process_buffer was given an invalid parameter");
+ return;
+ }
+ char cmd[MAXBUF];
+ int i;
+ if (!cmdbuf)
+ {
+ log(DEFAULT,"*** BUG *** process_buffer was given an invalid parameter");
+ return;
+ }
+ if (!strcmp(cmdbuf,""))
+ {
+ return;
+ }
+ strncpy(cmd,cmdbuf,MAXBUF);
+ if (!strcmp(cmd,""))
+ {
+ return;
+ }
+ if ((cmd[strlen(cmd)-1] == 13) || (cmd[strlen(cmd)-1] == 10))
+ {
+ cmd[strlen(cmd)-1] = '\0';
+ }
+ if ((cmd[strlen(cmd)-1] == 13) || (cmd[strlen(cmd)-1] == 10))
+ {
+ cmd[strlen(cmd)-1] = '\0';
+ }
+ if (!strcmp(cmd,""))
+ {
+ return;
+ }
+ log(DEBUG,"InspIRCd: processing: %s %s",user->nick,cmd);
+ tidystring(cmd);
+ if ((user) && (cmd))
+ {
+ process_command(user,cmd);
+ }
+}
+
+void DoSync(serverrec* serv, char* udp_host,int udp_port, long MyKey)
+{
+ char data[MAXBUF];
+ // send start of sync marker: Y <timestamp>
+ // at this point the ircd receiving it starts broadcasting this netburst to all ircds
+ // except the ones its receiving it from.
+ snprintf(data,MAXBUF,"Y %d",time(NULL));
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ // send users and channels
+ for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
+ {
+ snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s :%s",u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->server,u->second->fullname);
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ if (strcmp(chlist(u->second),""))
+ {
+ snprintf(data,MAXBUF,"J %s %s",u->second->nick,chlist(u->second));
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ }
+ }
+ // send channel modes, topics etc...
+ for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
+ {
+ snprintf(data,MAXBUF,"M %s +%s",c->second->name,chanmodes(c->second));
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ if (strcmp(c->second->topic,""))
+ {
+ snprintf(data,MAXBUF,"T %d %s %s :%s",c->second->topicset,c->second->setby,c->second->name,c->second->topic);
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ }
+ // send current banlist
+
+ for (BanList::iterator b = c->second->bans.begin(); b != c->second->bans.end(); b++)
+ {
+ snprintf(data,MAXBUF,"M %s +b %s",b->set_time,c->second->name,b->data);
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ }
+ }
+ // send end of sync marker: E <timestamp>
+ snprintf(data,MAXBUF,"F %d",time(NULL));
+ serv->SendPacket(data,udp_host,udp_port,MyKey);
+ // ircd sends its serverlist after the end of sync here
+}
+
+
+void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* src = strtok(params," ");
+ char* dest = strtok(NULL," :");
+ char* text = strtok(NULL,"\r\n");
+ text++;
+
+ userrec* user = Find(src);
+ if (user)
+ {
+ userrec* dst = Find(dest);
+
+ if (dst)
+ {
+ WriteTo(user, dst, "NOTICE %s :%s", dst->nick, text);
+ }
+ else
+ {
+ chanrec* d = FindChan(dest);
+ if (d)
+ {
+ ChanExceptSender(d, user, "NOTICE %s :%s", d->name, text);
+ }
+ }
+ }
+
+}
+
+
+void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* src = strtok(params," ");
+ char* dest = strtok(NULL," :");
+ char* text = strtok(NULL,"\r\n");
+ text++;
+
+ userrec* user = Find(src);
+ if (user)
+ {
+ userrec* dst = Find(dest);
+
+ if (dst)
+ {
+ WriteTo(user, dst, "PRIVMSG %s :%s", dst->nick, text);
+ }
+ else
+ {
+ chanrec* d = FindChan(dest);
+ if (d)
+ {
+ ChanExceptSender(d, user, "PRIVMSG %s :%s", d->name, text);
+ }
+ }
+ }
+
+}
+
+void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* nick = strtok(params," ");
+ char* from = strtok(params," ");
+ char* channel = strtok(NULL," ");
+ userrec* u = Find(nick);
+ userrec* user = Find(from);
+ chanrec* c = FindChan(channel);
+ if ((c) && (u) && (user))
+ {
+ u->InviteTo(c->name);
+ WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name);
+ }
+}
+
+void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* setby = strtok(params," ");
+ char* channel = strtok(NULL," :");
+ char* topic = strtok(NULL,"\r\n");
+ topic++;
+ userrec* u = Find(setby);
+ chanrec* c = FindChan(channel);
+ if ((c) && (u))
+ {
+ WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic);
+ strncpy(c->topic,topic,MAXTOPIC);
+ strncpy(c->setby,u->nick,NICKMAX);
+ }
+}
+
+
+void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* tm = strtok(params," ");
+ char* setby = strtok(NULL," ");
+ char* channel = strtok(NULL," :");
+ char* topic = strtok(NULL,"\r\n");
+ topic++;
+ time_t TS = atoi(tm);
+ chanrec* c = FindChan(channel);
+ if (c)
+ {
+ // in the case of topics and TS, the *NEWER*
+ if (TS <= c->topicset)
+ {
+ WriteChannelLocal(c,NULL,"TOPIC %s :%s",c->name,topic);
+ strncpy(c->topic,topic,MAXTOPIC);
+ strncpy(c->setby,setby,NICKMAX);
+ }
+ }
+}
+
+void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* pars[128];
+ char original[MAXBUF],target[MAXBUF];
+ strncpy(original,params,MAXBUF);
+ int index = 0;
+ char* parameter = strtok(params," ");
+ strncpy(target,parameter,MAXBUF);
+ while (parameter)
+ {
+ pars[index++] = parameter;
+ parameter = strtok(NULL," ");
+ }
+ merge_mode(pars,index);
+ if (FindChan(target))
+ {
+ WriteChannelLocal(FindChan(target), NULL, "MODE %s",original);
+ }
+ if (Find(target))
+ {
+ WriteTo(NULL,Find(target),"MODE %s",original);
+ }
+}
+
+// m is modes set by users only (not servers) valid targets are channels or users.
+
+void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ // m blah #chatspike +b *!test@*4
+ char* pars[128];
+ char original[MAXBUF];
+ strncpy(original,params,MAXBUF);
+
+ if (!strchr(params,' '))
+ {
+ WriteOpers("WARNING! 'm' token in data stream without any parameters! Something fishy is going on!");
+ return;
+ }
+
+ int index = 0;
+
+ char* src = strtok(params," ");
+ userrec* user = Find(src);
+
+ if (user)
+ {
+ log(DEBUG,"Found user: %s",user->nick);
+ char* parameter = strtok(NULL," ");
+ while (parameter)
+ {
+ pars[index++] = parameter;
+ parameter = strtok(NULL," ");
+ }
+
+ log(DEBUG,"Calling merge_mode2");
+ merge_mode2(pars,index,user);
+ }
+}
+
+
+void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* nick = strtok(params," ");
+ char* channel = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ userrec* user = Find(nick);
+ reason++;
+ if (user)
+ {
+ if (strcmp(reason,""))
+ {
+ del_channel(user,channel,reason,true);
+ }
+ else
+ {
+ del_channel(user,channel,NULL,true);
+ }
+ }
+}
+
+void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* nick = strtok(params," :");
+ char* reason = strtok(NULL,"\r\n");
+ reason++;
+
+ userrec* user = Find(nick);
+
+ if (user)
+ {
+ if (strlen(reason)>MAXQUIT)
+ {
+ reason[MAXQUIT-1] = '\0';
+ }
+
+
+ WriteCommonExcept(user,"QUIT :%s",reason);
+
+ user_hash::iterator iter = clientlist.find(user->nick);
+
+ if (iter != clientlist.end())
+ {
+ log(DEBUG,"deleting user hash value %d",iter->second);
+ if ((iter->second) && (user->registered == 7)) {
+ delete iter->second;
+ }
+ clientlist.erase(iter);
+ }
+
+ purge_empty_chans();
+ }
+}
+
+void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* oldnick = strtok(params," ");
+ char* newnick = strtok(NULL," ");
+
+ userrec* user = Find(oldnick);
+
+ if (user)
+ {
+ WriteCommon(user,"NICK %s",newnick);
+ user = ReHashNick(user->nick, newnick);
+ if (!user) return;
+ if (!user->nick) return;
+ strncpy(user->nick, newnick,NICKMAX);
+ log(DEBUG,"new nick set: %s",user->nick);
+ }
+}
+
+// k <SOURCE> <DEST> <CHANNEL> :<REASON>
+void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* src = strtok(params," ");
+ char* dest = strtok(NULL," ");
+ char* channel = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ reason++;
+ userrec* s = Find(src);
+ userrec* d = Find(dest);
+ chanrec* c = FindChan(channel);
+ if ((s) && (d) && (c))
+ {
+ kick_channel(s,d,c,reason);
}
}
+void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+{
+ char* tm = strtok(params," ");
+ char* nick = strtok(NULL," ");
+ char* host = strtok(NULL," ");
+ char* dhost = strtok(NULL," ");
+ char* ident = strtok(NULL," ");
+ char* modes = strtok(NULL," ");
+ char* server = strtok(NULL," :");
+ char* gecos = strtok(NULL,"\r\n");
+ gecos++;
+ modes++;
+ time_t TS = atoi(tm);
+ user_hash::iterator iter = clientlist.find(nick);
+ if (iter != clientlist.end())
+ {
+ // nick collision
+ WriteOpers("Nickname collision: %s@%s != %s@%s",nick,server,iter->second->nick,iter->second->server);
+ if (TS >= iter->second->age)
+ {
+ char str[MAXBUF];
+ snprintf(str,MAXBUF,"Killed (Nick Collision (%s@%s < %s@%s))",nick,server,iter->second->nick,iter->second->server);
+ WriteServ(iter->second->fd, "KILL %s :%s",iter->second->nick,str);
+ // client on remote server is older than the local user, kill the local user
+ kill_link(iter->second,str);
+ }
+ }
+ clientlist[nick] = new userrec();
+ // remote users have an fd of -1. This is so that our Write abstraction
+ // routines know to route any messages to this record away to whatever server
+ // theyre on.
+ clientlist[nick]->fd = -1;
+ strncpy(clientlist[nick]->nick, nick,NICKMAX);
+ strncpy(clientlist[nick]->host, host,160);
+ strncpy(clientlist[nick]->dhost, dhost,160);
+ strncpy(clientlist[nick]->server, server,256);
+ strncpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for '~'
+ strncpy(clientlist[nick]->fullname, gecos,128);
+ clientlist[nick]->signon = TS;
+ clientlist[nick]->nping = 0; // this is ignored for a remote user anyway.
+ clientlist[nick]->lastping = 1;
+ clientlist[nick]->port = 0; // so is this...
+ clientlist[nick]->registered = 7; // this however we need to set for them to receive messages and appear online
+ clientlist[nick]->idle_lastmsg = time(NULL); // this is unrealiable and wont actually be used locally
+ for (int i = 0; i < MAXCHANS; i++)
+ {
+ clientlist[nick]->chans[i].channel = NULL;
+ clientlist[nick]->chans[i].uc_modes = 0;
+ }
+}
-void createcommand(char* cmd, handlerfunc f, char flags, int minparams)
+void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
{
- command_t comm;
- /* create the command and push it onto the table */
- strcpy(comm.command,cmd);
- comm.handler_function = f;
- comm.flags_needed = flags;
- comm.min_params = minparams;
- comm.use_count = 0;
- comm.total_bytes = 0;
- cmdlist.push_back(comm);
- log(DEBUG,"Added command %s (%d parameters)",cmd,minparams);
+ long tdiff = time(NULL) - atoi(params);
+ if (tdiff)
+ WriteOpers("TS split for %s -> %s: %d",source->name,reply->name,tdiff);
}
-void SetupCommandTable(void)
-{
- createcommand("USER",handle_user,0,4);
- createcommand("NICK",handle_nick,0,1);
- createcommand("QUIT",handle_quit,0,0);
- createcommand("VERSION",handle_version,0,0);
- createcommand("PING",handle_ping,0,1);
- createcommand("PONG",handle_pong,0,1);
- createcommand("ADMIN",handle_admin,0,0);
- createcommand("PRIVMSG",handle_privmsg,0,2);
- createcommand("INFO",handle_info,0,0);
- createcommand("TIME",handle_time,0,0);
- createcommand("WHOIS",handle_whois,0,1);
- createcommand("WALLOPS",handle_wallops,'o',1);
- createcommand("NOTICE",handle_notice,0,2);
- createcommand("JOIN",handle_join,0,1);
- createcommand("NAMES",handle_names,0,1);
- createcommand("PART",handle_part,0,1);
- createcommand("KICK",handle_kick,0,2);
- createcommand("MODE",handle_mode,0,1);
- createcommand("TOPIC",handle_topic,0,1);
- createcommand("WHO",handle_who,0,1);
- createcommand("MOTD",handle_motd,0,0);
- createcommand("RULES",handle_join,0,0);
- createcommand("OPER",handle_oper,0,2);
- createcommand("LIST",handle_list,0,0);
- createcommand("DIE",handle_die,'o',1);
- createcommand("RESTART",handle_restart,'o',1);
- createcommand("KILL",handle_kill,'o',2);
- createcommand("REHASH",handle_rehash,'o',0);
- createcommand("LUSERS",handle_lusers,0,0);
- createcommand("STATS",handle_stats,0,1);
- createcommand("USERHOST",handle_userhost,0,1);
- createcommand("AWAY",handle_away,0,0);
- createcommand("ISON",handle_ison,0,0);
- createcommand("SUMMON",handle_summon,0,0);
- createcommand("USERS",handle_users,0,0);
- createcommand("INVITE",handle_invite,0,2);
- createcommand("PASS",handle_pass,0,1);
- createcommand("TRACE",handle_trace,'o',0);
- createcommand("WHOWAS",handle_whowas,0,1);
- createcommand("CONNECT",handle_connect,'o',1);
- createcommand("SQUIT",handle_squit,'o',1);
- createcommand("MODULES",handle_modules,'o',0);
-}
-
-void process_buffer(userrec *user)
+void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
{
- if (!user)
- {
- log(DEFAULT,"*** BUG *** process_buffer was given an invalid parameter");
- return;
- }
- char cmd[MAXBUF];
- int i;
- if (!user->inbuf)
- {
- log(DEFAULT,"*** BUG *** process_buffer was given an invalid parameter");
- return;
- }
- if (!strcmp(user->inbuf,""))
- {
- return;
- }
- strncpy(cmd,user->inbuf,MAXBUF);
- if (!strcmp(cmd,""))
- {
- return;
- }
- if ((cmd[strlen(cmd)-1] == 13) || (cmd[strlen(cmd)-1] == 10))
- {
- cmd[strlen(cmd)-1] = '\0';
- }
- if ((cmd[strlen(cmd)-1] == 13) || (cmd[strlen(cmd)-1] == 10))
- {
- cmd[strlen(cmd)-1] = '\0';
- }
- strcpy(user->inbuf,"");
- if (!strcmp(cmd,""))
- {
- return;
- }
- log(DEBUG,"InspIRCd: processing: %s %s",user->nick,cmd);
- tidystring(cmd);
- if (user)
+ // IMPORTANT NOTE
+ // The J token currently has no timestamp - this needs looking at
+ // because it will allow splitriding.
+ char* nick = strtok(params," ");
+ char* channel = strtok(NULL," ");
+ userrec* user = Find(nick);
+ while (channel)
{
- process_command(user,cmd);
+ if ((user != NULL) && (strcmp(channel,"")))
+ {
+ char privilage = '\0';
+ if (channel[0] != '#')
+ {
+ privilage = channel[0];
+ channel++;
+ }
+ add_channel(user,channel,"",true);
+
+ // now work out the privilages they should have on each channel
+ // and send the appropriate servermodes.
+ for (int i = 0; i != MAXCHANS; i++)
+ {
+ if (user->chans[i].channel)
+ {
+ if (!strcasecmp(user->chans[i].channel->name,channel))
+ {
+ if (privilage == '@')
+ {
+ user->chans[i].uc_modes = user->chans[i].uc_modes | UCMODE_OP;
+ WriteChannelLocal(user->chans[i].channel, NULL, "MODE %s +o %s",channel,user->nick);
+ }
+ if (privilage == '%')
+ {
+ user->chans[i].uc_modes = user->chans[i].uc_modes | UCMODE_HOP;
+ WriteChannelLocal(user->chans[i].channel, NULL, "MODE %s +h %s",channel,user->nick);
+ }
+ if (privilage == '+')
+ {
+ user->chans[i].uc_modes = user->chans[i].uc_modes | UCMODE_VOICE;
+ WriteChannelLocal(user->chans[i].channel, NULL, "MODE %s +v %s",channel,user->nick);
+ }
+ }
+ }
+ }
+
+ }
+ channel = strtok(NULL," ");
}
}
void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
{
- WriteOpers("Secure-UDP-Channel: Token='%c', Params='%s'",token,params);
+ switch(token)
+ {
+ // Y <TS>
+ // start netburst
+ case 'Y':
+ nb_start = time(NULL);
+ WriteOpers("Server %s is starting netburst.",source->name);
+ break;
+ // N <TS> <NICK> <HOST> <DHOST> <IDENT> <MODES> <SERVER> :<GECOS>
+ // introduce remote client
+ case 'N':
+ handle_N(token,params,source,reply,udp_host,udp_port);
+ break;
+ // t <NICK> <CHANNEL> :<TOPIC>
+ // change a channel topic
+ case 't':
+ handle_t(token,params,source,reply,udp_host,udp_port);
+ break;
+ // i <NICK> <CHANNEL>
+ // invite a user to a channel
+ case 'i':
+ handle_i(token,params,source,reply,udp_host,udp_port);
+ break;
+ // k <SOURCE> <DEST> <CHANNEL> :<REASON>
+ // kick a user from a channel
+ case 'k':
+ handle_k(token,params,source,reply,udp_host,udp_port);
+ break;
+ // n <NICK> <NEWNICK>
+ // change nickname of client -- a server should only be able to
+ // change the nicknames of clients that reside on it unless
+ // they are ulined.
+ case 'n':
+ handle_n(token,params,source,reply,udp_host,udp_port);
+ break;
+ // J <NICK> <CHANLIST>
+ // Join user to channel list, merge channel permissions
+ case 'J':
+ handle_J(token,params,source,reply,udp_host,udp_port);
+ break;
+ // T <TS> <CHANNEL> <TOPICSETTER> :<TOPIC>
+ // change channel topic (netburst only)
+ case 'T':
+ handle_T(token,params,source,reply,udp_host,udp_port);
+ break;
+ // M <TARGET> <MODES> [MODE-PARAMETERS]
+ // Server setting modes on an object
+ case 'M':
+ handle_M(token,params,source,reply,udp_host,udp_port);
+ break;
+ // m <SOURCE> <TARGET> <MODES> [MODE-PARAMETERS]
+ // User setting modes on an object
+ case 'm':
+ handle_m(token,params,source,reply,udp_host,udp_port);
+ break;
+ // P <SOURCE> <TARGET> :<TEXT>
+ // Send a private/channel message
+ case 'P':
+ handle_P(token,params,source,reply,udp_host,udp_port);
+ break;
+ // V <SOURCE> <TARGET> :<TEXT>
+ // Send a private/channel notice
+ case 'V':
+ handle_V(token,params,source,reply,udp_host,udp_port);
+ break;
+ // L <SOURCE> <CHANNEL> :<REASON>
+ // User parting a channel
+ case 'L':
+ handle_L(token,params,source,reply,udp_host,udp_port);
+ break;
+ // Q <SOURCE> :<REASON>
+ // user quitting
+ case 'Q':
+ handle_Q(token,params,source,reply,udp_host,udp_port);
+ break;
+ // F <TS>
+ // end netburst
+ case 'F':
+ WriteOpers("Server %s has completed netburst. (%d secs)",source->name,time(NULL)-nb_start);
+ handle_F(token,params,source,reply,udp_host,udp_port);
+ break;
+ // anything else
+ default:
+ WriteOpers("WARNING! Unknown datagram type '%c'",token);
+ break;
+ }
}
char* servername = strtok(params," ");
char* password = strtok(NULL," ");
char* serverdesc = finalparam+2;
- WriteOpers("CONNECT from %s (%s)",servername,udp_host,password,serverdesc);
+ WriteOpers("CONNECT from %s (%s)",servername,udp_host);
char Link_ServerName[1024];
int LinkPort = 0;
// search for a corresponding <link> block in the config files
- for (int i = 0; i < ConfValueEnum("link"); i++)
+ for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
{
- ConfValue("link","name",i,Link_ServerName);
- ConfValue("link","ipaddr",i,Link_IPAddr);
- ConfValue("link","port",i,Link_Port);
- ConfValue("link","recvpass",i,Link_Pass);
- ConfValue("link","sendpass",i,Link_SendPass);
+ ConfValue("link","name",i,Link_ServerName,&config_f);
+ ConfValue("link","ipaddr",i,Link_IPAddr,&config_f);
+ ConfValue("link","port",i,Link_Port,&config_f);
+ ConfValue("link","recvpass",i,Link_Pass,&config_f);
+ ConfValue("link","sendpass",i,Link_SendPass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
if (!strcasecmp(Link_ServerName,servername)) {
servers[j] = new serverrec;
strcpy(servers[j]->internal_addr,udp_host);
strcpy(servers[j]->name,servername);
+ strcpy(servers[j]->description,serverdesc);
+ servers[j]->internal_port = udp_port;
// create a server record for this server
snprintf(response,10240,"O %d",MyKey);
serv->SendPacket(response,udp_host,udp_port,0);
if (!strcasecmp(servers[i]->internal_addr,udp_host)) {
servers[i]->key = atoi(params);
log(DEBUG,"Key for this server is now %d",servers[i]->key);
- serv->SendPacket("Z blah blah",udp_host,udp_port,MyKey);
+ DoSync(serv,udp_host,udp_port,MyKey);
return;
}
}
int LinkPort = 0;
// search for a corresponding <link> block in the config files
- for (int i = 0; i < ConfValueEnum("link"); i++)
+ for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
{
- ConfValue("link","name",i,Link_ServerName);
- ConfValue("link","ipaddr",i,Link_IPAddr);
- ConfValue("link","port",i,Link_Port);
- ConfValue("link","recvpass",i,Link_Pass);
- ConfValue("link","sendpass",i,Link_SendPass);
+ ConfValue("link","name",i,Link_ServerName,&config_f);
+ ConfValue("link","ipaddr",i,Link_IPAddr,&config_f);
+ ConfValue("link","port",i,Link_Port,&config_f);
+ ConfValue("link","recvpass",i,Link_Pass,&config_f);
+ ConfValue("link","sendpass",i,Link_SendPass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
if (!strcasecmp(Link_ServerName,servername)) {
for (int j = 0; j < 255; j++) {
if (servers[j] != NULL) {
if (!strcasecmp(servers[j]->internal_addr,udp_host)) {
+ strcpy(servers[j]->description,serverdesc);
WriteOpers("Server %s authenticated, exchanging server keys...",servername);
snprintf(response,10240,"O %d",MyKey);
serv->SendPacket(response,udp_host,udp_port,0);
if (servers[j]->key == theirkey) {
// found a valid key for this server, can process restricted stuff here
process_restricted_commands(token,params,servers[j],serv,udp_host,udp_port);
-
return;
}
}
int InspIRCd(void)
{
- struct sockaddr_in client, server;
- char addrs[MAXBUF][255];
- int openSockfd[MAXSOCKS], incomingSockfd, result = TRUE;
- socklen_t length;
- int count = 0, scanDetectTrigger = TRUE, showBanner = FALSE;
- int selectResult = 0;
- char *temp, configToken[MAXBUF], stuff[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
- char resolvedHost[MAXBUF];
- fd_set selectFds;
- struct timeval tv;
-
- log_file = fopen("ircd.log","a+");
- if (!log_file)
- {
- printf("ERROR: Could not write to logfile ircd.log, bailing!\n\n");
- Exit(ERROR);
- }
-
- log(DEBUG,"InspIRCd: startup: begin");
- log(DEBUG,"$Id$");
- if (geteuid() == 0)
- {
- printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
- Exit(ERROR);
- log(DEBUG,"InspIRCd: startup: not starting with UID 0!");
- }
- SetupCommandTable();
- log(DEBUG,"InspIRCd: startup: default command table set up");
-
- ReadConfig();
- if (strcmp(DieValue,""))
- {
- printf("WARNING: %s\n\n",DieValue);
- exit(0);
- }
- log(DEBUG,"InspIRCd: startup: read config");
-
- int count2 = 0, count3 = 0;
- for (count = 0; count < ConfValueEnum("bind"); count++)
- {
- ConfValue("bind","port",count,configToken);
- ConfValue("bind","address",count,Addr);
- ConfValue("bind","type",count,Type);
- if (!strcmp(Type,"servers"))
- {
- char Default[MAXBUF];
- strcpy(Default,"no");
- ConfValue("bind","default",count,Default);
- if (strchr(Default,'y'))
- {
- defaultRoute = count3;
- log(DEBUG,"InspIRCd: startup: binding '%s:%s' is default server route",Addr,configToken);
- }
- me[count3] = new serverrec(ServerName,100L,false);
- me[count3]->CreateListener(Addr,atoi(configToken));
- count3++;
+ struct sockaddr_in client, server;
+ char addrs[MAXBUF][255];
+ int openSockfd[MAXSOCKS], incomingSockfd, result = TRUE;
+ socklen_t length;
+ int count = 0, scanDetectTrigger = TRUE, showBanner = FALSE;
+ int selectResult = 0, selectResult2 = 0;
+ char *temp, configToken[MAXBUF], stuff[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
+ char resolvedHost[MAXBUF];
+ fd_set selectFds;
+ struct timeval tv;
+
+ log_file = fopen("ircd.log","a+");
+ if (!log_file)
+ {
+ printf("ERROR: Could not write to logfile ircd.log, bailing!\n\n");
+ Exit(ERROR);
}
- else
+
+ log(DEBUG,"InspIRCd: startup: begin");
+ log(DEBUG,"$Id$");
+ if (geteuid() == 0)
{
- ports[count2] = atoi(configToken);
- strcpy(addrs[count2],Addr);
- count2++;
+ printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
+ Exit(ERROR);
+ log(DEBUG,"InspIRCd: startup: not starting with UID 0!");
}
- log(DEBUG,"InspIRCd: startup: read binding %s:%s [%s] from config",Addr,configToken, Type);
- }
- portCount = count2;
- UDPportCount = count3;
-
- log(DEBUG,"InspIRCd: startup: read %d total client ports and %d total server ports",portCount,UDPportCount);
-
- log(DEBUG,"InspIRCd: startup: InspIRCd is now running!");
-
- printf("\n");
-
- /* BugFix By Craig! :p */
- count2 = 0;
- for (count = 0; count2 < ConfValueEnum("module"); count2++)
- {
- char modfile[MAXBUF];
- ConfValue("module","name",count,configToken);
- sprintf(modfile,"%s/%s",MOD_PATH,configToken);
- printf("Loading module... \033[1;37m%s\033[0;37m\n",modfile);
- log(DEBUG,"InspIRCd: startup: Loading module: %s",modfile);
- /* If The File Doesnt exist, Trying to load it
- * Will Segfault the IRCd.. So, check to see if
- * it Exists, Before Proceeding. */
- if (FileExists(modfile))
- {
- factory[count] = new ircd_module(modfile);
- if (factory[count]->LastError())
- {
- log(DEBUG,"Unable to load %s: %s",modfile,factory[count]->LastError());
- sprintf("Unable to load %s: %s\nExiting...\n",modfile,factory[count]->LastError());
- Exit(ERROR);
+ SetupCommandTable();
+ log(DEBUG,"InspIRCd: startup: default command table set up");
+
+ ReadConfig();
+ if (strcmp(DieValue,""))
+ {
+ printf("WARNING: %s\n\n",DieValue);
+ exit(0);
+ }
+ log(DEBUG,"InspIRCd: startup: read config");
+
+ int count2 = 0, count3 = 0;
+
+ for (count = 0; count < ConfValueEnum("bind",&config_f); count++)
+ {
+ ConfValue("bind","port",count,configToken,&config_f);
+ ConfValue("bind","address",count,Addr,&config_f);
+ ConfValue("bind","type",count,Type,&config_f);
+ if (!strcmp(Type,"servers"))
+ {
+ char Default[MAXBUF];
+ strcpy(Default,"no");
+ ConfValue("bind","default",count,Default,&config_f);
+ if (strchr(Default,'y'))
+ {
+ defaultRoute = count3;
+ log(DEBUG,"InspIRCd: startup: binding '%s:%s' is default server route",Addr,configToken);
+ }
+ me[count3] = new serverrec(ServerName,100L,false);
+ me[count3]->CreateListener(Addr,atoi(configToken));
+ count3++;
+ }
+ else
+ {
+ ports[count2] = atoi(configToken);
+ strcpy(addrs[count2],Addr);
+ count2++;
}
- if (factory[count]->factory)
+ log(DEBUG,"InspIRCd: startup: read binding %s:%s [%s] from config",Addr,configToken, Type);
+ }
+ portCount = count2;
+ UDPportCount = count3;
+
+ log(DEBUG,"InspIRCd: startup: read %d total client ports and %d total server ports",portCount,UDPportCount);
+
+ log(DEBUG,"InspIRCd: startup: InspIRCd is now running!");
+
+ printf("\n");
+
+ /* BugFix By Craig! :p */
+ count = 0;
+ for (count2 = 0; count2 < ConfValueEnum("module",&config_f); count2++)
+ {
+ char modfile[MAXBUF];
+ ConfValue("module","name",count2,configToken,&config_f);
+ sprintf(modfile,"%s/%s",MOD_PATH,configToken,&config_f);
+ printf("Loading module... \033[1;37m%s\033[0;37m\n",modfile);
+ log(DEBUG,"InspIRCd: startup: Loading module: %s",modfile);
+ /* If The File Doesnt exist, Trying to load it
+ * Will Segfault the IRCd.. So, check to see if
+ * it Exists, Before Proceeding. */
+ if (FileExists(modfile))
{
- modules[count] = factory[count]->factory->CreateModule();
- /* save the module and the module's classfactory, if
- * this isnt done, random crashes can occur :/ */
- module_names.push_back(modfile);
+ factory[count] = new ircd_module(modfile);
+ if (factory[count]->LastError())
+ {
+ log(DEBUG,"Unable to load %s: %s",modfile,factory[count]->LastError());
+ sprintf("Unable to load %s: %s\nExiting...\n",modfile,factory[count]->LastError());
+ Exit(ERROR);
+ }
+ if (factory[count]->factory)
+ {
+ modules[count] = factory[count]->factory->CreateModule();
+ /* save the module and the module's classfactory, if
+ * this isnt done, random crashes can occur :/ */
+ module_names.push_back(modfile);
+ }
+ else
+ {
+ log(DEBUG,"Unable to load %s",modfile);
+ sprintf("Unable to load %s\nExiting...\n",modfile);
+ Exit(ERROR);
+ }
+ /* Increase the Count */
+ count++;
}
else
{
- log(DEBUG,"Unable to load %s",modfile);
- sprintf("Unable to load %s\nExiting...\n",modfile);
- Exit(ERROR);
+ log(DEBUG,"InspIRCd: startup: Module Not Found %s",modfile);
+ printf("Module Not Found: \033[1;37m%s\033[0;37m, Skipping\n",modfile);
}
- /* Increase the Count */
- count++;
+ }
+ MODCOUNT = count - 1;
+ log(DEBUG,"Total loaded modules: %d",MODCOUNT+1);
+
+ printf("\nInspIRCd is now running!\n");
+
+ startup_time = time(NULL);
+
+ if (nofork)
+ {
+ log(VERBOSE,"Not forking as -nofork was specified");
}
else
{
- log(DEBUG,"InspIRCd: startup: Module Not Found %s",modfile);
- printf("Module Not Found: \033[1;37m%s\033[0;37m, Skipping\n",modfile);
+ if (DaemonSeed() == ERROR)
+ {
+ log(DEBUG,"InspIRCd: startup: can't daemonise");
+ printf("ERROR: could not go into daemon mode. Shutting down.\n");
+ Exit(ERROR);
+ }
+ }
+
+
+ /* setup select call */
+ FD_ZERO(&selectFds);
+ log(DEBUG,"InspIRCd: startup: zero selects");
+ log(VERBOSE,"InspIRCd: startup: portCount = %d", portCount);
+
+ for (count = 0; count < portCount; count++)
+ {
+ if ((openSockfd[boundPortCount] = OpenTCPSocket()) == ERROR)
+ {
+ log(DEBUG,"InspIRCd: startup: bad fd %d",openSockfd[boundPortCount]);
+ return(ERROR);
+ }
+ if (BindSocket(openSockfd[boundPortCount],client,server,ports[count],addrs[count]) == ERROR)
+ {
+ log(DEBUG,"InspIRCd: startup: failed to bind port %d",ports[count]);
+ }
+ else /* well we at least bound to one socket so we'll continue */
+ {
+ boundPortCount++;
+ }
+ }
+
+ log(DEBUG,"InspIRCd: startup: total bound ports %d",boundPortCount);
+
+ /* if we didn't bind to anything then abort */
+ if (boundPortCount == 0)
+ {
+ log(DEBUG,"InspIRCd: startup: no ports bound, bailing!");
+ return (ERROR);
}
- }
- MODCOUNT = count - 1;
- log(DEBUG,"Total loaded modules: %d",MODCOUNT+1);
-
- printf("\nInspIRCd is now running!\n");
-
- startup_time = time(NULL);
-
- if (nofork)
- {
- log(VERBOSE,"Not forking as -nofork was specified");
- }
- else
- {
- if (DaemonSeed() == ERROR)
+
+ length = sizeof (client);
+ int flip_flop = 0, udp_port = 0;
+ char udp_msg[MAXBUF], udp_host[MAXBUF];
+
+ /* main loop, this never returns */
+ for (;;)
{
- log(DEBUG,"InspIRCd: startup: can't daemonise");
- printf("ERROR: could not go into daemon mode. Shutting down.\n");
- Exit(ERROR);
- }
- }
-
-
- /* setup select call */
- FD_ZERO(&selectFds);
- log(DEBUG,"InspIRCd: startup: zero selects");
- log(VERBOSE,"InspIRCd: startup: portCount = %d", portCount);
-
- for (count = 0; count < portCount; count++)
- {
- if ((openSockfd[boundPortCount] = OpenTCPSocket()) == ERROR)
- {
- log(DEBUG,"InspIRCd: startup: bad fd %d",openSockfd[boundPortCount]);
- return(ERROR);
- }
- if (BindSocket(openSockfd[boundPortCount],client,server,ports[count],addrs[count]) == ERROR)
- {
- log(DEBUG,"InspIRCd: startup: failed to bind port %d",ports[count]);
- }
- else /* well we at least bound to one socket so we'll continue */
- {
- boundPortCount++;
- }
- }
- log(DEBUG,"InspIRCd: startup: total bound ports %d",boundPortCount);
-
- /* if we didn't bind to anything then abort */
- if (boundPortCount == 0)
- {
- log(DEBUG,"InspIRCd: startup: no ports bound, bailing!");
- return (ERROR);
- }
+ fd_set sfd;
+ struct timeval tval;
+ FD_ZERO(&sfd);
- length = sizeof (client);
- int flip_flop = 0, udp_port = 0;
- char udp_msg[MAXBUF], udp_host[MAXBUF];
-
- /* main loop for multiplexing/resetting */
- for (;;)
- {
- /* set up select call */
- for (count = 0; count < boundPortCount; count++)
- {
- FD_SET (openSockfd[count], &selectFds);
- }
-
- /* added timeout! select was waiting forever... wank... :/ */
- tv.tv_usec = 0;
-
- flip_flop++;
- reap_counter++;
- if (flip_flop > 20)
- {
- tv.tv_usec = 1;
- flip_flop = 0;
- }
-
- vector<int>::iterator niterator;
-
+ user_hash::iterator count2 = clientlist.begin();
- // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue
- // them in a list, then reap the list every second or so.
- if (reap_counter>5000) {
- if (fd_reap.size() > 0) {
- for( int n = 0; n < fd_reap.size(); n++)
- {
- Blocking(fd_reap[n]);
- close(fd_reap[n]);
- NonBlocking(fd_reap[n]);
+ // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue
+ // them in a list, then reap the list every second or so.
+ if (reap_counter>5000)
+ {
+ if (fd_reap.size() > 0)
+ {
+ for( int n = 0; n < fd_reap.size(); n++)
+ {
+ Blocking(fd_reap[n]);
+ close(fd_reap[n]);
+ NonBlocking(fd_reap[n]);
+ }
}
+ fd_reap.clear();
+ reap_counter=0;
}
- fd_reap.clear();
- reap_counter=0;
- }
-
-
- tv.tv_sec = 0;
- selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv);
- for (int x = 0; x != UDPportCount; x++)
- {
- long theirkey = 0;
- if (me[x]->RecvPacket(udp_msg, udp_host, udp_port, theirkey))
- {
- if (strlen(udp_msg)<1) {
- log(DEBUG,"Invalid datagram from %s:%d:%d [route%d]",udp_host,udp_port,me[x]->port,x);
- }
- else {
+
+ for (int x = 0; x != UDPportCount; x++)
+ {
+ long theirkey = 0;
+ if (me[x]->RecvPacket(udp_msg, udp_host, udp_port, theirkey))
+ {
+ if (strlen(udp_msg)<1) {
+ log(DEBUG,"Invalid datagram from %s:%d:%d [route%d]",udp_host,udp_port,me[x]->port,x);
+ }
+ else
+ {
FOREACH_MOD OnPacketReceive(udp_msg);
// Packets must go back via the route they arrived on :)
handle_link_packet(theirkey, udp_msg, udp_host, udp_port, me[x]);
- }
- }
- }
+ // link packets can manipulate the usertable so beware of
+ // any loops here watching the user or channels hash
+ log(DEBUG,"Sync: exit 3");
+ goto label;
+ }
+ }
+ }
+
- for (user_hash::iterator count2 = clientlist.begin(); count2 != clientlist.end(); count2++)
+ while (count2 != clientlist.end())
{
- char data[MAXBUF];
+ char data[10240];
+ tval.tv_usec = tval.tv_sec = 0;
+ FD_ZERO(&sfd);
+ int total_in_this_set = 0;
+
+ user_hash::iterator xcount = count2;
+ user_hash::iterator endingiter = count2;
if (!count2->second) break;
if (count2->second)
- if (count2->second->fd)
+ if (count2->second->fd != 0)
{
- if (((time(NULL)) > count2->second->nping) && (isnick(count2->second->nick)) && (count2->second->registered == 7))
+ // assemble up to 64 sockets into an fd_set
+ // to implement a pooling mechanism.
+ //
+ // This should be up to 64x faster than the
+ // old implementation.
+ while (total_in_this_set < 64)
{
- if (!count2->second->lastping)
+ if (count2 != clientlist.end())
{
- log(DEBUG,"InspIRCd: ping timeout: %s",count2->second->nick);
- kill_link(count2->second,"Ping timeout");
- break;
+ // we don't check the state of remote users.
+ if (count2->second->fd > 0)
+ {
+ FD_SET (count2->second->fd, &sfd);
+
+ // registration timeout -- didnt send USER/NICK/HOST in the time specified in
+ // their connection class.
+ if ((time(NULL) > count2->second->timeout) && (count2->second->registered != 7))
+ {
+ log(DEBUG,"InspIRCd: registration timeout: %s",count2->second->nick);
+ kill_link(count2->second,"Registration timeout");
+ goto label;
+ }
+ if (((time(NULL)) > count2->second->nping) && (isnick(count2->second->nick)) && (count2->second->registered == 7))
+ {
+ if ((!count2->second->lastping) && (count2->second->registered == 7))
+ {
+ log(DEBUG,"InspIRCd: ping timeout: %s",count2->second->nick);
+ kill_link(count2->second,"Ping timeout");
+ goto label;
+ }
+ Write(count2->second->fd,"PING :%s",ServerName);
+ log(DEBUG,"InspIRCd: pinging: %s",count2->second->nick);
+ count2->second->lastping = 0;
+ count2->second->nping = time(NULL)+120;
+ }
+ }
+ count2++;
+ total_in_this_set++;
}
- Write(count2->second->fd,"PING :%s",ServerName);
- log(DEBUG,"InspIRCd: pinging: %s",count2->second->nick);
- count2->second->lastping = 0;
- count2->second->nping = time(NULL)+120;
+ else break;
}
+
+ endingiter = count2;
+ count2 = xcount; // roll back to where we were
+
+ int v = 0;
+
+ tval.tv_usec = 0;
+ tval.tv_sec = 0;
+ selectResult2 = select(65535, &sfd, NULL, NULL, &tval);
- result = read(count2->second->fd, data, 1);
- // result EAGAIN means nothing read
- if (result == EAGAIN)
- {
- }
- else
- if (result == 0)
- {
- if (count2->second)
- {
- log(DEBUG,"InspIRCd: Exited: %s",count2->second->nick);
- kill_link(count2->second,"Client exited");
- // must bail here? kill_link removes the hash, corrupting the iterator
- log(DEBUG,"Bailing from client exit");
- break;
- }
- }
- else if (result > 0)
+ // now loop through all of the items in this pool if any are waiting
+ //if (selectResult2 > 0)
+ for (user_hash::iterator count2a = xcount; count2a != endingiter; count2a++)
{
- if (count2->second)
+ result = EAGAIN;
+ if ((count2a->second->fd != -1) && (FD_ISSET (count2a->second->fd, &sfd)))
{
- strncat(count2->second->inbuf, data, result);
+ log(DEBUG,"Reading fd %d",count2a->second->fd);
+ memset(data, 0, 10240);
+ result = read(count2a->second->fd, data, 10240);
+
+ if (result)
+ {
+ log(DEBUG,"Read %d characters from socket",result);
+ userrec* current = count2a->second;
+ int currfd = current->fd;
+ char* l = strtok(data,"\n");
+ int floodlines = 0;
+ while (l)
+ {
+ floodlines++;
+ if ((floodlines > current->flood) && (current->flood != 0))
+ {
+ log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+ WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+ kill_link(current,"Excess flood");
+ goto label;
+ }
+ char sanitized[NetBufferSize];
+ memset(sanitized, 0, NetBufferSize);
+ int ptt = 0;
+ for (int pt = 0; pt < strlen(l); pt++)
+ {
+ if (l[pt] != '\r')
+ {
+ sanitized[ptt++] = l[pt];
+ }
+ }
+ sanitized[ptt] = '\0';
+ if (strlen(sanitized))
+ {
+
+
+ // we're gonna re-scan to check if the nick is gone, after every
+ // command - if it has, we're gonna bail
+ bool find_again = false;
+ process_buffer(sanitized,current);
+
+ // look for the user's record in case it's changed
+ for (user_hash::iterator c2 = clientlist.begin(); c2 != clientlist.end(); c2++)
+ {
+ if (c2->second->fd == currfd)
+ {
+ // found again, update pointer
+ current == c2->second;
+ find_again = true;
+ break;
+ }
+ }
+ if (!find_again)
+ goto label;
- if (strlen(count2->second->inbuf) > 509) {
- count2->second->inbuf[509] = '\r';
- count2->second->inbuf[510] = '\n';
- count2->second->inbuf[511] = '\0';
+ }
+ l = strtok(NULL,"\n");
+ }
+ goto label;
}
- if (strchr(count2->second->inbuf, '\n') || strchr(count2->second->inbuf, '\r') || (strlen(count2->second->inbuf) > 509))
+ if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
{
- /* at least one complete line is waiting to be processed */
- if (!count2->second->fd)
- break;
- else
- {
- process_buffer(count2->second);
- break;
- }
+ log(DEBUG,"killing: %s",count2a->second->nick);
+ kill_link(count2a->second,strerror(errno));
+ goto label;
+ }
+ }
+ // result EAGAIN means nothing read
+ if (result == EAGAIN)
+ {
+ }
+ else
+ if (result == 0)
+ {
+ if (count2->second)
+ {
+ log(DEBUG,"InspIRCd: Exited: %s",count2a->second->nick);
+ kill_link(count2a->second,"Client exited");
+ // must bail here? kill_link removes the hash, corrupting the iterator
+ log(DEBUG,"Bailing from client exit");
+ goto label;
}
}
+ else if (result > 0)
+ {
+ }
}
}
+ for (int q = 0; q < total_in_this_set; q++)
+ {
+ // there is no iterator += operator :(
+ //if (count2 != clientlist.end())
+ //{
+ count2++;
+ //}
+ }
+ }
+
+ // set up select call
+ for (count = 0; count < boundPortCount; count++)
+ {
+ FD_SET (openSockfd[count], &selectFds);
}
- /* select is reporting a waiting socket. Poll them all to find out which */
- if (selectResult > 0)
- {
- char target[MAXBUF], resolved[MAXBUF];
- for (count = 0; count < boundPortCount; count++)
- {
- if (FD_ISSET (openSockfd[count], &selectFds))
- {
- incomingSockfd = accept (openSockfd[count], (struct sockaddr *) &client, &length);
-
- address_cache::iterator iter = IP.find(client.sin_addr);
- bool iscached = false;
- if (iter == IP.end())
- {
- /* ip isn't in cache, add it */
- strncpy (target, (char *) inet_ntoa (client.sin_addr), MAXBUF);
- if(CleanAndResolve(resolved, target) != TRUE)
- {
- strncpy(resolved,target,MAXBUF);
- }
- /* hostname now in 'target' */
- IP[client.sin_addr] = new string(resolved);
- /* hostname in cache */
- }
- else
- {
- /* found ip (cached) */
- strncpy(resolved, iter->second->c_str(), MAXBUF);
- iscached = true;
- }
-
- if (incomingSockfd < 0)
- {
- WriteOpers("*** WARNING: Accept failed on port %d (%s)", ports[count],target);
- log(DEBUG,"InspIRCd: accept failed: %d",ports[count]);
- break;
- }
-
- AddClient(incomingSockfd, resolved, ports[count], iscached);
- log(DEBUG,"InspIRCd: adding client on port %d fd=%d",ports[count],incomingSockfd);
- break;
- }
-
- }
- }
- }
+ /* added timeout! select was waiting forever... wank... :/ */
+ tv.tv_usec = 0;
- /* not reached */
- close (incomingSockfd);
+ flip_flop++;
+ reap_counter++;
+ if (flip_flop > 20)
+ {
+ tv.tv_usec = 1;
+ flip_flop = 0;
+ }
+
+ tv.tv_sec = 0;
+ selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv);
+
+ /* select is reporting a waiting socket. Poll them all to find out which */
+ if (selectResult > 0)
+ {
+ char target[MAXBUF], resolved[MAXBUF];
+ for (count = 0; count < boundPortCount; count++)
+ {
+ if (FD_ISSET (openSockfd[count], &selectFds))
+ {
+ incomingSockfd = accept (openSockfd[count], (struct sockaddr *) &client, &length);
+
+ address_cache::iterator iter = IP.find(client.sin_addr);
+ bool iscached = false;
+ if (iter == IP.end())
+ {
+ /* ip isn't in cache, add it */
+ strncpy (target, (char *) inet_ntoa (client.sin_addr), MAXBUF);
+ if(CleanAndResolve(resolved, target) != TRUE)
+ {
+ strncpy(resolved,target,MAXBUF);
+ }
+ /* hostname now in 'target' */
+ IP[client.sin_addr] = new string(resolved);
+ /* hostname in cache */
+ }
+ else
+ {
+ /* found ip (cached) */
+ strncpy(resolved, iter->second->c_str(), MAXBUF);
+ iscached = true;
+ }
+
+ if (incomingSockfd < 0)
+ {
+ WriteOpers("*** WARNING: Accept failed on port %d (%s)", ports[count],target);
+ log(DEBUG,"InspIRCd: accept failed: %d",ports[count]);
+ }
+ else
+ {
+ AddClient(incomingSockfd, resolved, ports[count], iscached);
+ log(DEBUG,"InspIRCd: adding client on port %d fd=%d",ports[count],incomingSockfd);
+ }
+ goto label;
+ }
+ }
+ }
+ label:
+ if(0) {}; // "Label must be followed by a statement"... so i gave it one.
+}
+/* not reached */
+close (incomingSockfd);
}