]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/users.cpp
Fixed dns queue stuff?
[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         dns_done = false;
45         strcpy(result,"");
46         for (int i = 0; i < MAXCHANS; i++)
47         {
48                 this->chans[i].channel = NULL;
49                 this->chans[i].uc_modes = 0;
50         }
51         invites.clear();
52 }
53
54
55  
56 char* userrec::GetFullHost()
57 {
58         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
59         return result;
60 }
61
62
63 char* userrec::GetFullRealHost()
64 {
65         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
66         return result;
67 }
68
69 bool userrec::IsInvited(char* channel)
70 {
71         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
72         {
73                 if (i->channel) {
74                         if (!strcasecmp(i->channel,channel))
75                         {
76                                 return true;
77                         }
78                 }
79         }
80         return false;
81 }
82
83 void userrec::InviteTo(char* channel)
84 {
85         Invited i;
86         strlcpy(i.channel,channel,CHANMAX);
87         invites.push_back(i);
88 }
89
90 void userrec::RemoveInvite(char* channel)
91 {
92         log(DEBUG,"Removing invites");
93         if (channel)
94         {
95                 if (invites.size())
96                 {
97                         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
98                         {
99                                 if (i->channel)
100                                 {
101                                         if (!strcasecmp(i->channel,channel))
102                                         {
103                                                 invites.erase(i);
104                                                 return;
105                                         }
106                                 }
107                         }
108                 }
109         }
110 }
111
112 bool userrec::HasPermission(char* command)
113 {
114         char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
115         char* myclass;
116         char* mycmd;
117         char* savept;
118         char* savept2;
119         
120         // are they even an oper at all?
121         if (strchr(this->modes,'o'))
122         {
123                 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
124                 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
125                 {
126                         ConfValue("type","name",j,TypeName,&config_f);
127                         if (!strcmp(TypeName,this->oper))
128                         {
129                                 log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
130                                 ConfValue("type","classes",j,Classes,&config_f);
131                                 char* myclass = strtok_r(Classes," ",&savept);
132                                 while (myclass)
133                                 {
134                                         log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
135                                         for (int k =0; k < ConfValueEnum("class",&config_f); k++)
136                                         {
137                                                 ConfValue("class","name",k,ClassName,&config_f);
138                                                 if (!strcmp(ClassName,myclass))
139                                                 {
140                                                         ConfValue("class","commands",k,CommandList,&config_f);
141                                                         log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
142                                                         
143                                                         
144                                                         mycmd = strtok_r(CommandList," ",&savept2);
145                                                         while (mycmd)
146                                                         {
147                                                                 if (!strcasecmp(mycmd,command))
148                                                                 {
149                                                                         log(DEBUG,"*** Command %s found, returning true",command);
150                                                                         return true;
151                                                                 }
152                                                                 mycmd = strtok_r(NULL," ",&savept2);
153                                                         }
154                                                 }
155                                         }
156                                         myclass = strtok_r(NULL," ",&savept);
157                                 }
158                         }
159                 }
160         }
161         return false;
162 }
163
164