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