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