summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-01-12 20:14:43 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-01-12 20:14:43 +0000
commit8aa7f73bd76d5faacbfef59b308de7314d926fbf (patch)
tree26e61b6aa53ff4cea5367feb962951c4de330d1d /src
parentc4dffdedf72f6a2061e19725e4b50b2d28397085 (diff)
Changed channel user lists from vector to map
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2780 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp16
-rw-r--r--src/helperfuncs.cpp90
-rw-r--r--src/inspircd.cpp27
-rw-r--r--src/modules.cpp6
-rw-r--r--src/modules/m_spanningtree.cpp13
5 files changed, 65 insertions, 87 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index c51321a64..a1a7d60fa 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -160,25 +160,23 @@ long chanrec::GetUserCounter()
void chanrec::AddUser(char* castuser)
{
- internal_userlist.push_back(castuser);
+ internal_userlist[castuser] = castuser;
log(DEBUG,"Added casted user to channel's internal list");
}
void chanrec::DelUser(char* castuser)
{
- for (std::vector<char*>::iterator a = internal_userlist.begin(); a < internal_userlist.end(); a++)
+ std::map<char*,char*>::iterator a = internal_userlist.find(castuser);
+ if (a != internal_userlist.end())
{
- if (*a == castuser)
- {
- log(DEBUG,"Removed casted user from channel's internal list");
- internal_userlist.erase(a);
- return;
- }
+ log(DEBUG,"Removed casted user from channel's internal list");
+ internal_userlist.erase(a);
+ return;
}
log(DEBUG,"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!",name);
}
-std::vector<char*> *chanrec::GetUsers()
+std::map<char*,char*> *chanrec::GetUsers()
{
return &internal_userlist;
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 059f89be6..a97912530 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -346,11 +346,10 @@ void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- std::vector<char*> *ulist = Ptr->GetUsers();
- unsigned int x = ulist->size();
- for (unsigned int j = 0; j < x; j++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (otheruser->fd != FD_MAGIC_NUMBER)
WriteTo_NoFormat(user,otheruser,textbuffer);
@@ -364,11 +363,10 @@ void WriteChannel_NoFormat(chanrec* Ptr, userrec* user, const char* 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++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (otheruser->fd != FD_MAGIC_NUMBER)
WriteTo_NoFormat(user,otheruser,text);
@@ -393,11 +391,10 @@ void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- std::vector<char*> *ulist = Ptr->GetUsers();
- unsigned int x = ulist->size();
- for (unsigned int j = 0; j < x; j++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user))
{
@@ -420,11 +417,10 @@ void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* 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++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user))
{
@@ -456,11 +452,10 @@ void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
va_end(argsPtr);
- std::vector<char*> *ulist = Ptr->GetUsers();
- unsigned int x = ulist->size();
- for (unsigned int j = 0; j < x; j++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (IS_LOCAL(otheruser))
WriteServ_NoFormat(otheruser->fd,textbuffer);
@@ -474,11 +469,10 @@ void WriteChannelWithServ_NoFormat(char* ServName, chanrec* Ptr, const char* tex
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++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (IS_LOCAL(otheruser))
WriteServ_NoFormat(otheruser->fd,text);
@@ -503,11 +497,10 @@ void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- std::vector<char*> *ulist = Ptr->GetUsers();
- unsigned int x = ulist->size();
- for (unsigned int j = 0; j < x; j++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((IS_LOCAL(otheruser)) && (user != otheruser))
WriteFrom_NoFormat(otheruser->fd,user,textbuffer);
@@ -521,11 +514,10 @@ void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, const char* 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++)
+ std::map<char*,char*> *ulist= Ptr->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((IS_LOCAL(otheruser)) && (user != otheruser))
WriteFrom_NoFormat(otheruser->fd,user,text);
@@ -578,11 +570,10 @@ void WriteCommon(userrec *u, char* text, ...)
{
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++)
+ std::map<char*,char*> *ulist= u->chans[i].channel->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
{
@@ -623,11 +614,10 @@ void WriteCommon_NoFormat(userrec *u, const char* text)
{
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++)
+ std::map<char*,char*> *ulist= u->chans[i].channel->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
{
@@ -677,11 +667,10 @@ void WriteCommonExcept(userrec *u, char* text, ...)
{
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++)
+ std::map<char*,char*> *ulist= u->chans[i].channel->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (u != otheruser)
{
@@ -716,11 +705,10 @@ void WriteCommonExcept_NoFormat(userrec *u, const char* text)
{
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++)
+ std::map<char*,char*> *ulist= u->chans[i].channel->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[j];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (u != otheruser)
{
@@ -1082,10 +1070,10 @@ void userlist(userrec *user,chanrec *c)
snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
- std::vector<char*> *ulist = c->GetUsers();
- for (unsigned int i = 0; i < ulist->size(); i++)
+ std::map<char*,char*> *ulist= c->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[i];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
{
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index b690c2d87..35626fbb9 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -646,7 +646,8 @@ int InspIRCd::Run()
uslen = sizeof(sock_us);
length = sizeof(client);
incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
- if (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen))
+
+ if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
{
in_port = ntohs(sock_us.sin_port);
log(DEBUG,"Accepted socket %d",incomingSockfd);
@@ -655,29 +656,21 @@ int InspIRCd::Run()
* using gethostbyaddr(). That is sucky and we
* don't do that any more...
*/
- if (incomingSockfd >= 0)
+ NonBlocking(incomingSockfd);
+ if (Config->GetIOHook(in_port))
{
- NonBlocking(incomingSockfd);
- if (Config->GetIOHook(in_port))
- {
- Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, target, in_port);
- }
- stats->statsAccept++;
- AddClient(incomingSockfd, target, in_port, false, target);
- log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
- }
- else
- {
- WriteOpers("*** WARNING: accept() failed on port %lu (%s)",(unsigned long)in_port,target);
- log(DEBUG,"accept failed: %lu",(unsigned long)in_port);
- stats->statsRefused++;
+ Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, target, in_port);
}
+ stats->statsAccept++;
+ AddClient(incomingSockfd, target, in_port, false, target);
+ log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
}
else
{
- log(DEBUG,"Couldnt look up the port number for fd %lu (OS BROKEN?!)",incomingSockfd);
+ log(DEBUG,"Accept failed on fd %lu: %s",(unsigned long)incomingSockfd,strerror(errno));
shutdown(incomingSockfd,2);
close(incomingSockfd);
+ stats->statsRefused++;
}
break;
diff --git a/src/modules.cpp b/src/modules.cpp
index 0706184d4..4b8c0dffe 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -377,10 +377,10 @@ chanuserlist Server::GetUsers(chanrec* chan)
{
chanuserlist userl;
userl.clear();
- std::vector<char*> *list = chan->GetUsers();
- for (std::vector<char*>::iterator i = list->begin(); i != list->end(); i++)
+ std::map<char*,char*> *list = chan->GetUsers();
+ for (std::map<char*,char*>::iterator i = list->begin(); i != list->end(); i++)
{
- char* o = *i;
+ char* o = i->second;
userl.push_back((userrec*)o);
}
return userl;
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 1c0b91241..d8f4821ba 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -1083,10 +1083,10 @@ class TreeSocket : public InspSocket
log(DEBUG,"Sending FJOINs to other server for %s",c->name);
char list[MAXBUF];
snprintf(list,MAXBUF,":%s FJOIN %s %lu",Srv->GetServerName().c_str(),c->name,(unsigned long)c->age);
- std::vector<char*> *ulist = c->GetUsers();
- for (unsigned int i = 0; i < ulist->size(); i++)
+ std::map<char*,char*> *ulist = c->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[i];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
strlcat(list," ",MAXBUF);
strlcat(list,cmode(otheruser,c),MAXBUF);
@@ -2188,11 +2188,10 @@ void AddThisServer(TreeServer* server, std::deque<TreeServer*> &list)
// returns a list of DIRECT servernames for a specific channel
void GetListOfServersForChannel(chanrec* c, std::deque<TreeServer*> &list)
{
- std::vector<char*> *ulist = c->GetUsers();
- unsigned int ucount = ulist->size();
- for (unsigned int i = 0; i < ucount; i++)
+ std::map<char*,char*> *ulist = c->GetUsers();
+ for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- char* o = (*ulist)[i];
+ char* o = i->second;
userrec* otheruser = (userrec*)o;
if (otheruser->fd < 0)
{