]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Added /stats T
[user/henk/code/inspircd.git] / src / channels.cpp
index 1def64fd8bcfa1ee656b682e12c7041324c2de9e..fcc1c732d3d1912244fb4923c15d72576c1317bb 100644 (file)
@@ -1,3 +1,19 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *                       E-mail:
+ *                <brain@chatspike.net>
+ *               <Craig@chatspike.net>
+ *     
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
 #include "inspircd.h"
 #include "inspircd_io.h"
 #include "inspircd_util.h"
@@ -34,6 +50,7 @@
 #include "message.h"
 #include "mode.h"
 #include "xline.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
@@ -44,8 +61,8 @@
 using namespace std;
 
 extern int MODCOUNT;
-extern vector<Module*> modules;
-extern vector<ircd_module*> factory;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
 
 extern int LogLevel;
 extern char ServerName[MAXBUF];
@@ -87,6 +104,7 @@ extern serverrec* me[32];
 
 extern FILE *log_file;
 
+extern time_t TIME;
 
 using namespace std;
 
@@ -99,33 +117,31 @@ chanrec::chanrec()
        strcpy(topic,"");
        strcpy(setby,"");
        strcpy(key,"");
-       created = topicset = limit = 0;
+       created = topicset = limit = users = 0;
        topiclock = noexternal = inviteonly = moderated = secret = c_private = false;
+       internal_userlist.clear();
 }
 
 void chanrec::SetCustomMode(char mode,bool mode_on)
 {
        if (mode_on) {
-               char m[3];
+               static char m[3];
                m[0] = mode;
                m[1] = '\0';
                if (!strchr(this->custom_modes,mode))
                {
-                       strncat(custom_modes,m,MAXMODES);
+                       strlcat(custom_modes,m,MAXMODES);
                }
                log(DEBUG,"Custom mode %c set",mode);
        }
        else {
-               char temp[MAXBUF];
-               int count = 0;
-               for (int q = 0; q < strlen(custom_modes); q++) {
-                       if (custom_modes[q] != mode) {
-                               temp[count++] = mode;
-                       }
-               }
-               temp[count] = '\0';
-               strncpy(custom_modes,temp,MAXMODES);
-               log(DEBUG,"Custom mode %c removed",mode);
+
+               std::string a = this->custom_modes;
+               int pos = a.find(mode);
+               a.erase(pos,1);
+               strncpy(this->custom_modes,a.c_str(),MAXMODES);
+
+               log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
                this->SetCustomModeParam(mode,"",false);
        }
 }
@@ -137,8 +153,8 @@ void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
        log(DEBUG,"SetCustomModeParam called");
        ModeParameter M;
        M.mode = mode;
-       strcpy(M.channel,this->name);
-       strcpy(M.parameter,parameter);
+       strlcpy(M.channel,this->name,CHANMAX);
+       strlcpy(M.parameter,parameter,MAXBUF);
        if (mode_on)
        {
                log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
@@ -182,3 +198,46 @@ std::string chanrec::GetModeParameter(char mode)
        }
        return std::string("");
 }
+
+void chanrec::IncUserCounter()
+{
+       this->users++;
+       log(DEBUG,"Incremented channel user count for %s to %lu",name,(unsigned long)users);
+}
+
+void chanrec::DecUserCounter()
+{
+       if (this->users > 0)
+               this->users--;
+       log(DEBUG,"Decremented channel user count for %s to %lu",name,(unsigned long)users);
+}
+
+long chanrec::GetUserCounter()
+{
+       return (this->users);
+}
+
+void chanrec::AddUser(char* castuser)
+{
+       internal_userlist.push_back(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++)
+       {
+               if (*a == castuser)
+               {
+                       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()
+{
+       return &internal_userlist;
+}