]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/users.cpp
9b97eff05b1a9b5863db3b5d1a23fa59d1736366
[user/henk/code/inspircd.git] / src / users.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_config.h" 
18 #include "channels.h"
19 #include "users.h"
20 #include "inspircd.h"
21 #include <stdio.h>
22 #include "inspstring.h"
23
24 extern std::stringstream config_f;
25
26 userrec::userrec()
27 {
28         // the PROPER way to do it, AVOID bzero at *ALL* costs
29         strcpy(nick,"");
30         strcpy(ip,"127.0.0.1");
31         timeout = 0;
32         strcpy(ident,"");
33         strcpy(host,"");
34         strcpy(dhost,"");
35         strcpy(fullname,"");
36         strcpy(modes,"");
37         strcpy(inbuf,"");
38         strcpy(server,"");
39         strcpy(awaymsg,"");
40         strcpy(oper,"");
41         fd = lastping = signon = idle_lastmsg = nping = registered = 0;
42         flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
43         haspassed = false;
44         strcpy(result,"");
45         for (int i = 0; i < MAXCHANS; i++)
46         {
47                 this->chans[i].channel = NULL;
48                 this->chans[i].uc_modes = 0;
49         }
50         invites.clear();
51 }
52
53
54  
55 char* userrec::GetFullHost()
56 {
57         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
58         return result;
59 }
60
61
62 char* userrec::GetFullRealHost()
63 {
64         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
65         return result;
66 }
67
68 bool userrec::IsInvited(char* channel)
69 {
70         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
71         {
72                 if (i->channel) {
73                         if (!strcasecmp(i->channel,channel))
74                         {
75                                 return true;
76                         }
77                 }
78         }
79         return false;
80 }
81
82 void userrec::InviteTo(char* channel)
83 {
84         Invited i;
85         strlcpy(i.channel,channel,CHANMAX);
86         invites.push_back(i);
87 }
88
89 void userrec::RemoveInvite(char* channel)
90 {
91         log(DEBUG,"Removing invites");
92         if (channel)
93         {
94                 if (invites.size())
95                 {
96                         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
97                         {
98                                 if (i->channel)
99                                 {
100                                         if (!strcasecmp(i->channel,channel))
101                                         {
102                                                 invites.erase(i);
103                                                 return;
104                                         }
105                                 }
106                         }
107                 }
108         }
109 }
110
111 bool userrec::HasPermission(char* command)
112 {
113         char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
114         char* myclass;
115         char* mycmd;
116         char* savept;
117         char* savept2;
118         
119         // are they even an oper at all?
120         if (strchr(this->modes,'o'))
121         {
122                 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
123                 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
124                 {
125                         ConfValue("type","name",j,TypeName,&config_f);
126                         if (!strcmp(TypeName,this->oper))
127                         {
128                                 log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
129                                 ConfValue("type","classes",j,Classes,&config_f);
130                                 char* myclass = strtok_r(Classes," ",&savept);
131                                 while (myclass)
132                                 {
133                                         log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
134                                         for (int k =0; k < ConfValueEnum("class",&config_f); k++)
135                                         {
136                                                 ConfValue("class","name",k,ClassName,&config_f);
137                                                 if (!strcmp(ClassName,myclass))
138                                                 {
139                                                         ConfValue("class","commands",k,CommandList,&config_f);
140                                                         log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
141                                                         
142                                                         
143                                                         mycmd = strtok_r(CommandList," ",&savept2);
144                                                         while (mycmd)
145                                                         {
146                                                                 if (!strcasecmp(mycmd,command))
147                                                                 {
148                                                                         log(DEBUG,"*** Command %s found, returning true",command);
149                                                                         return true;
150                                                                 }
151                                                                 mycmd = strtok_r(NULL," ",&savept2);
152                                                         }
153                                                 }
154                                         }
155                                         myclass = strtok_r(NULL," ",&savept);
156                                 }
157                         }
158                 }
159         }
160         return false;
161 }
162
163