]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/users.cpp
Tidied up zline 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 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         recvq = "";
48         strcpy(result,"");
49         for (int i = 0; i < MAXCHANS; i++)
50         {
51                 this->chans[i].channel = NULL;
52                 this->chans[i].uc_modes = 0;
53         }
54         invites.clear();
55 }
56
57
58  
59 char* userrec::GetFullHost()
60 {
61         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
62         return result;
63 }
64
65
66 char* userrec::GetFullRealHost()
67 {
68         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
69         return result;
70 }
71
72 bool userrec::IsInvited(char* channel)
73 {
74         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
75         {
76                 if (i->channel) {
77                         if (!strcasecmp(i->channel,channel))
78                         {
79                                 return true;
80                         }
81                 }
82         }
83         return false;
84 }
85
86 void userrec::InviteTo(char* channel)
87 {
88         Invited i;
89         strlcpy(i.channel,channel,CHANMAX);
90         invites.push_back(i);
91 }
92
93 void userrec::RemoveInvite(char* channel)
94 {
95         log(DEBUG,"Removing invites");
96         if (channel)
97         {
98                 if (invites.size())
99                 {
100                         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
101                         {
102                                 if (i->channel)
103                                 {
104                                         if (!strcasecmp(i->channel,channel))
105                                         {
106                                                 invites.erase(i);
107                                                 return;
108                                         }
109                                 }
110                         }
111                 }
112         }
113 }
114
115 bool userrec::HasPermission(char* command)
116 {
117         char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
118         char* mycmd;
119         char* savept;
120         char* savept2;
121         
122         // are they even an oper at all?
123         if (strchr(this->modes,'o'))
124         {
125                 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
126                 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
127                 {
128                         ConfValue("type","name",j,TypeName,&config_f);
129                         if (!strcmp(TypeName,this->oper))
130                         {
131                                 log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
132                                 ConfValue("type","classes",j,Classes,&config_f);
133                                 char* myclass = strtok_r(Classes," ",&savept);
134                                 while (myclass)
135                                 {
136                                         log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
137                                         for (int k =0; k < ConfValueEnum("class",&config_f); k++)
138                                         {
139                                                 ConfValue("class","name",k,ClassName,&config_f);
140                                                 if (!strcmp(ClassName,myclass))
141                                                 {
142                                                         ConfValue("class","commands",k,CommandList,&config_f);
143                                                         log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
144                                                         
145                                                         
146                                                         mycmd = strtok_r(CommandList," ",&savept2);
147                                                         while (mycmd)
148                                                         {
149                                                                 if (!strcasecmp(mycmd,command))
150                                                                 {
151                                                                         log(DEBUG,"*** Command %s found, returning true",command);
152                                                                         return true;
153                                                                 }
154                                                                 mycmd = strtok_r(NULL," ",&savept2);
155                                                         }
156                                                 }
157                                         }
158                                         myclass = strtok_r(NULL," ",&savept);
159                                 }
160                         }
161                 }
162         }
163         return false;
164 }
165
166
167 void userrec::AddBuffer(std::string a)
168 {
169         std::string b = "";
170         for (int i = 0; i < a.length(); i++)
171                 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
172                         b = b + a[i];
173         std::stringstream stream(recvq);
174         stream << b;
175         recvq = stream.str();
176 }
177
178 bool userrec::BufferIsReady()
179 {
180         for (int i = 0; i < recvq.length(); i++)
181                 if (recvq[i] == '\n')
182                         return true;
183         return false;
184 }
185
186 void userrec::ClearBuffer()
187 {
188         recvq = "";
189 }
190
191 std::string userrec::GetBuffer()
192 {
193         log(DEBUG,"GetBuffer\n%s\n",recvq.c_str());
194         char* line = (char*)recvq.c_str();
195         std::string ret = "";
196         while ((*line != '\n') && (strlen(line)))
197         {
198                 ret = ret + *line;
199                 line++;
200         }
201         if ((*line == '\n') || (*line == '\r'))
202                 line++;
203         recvq = line;
204         return ret;
205 }
206