00001 #include "inspircd_config.h" 00002 #include "channels.h" 00003 #include "inspircd.h" 00004 #include <stdio.h> 00005 #include <string> 00006 #include <vector> 00007 00008 using namespace std; 00009 00010 vector<ModeParameter> custom_mode_params; 00011 00012 chanrec::chanrec() 00013 { 00014 strcpy(name,""); 00015 strcpy(custom_modes,""); 00016 strcpy(topic,""); 00017 strcpy(setby,""); 00018 strcpy(key,""); 00019 created = topicset = limit = 0; 00020 topiclock = noexternal = inviteonly = moderated = secret = c_private = false; 00021 } 00022 00023 void chanrec::SetCustomMode(char mode,bool mode_on) 00024 { 00025 if (mode_on) { 00026 char m[3]; 00027 m[0] = mode; 00028 m[1] = '\0'; 00029 if (!strchr(this->custom_modes,mode)) 00030 { 00031 strncat(custom_modes,m,MAXMODES); 00032 } 00033 log(DEBUG,"Custom mode %c set",mode); 00034 } 00035 else { 00036 char temp[MAXBUF]; 00037 int count = 0; 00038 for (int q = 0; q < strlen(custom_modes); q++) { 00039 if (custom_modes[q] != mode) { 00040 temp[count++] = mode; 00041 } 00042 } 00043 temp[count] = '\0'; 00044 strncpy(custom_modes,temp,MAXMODES); 00045 log(DEBUG,"Custom mode %c removed",mode); 00046 this->SetCustomModeParam(mode,"",false); 00047 } 00048 } 00049 00050 void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on) 00051 { 00052 00053 log(DEBUG,"SetCustomModeParam called"); 00054 ModeParameter M; 00055 M.mode = mode; 00056 strcpy(M.channel,this->name); 00057 strcpy(M.parameter,parameter); 00058 if (mode_on) 00059 { 00060 log(DEBUG,"Custom mode parameter %c %s added",mode,parameter); 00061 custom_mode_params.push_back(M); 00062 } 00063 else 00064 { 00065 if (custom_mode_params.size()) 00066 { 00067 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++) 00068 { 00069 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel))) 00070 { 00071 log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter); 00072 custom_mode_params.erase(i); 00073 return; 00074 } 00075 } 00076 } 00077 log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!"); 00078 } 00079 } 00080 00081 bool chanrec::IsCustomModeSet(char mode) 00082 { 00083 log(DEBUG,"Checking ISCustomModeSet: %c %s",mode,this->custom_modes); 00084 return (strchr(this->custom_modes,mode) != 0); 00085 } 00086 00087 std::string chanrec::GetModeParameter(char mode) 00088 { 00089 if (custom_mode_params.size()) 00090 { 00091 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++) 00092 { 00093 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel))) 00094 { 00095 return std::string(i->parameter); 00096 } 00097 } 00098 } 00099 return std::string(""); 00100 }