summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-08 16:07:25 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-08 16:07:25 +0000
commitc18d1040a312b36335783e742c8ec66be246d6ab (patch)
tree9b3b07d08a14b53c6779d643dca3e7c4509dd7ff
parent4f1d3a7192ea1b081b47f2ca1899aa25061b270d (diff)
Move whowas stuff into its own namespace, move more stuff into userrec
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4795 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/users.h45
-rw-r--r--src/cmd_whowas.cpp10
-rw-r--r--src/inspircd.cpp4
-rw-r--r--src/users.cpp95
4 files changed, 85 insertions, 69 deletions
diff --git a/include/users.h b/include/users.h
index 983ae193e..a01b0f28b 100644
--- a/include/users.h
+++ b/include/users.h
@@ -447,10 +447,12 @@ class userrec : public connection
userrec* UpdateNickHash(const char* New);
bool ForceNickChange(const char* newnick);
+ static void AddClient(int socket, int port, bool iscached, insp_inaddr ip);
+
void UnOper();
-long GlobalCloneCount();
-long LocalCloneCount();
+ long GlobalCloneCount();
+ long LocalCloneCount();
/** Default destructor
*/
@@ -459,26 +461,33 @@ long LocalCloneCount();
/** Used to hold WHOWAS information
*/
-class WhoWasGroup : public classbase
+
+namespace irc
{
- public:
- char* host;
- char* dhost;
- char* ident;
- const char* server;
- char* gecos;
- time_t signon;
+ namespace whowas
+ {
- WhoWasGroup(userrec* user);
- ~WhoWasGroup();
+ class WhoWasGroup : public classbase
+ {
+ public:
+ char* host;
+ char* dhost;
+ char* ident;
+ const char* server;
+ char* gecos;
+ time_t signon;
+
+ WhoWasGroup(userrec* user);
+ ~WhoWasGroup();
+ };
+
+ typedef std::deque<WhoWasGroup*> whowas_set;
+ typedef std::map<irc::string,whowas_set*> whowas_users;
+
+ void MaintainWhoWas(time_t TIME);
+ };
};
-typedef std::deque<WhoWasGroup*> whowas_set;
-typedef std::map<irc::string,whowas_set*> whowas_users;
-
-void MaintainWhoWas(time_t TIME);
-void AddClient(int socket, int port, bool iscached, insp_inaddr ip4);
-
/* Configuration callbacks */
bool InitTypes(const char* tag);
bool InitClasses(const char* tag);
diff --git a/src/cmd_whowas.cpp b/src/cmd_whowas.cpp
index 9d93517fe..ae3bdb953 100644
--- a/src/cmd_whowas.cpp
+++ b/src/cmd_whowas.cpp
@@ -22,11 +22,11 @@
#include "commands/cmd_whowas.h"
extern ServerConfig* Config;
-extern whowas_users whowas;
+extern irc::whowas::whowas_users whowas;
void cmd_whowas::Handle (const char** parameters, int pcnt, userrec* user)
{
- whowas_users::iterator i = whowas.find(parameters[0]);
+ irc::whowas::whowas_users::iterator i = whowas.find(parameters[0]);
if (i == whowas.end())
{
@@ -34,12 +34,12 @@ void cmd_whowas::Handle (const char** parameters, int pcnt, userrec* user)
}
else
{
- whowas_set* grp = i->second;
+ irc::whowas::whowas_set* grp = i->second;
if (grp->size())
{
- for (whowas_set::iterator ux = grp->begin(); ux != grp->end(); ux++)
+ for (irc::whowas::whowas_set::iterator ux = grp->begin(); ux != grp->end(); ux++)
{
- WhoWasGroup* u = *ux;
+ irc::whowas::WhoWasGroup* u = *ux;
time_t rawtime = u->signon;
tm *timeinfo;
char b[MAXBUF];
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 27029a6e4..a9d4cfb19 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -746,7 +746,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
if ((TIME % 3600) == 0)
{
- MaintainWhoWas(TIME);
+ irc::whowas::MaintainWhoWas(TIME);
}
}
@@ -879,7 +879,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
AddClient(incomingSockfd, in_port, false, client.sin6_addr);
#else
log(DEBUG,"Add ipv4 client");
- AddClient(incomingSockfd, in_port, false, client.sin_addr);
+ userrec::AddClient(incomingSockfd, in_port, false, client.sin_addr);
#endif
log(DEBUG,"Adding client on port %d fd=%d",in_port,incomingSockfd);
}
diff --git a/src/users.cpp b/src/users.cpp
index dabbc870f..3ecedaf58 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -46,7 +46,7 @@ extern ServerConfig *Config;
extern user_hash clientlist;
extern Server* MyServer;
-whowas_users whowas;
+irc::whowas::whowas_users whowas;
extern std::vector<userrec*> local_users;
@@ -725,75 +725,82 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason)
}
}
-WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
+namespace irc
{
- this->host = strdup(user->host);
- this->dhost = strdup(user->dhost);
- this->ident = strdup(user->ident);
- this->server = user->server;
- this->gecos = strdup(user->fullname);
-}
+ namespace whowas
+ {
-WhoWasGroup::~WhoWasGroup()
-{
- if (host)
- free(host);
- if (dhost)
- free(dhost);
- if (ident)
- free(ident);
- if (gecos)
- free(gecos);
-}
+ WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
+ {
+ this->host = strdup(user->host);
+ this->dhost = strdup(user->dhost);
+ this->ident = strdup(user->ident);
+ this->server = user->server;
+ this->gecos = strdup(user->fullname);
+ }
+
+ WhoWasGroup::~WhoWasGroup()
+ {
+ if (host)
+ free(host);
+ if (dhost)
+ free(dhost);
+ if (ident)
+ free(ident);
+ if (gecos)
+ free(gecos);
+ }
+
+ /* every hour, run this function which removes all entries over 3 days */
+ void MaintainWhoWas(time_t TIME)
+ {
+ for (whowas_users::iterator iter = ::whowas.begin(); iter != ::whowas.end(); iter++)
+ {
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ while ((n->begin() != n->end()) && ((*n->begin())->signon < TIME - 259200)) // 3 days
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ }
+ }
+ }
+ }
+ };
+};
/* adds or updates an entry in the whowas list */
void userrec::AddToWhoWas()
{
- whowas_users::iterator iter = whowas.find(this->nick);
+ irc::whowas::whowas_users::iterator iter = whowas.find(this->nick);
if (iter == whowas.end())
{
- whowas_set* n = new whowas_set;
- WhoWasGroup *a = new WhoWasGroup(this);
+ irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
+ irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
n->push_back(a);
whowas[this->nick] = n;
}
else
{
- whowas_set* group = (whowas_set*)iter->second;
+ irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
if (group->size() > 10)
{
- WhoWasGroup *a = (WhoWasGroup*)*(group->begin());
+ irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
DELETE(a);
group->pop_front();
}
- WhoWasGroup *a = new WhoWasGroup(this);
+ irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
group->push_back(a);
}
}
-/* every hour, run this function which removes all entries over 3 days */
-void MaintainWhoWas(time_t TIME)
-{
- for (whowas_users::iterator iter = whowas.begin(); iter != whowas.end(); iter++)
- {
- whowas_set* n = (whowas_set*)iter->second;
- if (n->size())
- {
- while ((n->begin() != n->end()) && ((*n->begin())->signon < TIME - 259200)) // 3 days
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- }
- }
- }
-}
-
/* add a client connection to the sockets list */
-void AddClient(int socket, int port, bool iscached, insp_inaddr ip)
+void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip)
{
std::string tempnick = ConvToStr(socket) + "-unknown";
user_hash::iterator iter = clientlist.find(tempnick);