1 .TH "userrec" 3 "13 May 2005" "InspIRCd" \" -*- nroff -*-
5 userrec \- Holds all information about a user This class stores all information about a user connected to the irc server.
11 \fC#include <users.h>\fP
13 Inherits \fBconnection\fP.
15 .SS "Public Member Functions"
19 .RI "\fBuserrec\fP ()"
22 .RI "virtual \fB~userrec\fP ()"
25 .RI "virtual char * \fBGetFullHost\fP ()"
27 .RI "\fIReturns the full displayed host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form. \fP"
29 .RI "virtual char * \fBGetFullRealHost\fP ()"
31 .RI "\fIReturns the full real host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form. \fP"
33 .RI "virtual bool \fBIsInvited\fP (char *channel)"
35 .RI "\fIReturns true if a user is invited to a channel. \fP"
37 .RI "virtual void \fBInviteTo\fP (char *channel)"
39 .RI "\fIAdds a channel to a users invite list (invites them to a channel). \fP"
41 .RI "virtual void \fBRemoveInvite\fP (char *channel)"
43 .RI "\fIRemoves a channel from a users invite list. \fP"
45 .RI "bool \fBHasPermission\fP (char *command)"
47 .RI "\fIReturns true or false for if a user can execute a privilaged oper command. \fP"
49 .RI "bool \fBAddBuffer\fP (std::string a)"
51 .RI "\fIThis method adds data to the buffer of the user. \fP"
53 .RI "bool \fBBufferIsReady\fP ()"
55 .RI "\fIThis method returns true if the buffer contains at least one carriage return character (e.g. \fP"
57 .RI "void \fBClearBuffer\fP ()"
59 .RI "\fIThis function clears the entire buffer by setting it to an empty string. \fP"
61 .RI "std::string \fBGetBuffer\fP ()"
63 .RI "\fIThis method returns the first available string at the tail end of the buffer and advances the tail end of the buffer past the string. \fP"
65 .RI "void \fBSetWriteError\fP (std::string error)"
67 .RI "\fISets the write error for a connection. \fP"
69 .RI "std::string \fBGetWriteError\fP ()"
71 .RI "\fIReturns the write error which last occured on this connection or an empty string if none occured. \fP"
73 .RI "void \fBAddWriteBuf\fP (std::string data)"
75 .RI "\fIAdds to the user's write buffer. \fP"
77 .RI "void \fBFlushWriteBuf\fP ()"
79 .RI "\fIFlushes as much of the user's buffer to the file descriptor as possible. \fP"
81 .SS "Public Attributes"
85 .RI "char \fBnick\fP [NICKMAX]"
87 .RI "\fIThe users nickname. \fP"
89 .RI "char \fBident\fP [16]"
91 .RI "\fIThe users ident reply. \fP"
93 .RI "char \fBdhost\fP [160]"
95 .RI "\fIThe host displayed to non-opers (used for cloaking etc). \fP"
97 .RI "char \fBfullname\fP [128]"
99 .RI "\fIThe users full name. \fP"
101 .RI "char \fBmodes\fP [MAXBUF]"
103 .RI "\fIThe user's mode string. \fP"
105 .RI "\fBucrec\fP \fBchans\fP [MAXCHANS]"
108 .RI "char \fBserver\fP [256]"
110 .RI "\fIThe server the user is connected to. \fP"
112 .RI "char \fBawaymsg\fP [512]"
114 .RI "\fIThe user's away message. \fP"
116 .RI "char \fBresult\fP [256]"
118 .RI "\fIStores the result of the last GetFullHost or GetRealHost call. \fP"
120 .RI "int \fBflood\fP"
122 .RI "\fINumber of lines the user can place into the buffer (up to the global NetBufferSize bytes) before they are disconnected for excess flood. \fP"
124 .RI "unsigned int \fBtimeout\fP"
126 .RI "\fINumber of seconds this user is given to send USER/NICK If they do not send their details in this time limit they will be disconnected. \fP"
128 .RI "char \fBoper\fP [NICKMAX]"
130 .RI "\fIThe oper type they logged in as, if they are an oper. \fP"
132 .RI "bool \fBdns_done\fP"
134 .RI "\fITrue when \fBDNS\fP lookups are completed. \fP"
136 .RI "unsigned int \fBpingmax\fP"
138 .RI "\fINumber of seconds between PINGs for this user (set from <connect:allow> tag. \fP"
140 .RI "char \fBpassword\fP [MAXBUF]"
142 .RI "\fIPassword specified by the user when they registered. \fP"
144 .RI "std::string \fBrecvq\fP"
146 .RI "\fIUser's receive queue. \fP"
148 .RI "std::string \fBsendq\fP"
150 .RI "\fIUser's send queue. \fP"
152 .RI "int \fBlines_in\fP"
154 .RI "\fIFlood counters. \fP"
156 .RI "time_t \fBreset_due\fP"
159 .RI "long \fBthreshold\fP"
162 .RI "std::string \fBWriteError\fP"
165 .RI "long \fBsendqmax\fP"
167 .RI "\fIMaximum size this user's sendq can become. \fP"
169 .RI "long \fBrecvqmax\fP"
171 .RI "\fIMaximum size this user's recvq can become. \fP"
173 .SS "Private Attributes"
177 .RI "\fBInvitedList\fP \fBinvites\fP"
179 .RI "\fIA list of channels the user has a pending invite to. \fP"
181 .SH "Detailed Description"
183 Holds all information about a user This class stores all information about a user connected to the irc server.
185 Everything about a connection is stored here primarily, from the user's socket ID (file descriptor) through to the user's nickname and hostname. Use the Find method of the server class to locate a specific user by nickname.
187 Definition at line 108 of file users.h.
188 .SH "Constructor & Destructor Documentation"
190 .SS "userrec::userrec ()"
192 Definition at line 28 of file users.cpp.
194 References awaymsg, connection::bytes_in, connection::bytes_out, ucrec::channel, chans, connection::cmds_in, connection::cmds_out, dhost, dns_done, connection::fd, flood, fullname, connection::haspassed, connection::host, ident, connection::idle_lastmsg, invites, connection::ip, connection::lastping, lines_in, modes, nick, connection::nping, oper, connection::port, recvq, connection::registered, reset_due, result, sendq, server, connection::signon, TIME, timeout, and ucrec::uc_modes.
198 30 // the PROPER way to do it, AVOID bzero at *ALL* costs
200 32 strcpy(ip,'127.0.0.1');
205 37 strcpy(fullname,'');
207 39 strcpy(server,'');
208 40 strcpy(awaymsg,'');
212 44 fd = lastping = signon = idle_lastmsg = nping = registered = 0;
213 45 flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
214 46 haspassed = false;
218 50 strcpy(result,'');
219 51 for (int i = 0; i < MAXCHANS; i++)
221 53 this->chans[i].channel = NULL;
222 54 this->chans[i].uc_modes = 0;
227 .SS "virtual userrec::~\fBuserrec\fP ()\fC [inline, virtual]\fP"
229 Definition at line 222 of file users.h.
234 .SH "Member Function Documentation"
236 .SS "bool userrec::AddBuffer (std::string a)"
238 This method adds data to the buffer of the user. The buffer can grow to any size within limits of the available memory, managed by the size of a std::string, however if any individual line in the buffer grows over 600 bytes in length (which is 88 chars over the RFC-specified limit per line) then the method will return false and the text will not be inserted.Definition at line 169 of file users.cpp.
240 References recvq, recvqmax, and SetWriteError().
244 171 std::string b = '';
245 172 for (int i = 0; i < a.length(); i++)
246 173 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
248 175 std::stringstream stream(recvq);
250 177 recvq = stream.str();
252 179 // count the size of the first line in the buffer.
253 180 while (i < recvq.length())
255 182 if (recvq[i++] == '\n')
258 185 if (recvq.length() > this->recvqmax)
260 187 this->SetWriteError('RecvQ exceeded');
261 188 WriteOpers('*** User %s RecvQ of %d exceeds connect class maximum of %d',this->nick,recvq.length(),this->recvqmax);
263 190 // return false if we've had more than 600 characters WITHOUT
264 191 // a carriage return (this is BAD, drop the socket)
265 192 return (i < 600);
268 .SS "void userrec::AddWriteBuf (std::string data)"
270 Adds to the user's write buffer. You may add any amount of text up to this users sendq value, if you exceed the sendq value, \fBSetWriteError()\fP will be called to set the users error string to 'SendQ exceeded', and further buffer adds will be dropped.Definition at line 225 of file users.cpp.
272 References GetWriteError(), sendq, sendqmax, and SetWriteError().
276 227 if (this->GetWriteError() != '')
278 229 if (sendq.length() + data.length() > this->sendqmax)
280 231 WriteOpers('*** User %s SendQ of %d exceeds connect class maximum of %d',this->nick,sendq.length() + data.length(),this->sendqmax);
281 232 this->SetWriteError('SendQ exceeded');
284 235 std::stringstream stream;
285 236 stream << sendq << data;
286 237 sendq = stream.str();
289 .SS "bool userrec::BufferIsReady ()"
291 This method returns true if the buffer contains at least one carriage return character (e.g. one complete line may be read)Definition at line 195 of file users.cpp.
297 197 for (int i = 0; i < recvq.length(); i++)
298 198 if (recvq[i] == '\n')
303 .SS "void userrec::ClearBuffer ()"
305 This function clears the entire buffer by setting it to an empty string. Definition at line 203 of file users.cpp.
309 Referenced by Server::PseudoToUser(), and Server::UserToPseudo().
316 .SS "void userrec::FlushWriteBuf ()"
318 Flushes as much of the user's buffer to the file descriptor as possible. This function may not always flush the entire buffer, rather instead as much of it as it possibly can. If the send() call fails to send the entire buffer, the buffer position is advanced forwards and the rest of the data sent at the next call to this method.Definition at line 241 of file users.cpp.
320 References connection::bytes_out, connection::cmds_out, sendq, and SetWriteError().
324 243 if (sendq.length())
326 245 char* tb = (char*)this->sendq.c_str();
327 246 int n_sent = write(this->fd,tb,this->sendq.length());
328 247 if (n_sent == -1)
330 249 this->SetWriteError(strerror(errno));
334 253 // advance the queue
336 255 this->sendq = tb;
337 256 // update the user's stats counters
338 257 this->bytes_out += n_sent;
339 258 this->cmds_out++;
344 .SS "std::string userrec::GetBuffer ()"
346 This method returns the first available string at the tail end of the buffer and advances the tail end of the buffer past the string. This means it is a one way operation in a similar way to strtok(), and multiple calls return multiple lines if they are available. The results of this function if there are no lines to be read are unknown, always use \fBBufferIsReady()\fP to check if it is ok to read the buffer before calling \fBGetBuffer()\fP.Definition at line 208 of file users.cpp.
354 212 char* line = (char*)recvq.c_str();
355 213 std::string ret = '';
356 214 while ((*line != '\n') && (strlen(line)))
358 216 ret = ret + *line;
361 219 if ((*line == '\n') || (*line == '\r'))
367 .SS "char * userrec::GetFullHost ()\fC [virtual]\fP"
369 Returns the full displayed host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form. Definition at line 61 of file users.cpp.
371 References dhost, ident, nick, and result.
375 63 snprintf(result,MAXBUF,'%s!%s@%s',nick,ident,dhost);
379 .SS "char * userrec::GetFullRealHost ()\fC [virtual]\fP"
381 Returns the full real host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form. If any form of hostname cloaking is in operation, e.g. through a module, then this method will ignore it and return the true hostname.Definition at line 68 of file users.cpp.
383 References connection::host, ident, nick, and result.
387 70 snprintf(result,MAXBUF,'%s!%s@%s',nick,ident,host);
391 .SS "std::string userrec::GetWriteError ()"
393 Returns the write error which last occured on this connection or an empty string if none occured. Definition at line 271 of file users.cpp.
395 References WriteError.
397 Referenced by AddWriteBuf().
401 273 return this->WriteError;
404 .SS "bool userrec::HasPermission (char * command)"
406 Returns true or false for if a user can execute a privilaged oper command. This is done by looking up their oper type from \fBuserrec::oper\fP, then referencing this to their oper classes and checking the commands they can execute.Definition at line 117 of file users.cpp.
408 References config_f, and DEBUG.
412 119 char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
417 124 // are they even an oper at all?
418 125 if (strchr(this->modes,'o'))
420 127 log(DEBUG,'*** HasPermission: %s is an oper',this->nick);
421 128 for (int j =0; j < ConfValueEnum('type',&config_f); j++)
423 130 ConfValue('type','name',j,TypeName,&config_f);
424 131 if (!strcmp(TypeName,this->oper))
426 133 log(DEBUG,'*** HasPermission: %s is an oper of type '%s'',this->nick,this->oper);
427 134 ConfValue('type','classes',j,Classes,&config_f);
428 135 char* myclass = strtok_r(Classes,' ',&savept);
431 138 log(DEBUG,'*** HasPermission: checking classtype '%s'',myclass);
432 139 for (int k =0; k < ConfValueEnum('class',&config_f); k++)
434 141 ConfValue('class','name',k,ClassName,&config_f);
435 142 if (!strcmp(ClassName,myclass))
437 144 ConfValue('class','commands',k,CommandList,&config_f);
438 145 log(DEBUG,'*** HasPermission: found class named %s with commands: '%s'',ClassName,CommandList);
441 148 mycmd = strtok_r(CommandList,' ',&savept2);
444 151 if (!strcasecmp(mycmd,command))
446 153 log(DEBUG,'*** Command %s found, returning true',command);
449 156 mycmd = strtok_r(NULL,' ',&savept2);
453 160 myclass = strtok_r(NULL,' ',&savept);
461 .SS "void userrec::InviteTo (char * channel)\fC [virtual]\fP"
463 Adds a channel to a users invite list (invites them to a channel). Definition at line 88 of file users.cpp.
465 References Invited::channel, and invites.
470 91 strlcpy(i.channel,channel,CHANMAX);
471 92 invites.push_back(i);
474 .SS "bool userrec::IsInvited (char * channel)\fC [virtual]\fP"
476 Returns true if a user is invited to a channel. Definition at line 74 of file users.cpp.
482 76 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
485 79 if (!strcasecmp(i->channel,channel))
494 .SS "void userrec::RemoveInvite (char * channel)\fC [virtual]\fP"
496 Removes a channel from a users invite list. This member function is called on successfully joining an invite only channel to which the user has previously been invited, to clear the invitation.Definition at line 95 of file users.cpp.
498 References DEBUG, and invites.
502 97 log(DEBUG,'Removing invites');
505 100 if (invites.size())
507 102 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
511 106 if (!strcasecmp(i->channel,channel))
513 108 invites.erase(i);
522 .SS "void userrec::SetWriteError (std::string error)"
524 Sets the write error for a connection. This is done because the actual disconnect of a client may occur at an inopportune time such as half way through /LIST output. The WriteErrors of clients are checked at a more ideal time (in the mainloop) and errored clients purged.Definition at line 263 of file users.cpp.
526 References DEBUG, and WriteError.
528 Referenced by AddBuffer(), AddWriteBuf(), and FlushWriteBuf().
532 265 log(DEBUG,'Setting error string for %s to '%s'',this->nick,error.c_str());
533 266 // don't try to set the error twice, its already set take the first string.
534 267 if (this->WriteError == '')
535 268 this->WriteError = error;
538 .SH "Member Data Documentation"
540 .SS "char \fBuserrec::awaymsg\fP[512]"
542 The user's away message. If this string is empty, the user is not marked as away.Definition at line 151 of file users.h.
544 Referenced by userrec().
545 .SS "\fBucrec\fP \fBuserrec::chans\fP[MAXCHANS]"
547 Definition at line 142 of file users.h.
549 Referenced by Server::PseudoToUser(), and userrec().
550 .SS "char \fBuserrec::dhost\fP[160]"
552 The host displayed to non-opers (used for cloaking etc). This usually matches the value of \fBuserrec::host\fP.Definition at line 130 of file users.h.
554 Referenced by GetFullHost(), and userrec().
555 .SS "bool \fBuserrec::dns_done\fP"
557 True when \fBDNS\fP lookups are completed. Definition at line 179 of file users.h.
559 Referenced by userrec().
560 .SS "int \fBuserrec::flood\fP"
562 Number of lines the user can place into the buffer (up to the global NetBufferSize bytes) before they are disconnected for excess flood. Definition at line 162 of file users.h.
564 Referenced by userrec().
565 .SS "char \fBuserrec::fullname\fP[128]"
567 The users full name. Definition at line 134 of file users.h.
569 Referenced by userrec().
570 .SS "char \fBuserrec::ident\fP[16]"
572 The users ident reply. Definition at line 125 of file users.h.
574 Referenced by GetFullHost(), GetFullRealHost(), Server::PseudoToUser(), userrec(), and Server::UserToPseudo().
575 .SS "\fBInvitedList\fP \fBuserrec::invites\fP\fC [private]\fP"
577 A list of channels the user has a pending invite to. Definition at line 114 of file users.h.
579 Referenced by InviteTo(), IsInvited(), RemoveInvite(), and userrec().
580 .SS "int \fBuserrec::lines_in\fP"
582 Flood counters. Definition at line 204 of file users.h.
584 Referenced by userrec().
585 .SS "char \fBuserrec::modes\fP[MAXBUF]"
587 The user's mode string. This may contain any of the following RFC characters: o, w, s, i Your module may define other mode characters as it sees fit.Definition at line 140 of file users.h.
589 Referenced by userrec().
590 .SS "char \fBuserrec::nick\fP[NICKMAX]"
592 The users nickname. An invalid nickname indicates an unregistered connection prior to the NICK command.Definition at line 121 of file users.h.
594 Referenced by ConfigReader::DumpErrors(), GetFullHost(), GetFullRealHost(), Server::PseudoToUser(), and userrec().
595 .SS "char \fBuserrec::oper\fP[NICKMAX]"
597 The oper type they logged in as, if they are an oper. This is used to check permissions in operclasses, so that we can say 'yay' or 'nay' to any commands they issue. The value of this is the value of a valid 'type name=' tag.Definition at line 175 of file users.h.
599 Referenced by userrec().
600 .SS "char \fBuserrec::password\fP[MAXBUF]"
602 Password specified by the user when they registered. This is stored even if the block doesnt need a password, so that modules may check it.Definition at line 189 of file users.h.
603 .SS "unsigned int \fBuserrec::pingmax\fP"
605 Number of seconds between PINGs for this user (set from <connect:allow> tag. Definition at line 183 of file users.h.
606 .SS "std::string \fBuserrec::recvq\fP"
608 User's receive queue. Lines from the IRCd awaiting processing are stored here. Upgraded april 2005, old system a bit hairy.Definition at line 195 of file users.h.
610 Referenced by AddBuffer(), BufferIsReady(), ClearBuffer(), GetBuffer(), and userrec().
611 .SS "long \fBuserrec::recvqmax\fP"
613 Maximum size this user's recvq can become. Definition at line 218 of file users.h.
615 Referenced by AddBuffer().
616 .SS "time_t \fBuserrec::reset_due\fP"
618 Definition at line 205 of file users.h.
620 Referenced by userrec().
621 .SS "char \fBuserrec::result\fP[256]"
623 Stores the result of the last GetFullHost or GetRealHost call. You may use this to increase the speed of use of this class.Definition at line 156 of file users.h.
625 Referenced by GetFullHost(), GetFullRealHost(), and userrec().
626 .SS "std::string \fBuserrec::sendq\fP"
628 User's send queue. Lines waiting to be sent are stored here until their buffer is flushed.Definition at line 200 of file users.h.
630 Referenced by AddWriteBuf(), FlushWriteBuf(), and userrec().
631 .SS "long \fBuserrec::sendqmax\fP"
633 Maximum size this user's sendq can become. Definition at line 214 of file users.h.
635 Referenced by AddWriteBuf().
636 .SS "char \fBuserrec::server\fP[256]"
638 The server the user is connected to. Definition at line 146 of file users.h.
640 Referenced by userrec().
641 .SS "long \fBuserrec::threshold\fP"
643 Definition at line 206 of file users.h.
644 .SS "unsigned int \fBuserrec::timeout\fP"
646 Number of seconds this user is given to send USER/NICK If they do not send their details in this time limit they will be disconnected. Definition at line 168 of file users.h.
648 Referenced by userrec().
649 .SS "std::string \fBuserrec::WriteError\fP"
651 Definition at line 210 of file users.h.
653 Referenced by GetWriteError(), and SetWriteError().
657 Generated automatically by Doxygen for InspIRCd from the source code.