#include "bancache.h"
#include "commands/cmd_whowas.h"
-static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
+static unsigned long* already_sent = NULL;
+
+
+void InitializeAlreadySent(SocketEngine* SE)
+{
+ already_sent = new unsigned long[SE->GetMaxFds()];
+ memset(already_sent, 0, sizeof(already_sent));
+}
/* XXX: Used for speeding up WriteCommon operations */
-unsigned long uniq_id = 0;
+unsigned long uniq_id = 1;
std::string User::ProcessNoticeMasks(const char *sm)
{
try
{
bool cached;
- const char* sip = this->GetIPString();
+ const char* sip = this->GetIPString(false);
/* Special case for 4in6 (Have i mentioned i HATE 4in6?) */
if (!strncmp(sip, "0::ffff:", 8))
void User::CloseSocket()
{
- ServerInstance->SE->Shutdown(this, 2);
- ServerInstance->SE->Close(this);
+ if (this->fd > -1)
+ {
+ ServerInstance->SE->Shutdown(this, 2);
+ ServerInstance->SE->Close(this);
+ }
}
char* User::GetFullHost()
}
}
-void User::QuitUser(InspIRCd* Instance, User *user, const std::string &quitreason, const char* operreason)
-{
- Instance->Logs->Log("USERS", DEBUG,"QuitUser: %s '%s'", user->nick, quitreason.c_str());
- user->Write("ERROR :Closing link (%s@%s) [%s]", user->ident, user->host, *operreason ? operreason : quitreason.c_str());
- user->quietquit = false;
- user->quitmsg = quitreason;
-
- if (!*operreason)
- user->operquitmsg = quitreason;
- else
- user->operquitmsg = operreason;
-
- Instance->GlobalCulls.AddItem(user);
-}
-
/* adds or updates an entry in the whowas list */
void User::AddToWhoWas()
{
if ((!a) || (a->GetType() == CC_DENY))
{
- User::QuitUser(ServerInstance, this, "Unauthorised connection");
+ ServerInstance->Users->QuitUser(this, "Unauthorised connection");
return;
}
else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
{
- User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)");
+ ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
return;
}
else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
{
- User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (global)");
+ ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
return;
}
*/
if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
{
- User::QuitUser(ServerInstance, this, "Invalid password");
+ ServerInstance->Users->QuitUser(this, "Invalid password");
return;
}
this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
this->WriteNumeric(001, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
- this->WriteNumeric(002, "%s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
+ this->WriteNumeric(002, "%s :Your host is %s, running version InspIRCd-1.2",this->nick,ServerInstance->Config->ServerName);
this->WriteNumeric(003, "%s :This server was created %s %s", this->nick, __TIME__, __DATE__);
- this->WriteNumeric(004, "%s %s %s %s %s %s", this->nick, ServerInstance->Config->ServerName, VERSION, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
+ this->WriteNumeric(004, "%s %s InspIRCd-1.2 %s %s %s", this->nick, ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
ServerInstance->Config->Send005(this);
-
this->WriteNumeric(42, "%s %s :your unique ID", this->nick, this->uuid);
bool User::ForceNickChange(const char* newnick)
{
- /*
- * XXX this makes no sense..
- * why do we do nothing for change on users not REG_ALL?
- * why do we trigger events twice for everyone previously (and just them now)
- * i think the first if () needs removing totally, or? -- w00t
- */
- if (this->registered != REG_ALL)
- {
- int MOD_RESULT = 0;
+ int MOD_RESULT = 0;
- this->InvalidateCache();
+ this->InvalidateCache();
- FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
+ FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
- if (MOD_RESULT)
- {
- ServerInstance->stats->statsCollisions++;
- return false;
- }
-
- if (ServerInstance->XLines->MatchesLine("Q",newnick))
- {
- ServerInstance->stats->statsCollisions++;
- return false;
- }
+ if (MOD_RESULT)
+ {
+ ServerInstance->stats->statsCollisions++;
+ return false;
}
- else
+
+ std::deque<classbase*> dummy;
+ Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
+ if (nickhandler) // wtfbbq, when would this not be here
{
- std::deque<classbase*> dummy;
- Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
- if (nickhandler) // wtfbbq, when would this not be here
- {
- nickhandler->HandleInternal(1, dummy);
- bool result = (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS);
- nickhandler->HandleInternal(0, dummy);
- return result;
- }
+ nickhandler->HandleInternal(1, dummy);
+ bool result = (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS);
+ nickhandler->HandleInternal(0, dummy);
+ return result;
}
- // Unreachable.
+ // Unreachable, we hope
return false;
}
* XXX the duplication here is horrid..
* do we really need two methods doing essentially the same thing?
*/
-const char* User::GetIPString()
+const char* User::GetIPString(bool translate4in6)
{
static char buf[1024];
{
strlcpy(&temp[1], buf, sizeof(temp) - 1);
*temp = '0';
+ if (translate4in6 && !strncmp(temp, "0::ffff:", 8))
+ {
+ this->cachedip = temp + 8;
+ return temp + 8;
+ }
+
this->cachedip = temp;
return temp;
}
uniq_id++;
+ if (!already_sent)
+ InitializeAlreadySent(ServerInstance->SE);
+
/* We dont want to be doing this n times, just once */
snprintf(tb,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
std::string out = tb;
return;
uniq_id++;
+
+ if (!already_sent)
+ InitializeAlreadySent(ServerInstance->SE);
+
snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost(),normal_text.c_str());
snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost(),oper_text.c_str());
std::string out1 = tb1;
return;
uniq_id++;
+
+ if (!already_sent)
+ InitializeAlreadySent(ServerInstance->SE);
+
snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
out1 = tb1;
void User::WriteWallOps(const std::string &text)
{
- if (!IS_OPER(this) && IS_LOCAL(this))
+ if (!IS_LOCAL(this))
return;
std::string wallop("WALLOPS :");
void User::WriteWallOps(const char* text, ...)
{
+ if (!IS_LOCAL(this))
+ return;
+
char textbuffer[MAXBUF];
va_list argsPtr;
{
if (!WriteError.empty())
{
- User::QuitUser(ServerInstance, this, GetWriteError());
+ ServerInstance->Users->QuitUser(this, GetWriteError());
}
}
}