extern time_t TIME;
extern char lowermap[255];
static char list[MAXBUF];
-extern userrec* fd_ref_table[65536];
-static char already_sent[65536];
+extern userrec* fd_ref_table[MAX_DESCRIPTORS];
+static char already_sent[MAX_DESCRIPTORS];
extern std::vector<userrec*> all_opers;
extern user_hash clientlist;
extern chan_hash chanlist;
log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size());
}
-void Write_NoFormat(int sock,char *text)
+void Write_NoFormat(int sock, const char *text)
{
if ((sock < 0) || (!text))
return;
else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
}
-void WriteServ_NoFormat(int sock, char* text)
+void WriteServ_NoFormat(int sock, const char* text)
{
if ((sock < 0) || (!text))
return;
else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
}
-void WriteFrom_NoFormat(int sock, userrec *user,char* text)
+void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
{
if ((sock < 0) || (!text) || (!user))
return;
}
}
-void WriteTo_NoFormat(userrec *source, userrec *dest,char *data)
+void WriteTo_NoFormat(userrec *source, userrec *dest, const char *data)
{
if ((!dest) || (!data))
return;
}
}
+void WriteChannel_NoFormat(chanrec* Ptr, userrec* user, const char* text)
+{
+ if ((!Ptr) || (!user) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
+ return;
+ }
+ std::vector<char*> *ulist = Ptr->GetUsers();
+ unsigned int x = ulist->size();
+ for (unsigned int j = 0; j < x; j++)
+ {
+ char* o = (*ulist)[j];
+ userrec* otheruser = (userrec*)o;
+ if (otheruser->fd != FD_MAGIC_NUMBER)
+ WriteTo_NoFormat(user,otheruser,text);
+ }
+}
+
+
/* 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 */
{
char* o = (*ulist)[j];
userrec* otheruser = (userrec*)o;
- if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
+ if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user))
{
if (!user)
{
}
}
+void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* text)
+{
+ if ((!Ptr) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
+ return;
+ }
+ std::vector<char*> *ulist = Ptr->GetUsers();
+ unsigned int x = ulist->size();
+ for (unsigned int j = 0; j < x; j++)
+ {
+ char* o = (*ulist)[j];
+ userrec* otheruser = (userrec*)o;
+ if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user))
+ {
+ if (!user)
+ {
+ WriteServ_NoFormat(otheruser->fd,text);
+ }
+ else
+ {
+ WriteTo_NoFormat(user,otheruser,text);
+ }
+ }
+ }
+}
+
+
+
void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
{
if ((!Ptr) || (!text))
}
}
+void WriteChannelWithServ_NoFormat(char* ServName, chanrec* Ptr, const char* text)
+{
+ if ((!Ptr) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
+ return;
+ }
+ std::vector<char*> *ulist = Ptr->GetUsers();
+ unsigned int x = ulist->size();
+ for (unsigned int j = 0; j < x; j++)
+ {
+ char* o = (*ulist)[j];
+ userrec* otheruser = (userrec*)o;
+ if (IS_LOCAL(otheruser))
+ WriteServ_NoFormat(otheruser->fd,text);
+ }
+}
+
+
+
/* write formatted text from a source user to all users on a channel except
* for the sender (for privmsg etc) */
}
}
+void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, const char* text)
+{
+ if ((!Ptr) || (!user) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
+ return;
+ }
+ std::vector<char*> *ulist = Ptr->GetUsers();
+ unsigned int x = ulist->size();
+ for (unsigned int j = 0; j < x; j++)
+ {
+ char* o = (*ulist)[j];
+ userrec* otheruser = (userrec*)o;
+ if ((IS_LOCAL(otheruser)) && (user != otheruser))
+ WriteFrom_NoFormat(otheruser->fd,user,text);
+ }
+}
+
std::string GetServerDescription(char* servername)
{
std::string description = "";
// receives their OWN message for WriteCommon
if (!sent_to_at_least_one)
{
- WriteFrom(u->fd,u,"%s",textbuffer);
+ WriteFrom_NoFormat(u->fd,u,textbuffer);
+ }
+}
+
+void WriteCommon_NoFormat(userrec *u, const char* text)
+{
+ if (!u)
+ {
+ log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
+ return;
+ }
+
+ if (u->registered != 7) {
+ log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
+ return;
+ }
+ // FIX: Stops a message going to the same person more than once
+ memset(&already_sent,0,MAX_DESCRIPTORS);
+
+ bool sent_to_at_least_one = false;
+
+ unsigned int y = u->chans.size();
+ for (unsigned int i = 0; i < y; i++)
+ {
+ if (u->chans[i].channel)
+ {
+ std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
+ unsigned int x = ulist->size();
+ for (unsigned int j = 0; j < x; j++)
+ {
+ char* o = (*ulist)[j];
+ userrec* otheruser = (userrec*)o;
+ if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
+ {
+ already_sent[otheruser->fd] = 1;
+ WriteFrom_NoFormat(otheruser->fd,u,text);
+ sent_to_at_least_one = true;
+ }
+ }
+ }
+ }
+ // if the user was not in any channels, no users will receive the text. Make sure the user
+ // receives their OWN message for WriteCommon
+ if (!sent_to_at_least_one)
+ {
+ WriteFrom_NoFormat(u->fd,u,text);
}
}
+
+
/* write a formatted string to all users who share at least one common
* channel, NOT including the source user e.g. for use in QUIT */
}
}
+void WriteCommonExcept_NoFormat(userrec *u, const char* text)
+{
+ if (!u)
+ {
+ log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
+ return;
+ }
+
+ if (u->registered != 7) {
+ log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
+ return;
+ }
+
+ memset(&already_sent,0,MAX_DESCRIPTORS);
+
+ unsigned int y = u->chans.size();
+ for (unsigned int i = 0; i < y; i++)
+ {
+ if (u->chans[i].channel)
+ {
+ std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
+ unsigned int x = ulist->size();
+ for (unsigned int j = 0; j < x; j++)
+ {
+ char* o = (*ulist)[j];
+ userrec* otheruser = (userrec*)o;
+ if (u != otheruser)
+ {
+ if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
+ {
+ already_sent[otheruser->fd] = 1;
+ WriteFrom_NoFormat(otheruser->fd,u,text);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+
void WriteOpers(char* text, ...)
{
if (!text)
{
/* list overflowed into
* multiple numerics */
- WriteServ(user->fd,"%s",list);
+ WriteServ_NoFormat(user->fd,list);
snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
}
}
/* if whats left in the list isnt empty, send it */
if (list[strlen(list)-1] != ':')
{
- WriteServ(user->fd,"%s",list);
+ WriteServ_NoFormat(user->fd,list);
}
}
// looks up a users password for their connection class (<ALLOW>/<DENY> tags)
-char* Passwd(userrec *user)
+ConnectClass GetClass(userrec *user)
{
for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
{
- if ((i->type == CC_ALLOW) && match(user->host,i->host.c_str()))
+ if (match(user->host,i->host.c_str()))
{
- return (char*)i->pass.c_str();
+ return *i;
}
}
- return "";
+ return *(Config->Classes.begin());
}
-bool IsDenied(userrec *user)
-{
- for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
- {
- if ((i->type == CC_DENY) && match(user->host,i->host.c_str()))
- {
- return true;
- }
- }
- return false;
-}
-
-
-
-
/* sends out an error notice to all connected clients (not to be used
* lightly!) */