+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
+ *
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted software; see
+ * the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
#include "inspircd.h"
#include "inspircd_io.h"
#include "inspircd_util.h"
#include "message.h"
#include "mode.h"
#include "xline.h"
+#include "inspstring.h"
+#include "dnsqueue.h"
#ifdef GCC3
#define nspace __gnu_cxx
using namespace std;
extern int MODCOUNT;
-extern vector<Module*> modules;
-extern vector<ircd_module*> factory;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
extern int LogLevel;
extern char ServerName[MAXBUF];
extern int DieDelay;
extern time_t startup_time;
extern int NetBufferSize;
+extern int MaxWhoResults;
extern time_t nb_start;
+extern bool nofork;
+
+extern time_t TIME;
+
extern std::vector<int> fd_reap;
extern std::vector<std::string> module_names;
-extern char bannerBuffer[MAXBUF];
+extern char MyExecutable[1024];
extern int boundPortCount;
extern int portCount;
extern int UDPportCount;
extern FILE *log_file;
+extern ClassVector Classes;
+
+const long duration_m = 60;
+const long duration_h = duration_m * 60;
+const long duration_d = duration_h * 24;
+const long duration_w = duration_d * 7;
+const long duration_y = duration_w * 52;
+
namespace nspace
{
- template<> struct nspace::hash<in_addr>
- {
- size_t operator()(const struct in_addr &a) const
- {
- size_t q;
- memcpy(&q,&a,sizeof(size_t));
- return q;
- }
- };
-
- template<> struct nspace::hash<string>
- {
- size_t operator()(const string &s) const
- {
- char a[MAXBUF];
- static struct hash<const char *> strhash;
- strcpy(a,s.c_str());
- strlower(a);
- return strhash(a);
- }
- };
-}
+#ifdef GCC34
+ template<> struct hash<in_addr>
+#else
+ template<> struct nspace::hash<in_addr>
+#endif
+ {
+ size_t operator()(const struct in_addr &a) const
+ {
+ size_t q;
+ memcpy(&q,&a,sizeof(size_t));
+ return q;
+ }
+ };
+#ifdef GCC34
+ template<> struct hash<string>
+#else
+ template<> struct nspace::hash<string>
+#endif
+ {
+ size_t operator()(const string &s) const
+ {
+ char a[MAXBUF];
+ static struct hash<const char *> strhash;
+ strlcpy(a,s.c_str(),MAXBUF);
+ strlower(a);
+ return strhash(a);
+ }
+ };
+}
struct StrHashComp
bool operator()(const string& s1, const string& s2) const
{
char a[MAXBUF],b[MAXBUF];
- strcpy(a,s1.c_str());
- strcpy(b,s2.c_str());
+ strlcpy(a,s1.c_str(),MAXBUF);
+ strlcpy(b,s2.c_str(),MAXBUF);
return (strcasecmp(a,b) == 0);
}
return;
}
- if (!has_channel(u,Ptr))
+ if (!has_channel(user,Ptr))
{
WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, parameters[0]);
return;
}
-
+
char reason[MAXBUF];
if (pcnt > 2)
{
- strncpy(reason,parameters[2],MAXBUF);
+ strlcpy(reason,parameters[2],MAXBUF);
if (strlen(reason)>MAXKICK)
{
reason[MAXKICK-1] = '\0';
}
else
{
- strcpy(reason,user->nick);
+ strlcpy(reason,user->nick,MAXBUF);
kick_channel(user,u,Ptr,reason);
}
NetSendToAll(buffer);
}
+void handle_loadmodule(char **parameters, int pcnt, userrec *user)
+{
+ if (LoadModule(parameters[0]))
+ {
+ WriteOpers("*** NEW MODULE: %s",parameters[0]);
+ WriteServ(user->fd,"975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"974 %s %s :Failed to load module: %s",user->nick, parameters[0],ModuleError());
+ }
+}
+
+void handle_unloadmodule(char **parameters, int pcnt, userrec *user)
+{
+ if (UnloadModule(parameters[0]))
+ {
+ WriteOpers("*** MODULE UNLOADED: %s",parameters[0]);
+ WriteServ(user->fd,"973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ModuleError());
+ }
+}
void handle_die(char **parameters, int pcnt, userrec *user)
{
void handle_restart(char **parameters, int pcnt, userrec *user)
{
- log(DEBUG,"restart: %s",user->nick);
+ char restart[1024];
+ char *argv[32];
+ log(DEFAULT,"Restart: %s",user->nick);
if (!strcmp(parameters[0],restartpass))
{
- WriteOpers("*** RESTART command from %s!%s@%s, Pretending to restart till this is finished :D",user->nick,user->ident,user->host);
- sleep(DieDelay);
- Exit(ERROR);
- /* Will finish this later when i can be arsed :) */
+ WriteOpers("*** RESTART command from %s!%s@%s, restarting server.",user->nick,user->ident,user->host);
+
+ argv[0] = MyExecutable;
+ argv[1] = "-wait";
+ if (nofork)
+ {
+ argv[2] = "-nofork";
+ }
+ else
+ {
+ argv[2] = NULL;
+ }
+ argv[3] = NULL;
+
+ // close ALL file descriptors
+ send_error("Server restarting.");
+ sleep(1);
+ for (int i = 0; i < 65536; i++)
+ {
+ int on = 0;
+ struct linger linger = { 0 };
+ setsockopt(i, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
+ linger.l_onoff = 1;
+ linger.l_linger = 0;
+ setsockopt(i, SOL_SOCKET, SO_LINGER, (const char*)&linger,sizeof(linger));
+ Blocking(i);
+ close(i);
+ }
+ sleep(5);
+
+ execv(MyExecutable,argv);
+
+ exit(0);
}
else
{
{
userrec *u = Find(parameters[0]);
char killreason[MAXBUF];
-
+
log(DEBUG,"kill: %s %s",parameters[0],parameters[1]);
if (u)
{
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnKill(user,u,parameters[1]));
+ if (MOD_RESULT) {
+ return;
+ }
+
if (strcmp(ServerName,u->server))
{
// remote kill
WriteOpers("*** Remote kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]);
- sprintf(killreason,"[%s] Killed (%s (%s))",ServerName,user->nick,parameters[1]);
+ snprintf(killreason,MAXBUF,"[%s] Killed (%s (%s))",ServerName,user->nick,parameters[1]);
WriteCommonExcept(u,"QUIT :%s",killreason);
// K token must go to ALL servers!!!
char buffer[MAXBUF];
// local kill
WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, ServerName,user->dhost,user->nick,parameters[1]);
WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]);
- sprintf(killreason,"Killed (%s (%s))",user->nick,parameters[1]);
+ snprintf(killreason,MAXBUF,"Killed (%s (%s))",user->nick,parameters[1]);
kill_link(u,killreason);
}
}
WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name);
return;
}
+
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnUserPreInvite(user,u,c));
+ if (MOD_RESULT == 1) {
+ return;
+ }
+
u->InviteTo(c->name);
WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name);
WriteServ(user->fd,"341 %s %s %s",user->nick,u->nick,c->name);
Ptr = FindChan(parameters[0]);
if (Ptr)
{
+ if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->secret))
+ {
+ WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
+ return;
+ }
if (Ptr->topicset)
{
WriteServ(user->fd,"332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
Ptr = FindChan(parameters[0]);
if (Ptr)
{
+ if ((Ptr) && (!has_channel(user,Ptr)))
+ {
+ WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
+ return;
+ }
if ((Ptr->topiclock) && (cstatus(user,Ptr)<STATUS_HOP))
{
WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
}
char topic[MAXBUF];
- strncpy(topic,parameters[1],MAXBUF);
+ strlcpy(topic,parameters[1],MAXBUF);
if (strlen(topic)>MAXTOPIC)
{
topic[MAXTOPIC-1] = '\0';
}
- strcpy(Ptr->topic,topic);
- strcpy(Ptr->setby,user->nick);
- Ptr->topicset = time(NULL);
+ strlcpy(Ptr->topic,topic,MAXBUF);
+ strlcpy(Ptr->setby,user->nick,NICKMAX);
+ Ptr->topicset = TIME;
WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic);
// t token must go to ALL servers!!!
c = FindChan(parameters[0]);
if (c)
{
- /*WriteServ(user->fd,"353 %s = %s :%s", user->nick, c->name,*/
+ if (((c) && (!has_channel(user,c))) && (c->secret))
+ {
+ WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name);
+ return;
+ }
userlist(user,c);
WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name);
}
userrec *dest;
chanrec *chan;
- user->idle_lastmsg = time(NULL);
+ user->idle_lastmsg = TIME;
if (loop_call(handle_privmsg,parameters,pcnt,user,0,pcnt-2,0))
return;
int MOD_RESULT = 0;
- FOREACH_RESULT(OnUserPreMessage(user,chan,TYPE_CHANNEL,std::string(parameters[1])));
+ std::string temp = parameters[1];
+ FOREACH_RESULT(OnUserPreMessage(user,chan,TYPE_CHANNEL,temp));
if (MOD_RESULT) {
return;
}
+ parameters[1] = (char*)temp.c_str();
ChanExceptSender(chan, user, "PRIVMSG %s :%s", chan->name, parameters[1]);
int MOD_RESULT = 0;
- FOREACH_RESULT(OnUserPreMessage(user,dest,TYPE_USER,std::string(parameters[1])));
+ std::string temp = parameters[1];
+ FOREACH_RESULT(OnUserPreMessage(user,dest,TYPE_USER,temp));
if (MOD_RESULT) {
return;
}
+ parameters[1] = (char*)temp.c_str();
userrec *dest;
chanrec *chan;
- user->idle_lastmsg = time(NULL);
+ user->idle_lastmsg = TIME;
if (loop_call(handle_notice,parameters,pcnt,user,0,pcnt-2,0))
return;
}
int MOD_RESULT = 0;
-
- FOREACH_RESULT(OnUserPreNotice(user,chan,TYPE_CHANNEL,std::string(parameters[1])));
+
+ std::string temp = parameters[1];
+ FOREACH_RESULT(OnUserPreNotice(user,chan,TYPE_CHANNEL,temp));
if (MOD_RESULT) {
return;
}
+ parameters[1] = (char*)temp.c_str();
ChanExceptSender(chan, user, "NOTICE %s :%s", chan->name, parameters[1]);
{
int MOD_RESULT = 0;
- FOREACH_RESULT(OnUserPreNotice(user,dest,TYPE_USER,std::string(parameters[1])));
+ std::string temp = parameters[1];
+ FOREACH_RESULT(OnUserPreNotice(user,dest,TYPE_USER,temp));
if (MOD_RESULT) {
return;
}
+ parameters[1] = (char*)temp.c_str();
if (!strcmp(dest->server,user->server))
{
}
}
+void handle_server(char **parameters, int pcnt, userrec *user)
+{
+ WriteServ(user->fd,"666 %s :You cannot identify as a server, you are a USER. IRC Operators informed.",user->nick);
+ WriteOpers("*** WARNING: %s attempted to issue a SERVER command and is registered as a user!",user->nick);
+}
void handle_info(char **parameters, int pcnt, userrec *user)
{
{
WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
}
- if (strchr(dest->modes,'o'))
+ if ((strchr(dest->modes,'o')) && (strcmp(dest->oper,"")))
{
- WriteServ(user->fd,"313 %s %s :is an IRC operator",user->nick, dest->nick);
+ WriteServ(user->fd,"313 %s %s :is %s %s on %s",user->nick, dest->nick,
+ (strchr("aeiou",dest->oper[0]) ? "an" : "a"),dest->oper, Network);
}
FOREACH_MOD OnWhois(user,dest);
if (!strcasecmp(user->server,dest->server))
{
// idle time and signon line can only be sent if youre on the same server (according to RFC)
- WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-time(NULL)), dest->signon);
+ WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon);
}
WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
void handle_who(char **parameters, int pcnt, userrec *user)
{
chanrec* Ptr = NULL;
+ char tmp[10];
/* theres more to do here, but for now just close the socket */
if (pcnt == 1)
{
if (user->chans[0].channel)
{
- Ptr = user->chans[0].channel;
+ int n_list = 0;
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- if ((common_channels(user,i->second)) && (isnick(i->second->nick)))
+ Ptr = i->second->chans[0].channel;
+ // suggested by phidjit and FCS
+ if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
+ // Bug Fix #29
+ strcpy(tmp, "");
+ if (strcmp(i->second->awaymsg, "")) {
+ strncat(tmp, "G", 9);
+ } else {
+ strncat(tmp, "H", 9);
+ }
+ if (strchr(i->second->modes,'o')) { strncat(tmp, "*", 9); }
+ WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
+ n_list++;
+ if (n_list > MaxWhoResults)
+ break;
}
}
}
if (Ptr)
{
- WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name);
+ WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
}
else
{
- WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, user->nick);
+ WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
}
return;
}
{
if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
+ // Fix Bug #29 - Part 2..
+ strcpy(tmp, "");
+ if (strcmp(i->second->awaymsg, "")) {
+ strncat(tmp, "G", 9);
+ } else {
+ strncat(tmp, "H", 9);
+ }
+ if (strchr(i->second->modes,'o')) { strncat(tmp, "*", 9); }
+ strcat(tmp, cmode(i->second, Ptr));
+ WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
}
}
- WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name);
+ WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
}
else
{
userrec* u = Find(parameters[0]);
if (u)
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, u->nick, u->ident, u->dhost, u->server, u->nick, u->fullname);
+ // Bug Fix #29 -- Part 29..
+ strcpy(tmp, "");
+ if (strcmp(u->awaymsg, "")) {
+ strncat(tmp, "G" ,9);
+ } else {
+ strncat(tmp, "H" ,9);
+ }
+ if (strchr(u->modes,'o')) { strncat(tmp, "*" ,9); }
+ WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->nick, u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
}
WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
}
{
if (strchr(i->second->modes,'o'))
{
- WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, user->nick, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
+ // If i were a rich man.. I wouldn't need to me making these bugfixes..
+ // But i'm a poor bastard with nothing better to do.
+ strcpy(tmp, "");
+ if (strcmp(i->second->awaymsg, "")) {
+ strncat(tmp, "G" ,9);
+ } else {
+ strncat(tmp, "H" ,9);
+ }
+
+ WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s",user->nick, user->nick, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
}
}
}
- WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, user->nick);
+ WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
return;
}
}
void handle_rehash(char **parameters, int pcnt, userrec *user)
{
WriteServ(user->fd,"382 %s %s :Rehashing",user->nick,CleanFilename(CONFIG_FILE));
- ReadConfig();
+ ReadConfig(false,user);
FOREACH_MOD OnRehash();
WriteOpers("%s is rehashing config file %s",user->nick,CleanFilename(CONFIG_FILE));
}
else {
WriteServ(user->fd,"NOTICE Auth :No ident response, ident prefixed with ~");
strcpy(user->ident,"~"); /* we arent checking ident... but these days why bother anyway? */
- strncat(user->ident,parameters[0],IDENTMAX);
- strncpy(user->fullname,parameters[3],128);
+ strlcat(user->ident,parameters[0],IDENTMAX);
+ strlcpy(user->fullname,parameters[3],128);
user->registered = (user->registered | 1);
}
}
void handle_userhost(char **parameters, int pcnt, userrec *user)
{
char Return[MAXBUF],junk[MAXBUF];
- sprintf(Return,"302 %s :",user->nick);
+ snprintf(Return,MAXBUF,"302 %s :",user->nick);
for (int i = 0; i < pcnt; i++)
{
userrec *u = Find(parameters[i]);
{
if (strchr(u->modes,'o'))
{
- sprintf(junk,"%s*=+%s@%s ",u->nick,u->ident,u->host);
- strcat(Return,junk);
+ snprintf(junk,MAXBUF,"%s*=+%s@%s ",u->nick,u->ident,u->host);
+ strlcat(Return,junk,MAXBUF);
}
else
{
- sprintf(junk,"%s=+%s@%s ",u->nick,u->ident,u->host);
- strcat(Return,junk);
+ snprintf(junk,MAXBUF,"%s=+%s@%s ",u->nick,u->ident,u->host);
+ strlcat(Return,junk,MAXBUF);
}
}
}
void handle_ison(char **parameters, int pcnt, userrec *user)
{
char Return[MAXBUF];
- sprintf(Return,"303 %s :",user->nick);
+ snprintf(Return,MAXBUF,"303 %s :",user->nick);
for (int i = 0; i < pcnt; i++)
{
userrec *u = Find(parameters[i]);
if (u)
{
- strcat(Return,u->nick);
- strcat(Return," ");
+ strlcat(Return,u->nick,MAXBUF);
+ strlcat(Return," ",MAXBUF);
}
}
WriteServ(user->fd,Return);
{
if (pcnt)
{
- strcpy(user->awaymsg,parameters[0]);
+ strlcpy(user->awaymsg,parameters[0],512);
WriteServ(user->fd,"306 %s :You have been marked as being away",user->nick);
}
else
{
- strcpy(user->awaymsg,"");
+ strlcpy(user->awaymsg,"",512);
WriteServ(user->fd,"305 %s :You are no longer marked as being away",user->nick);
}
}
char b[MAXBUF];
timeinfo = localtime(&rawtime);
- strcpy(b,asctime(timeinfo));
+ strlcpy(b,asctime(timeinfo),MAXBUF);
b[strlen(b)-1] = '\0';
WriteServ(user->fd,"314 %s %s %s %s * :%s",user->nick,i->second->nick,i->second->ident,i->second->dhost,i->second->fullname);
{
Version V = modules[i]->GetVersion();
char modulename[MAXBUF];
- strncpy(modulename,module_names[i].c_str(),256);
+ strlcpy(modulename,module_names[i].c_str(),256);
WriteServ(user->fd,"900 %s :0x%08lx %d.%d.%d.%d %s",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename));
}
}
void handle_stats(char **parameters, int pcnt, userrec *user)
{
+ char Link_ServerName[MAXBUF],Link_IPAddr[MAXBUF],Link_Port[MAXBUF];
if (pcnt != 1)
{
return;
parameters[0][1] = '\0';
}
+
+ if (!strcasecmp(parameters[0],"c"))
+ {
+ for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
+ {
+ ConfValue("link","name",i,Link_ServerName,&config_f);
+ ConfValue("link","ipaddr",i,Link_IPAddr,&config_f);
+ ConfValue("link","port",i,Link_Port,&config_f);
+ WriteServ(user->fd,"213 %s C *@%s * %s %s 0 M",user->nick,Link_IPAddr,Link_ServerName,Link_Port);
+ WriteServ(user->fd,"244 %s H * * %s",user->nick,Link_ServerName);
+ }
+ }
+
+ if (!strcasecmp(parameters[0],"i"))
+ {
+ int idx = 0;
+ for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
+ {
+ WriteServ(user->fd,"215 %s I * * * %d %d %s *",user->nick,MAXCLIENTS,idx,ServerName);
+ idx++;
+ }
+ }
+
+ if (!strcasecmp(parameters[0],"y"))
+ {
+ int idx = 0;
+ for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
+ {
+ WriteServ(user->fd,"218 %s Y %d %d 0 %d %d",user->nick,idx,120,i->flood,i->registration_timeout);
+ idx++;
+ }
+ }
+
+ if (!strcmp(parameters[0],"U"))
+ {
+ for (int i = 0; i < ConfValueEnum("uline",&config_f); i++)
+ {
+ ConfValue("uline","server",i,Link_ServerName,&config_f);
+ WriteServ(user->fd,"248 %s U %s",user->nick,Link_ServerName);
+ }
+ }
+
+ if (!strcmp(parameters[0],"P"))
+ {
+ int idx = 0;
+ for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
+ {
+ if (strchr(i->second->modes,'o'))
+ {
+ WriteServ(user->fd,"249 %s :%s (%s@%s) Idle: %d",user->nick,i->second->nick,i->second->ident,i->second->dhost,(TIME - i->second->idle_lastmsg));
+ idx++;
+ }
+ }
+ WriteServ(user->fd,"249 %s :%d OPER(s)",user->nick,idx);
+ //249 [Brain] :bwoadway-monitor (~wgmon@204.152.186.58) Idle: 18
+ }
+
+ if (!strcmp(parameters[0],"k"))
+ {
+ stats_k(user);
+ }
+
+ if (!strcmp(parameters[0],"g"))
+ {
+ stats_g(user);
+ }
+
+ if (!strcmp(parameters[0],"q"))
+ {
+ stats_q(user);
+ }
+
+ if (!strcmp(parameters[0],"Z"))
+ {
+ stats_z(user);
+ }
+
+ if (!strcmp(parameters[0],"e"))
+ {
+ stats_e(user);
+ }
+
/* stats m (list number of times each command has been used, plus bytecount) */
- if (!strcasecmp(parameters[0],"m"))
+ if (!strcmp(parameters[0],"m"))
{
for (int i = 0; i < cmdlist.size(); i++)
{
}
/* stats z (debug and memory info) */
- if (!strcasecmp(parameters[0],"z"))
+ if (!strcmp(parameters[0],"z"))
{
WriteServ(user->fd,"249 %s :Users(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,clientlist.size(),clientlist.size()*sizeof(userrec),clientlist.bucket_count());
WriteServ(user->fd,"249 %s :Channels(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,chanlist.size(),chanlist.size()*sizeof(chanrec),chanlist.bucket_count());
}
/* stats o */
- if (!strcasecmp(parameters[0],"o"))
+ if (!strcmp(parameters[0],"o"))
{
for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
{
}
/* stats l (show user I/O stats) */
- if (!strcasecmp(parameters[0],"l"))
+ if (!strcmp(parameters[0],"l"))
{
WriteServ(user->fd,"211 %s :server:port nick bytes_in cmds_in bytes_out cmds_out",user->nick);
for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
}
/* stats u (show server uptime) */
- if (!strcasecmp(parameters[0],"u"))
+ if (!strcmp(parameters[0],"u"))
{
time_t current_time = 0;
- current_time = time(NULL);
+ current_time = TIME;
time_t server_uptime = current_time - startup_time;
struct tm* stime;
stime = gmtime(&server_uptime);
snprintf(line,MAXBUF,"006 %s :%s",user->nick,ServerName);
while (strlen(line) < 50)
strcat(line," ");
- WriteServ(user->fd,"%s%d (%.2f%%)",line,local_count(),(float)(((float)local_count()/(float)usercnt())*100));
+ WriteServ(user->fd,"%s%d (%.2f%%)",line,local_count(),(float)(((float)local_count()/(float)registered_usercount())*100));
for (int j = 0; j < 32; j++)
{
if (me[j] != NULL)
snprintf(line,MAXBUF,"006 %s :%c-%s",user->nick,islast(me[j]->connectors[k].GetServerName().c_str()),me[j]->connectors[k].GetServerName().c_str());
while (strlen(line) < 50)
strcat(line," ");
- WriteServ(user->fd,"%s%d (%.2f%%)",line,map_count(me[j]->connectors[k].GetServerName().c_str()),(float)(((float)map_count(me[j]->connectors[k].GetServerName().c_str())/(float)usercnt())*100));
+ WriteServ(user->fd,"%s%d (%.2f%%)",line,map_count(me[j]->connectors[k].GetServerName().c_str()),(float)(((float)map_count(me[j]->connectors[k].GetServerName().c_str())/(float)registered_usercount())*100));
}
}
}
char Password[MAXBUF];
char OperType[MAXBUF];
char TypeName[MAXBUF];
- char Hostname[MAXBUF];
+ char HostName[MAXBUF];
+ char TheHost[MAXBUF];
int i,j;
+ bool found = false;
+ bool fail2 = false;
+ char global[MAXBUF];
+
+ snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
{
ConfValue("oper","name",i,LoginName,&config_f);
ConfValue("oper","password",i,Password,&config_f);
- if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1])))
+ ConfValue("oper","type",i,OperType,&config_f);
+ ConfValue("oper","host",i,HostName,&config_f);
+ if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1])) && (match(TheHost,HostName)))
{
- /* correct oper credentials */
- ConfValue("oper","type",i,OperType,&config_f);
- WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
- WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
- WriteServ(user->fd,"MODE %s :+o",user->nick);
- char global[MAXBUF];
- snprintf(global,MAXBUF,"M %s +o",user->nick);
- NetSendToAll(global);
+ fail2 = true;
for (j =0; j < ConfValueEnum("type",&config_f); j++)
{
ConfValue("type","name",j,TypeName,&config_f);
+
if (!strcmp(TypeName,OperType))
{
/* found this oper's opertype */
- ConfValue("type","host",j,Hostname,&config_f);
- ChangeDisplayedHost(user,Hostname);
+ snprintf(global,MAXBUF,"| %s %s",user->nick,TypeName);
+ NetSendToAll(global);
+ ConfValue("type","host",j,HostName,&config_f);
+ ChangeDisplayedHost(user,HostName);
+ strlcpy(user->oper,TypeName,NICKMAX);
+ found = true;
+ fail2 = false;
+ break;
}
}
- if (!strchr(user->modes,'o'))
- {
- strcat(user->modes,"o");
- }
+ }
+ if (found)
+ break;
+ }
+ if (found)
+ {
+ /* correct oper credentials */
+ WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
+ WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
+ if (!strchr(user->modes,'o'))
+ {
+ strcat(user->modes,"o");
+ WriteServ(user->fd,"MODE %s :+o",user->nick);
+ snprintf(global,MAXBUF,"M %s +o",user->nick);
+ NetSendToAll(global);
FOREACH_MOD OnOper(user);
- return;
+ log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
+ }
+ }
+ else
+ {
+ if (!fail2)
+ {
+ WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
+ WriteOpers("*** WARNING! qFailed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
+ log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
+ }
+ else
+ {
+ WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
+ WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
+ log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);
}
}
- /* no such oper */
- WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
- WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
+ return;
}
void handle_nick(char **parameters, int pcnt, userrec *user)
char buffer[MAXBUF];
snprintf(buffer,MAXBUF,"n %s %s",user->nick,parameters[0]);
NetSendToAll(buffer);
-
}
+ char oldnick[NICKMAX];
+ strlcpy(oldnick,user->nick,NICKMAX);
+
/* change the nick of the user in the users_hash */
user = ReHashNick(user->nick, parameters[0]);
/* actually change the nick within the record */
if (!user) return;
if (!user->nick) return;
- strncpy(user->nick, parameters[0],NICKMAX);
+ strlcpy(user->nick, parameters[0],NICKMAX);
log(DEBUG,"new nick set: %s",user->nick);
if (user->registered < 3)
+ {
user->registered = (user->registered | 2);
+ // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
+ // and unless we're lucky we'll get a duff one later on.
+ user->dns_done = (!lookup_dns(user->nick));
+ if (user->dns_done)
+ log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+ }
if (user->registered == 3)
{
/* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
ConnectUser(user);
}
- log(DEBUG,"exit nickchange: %s",user->nick);
+ if (user->registered == 7)
+ {
+ FOREACH_MOD OnUserPostNick(user,oldnick);
+ }
}
if ((c) && (u))
{
WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic);
- strncpy(c->topic,topic,MAXTOPIC);
- strncpy(c->setby,u->nick,NICKMAX);
- c->topicset = time(NULL);
+ strlcpy(c->topic,topic,MAXTOPIC);
+ strlcpy(c->setby,u->nick,NICKMAX);
+ c->topicset = TIME;
}
}
if (TS <= c->topicset)
{
WriteChannelLocal(c,NULL,"TOPIC %s :%s",c->name,topic);
- strncpy(c->topic,topic,MAXTOPIC);
- strncpy(c->setby,setby,NICKMAX);
+ strlcpy(c->topic,topic,MAXTOPIC);
+ strlcpy(c->setby,setby,NICKMAX);
}
}
}
{
char* pars[128];
char original[MAXBUF],target[MAXBUF];
- strncpy(original,params,MAXBUF);
+ strlcpy(original,params,MAXBUF);
int index = 0;
char* parameter = strtok(params," ");
- strncpy(target,parameter,MAXBUF);
+ strlcpy(target,parameter,MAXBUF);
while (parameter)
{
if (parameter[0] == ':')
// m blah #chatspike +b *!test@*4
char* pars[128];
char original[MAXBUF];
- strncpy(original,params,MAXBUF);
+ strlcpy(original,params,MAXBUF);
if (!strchr(params,' '))
{
user = ReHashNick(user->nick, newnick);
if (!user) return;
if (!user->nick) return;
- strncpy(user->nick, newnick,NICKMAX);
+ strlcpy(user->nick, newnick,NICKMAX);
log(DEBUG,"new nick set: %s",user->nick);
}
}
ircd_connector s;
s.SetState(STATE_DISCONNECTED);
s.SetServerName(params);
+
+ for (int j = 0; j < 32; j++)
+ {
+ if (me[j] != NULL)
+ {
+ for (int k = 0; k < me[j]->connectors.size(); k++)
+ {
+ if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),params))
+ {
+ // dont allow a server to be added twice
+ log(DEBUG,"ULined server %s already in the map!",params);
+ return;
+ }
+ }
+ }
+ }
+
source->connectors.push_back(s);
+ WriteOpers("Non-Mesh server %s has joined the network",params);
}
void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
char* dhost = strtok(NULL," ");
char* ident = strtok(NULL," ");
char* modes = strtok(NULL," ");
+ char* ipaddr = strtok(NULL," ");
char* server = strtok(NULL," :");
char* gecos = strtok(NULL,"\r\n");
gecos++;
// routines know to route any messages to this record away to whatever server
// theyre on.
clientlist[nick]->fd = -1;
- strncpy(clientlist[nick]->nick, nick,NICKMAX);
- strncpy(clientlist[nick]->host, host,160);
- strncpy(clientlist[nick]->dhost, dhost,160);
- strncpy(clientlist[nick]->server, server,256);
- strncpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for tilde
- strncpy(clientlist[nick]->fullname, gecos,128);
+ strlcpy(clientlist[nick]->nick, nick,NICKMAX);
+ strlcpy(clientlist[nick]->host, host,160);
+ strlcpy(clientlist[nick]->dhost, dhost,160);
+ strlcpy(clientlist[nick]->server, server,256);
+ strlcpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for tilde
+ strlcpy(clientlist[nick]->fullname, gecos,128);
clientlist[nick]->signon = TS;
clientlist[nick]->nping = 0; // this is ignored for a remote user anyway.
clientlist[nick]->lastping = 1;
clientlist[nick]->port = 0; // so is this...
clientlist[nick]->registered = 7; // this however we need to set for them to receive messages and appear online
- clientlist[nick]->idle_lastmsg = time(NULL); // this is unrealiable and wont actually be used locally
+ clientlist[nick]->idle_lastmsg = TIME; // this is unrealiable and wont actually be used locally
for (int i = 0; i < MAXCHANS; i++)
{
clientlist[nick]->chans[i].channel = NULL;
void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
{
- long tdiff = time(NULL) - atoi(params);
+ long tdiff = TIME - atoi(params);
if (tdiff)
WriteOpers("TS split for %s -> %s: %d",source->name,reply->name,tdiff);
}
userrec* user = Find(nick);
if (user)
- strncpy(user->fullname,gecos,MAXBUF);
+ strlcpy(user->fullname,gecos,MAXBUF);
}
void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
userrec* user = Find(nick);
if (user)
- strncpy(user->dhost,host,160);
+ strlcpy(user->dhost,host,160);
}
void handle_plus(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
long authcookie;
+void handle_hash(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ log(DEBUG,"Adding G-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ char* create_time = strtok(NULL," ");
+ char* duration = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ add_gline(atoi(duration),who,reason,mask);
+ // we must update the creation time on this gline
+ // now that we've added it, or it wont expire at the right time.
+ gline_set_creation_time(mask,atoi(create_time));
+ if (!atoi(duration))
+ {
+ WriteOpers("*** %s Added permenant G-Line on %s.",who,mask);
+ }
+ else
+ {
+ WriteOpers("*** %s Added timed G-Line on %s to expire in %d seconds.",who,mask,atoi(duration));
+ }
+ apply_lines();
+}
+
+void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Removing G-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ if (mask)
+ {
+ if (del_gline(mask))
+ {
+ if (who)
+ {
+ WriteOpers("*** %s Removed G-line on %s.",who,mask);
+ }
+ }
+ }
+}
+
+void handle_add_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ // { <mask> <who-set-it> <time-set> <duration> :<reason>
+ log(DEBUG,"Adding Q-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ char* create_time = strtok(NULL," ");
+ char* duration = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ add_qline(atoi(duration),who,reason,mask);
+ // we must update the creation time on this gline
+ // now that we've added it, or it wont expire at the right time.
+ qline_set_creation_time(mask,atoi(create_time));
+ qline_make_global(mask);
+ if (!atoi(duration))
+ {
+ WriteOpers("*** %s Added permenant Q-Line on %s.",who,mask);
+ }
+ else
+ {
+ WriteOpers("*** %s Added timed Q-Line on %s to expire in %d seconds.",who,mask,atoi(duration));
+ }
+ apply_lines();
+}
+
+void handle_del_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Removing Q-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ if (mask)
+ {
+ if (del_qline(mask))
+ {
+ if (who)
+ {
+ WriteOpers("*** %s Removed Q-line on %s.",who,mask);
+ }
+ }
+ }
+}
+
+void handle_add_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ // } <mask> <who-set-it> <time-set> <duration> :<reason>
+ log(DEBUG,"Adding Z-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ char* create_time = strtok(NULL," ");
+ char* duration = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ add_zline(atoi(duration),who,reason,mask);
+ // we must update the creation time on this gline
+ // now that we've added it, or it wont expire at the right time.
+ zline_set_creation_time(mask,atoi(create_time));
+ zline_make_global(mask);
+ if (!atoi(duration))
+ {
+ WriteOpers("*** %s Added permenant Z-Line on %s.",who,mask);
+ }
+ else
+ {
+ WriteOpers("*** %s Added timed Z-Line on %s to expire in %d seconds.",who,mask,atoi(duration));
+ }
+ apply_lines();
+}
+
+void handle_del_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Removing Z-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ if (mask)
+ {
+ if (del_zline(mask))
+ {
+ if (who)
+ {
+ WriteOpers("*** %s Removed Q-line on %s.",who,mask);
+ }
+ }
+ }
+}
+
+void handle_pipe(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ char* nick = strtok(params," ");
+ char* type = strtok(params," ");
+ userrec* u = Find(nick);
+ if (u)
+ {
+ strlcpy(u->oper,type,NICKMAX);
+ }
+}
+
void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host,char* ipaddr,int port)
{
// Y <TS>
// start netburst
case 'Y':
- nb_start = time(NULL);
+ nb_start = TIME;
WriteOpers("Server %s is starting netburst.",tcp_host);
// now broadcast this new servers address out to all servers that are linked to us,
// except the newcomer. They'll all attempt to connect back to it.
case '@':
handle_AT(token,params,source,reply,tcp_host);
break;
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ // add gline
+ case '#':
+ handle_hash(token,params,source,reply,tcp_host);
+ break;
+ // . <mask> <who>
+ // remove gline
+ case '.':
+ handle_dot(token,params,source,reply,tcp_host);
+ break;
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ // add gline
+ case '{':
+ handle_add_sqline(token,params,source,reply,tcp_host);
+ break;
+ // . <mask> <who>
+ // remove gline
+ case '[':
+ handle_del_sqline(token,params,source,reply,tcp_host);
+ break;
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ // add gline
+ case '}':
+ handle_add_szline(token,params,source,reply,tcp_host);
+ break;
+ // . <mask> <who>
+ // remove gline
+ case ']':
+ handle_del_szline(token,params,source,reply,tcp_host);
+ break;
+ // | <nick> <opertype>
+ // set opertype
+ case '|':
+ handle_pipe(token,params,source,reply,tcp_host);
+ break;
// F <TS>
// end netburst
case 'F':
- WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,time(NULL)-nb_start);
+ WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start);
handle_F(token,params,source,reply,tcp_host);
nb_start = 0;
// tell all the other servers to use this authcookie to connect back again
snprintf(buffer,MAXBUF,"+ %s %s %d %d",tcp_host,ipaddr,port,authcookie);
NetSendToAllExcept(tcp_host,buffer);
break;
+ case '/':
+ WriteOpers("Server %s is IRCServices-based server (assumes-SVSMODE) - Nickname Services: %s",tcp_host,params);
+ strlcpy(source->nickserv,params,NICKMAX);
+ break;
// F <TS>
// end netburst with no mesh creation
case 'f':
- WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,time(NULL)-nb_start);
+ WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start);
handle_F(token,params,source,reply,tcp_host);
nb_start = 0;
// tell everyone else about the new server name so they just add it in the disconnected
char data[MAXBUF];
char source[MAXBUF];
char command[MAXBUF];
- strcpy(data,udp_msg);
- strcpy(source,src);
- strcpy(command,comd);
+ strlcpy(data,udp_msg,512);
+ strlcpy(source,src,MAXBUF);
+ strlcpy(command,comd,MAXBUF);
udp_msg = old;
// unused numeric:
{
token = '*';
}
+ if (!strcmp(command,"432"))
+ {
+ token = '*';
+ }
if (!strcmp(command,"NOTICE"))
{
snprintf(udp_msg,MAXBUF,"V %s %s",source,data);
}
if (!strcmp(command,"SVSMODE"))
{
- snprintf(udp_msg,MAXBUF,"M %s",data);
+ snprintf(udp_msg,MAXBUF,"m %s %s",source,data);
log(DEBUG,"Rewrote SVSMODE from services to: '%s'",udp_msg);
token = udp_msg[0];
}
if (!strcmp(command,"SVS2MODE"))
{
- snprintf(udp_msg,MAXBUF,"M %s",data);
- log(DEBUG,"Rewrote SVSMODE from services to: '%s'",udp_msg);
+ snprintf(udp_msg,MAXBUF,"m %s %s",source,data);
+ log(DEBUG,"Rewrote SVS2MODE from services to: '%s'",udp_msg);
token = udp_msg[0];
}
// todo: this wont work without u:lines
log(DEBUG,"Rewrote KICK from services to: '%s'",udp_msg);
token = udp_msg[0];
}
+ if (!strcmp(command,"KILL"))
+ {
+ snprintf(udp_msg,MAXBUF,"K %s %s",source,data);
+ log(DEBUG,"Rewrote KILL from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
if (!strcmp(command,"SVSJOIN"))
{
snprintf(udp_msg,MAXBUF,"J %s",data);
char finalparam[1024];
strcpy(finalparam," :xxxx");
if (strstr(udp_msg," :")) {
- strncpy(finalparam,strstr(udp_msg," :"),1024);
+ strlcpy(finalparam,strstr(udp_msg," :"),1024);
}
{
WriteOpers("CONNECT aborted: Server %s already exists from %s",servername,ServerName);
char buffer[MAXBUF];
- sprintf(buffer,"E :Server %s already exists!",servername);
+ snprintf(buffer,MAXBUF,"E :Server %s already exists!",servername);
serv->SendPacket(buffer,tcp_host);
RemoveServer(tcp_host);
return;
ConfValue("link","sendpass",i,Link_SendPass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
- if (!strcasecmp(Link_ServerName,servername))
+ if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password)))
{
// we have a matching link line -
// send a 'diminutive' server message back...
ConfValue("link","sendpass",i,Link_SendPass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
- if (!strcasecmp(Link_ServerName,servername))
+ if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password)))
{
// matching link at this end too, we're all done!
// at this point we must begin key exchange and insert this
sprintf(buffer,"X 0");
serv->SendPacket(buffer,servername);
DoSync(me[j],servername);
- NetSendMyRoutingTable();
- sprintf(buffer,"H %s",servername);
+ snprintf(buffer,MAXBUF,"H %s",servername);
NetSendToAllExcept(servername,buffer);
+ WriteOpers("Non-Mesh server %s has joined the network",servername);
+ log(DEBUG,"******** SENDING MY ROUTING TABLE! *******");
+ NetSendMyRoutingTable();
return;
}
}
}
}
+long duration(char* str)
+{
+ char n_field[MAXBUF];
+ long total = 0;
+ char* str_end = str + strlen(str);
+ n_field[0] = 0;
+
+ for (char* i = str; i < str_end; i++)
+ {
+ // if we have digits, build up a string for the value in n_field,
+ // up to 10 digits in size.
+ if ((*i >= '0') && (*i <= '9'))
+ {
+ strlcat(n_field,i,10);
+ }
+ else
+ {
+ // we dont have a digit, check for numeric tokens
+ switch (tolower(*i))
+ {
+ case 's':
+ total += atoi(n_field);
+ break;
+
+ case 'm':
+ total += (atoi(n_field)*duration_m);
+ break;
+
+ case 'h':
+ total += (atoi(n_field)*duration_h);
+ break;
+
+ case 'd':
+ total += (atoi(n_field)*duration_d);
+ break;
+
+ case 'w':
+ total += (atoi(n_field)*duration_w);
+ break;
+
+ case 'y':
+ total += (atoi(n_field)*duration_y);
+ break;
+ }
+ n_field[0] = 0;
+ }
+ }
+ // add trailing seconds
+ total += atoi(n_field);
+
+ return total;
+}
+
void handle_kline(char **parameters, int pcnt, userrec *user)
{
+ if (pcnt >= 3)
+ {
+ add_kline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant K-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed K-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_kline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed K-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
+}
+
+void handle_eline(char **parameters, int pcnt, userrec *user)
+{
+ if (pcnt >= 3)
+ {
+ add_eline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant E-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed E-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_eline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed E-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** E-Line %s not found in list, try /stats e.",user->nick,parameters[0]);
+ }
+ }
+ // no need to apply the lines for an eline
}
void handle_gline(char **parameters, int pcnt, userrec *user)
{
+ char netdata[MAXBUF];
+ if (pcnt >= 3)
+ {
+ add_gline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ snprintf(netdata,MAXBUF,"# %s %s %ld %ld :%s",parameters[0],user->nick,TIME,duration(parameters[1]),parameters[2]);
+ NetSendToAll(netdata);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant G-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed G-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_gline(parameters[0]))
+ {
+ // . <mask> <who-removed-it>
+ snprintf(netdata,MAXBUF,". %s %s",parameters[0],user->nick);
+ WriteOpers("*** %s Removed G-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** G-Line %s not found in list, try /stats g.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
}
void handle_zline(char **parameters, int pcnt, userrec *user)
{
+ if (pcnt >= 3)
+ {
+ add_zline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant Z-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed Z-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_zline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed Z-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
}
void handle_qline(char **parameters, int pcnt, userrec *user)
{
+ if (pcnt >= 3)
+ {
+ add_qline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant Q-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed Q-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_qline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed Q-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** Q-Line %s not found in list, try /stats k.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
}