summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:44:48 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:44:48 +0000
commit9924e5631193ad581d885380fd11ae8bfb91fa0b (patch)
treea818b0bd77cf16e793a4a54c1aeafc0cbf1d0ddf
parent30583ca1f1687927e8bae2bc6cdd7cfde423bfd6 (diff)
Split LocalUser and RemoteUser
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11940 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/fakeuser.h32
-rw-r--r--include/inspircd.h1
-rw-r--r--include/modules.h23
-rw-r--r--include/usermanager.h2
-rw-r--r--include/users.h58
-rw-r--r--src/commands/cmd_wallops.cpp2
-rw-r--r--src/helperfuncs.cpp2
-rw-r--r--src/inspircd.cpp2
-rw-r--r--src/modules/m_cloaking.cpp2
-rw-r--r--src/modules/m_close.cpp2
-rw-r--r--src/modules/m_jumpserver.cpp2
-rwxr-xr-xsrc/modules/m_nationalchars.cpp2
-rw-r--r--src/modules/m_spanningtree/uid.cpp2
-rw-r--r--src/stats.cpp6
-rw-r--r--src/usermanager.cpp12
-rw-r--r--src/userprocess.cpp2
-rw-r--r--src/users.cpp32
-rw-r--r--src/xline.cpp8
18 files changed, 98 insertions, 94 deletions
diff --git a/include/fakeuser.h b/include/fakeuser.h
deleted file mode 100644
index a46971091..000000000
--- a/include/fakeuser.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
- *
- * InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
- *
- * This program is free but copyrighted software; see
- * the file COPYING for details.
- *
- * ---------------------------------------------------
- */
-
-#ifndef __FAKEUSER_H__
-#define __FAKEUSER_H__
-
-#include "users.h"
-
-class CoreExport FakeUser : public User
-{
- public:
- FakeUser(const std::string &uid) : User(uid)
- {
- SetFd(FD_FAKEUSER_NUMBER);
- }
-
- virtual const std::string GetFullHost();
- virtual const std::string GetFullRealHost();
- void SetFakeServer(std::string name);
-};
-
-#endif
diff --git a/include/inspircd.h b/include/inspircd.h
index b4f73d571..caebe2eeb 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -87,7 +87,6 @@ CoreExport extern InspIRCd* ServerInstance;
#include "inspstring.h"
#include "protocol.h"
#include "threadengine.h"
-#include "fakeuser.h"
#ifndef PATH_MAX
#warning Potentially broken system, PATH_MAX undefined
diff --git a/include/modules.h b/include/modules.h
index 5e6cf13f5..ae29b2176 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -198,29 +198,6 @@ do { \
WHILE_EACH_HOOK(n); \
} while (0)
-/** Represents a non-local user.
- * (in fact, any FD less than -1 does)
- */
-#define FD_MAGIC_NUMBER -42
-/** Represents a fake user (i.e. a server)
- */
-#define FD_FAKEUSER_NUMBER -7
-
-/* Useful macros */
-
-/** Is a local user */
-#define IS_LOCAL(x) (x->GetFd() > -1)
-/** Is a remote user */
-#define IS_REMOTE(x) (x->GetFd() < 0)
-/** Is a fake user */
-#define IS_SERVER(x) (x->GetFd() == FD_FAKEUSER_NUMBER)
-/** Is a module created user */
-#define IS_MODULE_CREATED(x) (x->GetFd() == FD_MAGIC_NUMBER)
-/** Is an oper */
-#define IS_OPER(x) (!x->oper.empty())
-/** Is away */
-#define IS_AWAY(x) (!x->awaymsg.empty())
-
/** Holds a module's Version information.
* The members (set by the constructor only) indicate details as to the version number
* of a module. A class of type Version is returned by the GetVersion method of the Module class.
diff --git a/include/usermanager.h b/include/usermanager.h
index 4c1f94248..885394f76 100644
--- a/include/usermanager.h
+++ b/include/usermanager.h
@@ -48,7 +48,7 @@ class CoreExport UserManager
/** Local client list, a vector containing only local clients
*/
- std::vector<User*> local_users;
+ std::vector<LocalUser*> local_users;
/** Oper list, a vector containing all local and remote opered users
*/
diff --git a/include/users.h b/include/users.h
index 5153ebdd4..c60d5f033 100644
--- a/include/users.h
+++ b/include/users.h
@@ -479,7 +479,7 @@ class CoreExport User : public StreamSocket
* @param Instance Creator instance
* @param uid User UUID, or empty to allocate one automatically
*/
- User(const std::string &uid = "");
+ User(const std::string &uid);
/** Check if the user matches a G or K line, and disconnect them if they do.
* @param doZline True if ZLines should be checked (if IP has changed since initial connect)
@@ -753,7 +753,7 @@ class CoreExport User : public StreamSocket
/** Write to the user, routing the line if the user is remote.
*/
- void SendText(const std::string& line);
+ virtual void SendText(const std::string& line) = 0;
/** Write to the user, routing the line if the user is remote.
*/
@@ -862,6 +862,60 @@ class CoreExport User : public StreamSocket
virtual CullResult cull();
};
+/** Represents a non-local user.
+ * (in fact, any FD less than -1 does)
+ */
+#define FD_MAGIC_NUMBER -42
+/** Represents a fake user (i.e. a server)
+ */
+#define FD_FAKEUSER_NUMBER -7
+
+/* Useful macros */
+
+/** Is a local user */
+#define IS_LOCAL(x) (x->GetFd() > -1)
+/** Is a remote user */
+#define IS_REMOTE(x) (x->GetFd() < 0)
+/** Is a fake user */
+#define IS_SERVER(x) (x->GetFd() == FD_FAKEUSER_NUMBER)
+/** Is a module created user */
+#define IS_MODULE_CREATED(x) (x->GetFd() == FD_MAGIC_NUMBER)
+/** Is an oper */
+#define IS_OPER(x) (!x->oper.empty())
+/** Is away */
+#define IS_AWAY(x) (!x->awaymsg.empty())
+
+class CoreExport LocalUser : public User
+{
+ public:
+ LocalUser();
+ virtual void SendText(const std::string& line);
+};
+
+class CoreExport RemoteUser : public User
+{
+ public:
+ RemoteUser(const std::string& uid) : User(uid)
+ {
+ SetFd(FD_MAGIC_NUMBER);
+ }
+ virtual void SendText(const std::string& line);
+};
+
+class CoreExport FakeUser : public User
+{
+ public:
+ FakeUser(const std::string &uid) : User(uid)
+ {
+ SetFd(FD_FAKEUSER_NUMBER);
+ }
+
+ virtual void SendText(const std::string& line);
+ virtual const std::string GetFullHost();
+ virtual const std::string GetFullRealHost();
+ void SetFakeServer(std::string name);
+};
+
/** Derived from Resolver, and performs user forward/reverse lookups.
*/
class CoreExport UserResolver : public Resolver
diff --git a/src/commands/cmd_wallops.cpp b/src/commands/cmd_wallops.cpp
index 52d28e987..d24a5887d 100644
--- a/src/commands/cmd_wallops.cpp
+++ b/src/commands/cmd_wallops.cpp
@@ -38,7 +38,7 @@ CmdResult CommandWallops::Handle (const std::vector<std::string>& parameters, Us
std::string wallop("WALLOPS :");
wallop.append(parameters[0]);
- for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
{
User* t = *i;
if (t->IsModeSet('w'))
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index cd173b55f..eced0c56a 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -123,7 +123,7 @@ Channel* InspIRCd::FindChan(const std::string &chan)
/* Send an error notice to all users, registered or not */
void InspIRCd::SendError(const std::string &s)
{
- for (std::vector<User*>::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
{
User* u = *i;
if (u->registered == REG_ALL)
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index d9f1d0423..ca6a59cac 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -99,7 +99,7 @@ void InspIRCd::Cleanup()
ports.clear();
/* Close all client sockets, or the new process inherits them */
- std::vector<User*>::reverse_iterator i = Users->local_users.rbegin();
+ std::vector<LocalUser*>::reverse_iterator i = Users->local_users.rbegin();
while (i != this->Users->local_users.rend())
{
User* u = *i++;
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 3be6e2163..c61868dc3 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -305,7 +305,7 @@ class ModuleCloaking : public Module
void CloakExistingUsers()
{
std::string* cloak;
- for (std::vector<User*>::iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); u++)
+ for (std::vector<LocalUser*>::iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); u++)
{
cloak = cu.ext.get(*u);
if (!cloak)
diff --git a/src/modules/m_close.cpp b/src/modules/m_close.cpp
index 24831a807..5c0c0188b 100644
--- a/src/modules/m_close.cpp
+++ b/src/modules/m_close.cpp
@@ -37,7 +37,7 @@ class CommandClose : public Command
{
std::map<std::string,int> closed;
- std::vector<User*>::reverse_iterator u = ServerInstance->Users->local_users.rbegin();
+ std::vector<LocalUser*>::reverse_iterator u = ServerInstance->Users->local_users.rbegin();
while (u != ServerInstance->Users->local_users.rend())
{
User* user = *u++;
diff --git a/src/modules/m_jumpserver.cpp b/src/modules/m_jumpserver.cpp
index b2bbe0d8c..d46e85bdd 100644
--- a/src/modules/m_jumpserver.cpp
+++ b/src/modules/m_jumpserver.cpp
@@ -95,7 +95,7 @@ class CommandJumpserver : public Command
if (redirect_all_immediately)
{
/* Redirect everyone but the oper sending the command */
- for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
{
User* t = *i;
if (!IS_OPER(t))
diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp
index 5e919dad6..e8a70d148 100755
--- a/src/modules/m_nationalchars.cpp
+++ b/src/modules/m_nationalchars.cpp
@@ -258,7 +258,7 @@ class ModuleNationalChars : public Module
if (!forcequit)
return;
- for (std::vector<User*>::iterator iter = ServerInstance->Users->local_users.begin(); iter != ServerInstance->Users->local_users.end(); ++iter)
+ for (std::vector<LocalUser*>::iterator iter = ServerInstance->Users->local_users.begin(); iter != ServerInstance->Users->local_users.end(); ++iter)
{
/* Fix by Brain: Dont quit UID users */
User* n = *iter;
diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp
index 4e3b07eea..340b7f496 100644
--- a/src/modules/m_spanningtree/uid.cpp
+++ b/src/modules/m_spanningtree/uid.cpp
@@ -86,7 +86,7 @@ bool TreeSocket::ParseUID(const std::string &source, parameterlist &params)
User* _new = NULL;
try
{
- _new = new User(params[0]);
+ _new = new RemoteUser(params[0]);
}
catch (...)
{
diff --git a/src/stats.cpp b/src/stats.cpp
index eb8fe0e45..f695104b0 100644
--- a/src/stats.cpp
+++ b/src/stats.cpp
@@ -98,7 +98,7 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results)
case 'P':
{
int idx = 0;
- for (user_hash::iterator i = this->Users->clientlist->begin(); i != this->Users->clientlist->end(); i++)
+ for (user_hash::iterator i = this->Users->clientlist->begin(); i != this->Users->clientlist->end(); i++)
{
if (IS_OPER(i->second) && !this->ULine(i->second->server))
{
@@ -247,7 +247,7 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results)
/* stats l (show user I/O stats) */
case 'l':
results.push_back(sn+" 211 "+user->nick+" :nick[ident@host] sendq cmds_out bytes_out cmds_in bytes_in time_open");
- for (std::vector<User*>::iterator n = this->Users->local_users.begin(); n != this->Users->local_users.end(); n++)
+ for (std::vector<LocalUser*>::iterator n = this->Users->local_users.begin(); n != this->Users->local_users.end(); n++)
{
User* i = *n;
results.push_back(sn+" 211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->dhost+"] "+ConvToStr(i->getSendQSize())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(this->Time() - i->age));
@@ -257,7 +257,7 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results)
/* stats L (show user I/O stats with IP addresses) */
case 'L':
results.push_back(sn+" 211 "+user->nick+" :nick[ident@ip] sendq cmds_out bytes_out cmds_in bytes_in time_open");
- for (std::vector<User*>::iterator n = this->Users->local_users.begin(); n != this->Users->local_users.end(); n++)
+ for (std::vector<LocalUser*>::iterator n = this->Users->local_users.begin(); n != this->Users->local_users.end(); n++)
{
User* i = *n;
results.push_back(sn+" 211 "+user->nick+" "+i->nick+"["+i->ident+"@"+i->GetIPString()+"] "+ConvToStr(i->getSendQSize())+" "+ConvToStr(i->cmds_out)+" "+ConvToStr(i->bytes_out)+" "+ConvToStr(i->cmds_in)+" "+ConvToStr(i->bytes_in)+" "+ConvToStr(this->Time() - i->age));
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 2eebb1ed0..db2b3a75c 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -23,10 +23,10 @@ void UserManager::AddUser(int socket, ClientListenSocket* via, irc::sockets::soc
/* NOTE: Calling this one parameter constructor for User automatically
* allocates a new UUID and places it in the hash_map.
*/
- User* New = NULL;
+ LocalUser* New = NULL;
try
{
- New = new User();
+ New = new LocalUser();
}
catch (...)
{
@@ -423,7 +423,7 @@ void UserManager::ServerNoticeAll(const char* text, ...)
snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
- for (std::vector<User*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
User* t = *i;
t->WriteServ(std::string(formatbuffer));
@@ -444,7 +444,7 @@ void UserManager::ServerPrivmsgAll(const char* text, ...)
snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
- for (std::vector<User*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
User* t = *i;
t->WriteServ(std::string(formatbuffer));
@@ -470,7 +470,7 @@ void UserManager::WriteMode(const char* modes, int flags, const char* text, ...)
if (flags == WM_AND)
{
- for (std::vector<User*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
User* t = *i;
bool send_to_user = true;
@@ -491,7 +491,7 @@ void UserManager::WriteMode(const char* modes, int flags, const char* text, ...)
}
else if (flags == WM_OR)
{
- for (std::vector<User*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
User* t = *i;
bool send_to_user = false;
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index d4de29075..aa05504d5 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -46,7 +46,7 @@ void InspIRCd::DoBackgroundUserStuff()
/*
* loop over all local users..
*/
- std::vector<User*>::reverse_iterator count2 = this->Users->local_users.rbegin();
+ std::vector<LocalUser*>::reverse_iterator count2 = this->Users->local_users.rbegin();
while (count2 != this->Users->local_users.rend())
{
User *curr = *count2;
diff --git a/src/users.cpp b/src/users.cpp
index fbb2309c3..e24f59a0c 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -233,13 +233,9 @@ User::User(const std::string &uid)
server_sa.sa.sa_family = AF_UNSPEC;
client_sa.sa.sa_family = AF_UNSPEC;
AllowedPrivs = AllowedOperCommands = NULL;
+ uuid = uid;
- if (uid.empty())
- uuid = ServerInstance->GetUID();
- else
- uuid = uid;
-
- ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
+ ServerInstance->Logs->Log("USERS", DEBUG, "New UUID for user: %s", uuid.c_str());
user_hash::iterator finduuid = ServerInstance->Users->uuidlist->find(uuid);
if (finduuid == ServerInstance->Users->uuidlist->end())
@@ -248,6 +244,10 @@ User::User(const std::string &uid)
throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
}
+LocalUser::LocalUser() : User(ServerInstance->GetUID())
+{
+}
+
User::~User()
{
if (uuid.length())
@@ -603,7 +603,7 @@ CullResult User::cull()
if (fd != INT_MAX)
Close();
- std::vector<User*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),this);
+ std::vector<LocalUser*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),this);
if (x != ServerInstance->Users->local_users.end())
ServerInstance->Users->local_users.erase(x);
else
@@ -1341,12 +1341,18 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
}
}
-void User::SendText(const std::string& line)
+void LocalUser::SendText(const std::string& line)
+{
+ Write(line);
+}
+
+void RemoteUser::SendText(const std::string& line)
+{
+ ServerInstance->PI->PushToClient(this, line);
+}
+
+void FakeUser::SendText(const std::string& line)
{
- if (IS_LOCAL(this))
- Write(line);
- else if (!IS_SERVER(this))
- ServerInstance->PI->PushToClient(this, line);
}
void User::SendText(const char *text, ...)
@@ -1557,7 +1563,7 @@ void User::SendAll(const char* command, const char* text, ...)
snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
std::string fmt = formatbuffer;
- for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
+ for (std::vector<LocalUser*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
{
(*i)->Write(fmt);
}
diff --git a/src/xline.cpp b/src/xline.cpp
index b101237a3..aa43ac43b 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -146,7 +146,7 @@ void XLineManager::CheckELines()
if (ELines.empty())
return;
- for (std::vector<User*>::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
+ for (std::vector<LocalUser*>::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
{
User* u = (User*)(*u2);
@@ -311,7 +311,7 @@ bool XLineManager::DelLine(const char* hostmask, const std::string &type, User*
void ELine::Unset()
{
/* remove exempt from everyone and force recheck after deleting eline */
- for (std::vector<User*>::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
+ for (std::vector<LocalUser*>::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
{
User* u = (User*)(*u2);
u->exempt = false;
@@ -415,7 +415,7 @@ void XLineManager::ExpireLine(ContainerIter container, LookupIter item)
// applies lines, removing clients and changing nicks etc as applicable
void XLineManager::ApplyLines()
{
- std::vector<User*>::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin();
+ std::vector<LocalUser*>::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin();
while (u2 != ServerInstance->Users->local_users.rend())
{
User* u = *u2++;
@@ -670,7 +670,7 @@ bool GLine::Matches(const std::string &str)
void ELine::OnAdd()
{
/* When adding one eline, only check the one eline */
- for (std::vector<User*>::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
+ for (std::vector<LocalUser*>::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
{
User* u = (User*)(*u2);
if (this->Matches(u))