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