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