summaryrefslogtreecommitdiff
path: root/src/users.cpp
blob: 2b02e70fb17d13750d39c356ad2b3bb16c010c73 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
 *                       E-mail:
 *                <brain@chatspike.net>
 *           	  <Craig@chatspike.net>
 *     
 * Written by Craig Edwards, Craig McLure, and others.
 * This program is free but copyrighted software; see
 *            the file COPYING for details.
 *
 * ---------------------------------------------------
 */

#include "inspircd_config.h" 
#include "channels.h"
#include "users.h"
#include "inspircd.h"
#include <stdio.h>

extern std::stringstream config_f;

userrec::userrec()
{
	// the PROPER way to do it, AVOID bzero at *ALL* costs
	strcpy(nick,"");
	strcpy(ip,"127.0.0.1");
	timeout = 0;
	strcpy(ident,"");
	strcpy(host,"");
	strcpy(dhost,"");
	strcpy(fullname,"");
	strcpy(modes,"");
	strcpy(inbuf,"");
	strcpy(server,"");
	strcpy(awaymsg,"");
	fd = lastping = signon = idle_lastmsg = nping = registered = 0;
	flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
	haspassed = false;
	strcpy(result,"");
	for (int i = 0; i < MAXCHANS; i++)
	{
		this->chans[i].channel = NULL;
		this->chans[i].uc_modes = 0;
	}
	invites.clear();
}


 
char* userrec::GetFullHost()
{
	sprintf(result,"%s!%s@%s",nick,ident,dhost);
	return result;
}


char* userrec::GetFullRealHost()
{
	sprintf(result,"%s!%s@%s",nick,ident,host);
	return result;
}

bool userrec::IsInvited(char* channel)
{
	for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
	{
		if (i->channel) {
			if (!strcasecmp(i->channel,channel))
			{
				return true;
			}
		}
	}
	return false;
}

void userrec::InviteTo(char* channel)
{
	Invited i;
	strcpy(i.channel,channel);
	invites.push_back(i);
}

void userrec::RemoveInvite(char* channel)
{
	log(DEBUG,"Removing invites");
	if (channel)
	{
		if (invites.size())
		{
 			for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
 			{
				if (i->channel)
				{
					if (!strcasecmp(i->channel,channel))
					{
						invites.erase(i);
						return;
		       	         	}
				}
        		}
        	}
        }
}

bool userrec::HasPermission(char* command)
{
	char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
	char* myclass;
	char* mycmd;
	char* savept;
	char* savept2;
	
	// are they even an oper at all?
	if (strchr(this->modes,'o'))
	{
		log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
		for (int j =0; j < ConfValueEnum("type",&config_f); j++)
		{
			ConfValue("type","name",j,TypeName,&config_f);
			if (!strcmp(TypeName,this->oper))
			{
				log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
				ConfValue("type","classes",j,Classes,&config_f);
				char* myclass = strtok_r(Classes," ",&savept);
				while (myclass)
				{
					log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
					for (int k =0; k < ConfValueEnum("class",&config_f); k++)
					{
						ConfValue("class","name",k,ClassName,&config_f);
						if (!strcmp(ClassName,myclass))
						{
							ConfValue("class","commands",k,CommandList,&config_f);
							log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
							
							
							mycmd = strtok_r(CommandList," ",&savept2);
							while (mycmd)
							{
								if (!strcasecmp(mycmd,command))
								{
									log(DEBUG,"*** Command %s found, returning true",command);
									return true;
								}
								mycmd = strtok_r(NULL," ",&savept2);
							}
						}
					}
					myclass = strtok_r(NULL," ",&savept);
				}
			}
		}
	}
	return false;
}