summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-09 17:52:10 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-09 17:52:10 +0000
commit2591562ada4cb1f866e5d1c98340fb19332b3844 (patch)
tree1cf18676c1851c39322d20fa208c0221e23ba6ac
parent1cbf29e3cd070c12437a657b47fc433008b2c74d (diff)
Move tons more stuff into class InspIRCd
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4819 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/helperfuncs.h15
-rw-r--r--include/inspircd.h23
-rw-r--r--include/modules.h37
-rw-r--r--include/users.h2
-rw-r--r--src/channels.cpp2
-rw-r--r--src/cmd_list.cpp2
-rw-r--r--src/cmd_lusers.cpp22
-rw-r--r--src/cmd_notice.cpp3
-rw-r--r--src/cmd_privmsg.cpp3
-rw-r--r--src/cmd_quit.cpp5
-rw-r--r--src/cmd_restart.cpp4
-rw-r--r--src/cmd_stats.cpp5
-rw-r--r--src/command_parse.cpp1
-rw-r--r--src/commands.cpp1
-rw-r--r--src/helperfuncs.cpp74
-rw-r--r--src/inspircd.cpp8
-rw-r--r--src/modules.cpp18
-rw-r--r--src/modules/m_chanprotect.cpp2
-rw-r--r--src/modules/m_globops.cpp3
-rw-r--r--src/modules/m_helpop.cpp4
-rw-r--r--src/modules/m_override.cpp2
-rw-r--r--src/modules/m_park.cpp6
-rw-r--r--src/modules/m_redirect.cpp2
-rw-r--r--src/modules/m_safelist.cpp2
-rw-r--r--src/modules/m_spanningtree.cpp24
-rw-r--r--src/modules/m_spy.cpp2
-rw-r--r--src/userprocess.cpp7
-rw-r--r--src/users.cpp34
-rw-r--r--src/xline.cpp3
29 files changed, 129 insertions, 187 deletions
diff --git a/include/helperfuncs.h b/include/helperfuncs.h
index b4089fa18..801e05bdb 100644
--- a/include/helperfuncs.h
+++ b/include/helperfuncs.h
@@ -52,30 +52,17 @@ void WriteOpers(const char* text, ...);
void WriteOpers_NoFormat(const char* text);
std::string GetServerDescription(const char* servername);
-void WriteMode(const char* modes, int flags, const char* text, ...);
-void NoticeAll(userrec *source, bool local_only, char* text, ...);
-void ServerNoticeAll(char* text, ...);
-void ServerPrivmsgAll(char* text, ...);
void strlower(char *n);
userrec* Find(const std::string &nick);
userrec* Find(const char* nick);
chanrec* FindChan(const char* chan);
+int usercount_i(chanrec *c);
long GetMaxBans(char* name);
void purge_empty_chans(userrec* u);
char* chanmodes(chanrec *chan, bool showkey);
void userlist(userrec *user,chanrec *c);
-int usercount_i(chanrec *c);
-int usercount(chanrec *c);
ConnectClass GetClass(userrec *user);
-void send_error(char *s);
void Error(int status);
-int usercnt(void);
-int registered_usercount(void);
-int usercount_invisible(void);
-int usercount_opers(void);
-int usercount_unknown(void);
-long chancount(void);
-long local_count();
void ShowMOTD(userrec *user);
void ShowRULES(userrec *user);
bool AllModulesReportReady(userrec* user);
diff --git a/include/inspircd.h b/include/inspircd.h
index 5aacd072d..f901200cd 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -83,6 +83,7 @@ class InspIRCd : public classbase
private:
char MODERR[MAXBUF];
bool expire_run;
+ servernamelist servernames;
void EraseFactory(int j);
void EraseModule(int j);
@@ -111,15 +112,31 @@ class InspIRCd : public classbase
std::vector<InspSocket*> module_sockets;
InspSocket* socket_ref[MAX_DESCRIPTORS]; /* XXX: This should probably be made private, with inline accessors */
userrec* fd_ref_table[MAX_DESCRIPTORS]; /* XXX: Ditto */
- user_hash clientlist; /* XXX: Ditto */
- chan_hash chanlist; /* XXX: Ditto */
- servernamelist servernames; /* XXX: Ditto */
+ user_hash clientlist;
+ chan_hash chanlist;
+ std::vector<userrec*> local_users;
DNS* Res;
void AddServerName(const std::string &servername);
const char* FindServerNamePtr(const std::string &servername);
bool FindServerName(const std::string &servername);
+ bool UserToPseudo(userrec* user, const std::string &message);
+ bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
+
+ void ServerNoticeAll(char* text, ...);
+ void ServerPrivmsgAll(char* text, ...);
+ void WriteMode(const char* modes, int flags, const char* text, ...);
+
+ int usercnt();
+ int registered_usercount();
+ int usercount_invisible();
+ int usercount_opers();
+ int usercount_unknown();
+ long chancount();
+ long local_count();
+
+ void SendError(const char *s);
std::string GetRevision();
std::string GetVersionString();
diff --git a/include/modules.h b/include/modules.h
index 6104b8715..6f9ebf9e9 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -1323,11 +1323,6 @@ class Server : public Extensible
*/
virtual bool IsNick(const std::string &nick);
- /** Returns a count of the number of users on a channel.
- * This will NEVER be 0, as if the chanrec exists, it will have at least one user in the channel.
- */
- virtual int CountUsers(chanrec* c);
-
/** Adds an InspTimer which will trigger at a future time
*/
virtual void AddTimer(InspTimer* T);
@@ -1421,21 +1416,7 @@ class Server : public Extensible
*/
virtual void SendMode(const char **parameters, int pcnt, userrec *user);
-
- /** Sends to all users matching a mode mask
- * You must specify one or more usermodes as the first parameter. These can be RFC specified modes such as +i,
- * or module provided modes, including ones provided by your own module.
- * In the second parameter you must place a flag value which indicates wether the modes you have given will be
- * logically ANDed or OR'ed. You may use one of either WM_AND or WM_OR.
- * for example, if you were to use:
- *
- * Serv->SendToModeMask("xi", WM_OR, "m00");
- *
- * Then the text 'm00' will be sent to all users with EITHER mode x or i. Conversely if you used WM_AND, the
- * user must have both modes set to receive the message.
- */
- virtual void SendToModeMask(const std::string &modes, int flags, const std::string &text);
-
+
/** Matches text against a glob pattern.
* Uses the ircd's internal matching function to match string against a globbing pattern, e.g. *!*@*.com
* Returns true if the literal successfully matches the pattern, false if otherwise.
@@ -1470,22 +1451,6 @@ class Server : public Extensible
*/
virtual bool IsUlined(const std::string &server);
- /** Remove a user's connection to the irc server, but leave their client in existence in the
- * user hash. When you call this function, the user's file descriptor will be replaced with the
- * value of FD_MAGIC_NUMBER and their old file descriptor will be closed. This idle client will
- * remain until it is restored with a valid file descriptor, or is removed from IRC by an operator
- * After this call, the pointer to user will be invalid.
- */
- virtual bool UserToPseudo(userrec* user, const std::string &message);
-
- /** This user takes one user, and switches their file descriptor with another user, so that one user
- * "becomes" the other. The user in 'alive' is booted off the server with the given message. The user
- * referred to by 'zombie' should have previously been locked with Server::UserToPseudo, otherwise
- * stale sockets and file descriptor leaks can occur. After this call, the pointer to alive will be
- * invalid, and the pointer to zombie will be equivalent in effect to the old pointer to alive.
- */
- virtual bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
-
/** Adds a G-line
* The G-line is propogated to all of the servers in the mesh and enforced as soon as it is added.
* The duration must be in seconds, however you can use the Server::CalcDuration method to convert
diff --git a/include/users.h b/include/users.h
index 42d0f7376..6e5a60b23 100644
--- a/include/users.h
+++ b/include/users.h
@@ -639,6 +639,8 @@ class userrec : public connection
int CountChannels();
+ void NoticeAll(char* text, ...);
+
/** Default destructor
*/
virtual ~userrec();
diff --git a/src/channels.cpp b/src/channels.cpp
index bf2596bb1..b9e88a5bd 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -325,7 +325,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c
FOREACH_RESULT(I_OnCheckLimit,OnCheckLimit(user, Ptr));
if (!MOD_RESULT)
{
- if (usercount(Ptr) >= Ptr->limit)
+ if (Ptr->GetUserCounter() >= Ptr->limit)
{
user->WriteServ("471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
return NULL;
diff --git a/src/cmd_list.cpp b/src/cmd_list.cpp
index 26fa3cc10..3dbb3c2e2 100644
--- a/src/cmd_list.cpp
+++ b/src/cmd_list.cpp
@@ -32,7 +32,7 @@ void cmd_list::Handle (const char** parameters, int pcnt, userrec *user)
bool n = i->second->HasUser(user);
if (((!(i->second->modes[CM_PRIVATE])) && (!(i->second->modes[CM_SECRET]))) || (n))
{
- long users = usercount(i->second);
+ long users = i->second->GetUserCounter();
if (users)
user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,users,chanmodes(i->second,n),i->second->topic);
}
diff --git a/src/cmd_lusers.cpp b/src/cmd_lusers.cpp
index 9c35bf35a..acb43c7ce 100644
--- a/src/cmd_lusers.cpp
+++ b/src/cmd_lusers.cpp
@@ -17,19 +17,23 @@
#include "users.h"
#include "commands.h"
#include "helperfuncs.h"
+#include "inspircd.h"
#include "commands/cmd_lusers.h"
+extern InspIRCd* ServerInstance;
+
void cmd_lusers::Handle (const char** parameters, int pcnt, userrec *user)
{
// this lusers command shows one server at all times because
// a protocol module must override it to show those stats.
- user->WriteServ("251 %s :There are %d users and %d invisible on 1 server",user->nick,usercnt()-usercount_invisible(),usercount_invisible());
- if (usercount_opers())
- user->WriteServ("252 %s %d :operator(s) online",user->nick,usercount_opers());
- if (usercount_unknown())
- user->WriteServ("253 %s %d :unknown connections",user->nick,usercount_unknown());
- if (chancount())
- user->WriteServ("254 %s %d :channels formed",user->nick,chancount());
- if (local_count())
- user->WriteServ("254 %s :I have %d clients and 0 servers",user->nick,local_count());
+ user->WriteServ("251 %s :There are %d users and %d invisible on 1 server",user->nick,ServerInstance->usercnt()-ServerInstance->usercount_invisible(),ServerInstance->usercount_invisible());
+ if (ServerInstance->usercount_opers())
+ user->WriteServ("252 %s %d :operator(s) online",user->nick,ServerInstance->usercount_opers());
+ if (ServerInstance->usercount_unknown())
+ user->WriteServ("253 %s %d :unknown connections",user->nick,ServerInstance->usercount_unknown());
+ if (ServerInstance->chancount())
+ user->WriteServ("254 %s %d :channels formed",user->nick,ServerInstance->chancount());
+ if (ServerInstance->local_count())
+ user->WriteServ("254 %s :I have %d clients and 0 servers",user->nick,ServerInstance->local_count());
}
+
diff --git a/src/cmd_notice.cpp b/src/cmd_notice.cpp
index fcadaddaf..f1e814198 100644
--- a/src/cmd_notice.cpp
+++ b/src/cmd_notice.cpp
@@ -30,7 +30,6 @@
#include "commands/cmd_notice.h"
extern InspIRCd* ServerInstance;
-extern InspIRCd* ServerInstance;
extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
@@ -57,7 +56,7 @@ void cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
const char* servermask = parameters[0] + 1;
if (match(ServerInstance->Config->ServerName,servermask))
{
- NoticeAll(user, true, "%s",parameters[1]);
+ user->NoticeAll("%s",parameters[1]);
}
FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
return;
diff --git a/src/cmd_privmsg.cpp b/src/cmd_privmsg.cpp
index d11f630a2..8a2175ecc 100644
--- a/src/cmd_privmsg.cpp
+++ b/src/cmd_privmsg.cpp
@@ -27,7 +27,6 @@
#include "commands/cmd_privmsg.h"
extern InspIRCd* ServerInstance;
-extern InspIRCd* ServerInstance;
extern int MODCOUNT;
extern ModuleList modules;
extern FactoryList factory;
@@ -55,7 +54,7 @@ void cmd_privmsg::Handle (const char** parameters, int pcnt, userrec *user)
const char* servermask = parameters[0] + 1;
if (match(ServerInstance->Config->ServerName,servermask))
{
- ServerPrivmsgAll("%s",parameters[1]);
+ ServerInstance->ServerPrivmsgAll("%s",parameters[1]);
}
FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
return;
diff --git a/src/cmd_quit.cpp b/src/cmd_quit.cpp
index f24abbe7c..feaab0fe4 100644
--- a/src/cmd_quit.cpp
+++ b/src/cmd_quit.cpp
@@ -40,7 +40,6 @@ extern int MODCOUNT;
extern ModuleList modules;
extern FactoryList factory;
extern time_t TIME;
-extern std::vector<userrec*> local_users;
void cmd_quit::Handle (const char** parameters, int pcnt, userrec *user)
{
@@ -91,10 +90,10 @@ void cmd_quit::Handle (const char** parameters, int pcnt, userrec *user)
if (user->fd > -1)
{
ServerInstance->SE->DelFd(user->fd);
- if (find(local_users.begin(),local_users.end(),user) != local_users.end())
+ if (find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user) != ServerInstance->local_users.end())
{
log(DEBUG,"Delete local user");
- local_users.erase(find(local_users.begin(),local_users.end(),user));
+ ServerInstance->local_users.erase(find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user));
}
user->CloseSocket();
}
diff --git a/src/cmd_restart.cpp b/src/cmd_restart.cpp
index baf5104f9..81c45386f 100644
--- a/src/cmd_restart.cpp
+++ b/src/cmd_restart.cpp
@@ -20,7 +20,7 @@
#include "helperfuncs.h"
#include "commands/cmd_restart.h"
-extern InspIRCd* ServerInstance;;
+extern InspIRCd* ServerInstance;
void cmd_restart::Handle (const char** parameters, int pcnt, userrec *user)
{
@@ -43,7 +43,7 @@ void cmd_restart::Handle (const char** parameters, int pcnt, userrec *user)
argv[3] = NULL;
// close ALL file descriptors
- send_error("Server restarting.");
+ ServerInstance->SendError("Server restarting.");
sleep(1);
for (int i = 0; i < MAX_DESCRIPTORS; i++)
{
diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp
index 30cc2eb0d..6f124d6eb 100644
--- a/src/cmd_stats.cpp
+++ b/src/cmd_stats.cpp
@@ -48,7 +48,6 @@ extern int MODCOUNT;
extern ModuleList modules;
extern FactoryList factory;
extern time_t TIME;
-extern std::vector<userrec*> local_users;
void cmd_stats::Handle (const char** parameters, int pcnt, userrec *user)
{
@@ -212,7 +211,7 @@ void DoStats(char statschar, userrec* user, string_list &results)
if (statschar == '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<userrec*>::iterator n = local_users.begin(); n != local_users.end(); n++)
+ for (std::vector<userrec*>::iterator n = ServerInstance->local_users.begin(); n != ServerInstance->local_users.end(); n++)
{
userrec* i = *n;
if (isnick(i->nick))
@@ -226,7 +225,7 @@ void DoStats(char statschar, userrec* user, string_list &results)
if (statschar == '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<userrec*>::iterator n = local_users.begin(); n != local_users.end(); n++)
+ for (std::vector<userrec*>::iterator n = ServerInstance->local_users.begin(); n != ServerInstance->local_users.end(); n++)
{
userrec* i = *n;
if (isnick(i->nick))
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index 57c8f44c1..4a375f365 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -53,7 +53,6 @@ extern InspIRCd* ServerInstance;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
-extern std::vector<userrec*> local_users;
extern int MODCOUNT;
extern time_t TIME;
diff --git a/src/commands.cpp b/src/commands.cpp
index 8504c174d..b1eb51490 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -64,7 +64,6 @@ const long duration_w = duration_d * 7;
const long duration_y = duration_w * 52;
extern std::vector<userrec*> all_opers;
-extern std::vector<userrec*> local_users;
void split_chlist(userrec* user, userrec* dest, const std::string &cl)
{
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index e9b969ee2..1f2a6646b 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -16,7 +16,6 @@
#include <stdarg.h>
#include "inspircd_config.h"
-#include "inspircd.h"
#include "configreader.h"
#include <unistd.h>
#include <fcntl.h>
@@ -43,6 +42,7 @@
#include "helperfuncs.h"
#include "hashcomp.h"
#include "typedefs.h"
+#include "inspircd.h"
extern int MODCOUNT;
extern ModuleList modules;
@@ -53,8 +53,6 @@ extern std::vector<userrec*> all_opers;
char LOG_FILE[MAXBUF];
-extern std::vector<userrec*> local_users;
-
static char TIMESTR[26];
static time_t LAST = 0;
@@ -169,7 +167,7 @@ void WriteOpers_NoFormat(const char* text)
}
}
-void ServerNoticeAll(char* text, ...)
+void InspIRCd::ServerNoticeAll(char* text, ...)
{
if (!text)
return;
@@ -190,7 +188,7 @@ void ServerNoticeAll(char* text, ...)
}
}
-void ServerPrivmsgAll(char* text, ...)
+void InspIRCd::ServerPrivmsgAll(char* text, ...)
{
if (!text)
return;
@@ -211,7 +209,7 @@ void ServerPrivmsgAll(char* text, ...)
}
}
-void WriteMode(const char* modes, int flags, const char* text, ...)
+void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...)
{
char textbuffer[MAXBUF];
int modelen;
@@ -267,32 +265,6 @@ void WriteMode(const char* modes, int flags, const char* text, ...)
}
}
-void NoticeAll(userrec *source, bool local_only, char* text, ...)
-{
- char textbuffer[MAXBUF];
- char formatbuffer[MAXBUF];
- va_list argsPtr;
-
- if ((!text) || (!source))
- {
- log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
- return;
- }
-
- va_start(argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
-
- for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
- {
- userrec* t = *i;
- t->WriteFrom(source,std::string(formatbuffer));
- }
-}
-
-
/* convert a string to lowercase. Note following special circumstances
* taken from RFC 1459. Many "official" server branches still hold to this
* rule so i will too;
@@ -557,12 +529,6 @@ int usercount_i(chanrec *c)
return count;
}
-int usercount(chanrec *c)
-{
- return (c ? c->GetUserCounter() : 0);
-}
-
-
/* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
* NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
* then their ip will be taken as 'priority' anyway, so for example,
@@ -585,11 +551,9 @@ ConnectClass GetClass(userrec *user)
* sends out an error notice to all connected clients (not to be used
* lightly!)
*/
-void send_error(char *s)
+void InspIRCd::SendError(const char *s)
{
- log(DEBUG,"send_error: %s",s);
-
- for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
+ for (std::vector<userrec*>::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
{
userrec* t = (userrec*)(*i);
if (t->registered == REG_ALL)
@@ -630,7 +594,7 @@ void Error(int status)
#else
log(DEFAULT,"You do not have execinfo.h so i could not backtrace -- on FreeBSD, please install the libexecinfo port.");
#endif
- send_error("Somebody screwed up... Whoops. IRC Server terminating.");
+ ServerInstance->SendError("Somebody screwed up... Whoops. IRC Server terminating.");
signal(SIGSEGV, SIG_DFL);
if (raise(SIGSEGV) == -1)
{
@@ -640,17 +604,17 @@ void Error(int status)
}
// this function counts all users connected, wether they are registered or NOT.
-int usercnt(void)
+int InspIRCd::usercnt()
{
- return ServerInstance->clientlist.size();
+ return clientlist.size();
}
// this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
-int registered_usercount(void)
+int InspIRCd::registered_usercount()
{
int c = 0;
- for (user_hash::const_iterator i = ServerInstance->clientlist.begin(); i != ServerInstance->clientlist.end(); i++)
+ for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
c += (i->second->registered == REG_ALL);
}
@@ -658,11 +622,11 @@ int registered_usercount(void)
return c;
}
-int usercount_invisible(void)
+int InspIRCd::usercount_invisible()
{
int c = 0;
- for (user_hash::const_iterator i = ServerInstance->clientlist.begin(); i != ServerInstance->clientlist.end(); i++)
+ for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
c += ((i->second->registered == REG_ALL) && (i->second->modes[UM_INVISIBLE]));
}
@@ -670,11 +634,11 @@ int usercount_invisible(void)
return c;
}
-int usercount_opers(void)
+int InspIRCd::usercount_opers()
{
int c = 0;
- for (user_hash::const_iterator i = ServerInstance->clientlist.begin(); i != ServerInstance->clientlist.end(); i++)
+ for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
if (*(i->second->oper))
c++;
@@ -682,7 +646,7 @@ int usercount_opers(void)
return c;
}
-int usercount_unknown(void)
+int InspIRCd::usercount_unknown()
{
int c = 0;
@@ -696,12 +660,12 @@ int usercount_unknown(void)
return c;
}
-long chancount(void)
+long InspIRCd::chancount()
{
- return ServerInstance->chanlist.size();
+ return chanlist.size();
}
-long local_count()
+long InspIRCd::local_count()
{
int c = 0;
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 5c3afe70c..ecda5abb9 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -70,8 +70,6 @@ InspIRCd* ServerInstance;
extern ModuleList modules;
extern FactoryList factory;
-std::vector<userrec*> local_users;
-
extern int MODCOUNT;
extern char LOG_FILE[MAXBUF];
@@ -115,7 +113,7 @@ void Exit(int status)
{
if (ServerInstance->Config->log_file)
fclose(ServerInstance->Config->log_file);
- send_error("Server shutdown.");
+ ServerInstance->SendError("Server shutdown.");
exit (status);
}
@@ -132,7 +130,7 @@ void Killed(int status)
{
if (ServerInstance->Config->log_file)
fclose(ServerInstance->Config->log_file);
- send_error("Server terminated.");
+ ServerInstance->SendError("Server terminated.");
exit(status);
}
@@ -961,7 +959,7 @@ int main(int argc, char** argv)
catch (std::bad_alloc)
{
log(DEFAULT,"You are out of memory! (got exception std::bad_alloc!)");
- send_error("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
+ ServerInstance->SendError("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
printf("Out of memory! (got exception std::bad_alloc!");
}
return 0;
diff --git a/src/modules.cpp b/src/modules.cpp
index 1c90bd7c0..46b6a16d1 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -15,7 +15,7 @@
*/
#include "inspircd_config.h"
-#include "inspircd.h"
+//#include "inspircd.h"
#include "configreader.h"
#include <unistd.h>
#include <sys/errno.h>
@@ -44,12 +44,12 @@
#include "modules.h"
#include "command_parse.h"
#include "dns.h"
+#include "inspircd.h"
extern InspIRCd* ServerInstance;
extern int MODCOUNT;
extern ModuleList modules;
extern FactoryList factory;
-extern std::vector<userrec*> local_users;
extern time_t TIME;
extern command_table cmdlist;
@@ -390,11 +390,6 @@ bool Server::MatchText(const std::string &sliteral, const std::string &spattern)
return match(sliteral.c_str(),spattern.c_str());
}
-void Server::SendToModeMask(const std::string &modes, int flags, const std::string &text)
-{
- WriteMode(modes.c_str(),flags,"%s",text.c_str());
-}
-
bool Server::IsUlined(const std::string &server)
{
return is_uline(server.c_str());
@@ -511,12 +506,7 @@ bool Server::AddResolver(Resolver* r)
return ServerInstance->Res->AddResolverClass(r);
}
-int Server::CountUsers(chanrec* c)
-{
- return usercount(c);
-}
-
-bool Server::UserToPseudo(userrec* user, const std::string &message)
+bool InspIRCd::UserToPseudo(userrec* user, const std::string &message)
{
unsigned int old_fd = user->fd;
user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
@@ -536,7 +526,7 @@ bool Server::UserToPseudo(userrec* user, const std::string &message)
return true;
}
-bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
+bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
{
log(DEBUG,"PseudoToUser");
zombie->fd = alive->fd;
diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp
index 3764b400e..53e725504 100644
--- a/src/modules/m_chanprotect.cpp
+++ b/src/modules/m_chanprotect.cpp
@@ -308,7 +308,7 @@ class ModuleChanProtect : public Module
// the config option for it is set
if (FirstInGetsFounder)
{
- if (Srv->CountUsers(channel) == 1)
+ if (channel->GetUserCounter() == 1)
{
// we're using Extensible::Extend to add data into user objects.
// this way is best as it adds data thats accessible to other modules
diff --git a/src/modules/m_globops.cpp b/src/modules/m_globops.cpp
index 2b2af1539..a02ad1172 100644
--- a/src/modules/m_globops.cpp
+++ b/src/modules/m_globops.cpp
@@ -28,6 +28,7 @@ using namespace std;
/* $ModDesc: Provides support for GLOBOPS and user mode +g */
static Server *Srv;
+extern InspIRCd* ServerInstance;
class cmd_globops : public command_t
{
@@ -45,7 +46,7 @@ class cmd_globops : public command_t
{
line = line + std::string(parameters[i]) + " ";
}
- Srv->SendToModeMask("og",WM_AND,line);
+ ServerInstance->WriteMode("og",WM_AND,line.c_str());
}
};
diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp
index 69f61ab1a..28e826276 100644
--- a/src/modules/m_helpop.cpp
+++ b/src/modules/m_helpop.cpp
@@ -26,6 +26,8 @@ using namespace std;
static ConfigReader *helpop;
static Server *Srv;
+extern InspIRCd* ServerInstance;
+
bool do_helpop(const char**, int, userrec*);
void sendtohelpop(userrec*, int, const char**);
@@ -177,7 +179,7 @@ void sendtohelpop(userrec *src, int pcnt, const char **params)
{
line = line + std::string(params[i]) + " ";
}
- Srv->SendToModeMask("oh",WM_AND,line);
+ ServerInstance->WriteMode("oh",WM_AND,line.c_str());
}
class HelpopException : public ModuleException
diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp
index 9cb2e28ae..c16a2125f 100644
--- a/src/modules/m_override.cpp
+++ b/src/modules/m_override.cpp
@@ -225,7 +225,7 @@ class ModuleOverride : public Module
return -1;
}
- if ((chan->limit > 0) && (Srv->CountUsers(chan) >= chan->limit) && (CanOverride(user,"LIMIT")))
+ if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
{
if (NoisyOverride)
chan->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :%s passed through your channel limit", cname, user->nick);
diff --git a/src/modules/m_park.cpp b/src/modules/m_park.cpp
index e26af09f2..779a4e8a0 100644
--- a/src/modules/m_park.cpp
+++ b/src/modules/m_park.cpp
@@ -25,6 +25,8 @@ using namespace std;
#include "modules.h"
#include "inspircd.h"
+extern InspIRCd* ServerInstance;
+
/* $ModDesc: Provides support for user parking/unparking */
class parking : public classbase
@@ -88,7 +90,7 @@ class cmd_park : public command_t
unsigned long* key = new unsigned long;
*key = abs(random() * 12345);
snprintf(msg,MAXBUF,"You are now parked. To unpark use /UNPARK %s %lu",user->nick, *key);
- Srv->UserToPseudo(user,std::string(msg));
+ ServerInstance->UserToPseudo(user,std::string(msg));
aw = new awaylog;
user->Extend("park_awaylog", aw);
user->Extend("park_key", key);
@@ -174,7 +176,7 @@ class cmd_unpark : public command_t
// remove all their old modes
user->WriteServ("MODE %s -%s",user->nick,user->FormatModes());
// now, map them to the parked user, while nobody can see :p
- Srv->PseudoToUser(user,unpark,"Unparked to "+std::string(parameters[0]));
+ ServerInstance->PseudoToUser(user,unpark,"Unparked to "+std::string(parameters[0]));
// set all their new modes
unpark->WriteServ("MODE %s +%s",unpark->nick,unpark->FormatModes());
// spool their away log to them
diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp
index ae45c67a3..d7f82f38e 100644
--- a/src/modules/m_redirect.cpp
+++ b/src/modules/m_redirect.cpp
@@ -135,7 +135,7 @@ class ModuleRedirect : public Module
{
if (chan->IsModeSet('L'))
{
- if (Srv->CountUsers(chan) >= chan->limit)
+ if (chan->GetUserCounter() >= chan->limit)
{
std::string channel = chan->GetModeParameter('L');
user->WriteServ("470 %s :%s has become full, so you are automatically being transferred to the linked channel %s",user->nick,cname,channel.c_str());
diff --git a/src/modules/m_safelist.cpp b/src/modules/m_safelist.cpp
index 38985dcb5..45177805e 100644
--- a/src/modules/m_safelist.cpp
+++ b/src/modules/m_safelist.cpp
@@ -102,7 +102,7 @@ class ListTimer : public InspTimer
bool has_user = (chan && chan->HasUser(u));
if ((chan) && (((!(chan->modes[CM_PRIVATE])) && (!(chan->modes[CM_SECRET]))) || (has_user)))
{
- long users = usercount(chan);
+ long users = chan->GetUserCounter();
if (users)
{
int counter = snprintf(buffer,MAXBUF,"322 %s %s %ld :[+%s] %s",u->nick,chan->name,users,chanmodes(chan,has_user),chan->topic);
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index d0d7389de..3206c5621 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -3483,23 +3483,23 @@ class ModuleSpanningTree : public Module
void HandleLusers(const char** parameters, int pcnt, userrec* user)
{
- unsigned int n_users = usercnt();
+ unsigned int n_users = ServerInstance->usercnt();
/* Only update these when someone wants to see them, more efficient */
- if ((unsigned int)local_count() > max_local)
- max_local = local_count();
+ if ((unsigned int)ServerInstance->local_count() > max_local)
+ max_local = ServerInstance->local_count();
if (n_users > max_global)
max_global = n_users;
- user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,n_users-usercount_invisible(),usercount_invisible(),this->CountServs());
- if (usercount_opers())
- user->WriteServ("252 %s %d :operator(s) online",user->nick,usercount_opers());
- if (usercount_unknown())
- user->WriteServ("253 %s %d :unknown connections",user->nick,usercount_unknown());
- if (chancount())
- user->WriteServ("254 %s %d :channels formed",user->nick,chancount());
- user->WriteServ("254 %s :I have %d clients and %d servers",user->nick,local_count(),this->CountLocalServs());
- user->WriteServ("265 %s :Current Local Users: %d Max: %d",user->nick,local_count(),max_local);
+ user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,n_users-ServerInstance->usercount_invisible(),ServerInstance->usercount_invisible(),this->CountServs());
+ if (ServerInstance->usercount_opers())
+ user->WriteServ("252 %s %d :operator(s) online",user->nick,ServerInstance->usercount_opers());
+ if (ServerInstance->usercount_unknown())
+ user->WriteServ("253 %s %d :unknown connections",user->nick,ServerInstance->usercount_unknown());
+ if (ServerInstance->chancount())
+ user->WriteServ("254 %s %d :channels formed",user->nick,ServerInstance->chancount());
+ user->WriteServ("254 %s :I have %d clients and %d servers",user->nick,ServerInstance->local_count(),this->CountLocalServs());
+ user->WriteServ("265 %s :Current Local Users: %d Max: %d",user->nick,ServerInstance->local_count(),max_local);
user->WriteServ("266 %s :Current Global Users: %d Max: %d",user->nick,n_users,max_global);
return;
}
diff --git a/src/modules/m_spy.cpp b/src/modules/m_spy.cpp
index faf4e431a..40be036ab 100644
--- a/src/modules/m_spy.cpp
+++ b/src/modules/m_spy.cpp
@@ -98,7 +98,7 @@ class cmd_spylist : public command_t
user->WriteServ("321 %s Channel :Users Name",user->nick);
for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
{
- user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount(i->second),chanmodes(i->second,true),i->second->topic);
+ user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),chanmodes(i->second,true),i->second->topic);
}
user->WriteServ("323 %s :End of channel list.",user->nick);
}
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index 88fdeec54..8b9235436 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -58,7 +58,6 @@ extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
extern time_t TIME;
extern time_t OLDTIME;
-extern std::vector<userrec*> local_users;
char data[65536];
void InspIRCd::ProcessUser(userrec* cu)
@@ -307,12 +306,12 @@ void InspIRCd::DoBackgroundUserStuff(time_t TIME)
CullList GlobalGoners;
/* XXX: IT IS NOT SAFE TO USE AN ITERATOR HERE. DON'T EVEN THINK ABOUT IT. */
- for (unsigned long count2 = 0; count2 != local_users.size(); count2++)
+ for (unsigned long count2 = 0; count2 != this->local_users.size(); count2++)
{
- if (count2 >= local_users.size())
+ if (count2 >= this->local_users.size())
break;
- userrec* curr = local_users[count2];
+ userrec* curr = this->local_users[count2];
if (curr)
{
diff --git a/src/users.cpp b/src/users.cpp
index cb6fbc1f3..40c29ded1 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -39,7 +39,6 @@ extern std::vector<InspSocket*> module_sockets;
extern int MODCOUNT;
extern time_t TIME;
extern Server* MyServer;
-extern std::vector<userrec*> local_users;
irc::whowas::whowas_users whowas;
static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
@@ -713,8 +712,8 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason)
if (IS_LOCAL(user))
{
ServerInstance->fd_ref_table[user->fd] = NULL;
- if (find(local_users.begin(),local_users.end(),user) != local_users.end())
- local_users.erase(find(local_users.begin(),local_users.end(),user));
+ if (find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user) != ServerInstance->local_users.end())
+ ServerInstance->local_users.erase(find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user));
}
ServerInstance->clientlist.erase(iter);
DELETE(user);
@@ -873,15 +872,15 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip)
_new->recvqmax = class_rqmax;
ServerInstance->fd_ref_table[socket] = _new;
- local_users.push_back(_new);
+ ServerInstance->local_users.push_back(_new);
- if (local_users.size() > ServerInstance->Config->SoftLimit)
+ if (ServerInstance->local_users.size() > ServerInstance->Config->SoftLimit)
{
userrec::QuitUser(_new,"No more connections allowed");
return;
}
- if (local_users.size() >= MAXCLIENTS)
+ if (ServerInstance->local_users.size() >= MAXCLIENTS)
{
userrec::QuitUser(_new,"No more connections allowed");
return;
@@ -946,7 +945,7 @@ long userrec::GlobalCloneCount()
long userrec::LocalCloneCount()
{
long x = 0;
- for (std::vector<userrec*>::const_iterator a = local_users.begin(); a != local_users.end(); a++)
+ for (std::vector<userrec*>::const_iterator a = ServerInstance->local_users.begin(); a != ServerInstance->local_users.end(); a++)
{
userrec* comp = *a;
#ifdef IPV6
@@ -1538,7 +1537,7 @@ void userrec::WriteWallOps(const std::string &text)
std::string wallop = "WALLOPS :";
wallop.append(text);
- for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
+ for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
{
userrec* t = *i;
if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
@@ -1634,3 +1633,22 @@ bool userrec::ChangeDisplayedHost(const char* host)
return true;
}
+void userrec::NoticeAll(char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ char formatbuffer[MAXBUF];
+ va_list argsPtr;
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
+
+ for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
+ {
+ userrec* t = *i;
+ t->WriteFrom(this, std::string(formatbuffer));
+ }
+}
+
diff --git a/src/xline.cpp b/src/xline.cpp
index 868508db6..d3821b528 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -44,7 +44,6 @@ extern InspIRCd* ServerInstance;
extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
-extern std::vector<userrec*> local_users;
/* Version two, now with optimized expiry!
*
@@ -665,7 +664,7 @@ void apply_lines(const int What)
CullList* Goners = new CullList();
char* check = NULL;
- for (std::vector<userrec*>::const_iterator u2 = local_users.begin(); u2 != local_users.end(); u2++)
+ for (std::vector<userrec*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++)
{
userrec* u = (userrec*)(*u2);
u->MakeHost(host);