summaryrefslogtreecommitdiff
path: root/src/channels.cpp
blob: 85aad0c57feb577ea7a6a198a3faa258195445fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "inspircd_config.h" 
#include "channels.h"
#include "inspircd.h"
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

std::vector<ModeParameter> custom_mode_params;

chanrec::chanrec()
{
	strcpy(name,"");
	strcpy(custom_modes,"");
	strcpy(topic,"");
	strcpy(setby,"");
	strcpy(key,"");
	created = topicset = limit = 0;
	topiclock = noexternal = inviteonly = moderated = secret = c_private = false;
}

void chanrec::SetCustomMode(char mode,bool mode_on)
{
	if (mode_on) {
		char m[3];
		m[0] = mode;
		m[1] = '\0';
		if (!strchr(this->custom_modes,mode))
		{
			strncat(custom_modes,m,MAXMODES);
		}
		log(DEBUG,"Custom mode %c set",mode);
	}
	else {
		char temp[MAXBUF];
		int count = 0;
		for (int q = 0; q < strlen(custom_modes); q++) {
			if (custom_modes[q] != mode) {
				temp[count++] = mode;
			}
		}
		temp[count] = '\0';
		strncpy(custom_modes,temp,MAXMODES);
		log(DEBUG,"Custom mode %c removed",mode);
		this->SetCustomModeParam(mode,"",false);
	}
}

void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
{

	log(DEBUG,"SetCustomModeParam called");
	ModeParameter M;
	M.mode = mode;
	strcpy(M.channel,this->name);
	strcpy(M.parameter,parameter);
	if (mode_on)
	{
		log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
		custom_mode_params.push_back(M);
	}
	else
	{
		if (custom_mode_params.size())
		{
			for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
			{
				if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
				{
					log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
					custom_mode_params.erase(i);
					return;
				}
			}
		}
		log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
	}
}

bool chanrec::IsCustomModeSet(char mode)
{
	log(DEBUG,"Checking ISCustomModeSet: %c %s",mode,this->custom_modes);
	return (strchr(this->custom_modes,mode) != 0);
}

std::string chanrec::GetModeParameter(char mode)
{
	if (custom_mode_params.size())
	{
		for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
		{
			if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
			{
				return std::string(i->parameter);
			}
		}
	}
	return std::string("");
}