00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 using namespace std;
00018
00019 #include "inspircd_config.h"
00020 #include "inspircd.h"
00021 #include "inspircd_io.h"
00022 #include "inspircd_util.h"
00023 #include <unistd.h>
00024 #include <sys/errno.h>
00025 #include <sys/ioctl.h>
00026 #include <sys/utsname.h>
00027 #include <time.h>
00028 #include <string>
00029 #ifdef GCC3
00030 #include <ext/hash_map>
00031 #else
00032 #include <hash_map>
00033 #endif
00034 #include <map>
00035 #include <sstream>
00036 #include <vector>
00037 #include <deque>
00038 #include "users.h"
00039 #include "ctables.h"
00040 #include "globals.h"
00041 #include "modules.h"
00042 #include "dynamic.h"
00043 #include "wildcard.h"
00044 #include "message.h"
00045 #include "mode.h"
00046 #include "xline.h"
00047 #include "inspstring.h"
00048 #include "helperfuncs.h"
00049
00050 #ifdef GCC3
00051 #define nspace __gnu_cxx
00052 #else
00053 #define nspace std
00054 #endif
00055
00056 extern ServerConfig* Config;
00057
00058 extern int MODCOUNT;
00059 extern std::vector<Module*> modules;
00060 extern std::vector<ircd_module*> factory;
00061 extern int WHOWAS_STALE;
00062 extern int WHOWAS_MAX;
00063 extern time_t startup_time;
00064 extern std::vector<std::string> module_names;
00065 extern int boundPortCount;
00066 extern std::stringstream config_f;
00067 extern time_t TIME;
00068
00069 using namespace std;
00070
00071 std::vector<ModeParameter> custom_mode_params;
00072
00073 chanrec::chanrec()
00074 {
00075 strcpy(name,"");
00076 strcpy(custom_modes,"");
00077 strcpy(topic,"");
00078 strcpy(setby,"");
00079 strcpy(key,"");
00080 created = topicset = limit = 0;
00081 binarymodes = 0;
00082 internal_userlist.clear();
00083 }
00084
00085 void chanrec::SetCustomMode(char mode,bool mode_on)
00086 {
00087 if (mode_on) {
00088 static char m[3];
00089 m[0] = mode;
00090 m[1] = '\0';
00091 if (!strchr(this->custom_modes,mode))
00092 {
00093 strlcat(custom_modes,m,MAXMODES);
00094 }
00095 log(DEBUG,"Custom mode %c set",mode);
00096 }
00097 else {
00098
00099 std::string a = this->custom_modes;
00100 int pos = a.find(mode);
00101 a.erase(pos,1);
00102 strncpy(this->custom_modes,a.c_str(),MAXMODES);
00103
00104 log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
00105 this->SetCustomModeParam(mode,"",false);
00106 }
00107 }
00108
00109
00110 void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
00111 {
00112
00113 log(DEBUG,"SetCustomModeParam called");
00114 ModeParameter M;
00115 M.mode = mode;
00116 strlcpy(M.channel,this->name,CHANMAX);
00117 strlcpy(M.parameter,parameter,MAXBUF);
00118 if (mode_on)
00119 {
00120 log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
00121 custom_mode_params.push_back(M);
00122 }
00123 else
00124 {
00125 if (custom_mode_params.size())
00126 {
00127 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
00128 {
00129 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
00130 {
00131 log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
00132 custom_mode_params.erase(i);
00133 return;
00134 }
00135 }
00136 }
00137 log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
00138 }
00139 }
00140
00141 bool chanrec::IsCustomModeSet(char mode)
00142 {
00143 return (strchr(this->custom_modes,mode));
00144 }
00145
00146 std::string chanrec::GetModeParameter(char mode)
00147 {
00148 if (custom_mode_params.size())
00149 {
00150 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
00151 {
00152 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
00153 {
00154 return i->parameter;
00155 }
00156 }
00157 }
00158 return "";
00159 }
00160
00161 long chanrec::GetUserCounter()
00162 {
00163 return (this->internal_userlist.size());
00164 }
00165
00166 void chanrec::AddUser(char* castuser)
00167 {
00168 internal_userlist.push_back(castuser);
00169 log(DEBUG,"Added casted user to channel's internal list");
00170 }
00171
00172 void chanrec::DelUser(char* castuser)
00173 {
00174 for (std::vector<char*>::iterator a = internal_userlist.begin(); a < internal_userlist.end(); a++)
00175 {
00176 if (*a == castuser)
00177 {
00178 log(DEBUG,"Removed casted user from channel's internal list");
00179 internal_userlist.erase(a);
00180 return;
00181 }
00182 }
00183 log(DEBUG,"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!",name);
00184 }
00185
00186 std::vector<char*> *chanrec::GetUsers()
00187 {
00188 return &internal_userlist;
00189 }