<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>InspIRCd: users.cpp Source File</title> <link href="inspircd.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.3.3 --> <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div> <h1>users.cpp</h1><a href="users_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/* +------------------------------------+</span> 00002 <span class="comment"> * | Inspire Internet Relay Chat Daemon |</span> 00003 <span class="comment"> * +------------------------------------+</span> 00004 <span class="comment"> *</span> 00005 <span class="comment"> * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.</span> 00006 <span class="comment"> * E-mail:</span> 00007 <span class="comment"> * <brain@chatspike.net></span> 00008 <span class="comment"> * <Craig@chatspike.net></span> 00009 <span class="comment"> * </span> 00010 <span class="comment"> * Written by Craig Edwards, Craig McLure, and others.</span> 00011 <span class="comment"> * This program is free but copyrighted software; see</span> 00012 <span class="comment"> * the file COPYING for details.</span> 00013 <span class="comment"> *</span> 00014 <span class="comment"> * ---------------------------------------------------</span> 00015 <span class="comment"> */</span> 00016 00017 <span class="preprocessor">#include "inspircd_config.h"</span> 00018 <span class="preprocessor">#include "<a class="code" href="channels_8h.html">channels.h</a>"</span> 00019 <span class="preprocessor">#include "<a class="code" href="users_8h.html">users.h</a>"</span> 00020 <span class="preprocessor">#include "inspircd.h"</span> 00021 <span class="preprocessor">#include <stdio.h></span> 00022 <span class="preprocessor">#include "inspstring.h"</span> 00023 <a name="l00024"></a><a class="code" href="users_8cpp.html#a0">00024</a> <span class="keyword">extern</span> std::stringstream <a class="code" href="channels_8cpp.html#a34">config_f</a>; 00025 <a name="l00026"></a><a class="code" href="users_8cpp.html#a1">00026</a> <span class="keyword">extern</span> time_t <a class="code" href="channels_8cpp.html#a37">TIME</a>; 00027 <a name="l00028"></a><a class="code" href="classuserrec.html#a0">00028</a> <a class="code" href="classuserrec.html#a0">userrec::userrec</a>() 00029 { 00030 <span class="comment">// the PROPER way to do it, AVOID bzero at *ALL* costs</span> 00031 strcpy(<a class="code" href="classuserrec.html#o0">nick</a>,<span class="stringliteral">""</span>); 00032 strcpy(<a class="code" href="classconnection.html#o2">ip</a>,<span class="stringliteral">"127.0.0.1"</span>); 00033 <a class="code" href="classuserrec.html#o10">timeout</a> = 0; 00034 strcpy(<a class="code" href="classuserrec.html#o1">ident</a>,<span class="stringliteral">""</span>); 00035 strcpy(<a class="code" href="classconnection.html#o1">host</a>,<span class="stringliteral">""</span>); 00036 strcpy(<a class="code" href="classuserrec.html#o2">dhost</a>,<span class="stringliteral">""</span>); 00037 strcpy(<a class="code" href="classuserrec.html#o3">fullname</a>,<span class="stringliteral">""</span>); 00038 strcpy(<a class="code" href="classuserrec.html#o4">modes</a>,<span class="stringliteral">""</span>); 00039 strcpy(<a class="code" href="classconnection.html#o3">inbuf</a>,<span class="stringliteral">""</span>); 00040 strcpy(<a class="code" href="classuserrec.html#o6">server</a>,<span class="stringliteral">""</span>); 00041 strcpy(<a class="code" href="classuserrec.html#o7">awaymsg</a>,<span class="stringliteral">""</span>); 00042 strcpy(<a class="code" href="classuserrec.html#o11">oper</a>,<span class="stringliteral">""</span>); 00043 <a class="code" href="classconnection.html#o0">fd</a> = <a class="code" href="classconnection.html#o12">lastping</a> = <a class="code" href="classconnection.html#o13">signon</a> = <a class="code" href="classconnection.html#o14">idle_lastmsg</a> = <a class="code" href="classconnection.html#o15">nping</a> = <a class="code" href="classconnection.html#o10">registered</a> = 0; 00044 <a class="code" href="classuserrec.html#o9">flood</a> = <a class="code" href="classconnection.html#o9">port</a> = <a class="code" href="classconnection.html#o4">bytes_in</a> = <a class="code" href="classconnection.html#o5">bytes_out</a> = <a class="code" href="classconnection.html#o6">cmds_in</a> = <a class="code" href="classconnection.html#o7">cmds_out</a> = 0; 00045 <a class="code" href="classconnection.html#o8">haspassed</a> = <span class="keyword">false</span>; 00046 <a class="code" href="classuserrec.html#o12">dns_done</a> = <span class="keyword">false</span>; 00047 strcpy(<a class="code" href="classuserrec.html#o8">result</a>,<span class="stringliteral">""</span>); 00048 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < MAXCHANS; i++) 00049 { 00050 this-><a class="code" href="classuserrec.html#o5">chans</a>[i].<a class="code" href="classucrec.html#o1">channel</a> = NULL; 00051 this-><a class="code" href="classuserrec.html#o5">chans</a>[i].<a class="code" href="classucrec.html#o0">uc_modes</a> = 0; 00052 } 00053 <a class="code" href="classuserrec.html#r0">invites</a>.clear(); 00054 } 00055 00056 00057 <a name="l00058"></a><a class="code" href="classuserrec.html#a2">00058</a> <span class="keywordtype">char</span>* <a class="code" href="classuserrec.html#a2">userrec::GetFullHost</a>() 00059 { 00060 snprintf(<a class="code" href="classuserrec.html#o8">result</a>,MAXBUF,<span class="stringliteral">"%s!%s@%s"</span>,<a class="code" href="classuserrec.html#o0">nick</a>,<a class="code" href="classuserrec.html#o1">ident</a>,<a class="code" href="classuserrec.html#o2">dhost</a>); 00061 <span class="keywordflow">return</span> <a class="code" href="classuserrec.html#o8">result</a>; 00062 } 00063 00064 <a name="l00065"></a><a class="code" href="classuserrec.html#a3">00065</a> <span class="keywordtype">char</span>* <a class="code" href="classuserrec.html#a3">userrec::GetFullRealHost</a>() 00066 { 00067 snprintf(<a class="code" href="classuserrec.html#o8">result</a>,MAXBUF,<span class="stringliteral">"%s!%s@%s"</span>,<a class="code" href="classuserrec.html#o0">nick</a>,<a class="code" href="classuserrec.html#o1">ident</a>,<a class="code" href="classconnection.html#o1">host</a>); 00068 <span class="keywordflow">return</span> <a class="code" href="classuserrec.html#o8">result</a>; 00069 } 00070 <a name="l00071"></a><a class="code" href="classuserrec.html#a4">00071</a> <span class="keywordtype">bool</span> <a class="code" href="classuserrec.html#a4">userrec::IsInvited</a>(<span class="keywordtype">char</span>* channel) 00072 { 00073 <span class="keywordflow">for</span> (InvitedList::iterator i = <a class="code" href="classuserrec.html#r0">invites</a>.begin(); i != <a class="code" href="classuserrec.html#r0">invites</a>.end(); i++) 00074 { 00075 <span class="keywordflow">if</span> (i->channel) { 00076 <span class="keywordflow">if</span> (!strcasecmp(i->channel,channel)) 00077 { 00078 <span class="keywordflow">return</span> <span class="keyword">true</span>; 00079 } 00080 } 00081 } 00082 <span class="keywordflow">return</span> <span class="keyword">false</span>; 00083 } 00084 <a name="l00085"></a><a class="code" href="classuserrec.html#a5">00085</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a5">userrec::InviteTo</a>(<span class="keywordtype">char</span>* channel) 00086 { 00087 <a class="code" href="classInvited.html">Invited</a> i; 00088 strlcpy(i.<a class="code" href="classInvited.html#o0">channel</a>,channel,CHANMAX); 00089 <a class="code" href="classuserrec.html#r0">invites</a>.push_back(i); 00090 } 00091 <a name="l00092"></a><a class="code" href="classuserrec.html#a6">00092</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a6">userrec::RemoveInvite</a>(<span class="keywordtype">char</span>* channel) 00093 { 00094 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Removing invites"</span>); 00095 <span class="keywordflow">if</span> (channel) 00096 { 00097 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#r0">invites</a>.size()) 00098 { 00099 <span class="keywordflow">for</span> (InvitedList::iterator i = <a class="code" href="classuserrec.html#r0">invites</a>.begin(); i != <a class="code" href="classuserrec.html#r0">invites</a>.end(); i++) 00100 { 00101 <span class="keywordflow">if</span> (i->channel) 00102 { 00103 <span class="keywordflow">if</span> (!strcasecmp(i->channel,channel)) 00104 { 00105 <a class="code" href="classuserrec.html#r0">invites</a>.erase(i); 00106 <span class="keywordflow">return</span>; 00107 } 00108 } 00109 } 00110 } 00111 } 00112 } 00113 <a name="l00114"></a><a class="code" href="classuserrec.html#a7">00114</a> <span class="keywordtype">bool</span> <a class="code" href="classuserrec.html#a7">userrec::HasPermission</a>(<span class="keywordtype">char</span>* command) 00115 { 00116 <span class="keywordtype">char</span> TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF]; 00117 <span class="keywordtype">char</span>* myclass; 00118 <span class="keywordtype">char</span>* mycmd; 00119 <span class="keywordtype">char</span>* savept; 00120 <span class="keywordtype">char</span>* savept2; 00121 00122 <span class="comment">// are they even an oper at all?</span> 00123 <span class="keywordflow">if</span> (strchr(this->modes,<span class="charliteral">'o'</span>)) 00124 { 00125 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: %s is an oper"</span>,this->nick); 00126 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j =0; j < ConfValueEnum(<span class="stringliteral">"type"</span>,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); j++) 00127 { 00128 ConfValue(<span class="stringliteral">"type"</span>,<span class="stringliteral">"name"</span>,j,TypeName,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); 00129 <span class="keywordflow">if</span> (!strcmp(TypeName,this->oper)) 00130 { 00131 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: %s is an oper of type '%s'"</span>,this->nick,this->oper); 00132 ConfValue(<span class="stringliteral">"type"</span>,<span class="stringliteral">"classes"</span>,j,Classes,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); 00133 <span class="keywordtype">char</span>* myclass = strtok_r(Classes,<span class="stringliteral">" "</span>,&savept); 00134 <span class="keywordflow">while</span> (myclass) 00135 { 00136 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: checking classtype '%s'"</span>,myclass); 00137 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k =0; k < ConfValueEnum(<span class="stringliteral">"class"</span>,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); k++) 00138 { 00139 ConfValue(<span class="stringliteral">"class"</span>,<span class="stringliteral">"name"</span>,k,ClassName,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); 00140 <span class="keywordflow">if</span> (!strcmp(ClassName,myclass)) 00141 { 00142 ConfValue(<span class="stringliteral">"class"</span>,<span class="stringliteral">"commands"</span>,k,CommandList,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); 00143 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: found class named %s with commands: '%s'"</span>,ClassName,CommandList); 00144 00145 00146 mycmd = strtok_r(CommandList,<span class="stringliteral">" "</span>,&savept2); 00147 <span class="keywordflow">while</span> (mycmd) 00148 { 00149 <span class="keywordflow">if</span> (!strcasecmp(mycmd,command)) 00150 { 00151 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** Command %s found, returning true"</span>,command); 00152 <span class="keywordflow">return</span> <span class="keyword">true</span>; 00153 } 00154 mycmd = strtok_r(NULL,<span class="stringliteral">" "</span>,&savept2); 00155 } 00156 } 00157 } 00158 myclass = strtok_r(NULL,<span class="stringliteral">" "</span>,&savept); 00159 } 00160 } 00161 } 00162 } 00163 <span class="keywordflow">return</span> <span class="keyword">false</span>; 00164 } 00165 00166 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sat Apr 16 18:57:14 2005 for InspIRCd by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.3 </small></address> </body> </html>