Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

users.cpp

Go to the documentation of this file.
00001 /*
00002 Manages userrec objects
00003 */
00004 
00005 #include "inspircd_config.h" 
00006 #include "channels.h"
00007 #include "users.h"
00008 #include "inspircd.h"
00009 #include <stdio.h>
00010 
00011 extern std::stringstream config_f;
00012 
00013 userrec::userrec()
00014 {
00015         // the PROPER way to do it, AVOID bzero at *ALL* costs
00016         strcpy(nick,"");
00017         strcpy(ip,"127.0.0.1");
00018         timeout = 0;
00019         strcpy(ident,"");
00020         strcpy(host,"");
00021         strcpy(dhost,"");
00022         strcpy(fullname,"");
00023         strcpy(modes,"");
00024         strcpy(inbuf,"");
00025         strcpy(server,"");
00026         strcpy(awaymsg,"");
00027         fd = lastping = signon = idle_lastmsg = nping = registered = 0;
00028         flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
00029         haspassed = false;
00030         strcpy(result,"");
00031         for (int i = 0; i < MAXCHANS; i++)
00032         {
00033                 this->chans[i].channel = NULL;
00034                 this->chans[i].uc_modes = 0;
00035         }
00036         invites.clear();
00037 }
00038 
00039 
00040  
00041 char* userrec::GetFullHost()
00042 {
00043         sprintf(result,"%s!%s@%s",nick,ident,dhost);
00044         return result;
00045 }
00046 
00047 
00048 char* userrec::GetFullRealHost()
00049 {
00050         sprintf(result,"%s!%s@%s",nick,ident,host);
00051         return result;
00052 }
00053 
00054 bool userrec::IsInvited(char* channel)
00055 {
00056         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
00057         {
00058                 if (i->channel) {
00059                         if (!strcasecmp(i->channel,channel))
00060                         {
00061                                 return true;
00062                         }
00063                 }
00064         }
00065         return false;
00066 }
00067 
00068 void userrec::InviteTo(char* channel)
00069 {
00070         Invited i;
00071         strcpy(i.channel,channel);
00072         invites.push_back(i);
00073 }
00074 
00075 void userrec::RemoveInvite(char* channel)
00076 {
00077         log(DEBUG,"Removing invites");
00078         if (channel)
00079         {
00080                 if (invites.size())
00081                 {
00082                         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
00083                         {
00084                                 if (i->channel)
00085                                 {
00086                                         if (!strcasecmp(i->channel,channel))
00087                                         {
00088                                                 invites.erase(i);
00089                                                 return;
00090                                         }
00091                                 }
00092                         }
00093                 }
00094         }
00095 }
00096 
00097 bool userrec::HasPermission(char* command)
00098 {
00099         char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
00100         char* myclass;
00101         char* mycmd;
00102         char* savept;
00103         char* savept2;
00104         
00105         // are they even an oper at all?
00106         if (strchr(this->modes,'o'))
00107         {
00108                 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
00109                 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
00110                 {
00111                         ConfValue("type","name",j,TypeName,&config_f);
00112                         if (!strcmp(TypeName,this->oper))
00113                         {
00114                                 log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
00115                                 ConfValue("type","classes",j,Classes,&config_f);
00116                                 char* myclass = strtok_r(Classes," ",&savept);
00117                                 while (myclass)
00118                                 {
00119                                         log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
00120                                         for (int k =0; k < ConfValueEnum("class",&config_f); k++)
00121                                         {
00122                                                 ConfValue("class","name",k,ClassName,&config_f);
00123                                                 if (!strcmp(ClassName,myclass))
00124                                                 {
00125                                                         ConfValue("class","commands",k,CommandList,&config_f);
00126                                                         log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
00127                                                         
00128                                                         
00129                                                         mycmd = strtok_r(CommandList," ",&savept2);
00130                                                         while (mycmd)
00131                                                         {
00132                                                                 if (!strcasecmp(mycmd,command))
00133                                                                 {
00134                                                                         log(DEBUG,"*** Command %s found, returning true",command);
00135                                                                         return true;
00136                                                                 }
00137                                                                 mycmd = strtok_r(NULL," ",&savept2);
00138                                                         }
00139                                                 }
00140                                         }
00141                                         myclass = strtok_r(NULL," ",&savept);
00142                                 }
00143                         }
00144                 }
00145         }
00146         return false;
00147 }
00148 
00149 

Generated on Sat May 1 20:57:47 2004 for InspIRCd by doxygen1.3-rc3