]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/channels.cpp
Removed deprecated direct reference to file_cache MOTD, RULES
[user/henk/code/inspircd.git] / src / channels.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "inspircd_io.h"
22 #include "inspircd_util.h"
23 #include <unistd.h>
24 #include <sys/errno.h>
25 #include <sys/ioctl.h>
26 #include <sys/utsname.h>
27 #include <time.h>
28 #include <string>
29 #ifdef GCC3
30 #include <ext/hash_map>
31 #else
32 #include <hash_map>
33 #endif
34 #include <map>
35 #include <sstream>
36 #include <vector>
37 #include <deque>
38 #include "users.h"
39 #include "ctables.h"
40 #include "globals.h"
41 #include "modules.h"
42 #include "dynamic.h"
43 #include "wildcard.h"
44 #include "message.h"
45 #include "mode.h"
46 #include "xline.h"
47 #include "inspstring.h"
48 #include "helperfuncs.h"
49
50 #ifdef GCC3
51 #define nspace __gnu_cxx
52 #else
53 #define nspace std
54 #endif
55
56 extern ServerConfig* Config;
57
58 extern int MODCOUNT;
59 extern std::vector<Module*> modules;
60 extern std::vector<ircd_module*> factory;
61 extern int WHOWAS_STALE;
62 extern int WHOWAS_MAX;
63 extern time_t startup_time;
64 extern std::vector<std::string> module_names;
65 extern int boundPortCount;
66 extern std::stringstream config_f;
67 extern time_t TIME;
68
69 using namespace std;
70
71 std::vector<ModeParameter> custom_mode_params;
72
73 chanrec::chanrec()
74 {
75         strcpy(name,"");
76         strcpy(custom_modes,"");
77         strcpy(topic,"");
78         strcpy(setby,"");
79         strcpy(key,"");
80         created = topicset = limit = 0;
81         binarymodes = 0;
82         internal_userlist.clear();
83 }
84
85 void chanrec::SetCustomMode(char mode,bool mode_on)
86 {
87         if (mode_on) {
88                 static char m[3];
89                 m[0] = mode;
90                 m[1] = '\0';
91                 if (!strchr(this->custom_modes,mode))
92                 {
93                         strlcat(custom_modes,m,MAXMODES);
94                 }
95                 log(DEBUG,"Custom mode %c set",mode);
96         }
97         else {
98
99                 std::string a = this->custom_modes;
100                 int pos = a.find(mode);
101                 a.erase(pos,1);
102                 strncpy(this->custom_modes,a.c_str(),MAXMODES);
103
104                 log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
105                 this->SetCustomModeParam(mode,"",false);
106         }
107 }
108
109
110 void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
111 {
112
113         log(DEBUG,"SetCustomModeParam called");
114         ModeParameter M;
115         M.mode = mode;
116         strlcpy(M.channel,this->name,CHANMAX);
117         strlcpy(M.parameter,parameter,MAXBUF);
118         if (mode_on)
119         {
120                 log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
121                 custom_mode_params.push_back(M);
122         }
123         else
124         {
125                 if (custom_mode_params.size())
126                 {
127                         for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
128                         {
129                                 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
130                                 {
131                                         log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
132                                         custom_mode_params.erase(i);
133                                         return;
134                                 }
135                         }
136                 }
137                 log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
138         }
139 }
140
141 bool chanrec::IsCustomModeSet(char mode)
142 {
143         return (strchr(this->custom_modes,mode));
144 }
145
146 std::string chanrec::GetModeParameter(char mode)
147 {
148         if (custom_mode_params.size())
149         {
150                 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
151                 {
152                         if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
153                         {
154                                 return i->parameter;
155                         }
156                 }
157         }
158         return "";
159 }
160
161 long chanrec::GetUserCounter()
162 {
163         return (this->internal_userlist.size());
164 }
165
166 void chanrec::AddUser(char* castuser)
167 {
168         internal_userlist.push_back(castuser);
169         log(DEBUG,"Added casted user to channel's internal list");
170 }
171
172 void chanrec::DelUser(char* castuser)
173 {
174         for (std::vector<char*>::iterator a = internal_userlist.begin(); a < internal_userlist.end(); a++)
175         {
176                 if (*a == castuser)
177                 {
178                         log(DEBUG,"Removed casted user from channel's internal list");
179                         internal_userlist.erase(a);
180                         return;
181                 }
182         }
183         log(DEBUG,"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!",name);
184 }
185
186 std::vector<char*> *chanrec::GetUsers()
187 {
188         return &internal_userlist;
189 }