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