]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/channels.cpp
1904bfa26c561e2a367138174c4705cbbdc5281f
[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 #include "inspircd.h"
18 #include "inspircd_io.h"
19 #include "inspircd_util.h"
20 #include "inspircd_config.h"
21 #include <unistd.h>
22 #include <sys/errno.h>
23 #include <sys/ioctl.h>
24 #include <sys/utsname.h>
25 #include <time.h>
26 #include <string>
27 #ifdef GCC3
28 #include <ext/hash_map>
29 #else
30 #include <hash_map>
31 #endif
32 #include <map>
33 #include <sstream>
34 #include <vector>
35 #include <deque>
36 #include "connection.h"
37 #include "users.h"
38 #include "servers.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 using namespace std;
57
58 extern int MODCOUNT;
59 extern std::vector<Module*> modules;
60 extern std::vector<ircd_module*> factory;
61
62 extern int LogLevel;
63 extern char ServerName[MAXBUF];
64 extern char Network[MAXBUF];
65 extern char ServerDesc[MAXBUF];
66 extern char AdminName[MAXBUF];
67 extern char AdminEmail[MAXBUF];
68 extern char AdminNick[MAXBUF];
69 extern char diepass[MAXBUF];
70 extern char restartpass[MAXBUF];
71 extern char motd[MAXBUF];
72 extern char rules[MAXBUF];
73 extern char list[MAXBUF];
74 extern char PrefixQuit[MAXBUF];
75 extern char DieValue[MAXBUF];
76
77 extern int debugging;
78 extern int WHOWAS_STALE;
79 extern int WHOWAS_MAX;
80 extern int DieDelay;
81 extern time_t startup_time;
82 extern int NetBufferSize;
83 int MaxWhoResults;
84 extern time_t nb_start;
85
86 extern std::vector<int> fd_reap;
87 extern std::vector<std::string> module_names;
88
89 extern int boundPortCount;
90 extern int portCount;
91 extern int SERVERportCount;
92 extern int ports[MAXSOCKS];
93 extern int defaultRoute;
94
95 extern std::vector<long> auth_cookies;
96 extern std::stringstream config_f;
97
98 extern serverrec* me[32];
99
100 extern FILE *log_file;
101
102 extern time_t TIME;
103
104 using namespace std;
105
106 std::vector<ModeParameter> custom_mode_params;
107
108 chanrec::chanrec()
109 {
110         strcpy(name,"");
111         strcpy(custom_modes,"");
112         strcpy(topic,"");
113         strcpy(setby,"");
114         strcpy(key,"");
115         created = topicset = limit = 0;
116         binarymodes = 0;
117         internal_userlist.clear();
118 }
119
120 void chanrec::SetCustomMode(char mode,bool mode_on)
121 {
122         if (mode_on) {
123                 static char m[3];
124                 m[0] = mode;
125                 m[1] = '\0';
126                 if (!strchr(this->custom_modes,mode))
127                 {
128                         strlcat(custom_modes,m,MAXMODES);
129                 }
130                 log(DEBUG,"Custom mode %c set",mode);
131         }
132         else {
133
134                 std::string a = this->custom_modes;
135                 int pos = a.find(mode);
136                 a.erase(pos,1);
137                 strncpy(this->custom_modes,a.c_str(),MAXMODES);
138
139                 log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
140                 this->SetCustomModeParam(mode,"",false);
141         }
142 }
143
144
145 void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
146 {
147
148         log(DEBUG,"SetCustomModeParam called");
149         ModeParameter M;
150         M.mode = mode;
151         strlcpy(M.channel,this->name,CHANMAX);
152         strlcpy(M.parameter,parameter,MAXBUF);
153         if (mode_on)
154         {
155                 log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
156                 custom_mode_params.push_back(M);
157         }
158         else
159         {
160                 if (custom_mode_params.size())
161                 {
162                         for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
163                         {
164                                 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
165                                 {
166                                         log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
167                                         custom_mode_params.erase(i);
168                                         return;
169                                 }
170                         }
171                 }
172                 log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
173         }
174 }
175
176 bool chanrec::IsCustomModeSet(char mode)
177 {
178         log(DEBUG,"Checking ISCustomModeSet: %c %s",mode,this->custom_modes);
179         return (strchr(this->custom_modes,mode) != 0);
180 }
181
182 std::string chanrec::GetModeParameter(char mode)
183 {
184         if (custom_mode_params.size())
185         {
186                 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
187                 {
188                         if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
189                         {
190                                 return i->parameter;
191                         }
192                 }
193         }
194         return "";
195 }
196
197 long chanrec::GetUserCounter()
198 {
199         return (this->internal_userlist.size());
200 }
201
202 void chanrec::AddUser(char* castuser)
203 {
204         internal_userlist.push_back(castuser);
205         log(DEBUG,"Added casted user to channel's internal list");
206 }
207
208 void chanrec::DelUser(char* castuser)
209 {
210         for (std::vector<char*>::iterator a = internal_userlist.begin(); a < internal_userlist.end(); a++)
211         {
212                 if (*a == castuser)
213                 {
214                         log(DEBUG,"Removed casted user from channel's internal list");
215                         internal_userlist.erase(a);
216                         return;
217                 }
218         }
219         log(DEBUG,"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!",name);
220 }
221
222 std::vector<char*> *chanrec::GetUsers()
223 {
224         return &internal_userlist;
225 }