]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/channels.cpp
ConfigReader fixes to cope with tab characters (why didnt we notice this before?)
[user/henk/code/inspircd.git] / src / channels.cpp
1 #include "inspircd_config.h" 
2 #include "channels.h"
3 #include "inspircd.h"
4 #include <stdio.h>
5 #include <string>
6 #include <vector>
7
8 using namespace std;
9
10 std::vector<ModeParameter> custom_mode_params;
11
12 chanrec::chanrec()
13 {
14         strcpy(name,"");
15         strcpy(custom_modes,"");
16         strcpy(topic,"");
17         strcpy(setby,"");
18         strcpy(key,"");
19         created = topicset = limit = 0;
20         topiclock = noexternal = inviteonly = moderated = secret = c_private = false;
21 }
22
23 void chanrec::SetCustomMode(char mode,bool mode_on)
24 {
25         if (mode_on) {
26                 char m[3];
27                 m[0] = mode;
28                 m[1] = '\0';
29                 if (!strchr(this->custom_modes,mode))
30                 {
31                         strncat(custom_modes,m,MAXMODES);
32                 }
33                 log(DEBUG,"Custom mode %c set",mode);
34         }
35         else {
36                 char temp[MAXBUF];
37                 int count = 0;
38                 for (int q = 0; q < strlen(custom_modes); q++) {
39                         if (custom_modes[q] != mode) {
40                                 temp[count++] = mode;
41                         }
42                 }
43                 temp[count] = '\0';
44                 strncpy(custom_modes,temp,MAXMODES);
45                 log(DEBUG,"Custom mode %c removed",mode);
46                 this->SetCustomModeParam(mode,"",false);
47         }
48 }
49
50 void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
51 {
52
53         log(DEBUG,"SetCustomModeParam called");
54         ModeParameter M;
55         M.mode = mode;
56         strcpy(M.channel,this->name);
57         strcpy(M.parameter,parameter);
58         if (mode_on)
59         {
60                 log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
61                 custom_mode_params.push_back(M);
62         }
63         else
64         {
65                 if (custom_mode_params.size())
66                 {
67                         for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
68                         {
69                                 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
70                                 {
71                                         log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
72                                         custom_mode_params.erase(i);
73                                         return;
74                                 }
75                         }
76                 }
77                 log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
78         }
79 }
80
81 bool chanrec::IsCustomModeSet(char mode)
82 {
83         log(DEBUG,"Checking ISCustomModeSet: %c %s",mode,this->custom_modes);
84         return (strchr(this->custom_modes,mode) != 0);
85 }
86
87 std::string chanrec::GetModeParameter(char mode)
88 {
89         if (custom_mode_params.size())
90         {
91                 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
92                 {
93                         if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
94                         {
95                                 return std::string(i->parameter);
96                         }
97                 }
98         }
99         return std::string("");
100 }