1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
22 #include "inspstring.h"
24 extern std::stringstream config_f;
30 // the PROPER way to do it, AVOID bzero at *ALL* costs
32 strcpy(ip,"127.0.0.1");
45 fd = lastping = signon = idle_lastmsg = nping = registered = 0;
46 flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
51 for (int i = 0; i < MAXCHANS; i++)
53 this->chans[i].channel = NULL;
54 this->chans[i].uc_modes = 0;
61 char* userrec::GetFullHost()
63 snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
68 char* userrec::GetFullRealHost()
70 snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
74 bool userrec::IsInvited(char* channel)
76 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
79 if (!strcasecmp(i->channel,channel))
88 void userrec::InviteTo(char* channel)
91 strlcpy(i.channel,channel,CHANMAX);
95 void userrec::RemoveInvite(char* channel)
97 log(DEBUG,"Removing invites");
102 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
106 if (!strcasecmp(i->channel,channel))
117 bool userrec::HasPermission(char* command)
119 char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
124 // are they even an oper at all?
125 if (strchr(this->modes,'o'))
127 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
128 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
130 ConfValue("type","name",j,TypeName,&config_f);
131 if (!strcmp(TypeName,this->oper))
133 log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
134 ConfValue("type","classes",j,Classes,&config_f);
135 char* myclass = strtok_r(Classes," ",&savept);
138 log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
139 for (int k =0; k < ConfValueEnum("class",&config_f); k++)
141 ConfValue("class","name",k,ClassName,&config_f);
142 if (!strcmp(ClassName,myclass))
144 ConfValue("class","commands",k,CommandList,&config_f);
145 log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
148 mycmd = strtok_r(CommandList," ",&savept2);
151 if (!strcasecmp(mycmd,command))
153 log(DEBUG,"*** Command %s found, returning true",command);
156 mycmd = strtok_r(NULL," ",&savept2);
160 myclass = strtok_r(NULL," ",&savept);
169 bool userrec::AddBuffer(std::string a)
172 for (int i = 0; i < a.length(); i++)
173 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
175 std::stringstream stream(recvq);
177 recvq = stream.str();
179 // count the size of the first line in the buffer.
180 while (i < recvq.length())
182 if (recvq[i++] == '\n')
185 // return false if we've had more than 600 characters WITHOUT
186 // a carriage return (this is BAD, drop the socket)
190 bool userrec::BufferIsReady()
192 for (int i = 0; i < recvq.length(); i++)
193 if (recvq[i] == '\n')
198 void userrec::ClearBuffer()
203 std::string userrec::GetBuffer()
207 char* line = (char*)recvq.c_str();
208 std::string ret = "";
209 while ((*line != '\n') && (strlen(line)))
214 if ((*line == '\n') || (*line == '\r'))