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");
43 fd = lastping = signon = idle_lastmsg = nping = registered = 0;
44 flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
49 for (int i = 0; i < MAXCHANS; i++)
51 this->chans[i].channel = NULL;
52 this->chans[i].uc_modes = 0;
59 char* userrec::GetFullHost()
61 snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
66 char* userrec::GetFullRealHost()
68 snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
72 bool userrec::IsInvited(char* channel)
74 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
77 if (!strcasecmp(i->channel,channel))
86 void userrec::InviteTo(char* channel)
89 strlcpy(i.channel,channel,CHANMAX);
93 void userrec::RemoveInvite(char* channel)
95 log(DEBUG,"Removing invites");
100 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
104 if (!strcasecmp(i->channel,channel))
115 bool userrec::HasPermission(char* command)
117 char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
122 // are they even an oper at all?
123 if (strchr(this->modes,'o'))
125 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
126 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
128 ConfValue("type","name",j,TypeName,&config_f);
129 if (!strcmp(TypeName,this->oper))
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);
136 log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
137 for (int k =0; k < ConfValueEnum("class",&config_f); k++)
139 ConfValue("class","name",k,ClassName,&config_f);
140 if (!strcmp(ClassName,myclass))
142 ConfValue("class","commands",k,CommandList,&config_f);
143 log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
146 mycmd = strtok_r(CommandList," ",&savept2);
149 if (!strcasecmp(mycmd,command))
151 log(DEBUG,"*** Command %s found, returning true",command);
154 mycmd = strtok_r(NULL," ",&savept2);
158 myclass = strtok_r(NULL," ",&savept);
167 void userrec::AddBuffer(std::string a)
170 for (int i = 0; i < a.length(); i++)
171 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
173 std::stringstream stream(recvq);
175 recvq = stream.str();
178 bool userrec::BufferIsReady()
180 for (int i = 0; i < recvq.length(); i++)
181 if (recvq[i] == '\n')
186 void userrec::ClearBuffer()
191 std::string userrec::GetBuffer()
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)))
201 if ((*line == '\n') || (*line == '\r'))