November Overhaul

This commit is contained in:
joonicks 2025-11-20 14:55:08 +01:00
parent 63274131e0
commit b01bdf7082
40 changed files with 1104 additions and 1185 deletions

View File

@ -1,8 +1,11 @@
3.5(.dev) --
* Changed: Apparently Eggheads changed the uptime protocol without telling anyone.
* Fixed: Channel stats would be desynched after bot being kicked and rejoining.
* Added: New debug command: INJECT <rest>. Inject data as if it came from the server itself.
* Fixed: prot_action enforced protection levels above SET PROT.
* Fixed: Apparently Eggheads changed the uptime protocol without telling anyone.
* Changed: Branchless more compact base64 conversion for RANDSRC in send_spy().
* Changed: New botnet connection announced on spy sstatus instead of spy botnet.
* Changed: New botnet connection announced on spy status instead of spy botnet.
* Changed: Adjusted output of INFO command.
* Changed: Rewrote how SERVERGROUP works. Config files might need changes.
* Removed: SERVERGROUP command.
@ -10,11 +13,12 @@
* Removed: IDWRAP code. It was my personal thing.
* Changed: on_msg now matches commands using a hash function instead
of iterating through the list of commands using strcasecmp.
* Changed: Bumped version because of undocumented changes.
* Added: More help files; BOOT, DEBUG, NOTE, READ
* Changed: Updated several helpfiles.
* Changed: Table of builtin commands taken out of gencmd.c and put into
commands.h for easier editing.
* Added: ESAY $load to show system CPU loadavg (HOSTINFO feature).
* Changed: Bumped version because of undocumented changes.
3.2 -- October 21, 2025.

View File

@ -2,14 +2,15 @@
Spy on a certain source of messages. When you join DCC chat,
the STATUS source is added by default as a spy source for you.
If no arguments are given, the current list of active spy
channels is shown. Output is not line buffered and can cause
excess flood if not careful.
channels is shown.
(sources)
STATUS Status messages.
MESSAGE Pivate messages that the bot receives.
RAWIRC Lines received from irc server before processing.
RANDSRC Collect randomness from IRC activity, best saved to a file.
SYSMON Hostinfo events.
URL Captured URLs.
guid: Messages from a bot specified by guid.
botnick: Messages from a bot specified by nick.
channel Activities on the specified channel.

View File

@ -1,6 +1,6 @@
#
# EnergyMech, IRC bot software
# Copyright (c) 1997-2021 proton
# Copyright (c) 1997-2025 proton
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -27,6 +27,7 @@ LPROF = @lprof@
LIBS = @libflags@
PIPEFLAG = @pipeflag@
GDBFLAG = @gdbflag@
FLTO_FLAG = @flto_flag@
WARNFLAG = @W_FLAGS@
OPTIMIZE = @O_FLAGS@
PYINCLUDE = @PYINCLUDE@
@ -35,7 +36,7 @@ I_PERL = @I_PERL@
L_PERL = @L_PERL@
CFLAGS = @CFLAGS@
LFLAGS = $(PIPEFLAG) $(GDBFLAG)
LFLAGS = $(PIPEFLAG) $(GDBFLAG) $(FLTO_FLAG)
CC = @CC@
MV = mv -f
@ -127,8 +128,8 @@ test: $(TESTFILES)
./calctest
./safepathtest
aliastest: alias.c githash.h mcmd.h string.o
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o aliastest $< string.o $(LPROF) $(LIBS) -DTEST
aliastest: alias.c githash.h mcmd.h string.o function.o
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o aliastest $< string.o function.o $(LPROF) $(LIBS) -DTEST
calctest: calc.c githash.h mcmd.h string.o
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o calctest $< string.o $(LPROF) $(LIBS) -DTEST

View File

@ -63,7 +63,7 @@ char *cipher(char *arg)
static char res[40];
uint32_t B1a,B2a,B3a,B4a;
uint32_t B1b,B2b,B3b,B4b;
uchar *ptr;
unsigned char *ptr;
uint32_t R1;
int i;
@ -72,7 +72,7 @@ char *cipher(char *arg)
B1a = B2a = B3a = B4a = 0;
B1b = B2b = B3b = B4b = 0;
ptr = arg;
ptr = (unsigned char *)arg;
while(*ptr)
{
@ -271,10 +271,10 @@ void change_authnick(char *nuh, char *newnuh)
}
}
LS User *au_user;
LS const char *au_userhost;
LS const char *au_channel;
LS int au_access;
User *au_user;
const char *au_userhost;
const char *au_channel;
int au_access;
void aucheck(User *user)
{
@ -454,7 +454,6 @@ See also: passwd, setpass
*/
void do_auth(COMMAND_ARGS)
{
Auth *au;
#ifdef BOTNET
char *checksum;
#endif /* BOTNET */

View File

@ -128,7 +128,6 @@ new_blank:
op = 0;
para = 0;
op_or_num:
if (*input == '+')
{
op = OPER_ADD;
@ -204,9 +203,11 @@ iterate:
para = -1;
for(i=0;i<=cop_count;i++)
{
#ifdef TEST
if (cop[i].paralevel >= 0)
printf("number %lu, operation %i, decimals %i, paralevel %i\n",
cop[i].number,cop[i].operation,cop[i].decimals,cop[i].paralevel);
#endif /* TEST */
if (cop[i].paralevel >= para)
para = cop[i].paralevel;
}
@ -281,7 +282,7 @@ int bas2int(const char *src, int base)
char ch;
errno = EINVAL;
n = 0;
v = n = 0;
while(*src)
{
@ -291,22 +292,20 @@ int bas2int(const char *src, int base)
switch(base)
{
case 16:
ch = tolowertab[(uchar)*src];
if (*src <= '9')
v = *src - '0';
else
{
ch = tolowertab[(uchar)*src];
if (ch >= 'a' && ch <= 'f')
v = ch - 'a' + 10;
else
return(-1);
}
break;
case 8:
if (*src >= '8')
return(-1);
v = *src - '0';
break;
case 2:
if (*src >= '2')
if(*src >= ('0'+base))
return(-1);
v = *src - '0';
}
@ -329,7 +328,6 @@ void do_calc(COMMAND_ARGS)
{
char prep[MSGLEN];
CalcOp cop[MAX_COP];
int cp = 0;
memset(&cop,0,sizeof(cop));
@ -345,22 +343,22 @@ void do_calc(COMMAND_ARGS)
void do_convert(COMMAND_ARGS)
{
char output[200];
char *ops, *srcnum, *dst;
char *srcnum, *dst;
char inval, outval;
int num, todec, tochr, tooct, tohex, tobin;
ops = chop(&rest);
srcnum = chop(&rest);
if (ops == NULL || srcnum == NULL)
if (cx.rest_end < rest+2)
return;
todec = tochr = tooct = tohex = tobin = 0;
inval = rest[0];
outval = rest[1];
rest += 2;
srcnum = chop(&rest);
switch(ops[1])
todec = tochr = tooct = tohex = tobin = (outval == ' ' || outval == 0) ? 0 : 1;
switch(outval)
{
case 0:
todec = tochr = tooct = tohex = tobin = 1;
break;
case 'b':
tobin = 1;
break;
@ -375,19 +373,12 @@ void do_convert(COMMAND_ARGS)
break;
}
num = 0;
errno = EINVAL;
switch(*ops)
switch(inval)
{
case 'b':
errno = 0;
for(num=0;*srcnum;)
{
num = num << 1;
if (*srcnum != '0' && *srcnum != '1')
return;
num += *srcnum - '0';
srcnum++;
}
num = bas2int(srcnum,2);
break;
case 'c':
num = srcnum[0];
@ -396,8 +387,7 @@ void do_convert(COMMAND_ARGS)
errno = tochr = 0;
break;
case 'd':
num = asc2int(srcnum);
/*todec = 0;*/
num = asc2int(srcnum); /* sets errno */
break;
case 'h':
if (*srcnum == '$')
@ -405,11 +395,9 @@ void do_convert(COMMAND_ARGS)
if (*srcnum == '0' && srcnum[1] == 'x')
srcnum += 2;
num = bas2int(srcnum,16);
/*tohex = 1;*/
break;
case 'o':
num = bas2int(srcnum,8);
/* tooct = 0;*/
break;
}
if (errno)

View File

@ -209,9 +209,9 @@ int reverse_mode(char *from, Chan *chan, int m, int s)
mode = (char)m;
sign = (char)s;
if (STRCHR(ptr,mode) && (sign == '+'))
if (stringchr(ptr,mode) && (sign == '+'))
return(FALSE);
if (!STRCHR(ptr,mode) && (sign == '-'))
if (!stringchr(ptr,mode) && (sign == '-'))
return(FALSE);
if (get_useraccess(from,chan->name) >= ASSTLEVEL)
{
@ -270,6 +270,12 @@ void chan_modestr(Chan *chan, char *dest)
}
}
char *get_nuh(const ChanUser *user)
{
sprintf(nuh_buf,"%s!%s",user->nick,user->userhost);
return(nuh_buf);
}
char *find_nuh(char *nick)
{
Chan *chan;
@ -283,6 +289,36 @@ char *find_nuh(char *nick)
return(NULL);
}
/*
* NOTE! beware of conflicts in the use of nuh_buf, its also used by find_nuh()
*/
char *nick2uh(char *from, char *userhost)
{
if (stringchr(userhost,'!') && stringchr(userhost,'@'))
{
stringcpy(nuh_buf,userhost);
}
else
if (!stringchr(userhost,'!') && !stringchr(userhost,'@'))
{
/* find_nuh() stores nickuserhost in nuh_buf */
if (find_nuh(userhost) == NULL)
{
if (from)
to_user(from,"No information found for %s",userhost);
return(NULL);
}
}
else
{
stringcpy(nuh_buf,"*!");
if (!stringchr(userhost,'@'))
stringcat(nuh_buf,"*@");
stringcat(nuh_buf,userhost);
}
return(nuh_buf);
}
Ban *make_ban(Ban **banlist, char *from, char *banmask, time_t when)
{
Ban *new;
@ -361,7 +397,7 @@ void channel_massmode(const Chan *chan, char *pattern, int filtmode, char mode,
if ((pat = chop(&pattern)) == NULL)
return;
ispat = (STRCHR(pat,'*')) ? TRUE : FALSE;
ispat = (stringchr(pat,'*')) ? TRUE : FALSE;
maxmode = current->setting[INT_MODES].int_var;
mal = chan->setting[INT_MAL].int_var;
*burst = 0;
@ -378,7 +414,7 @@ void channel_massmode(const Chan *chan, char *pattern, int filtmode, char mode,
s = deopstring;
while(*s) s++;
debug("(...) deopstring "mx_pfmt" uh "mx_pfmt" ("mx_pfmt")\n",(mx_ptr)deopstring,(mx_ptr)uh,(mx_ptr)s);
s = STRCHR(deopstring,0);
s = stringchr(deopstring,0);
debug("(...) deopstring "mx_pfmt" uh "mx_pfmt" ("mx_pfmt")\n",(mx_ptr)deopstring,(mx_ptr)uh,(mx_ptr)s);
}
#endif /* DEBUG */
@ -455,7 +491,7 @@ void channel_massmode(const Chan *chan, char *pattern, int filtmode, char mode,
cu = cu->next;
if (!cu && (pat = chop(&pattern)))
{
ispat = (STRCHR(pat,'*')) ? TRUE : FALSE;
ispat = (stringchr(pat,'*')) ? TRUE : FALSE;
cu = chan->users;
}
}
@ -663,12 +699,6 @@ void purge_chanusers(Chan *chan)
remove_chanuser(chan,chan->users->nick);
}
char *get_nuh(const ChanUser *user)
{
sprintf(nuh_buf,"%s!%s",user->nick,user->userhost);
return(nuh_buf);
}
/*
*
* commands associated with channels
@ -975,7 +1005,7 @@ void do_cchan(COMMAND_ARGS)
to_user(from,ERR_CHAN,channel);
return;
}
to_user(from,"Current channel: %s",
to_user_q(from,"Current channel: %s",
(current->activechan) ? current->activechan->name : TEXT_NONE);
}

View File

@ -169,39 +169,39 @@ struct CommandList
/*
* Level 60
*/
{ 0, "SHOWIDLE", "do_showidle", 60 | CCPW | CAXS | DCC | ACCHAN },
{ 0, "USERLIST", "do_userlist", 60 | CCPW | DCC },
{ 0, "SHOWIDLE", "do_showidle", 60 | CAXS | DCC | ACCHAN },
{ 0, "USERLIST", "do_userlist", 60 | DCC },
#ifdef CTCP
{ 0, "CTCP", "do_ping_ctcp", 60 | CCPW | CARGS },
{ 0, "PING", "do_ping_ctcp", 60 | CCPW | CARGS },
{ 0, "CTCP", "do_ping_ctcp", 60 | CARGS },
{ 0, "PING", "do_ping_ctcp", 60 | CARGS },
#endif /* CTCP */
/*
* Level 70 == JOINLEVEL
*/
{ 0, "CYCLE", "do_cycle", 70 | CCPW | CAXS | ACCHAN },
{ 0, "FORGET", "do_forget", 70 | CCPW | CAXS },
{ 0, "JOIN", "do_join", 70 | CCPW | CARGS },
{ 0, "KS", "do_kicksay", 70 | CCPW | REDIR | LBUF },
{ 0, "PART", "do_part", 70 | CCPW | CAXS | ACCHAN },
{ 0, "RKS", "do_rkicksay", 70 | CCPW | CARGS },
{ 0, "SETPASS", "do_setpass", 70 | CCPW | NOPUB | CARGS },
{ 0, "CYCLE", "do_cycle", 70 | CAXS | ACCHAN },
{ 0, "FORGET", "do_forget", 70 | CAXS },
{ 0, "JOIN", "do_join", 70 | CARGS },
{ 0, "KS", "do_kicksay", 70 | REDIR | LBUF },
{ 0, "PART", "do_part", 70 | CAXS | ACCHAN },
{ 0, "RKS", "do_rkicksay", 70 | CARGS },
{ 0, "SETPASS", "do_setpass", 70 | NOPUB | CARGS },
#ifdef NOTIFY
{ 0, "NOTIFY", "do_notify", 70 | CCPW | DCC | GAXS | REDIR | LBUF },
{ 0, "NOTIFY", "do_notify", 70 | DCC | GAXS | REDIR | LBUF },
#endif /* NOTIFY */
/*
* Level 80 == ASSTLEVEL
*/
{ 0, "AWAY", "do_away", 80 | CCPW | GAXS },
{ 0, "BOOT", "do_boot", 80 | CCPW | GAXS | CARGS },
{ 0, "AWAY", "do_away", 80 | GAXS },
{ 0, "BOOT", "do_boot", 80 | GAXS | CARGS },
#if defined(BOTNET) && defined(REDIRECT)
{ 0, "CMD", "do_cmd", 80 | CCPW | CARGS },
{ 0, "CMD", "do_cmd", 80 | CARGS },
#endif /* BOTNET && REDIRECT */
{ 0, "CQ", "do_clearqueue", 80 | CCPW | GAXS },
{ 0, "LAST", "do_last", 80 | CCPW | DCC },
{ 0, "LOAD", "do_load", 80 | CCPW | GAXS },
{ 0, "MSG", "do_msg", 80 | CCPW | CARGS },
{ 0, "CQ", "do_clearqueue", 80 | GAXS },
{ 0, "LAST", "do_last", 80 | DCC },
{ 0, "LOAD", "do_load", 80 | GAXS },
{ 0, "MSG", "do_msg", 80 | CARGS },
{ 0, "NEXTSERVER", "do_server", 80 | CCPW | GAXS },
{ 0, "SAVE", "do_save", 80 | CCPW | GAXS },
{ 0, "SERVER", "do_server", 80 | CCPW | GAXS | REDIR | NOPUB | NOARGF },
@ -252,6 +252,7 @@ struct CommandList
#ifdef DEBUG
{ 0, "DEBUG", "do_debug", 100 | CCPW | GAXS },
{ 0, "CRASH", "do_crash", 100 | CCPW | GAXS },
{ 0, "INJECT", "do_inject", 100 | CCPW | CARGS | GAXS },
#endif /* DEBUG */
#ifdef PERL
#ifdef PLEASE_HACK_MY_SHELL

View File

@ -728,7 +728,7 @@ int sub_compile_timer(int limit, uint32_t *flags1, uint32_t *flags2, char *args)
s = chop(&args);
if (s && *s)
{
if ((dash = STRCHR(s,'-')))
if ((dash = stringchr(s,'-')))
{
*(dash++) = 0;
if (!*dash)
@ -968,7 +968,7 @@ void update(SequenceTime *this)
if ((now - current->activity) > (x * 60))
{
temp = randstring(AWAYFILE);
to_server(AWAYFORM,(temp && *temp) ? temp : "auto-away",time2away(now));
to_server(AWAYFORM,(temp && *temp) ? temp : "auto-away",maketimestr(now,TFMT_AWAY));
current->away = TRUE;
}
}
@ -1162,7 +1162,9 @@ breaksock:
#ifdef DEBUG
debug("[PSI] {%i} errno = %i; closing server socket\n",current->sock,errno);
#endif /* DEBUG */
#ifdef WINGATE
breaksock2:
#endif /* WINGATE */
*current->sockdata = 0;
close(current->sock);
current->sock = -1;
@ -1183,12 +1185,12 @@ void do_version(COMMAND_ARGS)
void do_core(COMMAND_ARGS)
{
char tmp[MSGLEN];
#ifdef HOSTINFO
char *h,hostname[256];
struct utsname un;
#endif /* HOSTINFO */
const char *extra;
char tmp[MSGLEN]; /* big buffers at the top */
Server *sp;
Chan *chan;
User *user;
@ -1205,11 +1207,16 @@ void do_core(COMMAND_ARGS)
bu++;
}
*tmp = 0;
if (*current->modes)
{
sprintf(tmp," (+%s)",current->modes);
}
i = stringcmp(getbotnick(current),getbotwantnick(current));
if (i)
table_buffer(TEXT_CURRNICKWANT,getbotnick(current),getbotwantnick(current),current->guid);
table_buffer(TEXT_CURRNICKWANT,getbotnick(current),tmp,getbotwantnick(current),current->guid);
else
table_buffer(TEXT_CURRNICKHAS,getbotnick(current),current->guid);
table_buffer(TEXT_CURRNICKHAS,getbotnick(current),tmp,current->guid);
table_buffer(TEXT_USERLISTSTATS,u,su,EXTRA_CHAR(su),bu,EXTRA_CHAR(bu));
pt = tmp;
@ -1261,12 +1268,11 @@ void do_core(COMMAND_ARGS)
#endif /* WINGATE */
sp = find_server(current->server);
if (sp)
table_buffer(TEXT_CURRSERVER,
(sp->realname[0]) ? sp->realname : sp->name,sp->port);
table_buffer((stringcmp(sp->group,DEFAULTSTR)) ? TEXT_CURRSERVGRP : TEXT_CURRSERVER,
(sp->realname[0]) ? sp->realname : sp->name,sp->port,sp->group);
else
table_buffer(TEXT_CURRSERVERNOT);
table_buffer(TEXT_SERVERONTIME,idle2str(current->ontime,FALSE));
table_buffer(TEXT_BOTMODES,(*current->modes) ? current->modes : TEXT_NONE);
#ifdef HOSTINFO
hostname[255] = 0;
if (gethostname(hostname,250) < 0)
@ -1277,19 +1283,21 @@ void do_core(COMMAND_ARGS)
if (uname(&un) == 0)
table_buffer(TEXT_HOSTINFO,h,un.sysname,un.release,un.machine);
#endif /* HOSTINFO */
table_buffer(TEXT_CURRENTTIME,time2str(now));
table_buffer(TEXT_BOTSTARTED,time2str(uptime));
table_buffer(TEXT_CURRENTTIME,maketimestr(now,TFMT_FULL));
table_buffer(TEXT_BOTSTARTED,maketimestr(uptime,TFMT_FULL));
table_buffer(TEXT_BOTUPTIME,idle2str(uptime,FALSE));
table_buffer(TEXT_BOTVERSION,VERSION,SRCDATE);
table_buffer(TEXT_BOTFEATURES,__mx_opts);
#ifdef DEBUG
extra = EMPTYSTR;
if (debugfile && dodebug)
extra = debugfile;
#ifdef __profiling__
table_buffer("Debug\t%s%s%s, Compiled with Profiling",
table_buffer("Debug\t%s%s, Compiled with Profiling",
#else
table_buffer("Debug\t%s%s%s",
table_buffer("Debug\t%s%s",
#endif
(const char *[]){"Off","On, Output = "}[dodebug],
(debugfile==NULL) ? ((dodebug==TRUE) ? "Stdout" : EMPTYSTR) : debugfile);
(dodebug) ? "On, Output = " : "Off",extra);
#endif /* DEBUG */
table_send(from,2);
}
@ -1559,7 +1567,7 @@ void do_away(COMMAND_ARGS)
current->activity = now;
return;
}
to_server(AWAYFORM,rest,time2away(now));
to_server(AWAYFORM,rest,maketimestr(now,TFMT_AWAY));
to_user(from,TEXT_NOWSETAWAY);
current->away = TRUE;
}
@ -1632,7 +1640,7 @@ void do_nick(COMMAND_ARGS)
void do_time(COMMAND_ARGS)
{
to_user_q(from,"Current time: %s",time2away(now));
to_user_q(from,"Current time: %s",maketimestr(now,TFMT_AWAY));
}
void do_upontime(COMMAND_ARGS)

View File

@ -99,7 +99,8 @@ int dcc_sendfile(char *target, char *filename)
{
struct sockaddr_in sai;
Client *client;
int s,f,sz;
int s,f;
unsigned int sz;
char tempfile[strlen(filename)+strlen(DCC_PUBLICFILES)+2]; // strlen(DCC_PUBLICFILES) evaluates at compile time to a constant.
stringcpy(tempfile,DCC_PUBLICFILES);
@ -671,7 +672,7 @@ void ctcp_version(char *from, char *to, char *rest)
#endif /* CTCP */
LS const struct
const struct
{
char *name;
void (*func)(char *, char *, char *);

View File

@ -36,9 +36,9 @@
#define boolstr(x) (x) ? "TRUE" : "FALSE"
LS const char tabs[20] = "\t\t\t\t\t\t\t\t\t\t";
const char tabs[20] = "\t\t\t\t\t\t\t\t\t\t";
LS const struct
const struct
{
char *name;
int size;
@ -114,7 +114,7 @@ LS const struct
#define RARE_SE ,"RARE"
#define DBUG_SE ,"DBUG"
LS struct
struct
{
void *func;
char *name;
@ -248,6 +248,28 @@ LS struct
{ 0, "(unknown)" },
{ NULL, }};
#ifdef HOSTINFO
#include <sys/inotify.h>
const DEFstruct inomasks[] =
{
{ IN_ACCESS, "IN_ACCESS" }, /* File was accessed (read) */
{ IN_ATTRIB, "IN_ATTRIB" }, /* Metadata changed, e.g., permissions, timestamps, extended attributes, link count, UID, GID, etc. */
{ IN_CLOSE_WRITE, "IN_CLOSE_WRITE" }, /* File opened for writing was closed */
{ IN_CLOSE_NOWRITE, "IN_CLOSE_NOWRITE" }, /* File not opened for writing was closed */
{ IN_CREATE, "IN_CREATE" }, /* File/directory created in watched directory */
{ IN_DELETE, "IN_DELETE" }, /* File/directory deleted from watched directory */
{ IN_DELETE_SELF, "IN_DELETE_SELF" }, /* Watched file/directory was itself deleted */
{ IN_MODIFY, "IN_MODIFY" }, /* File was modified */
{ IN_MOVE_SELF, "IN_MOVE_SELF" }, /* Watched file/directory was itself moved */
{ IN_MOVED_FROM, "IN_MOVED_FROM" }, /* Generated for the directory containing the old filename when a file is renamed */
{ IN_MOVED_TO, "IN_MOVED_TO" }, /* Generated for the directory containing the new filename when a file is renamed */
{ IN_OPEN, "IN_OPEN" }, /* File was opened */
{ 0, }};
#endif /* HOSTINFO */
#ifdef SCRIPTING
const DEFstruct SCRIPTdefs[] =
@ -497,7 +519,7 @@ char *atime(time_t when)
char *pt,*zp;
pt = ctime(&when);
zp = STRCHR(pt,'\n');
zp = stringchr(pt,'\n');
*zp = 0;
return(pt);
}
@ -1417,6 +1439,12 @@ int wrap_debug(void)
return(1);
}
void do_inject(COMMAND_ARGS)
{
set_mallocdoer(do_inject);
current->inject = stringdup(rest);
}
void do_debug(COMMAND_ARGS)
{
const char *arg;

View File

@ -1,7 +1,7 @@
/*
EnergyMech, IRC bot software
Parts Copyright (c) 1997-2018 proton
Parts Copyright (c) 1997-2025 proton
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -21,15 +21,6 @@
#ifndef DEFINES_H
#define DEFINES_H 1
/*
* dont export too many symbols...
*/
#ifdef LIBRARY
#define LS static
#else /* not LIBRARY */
#define LS /* nothing */
#endif /* LIBRARY */
/*
* startup ==
*/
@ -104,16 +95,9 @@
#define QM_PRI_LOW 100
/*
* Bitfield for short_tv being set to 1 or 30 seconds
* stats.c
*/
#define TV_TELNET_NICK 0x0002
#define TV_UCACHE 0x0004
#define TV_SERVCONNECT 0x0008
#define TV_LINEBUF 0x0010
#define TV_BOTNET 0x0020
#define TV_REJOIN 0x0040
#define TV_TRIVIA 0x0080
#define CSTAT_PARTIAL 1
/* Misc Crap: */
@ -148,6 +132,227 @@
#define FUH_USERHOST 1
#define FUH_HOST 2
/*
* why would channel structs contain global vars?
* they shouldnt! and now they dont! :)
*/
#define CHANSET_SIZE INT_AAWAY
/*
* For botlinks
*/
/* BotNet->status */
#define BN_UNKNOWN 0
#define BN_DEAD 1
#define BN_LINKSOCK 2
#define BN_CONNECT 3
#define BN_BANNERSENT 4
#define BN_WAITAUTH 5
#define BN_WAITLINK 6
#define BN_LINKED 7
#define BNAUTH_PLAINTEXT 0
#define BNAUTH_DES 1
#define BNAUTH_MD5 2
#define BNAUTH_SHA 3
/* for server connect status */
#define CN_NOSOCK 0
#define CN_DNSLOOKUP 1
#define CN_TRYING 2
#define CN_CONNECTED 3
#define CN_ONLINE 4
#define CN_DISCONNECT 5
#define CN_BOTDIE 6
#define CN_NEXTSERV 7
#define CN_WINGATEWAIT 8
#define CN_SPINNING 9 /* after exhausting serverlist */
#define SERVERSILENCETIMEOUT 360 /* server connection idle timeout */
/* DCC Kill flags (BYE command) */
#define DCC_NULL 0
#define DCC_COMMAND 1
#define DCC_KILL 2
/*
* is_safepath
*/
#define FILE_IS_SAFE 1
#define FILE_MUST_EXIST 1
#define FILE_MAY_EXIST 2
#define FILE_MUST_NOTEXIST 3
/* check_mass() */
#define CHK_CAPS 0
#define CHK_PUB 1
#define CHK_PUBLIC CHK_PUB
#define CHK_DEOP 2
#define CHK_BAN 3
#define CHK_KICK 4
#define INDEX_FLOOD 0
#define INDEX_BAN 1
#define INDEX_DEOP 2
#define INDEX_KICK 3
#define INDEX_NICK 4
#define INDEX_CAPS 5
#define INDEX_MAX 6
/*
*
*/
#define IRCX_WALLCHOPS 1
#define IRCX_WALLVOICES 2
#define IRCX_IMODE 4
#define IRCX_EMODE 8
/*
* dns.c
*/
#define MAX_NAMESERVERS 4
/*
* scripting events
*/
#define MEV_PARSE 0
#define MEV_TIMER 1
#define MEV_COMMAND 2
#define MEV_BOTNET 3
#define MEV_DCC_COMPLETE 4
#define MEV_DNSRESULT 5
/*
* notify defines
*/
#define NF_OFFLINE 0
#define NF_WHOIS 1
#define NF_MASKONLINE 2 /* anything above NF_MASKONLINE is "online" */
#define NF_NOMATCH 3
/*
* redirect.c
*/
#define R_NOTICE 0
#define R_PRIVMSG 1
#define R_FILE 2
#define R_BOTNET 3
/*
* seen selector types
*/
#define SEEN_PARTED 0
#define SEEN_QUIT 1
#define SEEN_NEWNICK 2
#define SEEN_KICKED 3
/* server error types */
#define SP_NULL 0
#define SP_NOAUTH 1
#define SP_KLINED 2
#define SP_FULLCLASS 3
#define SP_TIMEOUT 4
#define SP_ERRCONN 5
#define SP_DIFFPORT 6
#define SP_NO_DNS 7
#define SP_THROTTLED 8
/*
* spying types, source and target types are mixed
*/
#define SPY_FILE 1
#define SPY_DCC 2
#define SPY_CHANNEL 3
#define SPY_STATUS 4
#define SPY_MESSAGE 5
#define SPY_RAWIRC 6
#define SPY_BOTNET 7
#ifdef URLCAPTURE
#define SPY_URL 8
#endif /* URLCAPTURE */
#ifdef HOSTINFO
#define SPY_SYSMON 9
#endif /* HOSTINFO */
#define SPY_RANDSRC 10
#define SPYF_ANY 1
#define SPYF_CHANNEL (1 << SPY_CHANNEL)
#define SPYF_STATUS (1 << SPY_STATUS)
#define SPYF_MESSAGE (1 << SPY_MESSAGE)
#define SPYF_RAWIRC (1 << SPY_RAWIRC)
#define SPYF_BOTNET (1 << SPY_BOTNET)
#define SPYF_URL (1 << SPY_URL)
#define SPYF_RANDSRC (1 << SPY_RANDSRC)
/*
* function.c :: maketimestr()
*/
#define TFMT_LOG 0x20506
#define TFMT_FULL 0x60402
#define TFMT_AWAY 0x40307
#define TFMT_CLOCK 0x1
#define TFMT_DATE 0x4
/*
* Bitfield for short_tv being set to 1 or 30 seconds
*/
#define TV_TELNET_NICK 0x0002
#define TV_UCACHE 0x0004
#define TV_SERVCONNECT 0x0008
#define TV_LINEBUF 0x0010
#define TV_BOTNET 0x0020
#define TV_REJOIN 0x0040
#define TV_TRIVIA 0x0080
/*
* uptime defines
*/
#define UPTIME_ENERGYMECH 1 /* http://www.energymech.net */
#define UPTIME_EGGDROP 2 /* http://www.eggheads.org */
#define UPTIME_MINIMECH 3 /* http://www.energymech.net */
#define UPTIME_WINMECH 4 /* http://www.energymech.net */
#define UPTIME_RACBOT 5 /* http://www.racbot.org */
#define UPTIME_MIRC 6 /* http://www.mirc.com */
#define UPTIME_HAL9000 7 /* http://www.2010.org */
#define UPTIME_ANABOT 8 /* http://www.sirklabs.hu/ana-liza/ */
#define UPTIME_ANGELBOT 9 /* unknown */
#define UPTIME_FIRECLAW 10 /* http://www.fireclaw.org */
#define UPTIME_GARNAX 11 /* http://garnax.mircx.com */
#define UPTIME_WINEGGDROP 12 /* http://www.eggheads.org */
#define UPTIME_SUPYBOT 14 /* http://supybot.sourceforge.net */
#define UPTIME_GENERICDEATH 5000 /* generic death */
#define UPTIME_SIGSEGV 5001
#define UPTIME_SIGBUS 5002
#define UPTIME_SIGTERM 5003
#define UPTIME_SIGINT 5004
#define UPTIMEHOST "uptime.eggheads.org"
#ifdef __CYGWIN__
#define UPTIME_BOTTYPE UPTIME_WINMECH
#else
#define UPTIME_BOTTYPE UPTIME_ENERGYMECH
#endif /* __CYGWIN__ */
/* VHOST types */
#define VH_ZERO 0
#define VH_IPALIAS (1 << 1)
#define VH_IPALIAS_FAIL (1 << 2)
#define VH_IPALIAS_BOTH (VH_IPALIAS|VH_IPALIAS_FAIL)
#define VH_WINGATE (1 << 3)
#define VH_WINGATE_FAIL (1 << 4)
#define VH_WINGATE_BOTH (VH_WINGATE|VH_WINGATE_FAIL)
/* Type of Variable: */
#define INT_VAR 0x01
@ -174,14 +379,6 @@
#define IsChar(x) ((VarName[x].type & CHR_VAR) == CHR_VAR)
#define IsProc(x) (VarName[x].type & PROC_VAR)
/*
* is_safepath
*/
#define FILE_IS_SAFE 1
#define FILE_MUST_EXIST 1
#define FILE_MAY_EXIST 2
#define FILE_MUST_NOTEXIST 3
/*
* see settings.h for the actual setting struct
*/
@ -301,205 +498,5 @@ enum {
SIZE_VARS
};
/*
* why would channel structs contain global vars?
* they shouldnt! and now they dont! :)
*/
#define CHANSET_SIZE INT_AAWAY
/*
* For botlinks
*/
#ifdef BOTNET
/* BotNet->status */
#define BN_UNKNOWN 0
#define BN_DEAD 1
#define BN_LINKSOCK 2
#define BN_CONNECT 3
#define BN_BANNERSENT 4
#define BN_WAITAUTH 5
#define BN_WAITLINK 6
#define BN_LINKED 7
#define BNAUTH_PLAINTEXT 0
#define BNAUTH_DES 1
#define BNAUTH_MD5 2
#define BNAUTH_SHA 3
#endif /* BOTNET */
/* for connect status */
#define CN_NOSOCK 0
#define CN_DNSLOOKUP 1
#define CN_TRYING 2
#define CN_CONNECTED 3
#define CN_ONLINE 4
#define CN_DISCONNECT 5
#define CN_BOTDIE 6
#define CN_NEXTSERV 7
#define CN_WINGATEWAIT 8
#define CN_SPINNING 9 /* after exhausting serverlist */
#define SERVERSILENCETIMEOUT 360 /* server connection idle timeout */
/* DCC Kill flags (BYE command) */
#define DCC_NULL 0
#define DCC_COMMAND 1
#define DCC_KILL 2
/* VHOST types */
#define VH_ZERO 0
#define VH_IPALIAS (1 << 1)
#define VH_IPALIAS_FAIL (1 << 2)
#define VH_IPALIAS_BOTH (VH_IPALIAS|VH_IPALIAS_FAIL)
#define VH_WINGATE (1 << 3)
#define VH_WINGATE_FAIL (1 << 4)
#define VH_WINGATE_BOTH (VH_WINGATE|VH_WINGATE_FAIL)
/* server error types */
#define SP_NULL 0
#define SP_NOAUTH 1
#define SP_KLINED 2
#define SP_FULLCLASS 3
#define SP_TIMEOUT 4
#define SP_ERRCONN 5
#define SP_DIFFPORT 6
#define SP_NO_DNS 7
#define SP_THROTTLED 8
/* check_mass() */
#define INDEX_FLOOD 0
#define INDEX_BAN 1
#define INDEX_DEOP 2
#define INDEX_KICK 3
#define INDEX_NICK 4
#define INDEX_CAPS 5
#define INDEX_MAX 6
#define CHK_CAPS 0
#define CHK_PUB 1
#define CHK_PUBLIC CHK_PUB
#define CHK_DEOP 2
#define CHK_BAN 3
#define CHK_KICK 4
/*
* seen selector types
*/
#define SEEN_PARTED 0
#define SEEN_QUIT 1
#define SEEN_NEWNICK 2
#define SEEN_KICKED 3
/*
* spying types, source and target types are mixed
*/
#define SPY_FILE 1
#define SPY_DCC 2
#define SPY_CHANNEL 3
#define SPY_STATUS 4
#define SPY_MESSAGE 5
#define SPY_RAWIRC 6
#define SPY_BOTNET 7
#ifdef URLCAPTURE
#define SPY_URL 8
#endif /* URLCAPTURE */
#ifdef HOSTINFO
#define SPY_SYSMON 9
#endif /* HOSTINFO */
#define SPY_RANDSRC 10
#define SPYF_ANY 1
#define SPYF_CHANNEL (1 << SPY_CHANNEL)
#define SPYF_STATUS (1 << SPY_STATUS)
#define SPYF_MESSAGE (1 << SPY_MESSAGE)
#define SPYF_RAWIRC (1 << SPY_RAWIRC)
#define SPYF_BOTNET (1 << SPY_BOTNET)
#define SPYF_URL (1 << SPY_URL)
#define SPYF_RANDSRC (1 << SPY_RANDSRC)
/*
* notify defines
*/
#define NF_OFFLINE 0
#define NF_WHOIS 1
#define NF_MASKONLINE 2 /* anything above NF_MASKONLINE is "online" */
#define NF_NOMATCH 3
/*
* uptime defines
*/
#define UPTIME_ENERGYMECH 1 /* http://www.energymech.net */
#define UPTIME_EGGDROP 2 /* http://www.eggheads.org */
#define UPTIME_MINIMECH 3 /* http://www.energymech.net */
#define UPTIME_WINMECH 4 /* http://www.energymech.net */
#define UPTIME_RACBOT 5 /* http://www.racbot.org */
#define UPTIME_MIRC 6 /* http://www.mirc.com */
#define UPTIME_HAL9000 7 /* http://www.2010.org */
#define UPTIME_ANABOT 8 /* http://www.sirklabs.hu/ana-liza/ */
#define UPTIME_ANGELBOT 9 /* unknown */
#define UPTIME_FIRECLAW 10 /* http://www.fireclaw.org */
#define UPTIME_GARNAX 11 /* http://garnax.mircx.com */
#define UPTIME_WINEGGDROP 12 /* http://www.eggheads.org */
#define UPTIME_SUPYBOT 14 /* http://supybot.sourceforge.net */
#define UPTIME_GENERICDEATH 5000 /* generic death */
#define UPTIME_SIGSEGV 5001
#define UPTIME_SIGBUS 5002
#define UPTIME_SIGTERM 5003
#define UPTIME_SIGINT 5004
#define UPTIMEHOST "uptime.eggheads.org"
#ifdef __CYGWIN__
#define UPTIME_BOTTYPE UPTIME_WINMECH
#else
#define UPTIME_BOTTYPE UPTIME_ENERGYMECH
#endif /* __CYGWIN__ */
/*
* scripting events
*/
#define MEV_PARSE 0
#define MEV_TIMER 1
#define MEV_COMMAND 2
#define MEV_BOTNET 3
#define MEV_DCC_COMPLETE 4
#define MEV_DNSRESULT 5
/*
*
*/
#define IRCX_WALLCHOPS 1
#define IRCX_WALLVOICES 2
#define IRCX_IMODE 4
#define IRCX_EMODE 8
/*
* stats.c
*/
#define CSTAT_PARTIAL 1
/*
* dns.c
*/
#define MAX_NAMESERVERS 4
/*
* redirect.c
*/
#define R_NOTICE 0
#define R_PRIVMSG 1
#define R_FILE 2
#define R_BOTNET 3
#endif /* DEFINES_H */

View File

@ -230,7 +230,7 @@ void parse_query(int psz, dnsQuery *query)
dnsList *dns;
const char *src,*rtyp;
char token[64],token2[64];
int sz,n;
int n,pick;
src = (const char*)query;
@ -240,7 +240,7 @@ void parse_query(int psz, dnsQuery *query)
token[16] = 0;
n = ntohs(query->flags);
debug("(parse_query) %i: flags = %i { %s %i %s%s%s%s%s }\n",
sz,n,token,
psz,n,token,
(n&15), /* result code */
(n&32768) ? "QR 1 (Answer) ":"QR 0 (Question) ",
(n&1024) ? "AA ":"",
@ -333,10 +333,10 @@ void parse_query(int psz, dnsQuery *query)
}
n = ntohs(query->authorities);
sz = (n > 1) ? RANDOM(1,n) : 1;
pick = (n > 1) ? RANDOM(1,n) : 1;
#ifdef DEBUG
if (n)
debug("(parse_query) auth: select %i count %i\n",sz,n);
debug("(parse_query) auth: select %i count %i\n",pick,n);
#endif /* DEBUG */
while(n)
{
@ -349,7 +349,7 @@ void parse_query(int psz, dnsQuery *query)
dnsAuthority *da;
get_dns_token(src,(const char *)query,token2,psz);
if (sz == n)
if (pick == n)
{
if (dns->auth == NULL)
{
@ -374,7 +374,7 @@ void parse_query(int psz, dnsQuery *query)
}
}
#ifdef DEBUG
debug("(parse_query) authorities: %s = %s%s\n",token,token2,(sz==n) ? MATCH_ALL : "");
debug("(parse_query) authorities: %s = %s%s\n",token,token2,(pick==n) ? MATCH_ALL : "");
#endif /* DEBUG */
}
#ifdef DEBUG
@ -508,6 +508,8 @@ void parse_query(int psz, dnsQuery *query)
}
if (src)
{
int sz;
dns->id = rand();
#ifdef DEBUG
debug("(parse_query) %i: asking %s who is `%s'\n",dns->id,inet_ntoa(sai.sin_addr),src);
@ -529,6 +531,8 @@ void parse_query(int psz, dnsQuery *query)
Free((char**)&dns->auth2);
if (src == NULL && dns->ip.s_addr == 0 && dns->cname && dns->host && dns->auth == NULL && dns->auth2 == NULL)
{
int sz;
dns->id = rand();
sai.sin_addr.s_addr = (ia_ns[dnsserver].s_addr == 0) ? ia_default.s_addr : ia_ns[dnsserver].s_addr;
#ifdef DEBUG
@ -637,8 +641,9 @@ restart:
void process_rawdns(void)
{
struct sockaddr_in sai;
unsigned int sz;
char packet[512];
int sz,n;
int n;
sz = sizeof(sai);
n = recvfrom(dnssock,packet,512,0,(struct sockaddr*)&sai,&sz);
@ -667,7 +672,7 @@ char *poll_rawdns(char *hostname)
return(NULL);
}
LS int backup_debug;
int backup_debug;
int read_dnsroot(char *line)
{
@ -847,7 +852,7 @@ void do_dns(COMMAND_ARGS)
uint32_t ip;
/* to date, all hostnames contain atleast one dot */
if ((STRCHR(rest,'.')))
if ((stringchr(rest,'.')))
{
host = rest;
}

View File

@ -30,9 +30,9 @@
#include "h.h"
#include "text.h"
char timebuf[64]; /* max format lentgh == 20+1 */
char idlestr[64]; /* max format lentgh == 24+1 */
const char monlist[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
const char daylist[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
@ -269,91 +269,6 @@ void dupe_strp(Strp *sp, Strp **pp)
}
}
Strp *output_table = NULL;
void table_buffer(const char *format, ...)
{
va_list msg;
va_start(msg,format);
vsprintf(globaldata,format,msg);
va_end(msg);
set_mallocdoer(table_buffer);
append_strp(&output_table,globaldata);
}
void table_send(const char *from, const int space)
{
char message[MAXLEN];
Strp *sp,*next;
char *src,*o,*end;
int i,u,g,x,columns[16];
memset(columns,0,sizeof(columns));
for(sp=output_table;sp;sp=sp->next)
{
u = i = 0;
src = o = sp->p;
while(*src)
{
/* Dont count control codes */
if (*src == '\037' || *src == '\002')
u++;
if (*src == '\t' || *src == '\r')
{
x = (src - o) - u;
if (x > columns[i])
columns[i] = x;
i++;
o = src+1;
u = 0;
}
src++;
}
}
for(sp=output_table;sp;sp=next)
{
next = sp->next;
o = message;
src = sp->p;
g = x = i = 0;
while(*src)
{
if (g)
{
end = src;
while(*end && *end != '\t' && *end != '\r')
end++;
g -= (end - src);
while(g-- > 0)
*(o++) = ' ';
}
if (*src == '\037' || *src == '\002')
x++;
if (*src == '\t' || *src == '\r')
{
if (*src == '\r')
g = columns[i+1];
src++;
x += (columns[i++] + space);
while(o < (message + x))
*(o++) = ' ';
}
else
*(o++) = *(src++);
}
*o = 0;
to_user(from,FMT_PLAIN,message);
Free((char**)&sp);
}
output_table = NULL;
}
char *getuh(char *nuh)
{
char *s;
@ -363,12 +278,11 @@ char *getuh(char *nuh)
{
if (*s == '!')
{
nuh = s + 1;
/*
* We have to grab everything from the first '!' since some
* braindamaged ircds allow '!' in the "user" part of the nuh
*/
break;
return(s + 1);
}
s++;
}
@ -430,161 +344,59 @@ a: ++(*src);
/*
* time to string routines
00000020 g O .rodata 00000030 monlist
00000000 g O .rodata 0000001c daylist
0000000000001279 g F .text 0000000000000166 maketimestr
000000000000175c g F .text 0000000000000073 logtime
00000000000018f7 g F .text 0000000000000052 time2medium
0000000000001949 g F .text 000000000000005d time2small
000000000000184a g F .text 00000000000000ad time2away
00000000000017cf g F .text 000000000000007b time2str
00000121 maketimestr 289
000004af g F .text.a 00000064 logtime 100
00000513 g F .text.a 0000006f time2str 111
00000582 g F .text.a 0000009c time2away 156 } 523
0000061e g F .text.a 0000004a time2medium 74
00000668 g F .text.a 00000052 time2small 82
000006ba g F .text.a 00000160 idle2str
*/
char *maketimestr(time_t when, char *buffer, int format)
char *maketimestr(time_t when, int format)
{
struct tm *btime;
char *dest,ampm;
char *dest,*f,ampm;
int option;
btime = localtime(&when);
dest = buffer;
dest = timebuf;
do
{
option = format & 0xf;
option = format & 0x7;
format = format >> 4;
if (dest > buffer)
*(dest++) = ' ';
f = "%02i:%02i:%02i";
switch(option)
{
case 1:/* HH:mm:ss */
dest += sprintf(dest,"%02i:%02i:%02i",btime->tm_hour,btime->tm_min,btime->tm_sec);
case 0:
*(dest++) = ' ';
break;
case 2:/* skip back 3 (remove :ss) */
dest -= 4;
*dest = 0;
case 1:/* HH:mm */
f += 5;
case 2:/* HH:mm:ss */
dest += sprintf(dest,f,btime->tm_hour,btime->tm_min,btime->tm_sec);
break;
case 3:/* WeekDay */
dest += sprintf(dest,"%s",daylist[btime->tm_wday]);
/* stringcpy return a pointer to the last char, not how many chars was copied */
dest = stringcpy(dest,daylist[btime->tm_wday]);
break;
case 4:/* Month */
dest += sprintf(dest,"%s",monlist[btime->tm_mon]);
case 4:/* ascii-Month Day */
dest += sprintf(dest,"%s %i",monlist[btime->tm_mon],btime->tm_mday);
break;
case 5:/* Day */
dest += sprintf(dest,"%i",btime->tm_mday);
case 5:/* num-Month Day */
dest += sprintf(dest,"%02i %02i",btime->tm_mon+1,btime->tm_mday);
break;
case 6:/* Year */
dest += sprintf(dest,"%i",btime->tm_year+1900);
break;
case 7:/* am/pm */
if (btime->tm_hour < 12)
{
if (btime->tm_hour == 0)
btime->tm_hour = 12;
ampm = 'a';
}
else
{
if (btime->tm_hour != 12)
btime->tm_hour -= 12;
ampm = 'p';
}
unsigned char a,b;
a = ((unsigned char)btime->tm_hour - 1);
a >>= 7;
b = ((unsigned char)btime->tm_hour - 12);
b >>= 7;
btime->tm_hour += (a * 12) - 12 * (b^1);
ampm = 'p' - (b * ('p' - 'a'));
dest += sprintf(dest,"%i:%02i%cm",btime->tm_hour,btime->tm_min,ampm);
break;
}
}
while(format);
return(buffer);
}
char *logtime(time_t when)
{
struct tm *btime;
btime = localtime(&when);
/* Month Day Year HH:mm:ss */
sprintf(timebuf,"%s %i %i %02i:%02i:%02i", /* max format length: 20+1 */
monlist[btime->tm_mon],btime->tm_mday,btime->tm_year+1900,
btime->tm_hour,btime->tm_min,btime->tm_sec);
return(timebuf);
}
char *time2str(time_t when)
{
struct tm *btime;
if (!when)
return(NULL);
btime = localtime(&when);
/* HH:mm:ss Month Day Year */
sprintf(timebuf,"%02i:%02i:%02i %s %02i %i", /* max format length: 20+1 */
btime->tm_hour,btime->tm_min,btime->tm_sec,monlist[btime->tm_mon],
btime->tm_mday,btime->tm_year+1900);
return(timebuf);
}
char *time2away(time_t when)
{
struct tm *btime;
char ampm;
if (!when)
return(NULL);
btime = localtime(&when);
if (btime->tm_hour < 12)
{
if (btime->tm_hour == 0)
btime->tm_hour = 12;
ampm = 'a';
}
else
{
if (btime->tm_hour != 12)
btime->tm_hour -= 12;
ampm = 'p';
}
/* HH:mm am/pm WeekDay Month Day */
sprintf(timebuf,"%i:%02i%cm %s %s %i", /* max format length: 18+1 */
btime->tm_hour,btime->tm_min,ampm,daylist[btime->tm_wday],
monlist[btime->tm_mon],btime->tm_mday);
return(timebuf);
}
char *time2medium(time_t when)
{
struct tm *btime;
btime = localtime(&when);
/* HH:mm */
sprintf(timebuf,"%02i:%02i", /* max format length: 5+1 */
btime->tm_hour,btime->tm_min);
return(timebuf);
}
char *time2small(time_t when)
{
struct tm *btime;
btime = localtime(&when);
/* Month Day */
sprintf(timebuf,"%s %02i", /* max format length: 6+1 */
monlist[btime->tm_mon],btime->tm_mday);
return(timebuf);
}
@ -749,7 +561,7 @@ char *format_uh(char *userhost, int type)
char tmpmask[NUHLEN];
char *u,*h;
if (STRCHR(userhost,'*'))
if (stringchr(userhost,'*'))
return(userhost);
stringcpy(tmpmask,userhost);
@ -773,87 +585,6 @@ char *format_uh(char *userhost, int type)
return(userhost);
}
/*
* NOTE! beware of conflicts in the use of nuh_buf, its also used by find_nuh()
*/
char *nick2uh(char *from, char *userhost)
{
if (STRCHR(userhost,'!') && STRCHR(userhost,'@'))
{
stringcpy(nuh_buf,userhost);
}
else
if (!STRCHR(userhost,'!') && !STRCHR(userhost,'@'))
{
/* find_nuh() stores nickuserhost in nuh_buf */
if (find_nuh(userhost) == NULL)
{
if (from)
to_user(from,"No information found for %s",userhost);
return(NULL);
}
}
else
{
stringcpy(nuh_buf,"*!");
if (!STRCHR(userhost,'@'))
stringcat(nuh_buf,"*@");
stringcat(nuh_buf,userhost);
}
return(nuh_buf);
}
void deop_ban(Chan *chan, ChanUser *victim, char *mask)
{
if (!mask)
mask = format_uh(get_nuh(victim),FUH_USERHOST);
send_mode(chan,85,QM_CHANUSER,'-','o',victim);
send_mode(chan,90,QM_RAWMODE,'+','b',mask);
}
void deop_siteban(Chan *chan, ChanUser *victim)
{
char *mask;
mask = format_uh(get_nuh(victim),FUH_HOST);
deop_ban(chan,victim,mask);
}
void screwban_format(char *userhost)
{
int sz,n,pos;
#ifdef DEBUG
debug("(screwban_format) %s\n",userhost);
#endif /* DEBUG */
if ((sz = strlen(userhost)) < 8)
return;
n = RANDOM(4,sz);
while(--n)
{
pos = RANDOM(0,(sz - 1));
if (!STRCHR("?!@*",userhost[pos]))
{
userhost[pos] = (RANDOM(0,3) == 0) ? '*' : '?';
}
}
}
void deop_screwban(Chan *chan, ChanUser *victim)
{
char *mask;
int i;
for(i=2;--i;)
{
mask = format_uh(get_nuh(victim),FUH_USERHOST);
screwban_format(mask);
deop_ban(chan,victim,mask);
}
}
int is_nick(const char *nick)
{
uchar *p;
@ -913,6 +644,46 @@ int get_number(const char *rest)
return(n);
}
#define checkifdigit(xcx) (xcx >= '0' && xcx <= '9')
void parse_range(char **s, int *a)
{
int v;
a[0] = -1;
a[1] = -1;
a[2] = 0;
if (0 == checkifdigit(**s))
return;
v = 0;
while(checkifdigit(**s))
{
v = (v * 10) + **s - '0';
(*s)++;
}
a[0] = v;
/* optional second number */
if (**s == '-')
{
a[2] = 1;
(*s)++;
}
if (0 == checkifdigit(**s))
return;
v = 0;
while(checkifdigit(**s))
{
v = (v * 10) + **s - '0';
(*s)++;
}
a[1] = v;
}
void fix_config_line(char *text)
{
char *s,*space;
@ -1172,26 +943,16 @@ int main(int argc, char **argv, char **envp)
}
time(&now);
when = now - 100000;
#define LOGTIME_FMT 0x1654
#define TIME2STR_FMT 0x6541
#define TIME2AWAY_FMT 0x5437
#define TIME2MEDIUM_FMT 0x21
#define TIME2SMALL_FMT 0x54
debug("logtime %s\n",logtime(when));
debug("maketimestr %s\n",maketimestr(when,mybuffer,LOGTIME_FMT));
debug("time2str %s\n",time2str(when));
debug("maketimestr %s\n",maketimestr(when,mybuffer,TIME2STR_FMT));
debug("time2away %s\n",time2away(when));
debug("maketimestr %s\n",maketimestr(when,mybuffer,TIME2AWAY_FMT));
debug("time2medium %s\n",time2medium(when));
debug("maketimestr %s\n",maketimestr(when,mybuffer,TIME2MEDIUM_FMT));
debug("time2small %s\n",time2small(when));
debug("maketimestr %s\n",maketimestr(when,mybuffer,TIME2SMALL_FMT));
debug("%s\n",idle2str(when,1));
debug("%s\n",idle2str(when,0));
for(r=0;r<10;r++)
{
when = now - (int[]){100000,888,534569,999999,99,9000,84600,7777777,56565656+3600,78987654}[r];
debug("\nmaketimestr %s\n",maketimestr(when,TFMT_LOG));
debug("maketimestr %s\n",maketimestr(when,TFMT_FULL));
debug("maketimestr %s\n",maketimestr(when,TFMT_AWAY));
debug("maketimestr %s\n",maketimestr(when,TFMT_CLOCK));
debug("maketimestr %s\n",maketimestr(when,TFMT_DATE));
}
}
#endif /* TEST */

View File

@ -21,7 +21,7 @@
#ifndef GLOBAL_H
#define GLOBAL_H 1
#ifdef MAIN_C
#if defined(MAIN_C) || defined(TEST)
#define MDEF(x) = x
#define BEG
@ -42,6 +42,7 @@
struct CoreData /* Collect core data all in one place */
{
time_t now;
time_t system_uptime;
Mech *current;
char *rest_end;
char *chop_end;
@ -309,7 +310,7 @@ BEG int spawning_lamer MDEF(0);
#define CRLF 0x08
#define FNICK (NICK|FIRST)
#define NNICK (NICK|NUM)
#define NUMNI (NICK|NUM)
#if defined(MAIN_C) || defined(MAKETABLES)
@ -391,6 +392,15 @@ const uchar nickcmptab[256] =
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
/*
#define NUM 0x01
#define NICK 0x02
#define FIRST 0x04
#define CRLF 0x08
#define FNICK (NICK|FIRST)
#define NUMNI (NICK|NUM)
*/
const uchar attrtab[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x07 */
@ -399,8 +409,10 @@ const uchar attrtab[256] =
0, 0, 0, 0, 0, 0, 0, 0, /* 0x18 - 0x1F */
0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x27 */
0, 0, 0, 0, 0, NICK, 0, 0, /* 0x28 - 0x2F */
NNICK, NNICK, NNICK, NNICK, NNICK, NNICK, NNICK, NNICK, /* 0x30 - 0x37 */
NNICK, NNICK, 0, 0, 0, 0, 0, 0, /* 0x38 - 0x3F */
NUMNI, NUMNI, NUMNI, NUMNI, NUMNI, NUMNI, NUMNI, NUMNI, /* 0x30 - 0x37 */
NUMNI, NUMNI, 0, 0, 0, 0, 0, 0, /* 0x38 - 0x3F */
0, FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, /* 0x40 - 0x47 */
FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, /* 0x48 - 0x4F */
FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, FNICK, /* 0x50 - 0x57 */

197
src/h.h
View File

@ -27,6 +27,12 @@
#define __INLINE__
#endif
#if defined(__GNUC__)
#define __notused__ __attribute__((unused))
#else
#define __notused__
#endif
#define ischannel(x) (*x == '#')
#define nullstr(x) ((x) ? x : NULLSTR)
@ -36,8 +42,7 @@
#define COMMAND_ARGS char *from, const char *to, char *rest, const int cmdaccess
#define STRCHR stringchr
#define STREND(x) STRCHR(x,0)
#define STREND(x) stringchr(x,0)
/*
* some default code for socket flags
@ -137,8 +142,8 @@ void process_bounce(void) __page(CORE_SEG);
/* calc.c */
void do_convert(COMMAND_ARGS) __page(CMD1_SEG);
void do_calc(COMMAND_ARGS) __page(CMD1_SEG);
void do_convert(COMMAND_ARGS) __page(CMD1_SEG);
/* channel.c */
@ -152,7 +157,9 @@ void reverse_topic(Chan *, char *, char *) __page(CORE_SEG);
void cycle_channel(Chan *) __page(CMD1_SEG);
int reverse_mode(char *, Chan *, int, int) __page(CORE_SEG);
void chan_modestr(Chan *, char *) __page(CORE_SEG);
char *get_nuh(const ChanUser *) __page(CORE_SEG);
char *find_nuh(char *) __page(CORE_SEG);
char *nick2uh(char *, char *) __page(CORE_SEG);
Ban *make_ban(Ban **, char *, char *, time_t);
void delete_ban(Chan *, char *);
void delete_modemask(Chan *, char *, int);
@ -163,7 +170,6 @@ ChanUser *find_chanbot(Chan *, const char *) __page(CORE_SEG);
void remove_chanuser(Chan *, const char *) __page(CORE_SEG);
void make_chanuser(char *, char *) __page(CORE_SEG);
void purge_chanusers(Chan *) __page(CMD1_SEG);
char *get_nuh(const ChanUser *) __page(CORE_SEG);
void do_join(COMMAND_ARGS) __page(CMD1_SEG);
void do_part(COMMAND_ARGS) __page(CMD1_SEG);
void do_cycle(COMMAND_ARGS) __page(CMD1_SEG);
@ -175,10 +181,10 @@ void do_names(COMMAND_ARGS) __page(CMD1_SEG);
void do_cchan(COMMAND_ARGS) __page(CMD1_SEG);
void do_invite(COMMAND_ARGS) __page(CMD1_SEG);
void do_sayme(COMMAND_ARGS) __page(CMD1_SEG);
LS void do_who(COMMAND_ARGS) __page(CMD1_SEG);
LS void do_topic(COMMAND_ARGS) __page(CMD1_SEG);
LS void do_showidle(COMMAND_ARGS) __page(CMD1_SEG);
LS void do_idle(COMMAND_ARGS) __page(CMD1_SEG);
void do_who(COMMAND_ARGS) __page(CMD1_SEG);
void do_topic(COMMAND_ARGS) __page(CMD1_SEG);
void do_showidle(COMMAND_ARGS) __page(CMD1_SEG);
void do_idle(COMMAND_ARGS) __page(CMD1_SEG);
/* core.c */
@ -260,8 +266,9 @@ char *uint32tobin(int limit, uint32_t x);
void debug_scripthook(void);
void run_debug(void);
int wrap_debug(void);
void do_debug(COMMAND_ARGS) __page(CMD1_SEG);
void do_crash(COMMAND_ARGS) __page(RARE_SEG);
void do_debug(COMMAND_ARGS) __page(CMD1_SEG);
void do_inject(COMMAND_ARGS) __page(CMD1_SEG);
void debug(char *format, ...) __page(CORE_SEG);
/* dns.c */
@ -284,43 +291,34 @@ void do_dnsserver(COMMAND_ARGS) __page(CMD1_SEG);
void do_dns(COMMAND_ARGS) __page(CMD1_SEG);
/* dynamode.c */
/* function.c */
LS void *Calloc(int) __page(CORE_SEG);
LS void Free(char **) __page(CORE_SEG);
LS Strp *make_strp(Strp **, const char *) __page(CORE_SEG);
LS Strp *append_strp(Strp **, const char *) __page(CORE_SEG);
LS Strp *prepend_strp(Strp **, const char *) __page(CORE_SEG);
LS void purge_linklist(void **) __page(CORE_SEG);
LS void dupe_strp(Strp *, Strp **) __page(CORE_SEG);
LS const int StrlenX(const char *, ...) __page(CORE_SEG);
LS const int Strlen2(const char *, const char *) __page(CORE_SEG);
LS char *getuh(char *) __page(CORE_SEG);
LS char *get_token(char **, const char *) __page(CORE_SEG);
LS char *logtime(time_t) __page(CORE_SEG);
LS char *time2str(time_t) __page(CORE_SEG);
LS char *time2away(time_t) __page(CORE_SEG);
LS char *time2medium(time_t) __page(CORE_SEG);
LS char *time2small(time_t) __page(CORE_SEG);
LS char *idle2str(time_t, int) __page(CORE_SEG);
LS const char *get_channel(const char *, char **) __page(CORE_SEG);
LS const char *get_channel2(const char *, char **) __page(CORE_SEG);
LS char *cluster(char *) __page(CORE_SEG);
LS char *format_uh(char *, int) __page(CORE_SEG);
LS char *nick2uh(char *, char *) __page(CORE_SEG);
LS void deop_ban(Chan *, ChanUser *, char *) __page(CORE_SEG);
LS void deop_siteban(Chan *, ChanUser *) __page(CORE_SEG);
LS void screwban_format(char *) __page(CORE_SEG);
LS void deop_screwban(Chan *, ChanUser *) __page(CORE_SEG);
LS int is_nick(const char *) __page(CORE_SEG);
LS int asc2int(const char *) __page(CORE_SEG);
LS int get_number(const char *) __page(CORE_SEG);
LS void fix_config_line(char *) __page(CFG1_SEG);
LS int matches(const char *, const char *) __page(CORE_SEG);
LS int num_matches(const char *, const char *) __page(CORE_SEG);
LS void table_buffer(const char *, ...) __page(CMD1_SEG);
LS void table_send(const char *, const int) __page(CMD1_SEG);
LS int is_safepath(const char *, int) __page(CORE_SEG);
void *Calloc(int) __page(CORE_SEG);
void Free(char **) __page(CORE_SEG);
Strp *make_strp(Strp **, const char *) __page(CORE_SEG);
Strp *append_strp(Strp **, const char *) __page(CORE_SEG);
Strp *prepend_strp(Strp **, const char *) __page(CORE_SEG);
void purge_linklist(void **) __page(CORE_SEG);
void dupe_strp(Strp *, Strp **) __page(CORE_SEG);
const int StrlenX(const char *, ...) __page(CORE_SEG);
const int Strlen2(const char *, const char *) __page(CORE_SEG);
char *getuh(char *) __page(CORE_SEG);
char *get_token(char **, const char *) __page(CORE_SEG);
char *maketimestr(time_t, int) __page(CORE_SEG);
char *idle2str(time_t, int) __page(CORE_SEG);
const char *get_channel(const char *, char **) __page(CORE_SEG);
const char *get_channel2(const char *, char **) __page(CORE_SEG);
char *cluster(char *) __page(CORE_SEG);
char *format_uh(char *, int) __page(CORE_SEG);
int is_nick(const char *) __page(CORE_SEG);
int asc2int(const char *) __page(CORE_SEG);
int get_number(const char *) __page(CORE_SEG);
void parse_range(char **, int *) __page(CORE_SEG);
void fix_config_line(char *) __page(CFG1_SEG);
int matches(const char *, const char *) __page(CORE_SEG);
int num_matches(const char *, const char *) __page(CORE_SEG);
int is_safepath(const char *, int) __page(CORE_SEG);
/* greet.c */
@ -350,25 +348,27 @@ void do_filemon(COMMAND_ARGS) __page(CMD1_SEG);
/* io.c */
LS uint32_t get_ip(const char *) __page(CORE_SEG);
LS void SockFlags(int) __page(CORE_SEG);
LS int SockOpts(void) __page(CORE_SEG);
LS int SockListener(int) __page(CORE_SEG);
LS int SockConnect(char *, int, int) __page(CORE_SEG);
LS int SockAccept(int) __page(CORE_SEG);
uint32_t get_ip(const char *) __page(CORE_SEG);
void SockFlags(int) __page(CORE_SEG);
int SockOpts(void) __page(CORE_SEG);
int SockListener(int) __page(CORE_SEG);
int SockConnect(char *, int, int) __page(CORE_SEG);
int SockAccept(int) __page(CORE_SEG);
int to_file(const int sock, const char *format, ...) __page(CORE_SEG);
void to_server(const char *format, ...) __page(CORE_SEG);
void to_user_q(const char *, const char *, ...) __page(CMD1_SEG);
void to_user(const char *, const char *, ...) __page(CORE_SEG);
void table_buffer(const char *, ...) __page(CMD1_SEG);
void table_send(const char *, const int) __page(CMD1_SEG);
char *sockread(int, char *, char *) __page(CORE_SEG);
void readline(int, int (*)(char *)) __page(CMD1_SEG);
void remove_ks(KillSock *);
int killsock(int);
LS void do_clearqueue(COMMAND_ARGS) __page(CMD1_SEG);
void do_clearqueue(COMMAND_ARGS) __page(CMD1_SEG);
/* irc.c */
LS void make_ireq(int, const char *, const char *) __page(CMD1_SEG);
void make_ireq(int, const char *, const char *) __page(CMD1_SEG);
void send_pa(int type, const char *nick, const char *format, ...);
void do_irclusers(COMMAND_ARGS) __page(CMD1_SEG);
void do_ircstats(COMMAND_ARGS) __page(CMD1_SEG);
@ -383,50 +383,50 @@ void purge_kicklist(void);
void do_kicksay(COMMAND_ARGS) __page(CMD1_SEG);
void do_rkicksay(COMMAND_ARGS) __page(CMD1_SEG);
/* lib/string.c */
/* string.c */
LS char *chop(char **) __page(CORE_SEG);
LS void unchop(char *, const char *) __page(CORE_SEG);
LS int stringcasecmp(const char *, const char *) __page(CORE_SEG);
LS int stringcmp(const char *, const char *) __page(CORE_SEG);
LS int nickcmp(const char *, const char *) __page(CORE_SEG);
LS char *nickcpy(char *, const char *) __page(CORE_SEG);
LS void stringcpy_n(char *, const char *, int) __page(CORE_SEG);
LS char *stringcpy(char *, const char *) __page(CORE_SEG);
LS char *stringchr(const char *, int) __page(CORE_SEG);
LS char *stringdup(const char *) __page(CORE_SEG);
LS char *stringcat(char *, const char *) __page(CORE_SEG);
LS char *tolowercat(char *, const char *) __page(CORE_SEG);
char *chop(char **) __page(CORE_SEG);
void unchop(char *, const char *) __page(CORE_SEG);
int stringcasecmp(const char *, const char *) __page(CORE_SEG);
int stringcmp(const char *, const char *) __page(CORE_SEG);
int nickcmp(const char *, const char *) __page(CORE_SEG);
char *nickcpy(char *, const char *) __page(CORE_SEG);
void stringcpy_n(char *, const char *, int) __page(CORE_SEG);
char *stringcpy(char *, const char *) __page(CORE_SEG);
char *stringchr(const char *, int) __page(CORE_SEG);
char *stringdup(const char *) __page(CORE_SEG);
char *stringcat(char *, const char *) __page(CORE_SEG);
char *tolowercat(char *, const char *) __page(CORE_SEG);
/* main.c */
void mech_exec(void) __page(RARE_SEG);
int randstring_count(char *line) __page(CMD1_SEG);
int randstring_getline(char *line) __page(CMD1_SEG);
LS char *randstring(const char *) __page(CORE_SEG);
LS int sig_hup_callback(char *) __page(RARE_SEG); /* rare */
LS void do_sighup(void) __page(CMD1_SEG);
LS void sig_hup(int) __page(RARE_SEG); /* rare */
LS void sig_child(int) __page(RARE_SEG); /* rare */
LS void sig_alrm(int) __page(RARE_SEG); /* rare */
LS void sig_pipe(int) __page(CORE_SEG);
LS void do_sigusr1(void) __page(CMD1_SEG);
LS void sig_usr1(int) __page(CMD1_SEG);
LS void sig_usr2(int) __page(DBUG_SEG); /* DEBUG */
LS void sig_suicide() __attr(RARE_SEG, __noreturn__); /* rare */
LS void do_sigint(void) __attr(RARE_SEG, __noreturn__); /* rare */
LS void sig_int(int) __page(RARE_SEG); /* rare */
LS void sig_ill(int) __page(RARE_SEG);
LS void sig_abrt(int) __page(RARE_SEG);
LS void sig_bus(int) __attr(RARE_SEG, __noreturn__);
char *randstring(const char *) __page(CORE_SEG);
int sig_hup_callback(char *) __page(RARE_SEG); /* rare */
void do_sighup(void) __page(CMD1_SEG);
void sig_hup(int) __page(RARE_SEG); /* rare */
void sig_child(int) __page(RARE_SEG); /* rare */
void sig_alrm(int) __page(RARE_SEG); /* rare */
void sig_pipe(int) __page(CORE_SEG);
void do_sigusr1(void) __page(CMD1_SEG);
void sig_usr1(int) __page(CMD1_SEG);
void sig_usr2(int) __page(DBUG_SEG); /* DEBUG */
void sig_suicide() __attr(RARE_SEG, __noreturn__); /* rare */
void do_sigint(void) __attr(RARE_SEG, __noreturn__); /* rare */
void sig_int(int) __page(RARE_SEG); /* rare */
void sig_ill(int) __page(RARE_SEG);
void sig_abrt(int) __page(RARE_SEG);
void sig_bus(int) __attr(RARE_SEG, __noreturn__);
#if defined(__linux__) && defined(__x86_64__) && defined(DEBUG) && !defined(__STRICT_ANSI__)
LS void sig_segv(int, siginfo_t *, void *) __attr(RARE_SEG, __noreturn__);
void sig_segv(int, siginfo_t *, void *) __attr(RARE_SEG, __noreturn__);
#else
LS void sig_segv(int) __attr(RARE_SEG, __noreturn__);
void sig_segv(int) __attr(RARE_SEG, __noreturn__);
#endif
LS void sig_term(int) __attr(RARE_SEG, __noreturn__); /* rare */
void sig_term(int) __attr(RARE_SEG, __noreturn__); /* rare */
int main(int argc, char **argv, char **envp) __page(INIT_SEG);
int parse_commandline(int argc, char **argv, char **envp) __page(INIT_SEG);
void parse_commandline(int argc, char **argv, char **envp) __page(INIT_SEG);
void mainloop(void) __attr(CORE_SEG, __noreturn__);
/* net.c */
@ -548,7 +548,6 @@ void parse_346(char *from, char *rest) __page(CORE_SEG);
void parse_348(char *from, char *rest) __page(CORE_SEG);
void parse_368(char *from, char *rest) __page(CORE_SEG);
void parse_005(char *from, char *rest) __page(CORE_SEG);
static __INLINE__ uint32_t stringhash(char *) __page(CORE_SEG);
void parse_server_input(char *) __page(CORE_SEG);
/* partyline.c */
@ -572,6 +571,10 @@ void do_perlscript(COMMAND_ARGS) __page(CMD1_SEG);
/* prot.c */
void screwban_format(char *) __page(CORE_SEG);
void deop_ban(Chan *, ChanUser *, char *) __page(CORE_SEG);
void deop_siteban(Chan *, ChanUser *) __page(CORE_SEG);
void deop_screwban(Chan *, ChanUser *) __page(CORE_SEG);
void send_kick(Chan *chan, const char *nick, const char *format, ...);
void push_kicks(Chan *chan);
void unmode_chanuser(Chan *chan, ChanUser *cu);
@ -656,7 +659,7 @@ void send_spy(const char *src, const char *format, ...) __page(CORE_SEG);
void send_global(const char *src, const char *format, ...) __page(CORE_SEG);
void spy_typecount(Mech *bot) __page(CORE_SEG);
int spy_source(char *from, int *t_src, const char **src) __page(CORE_SEG);
char *urlhost(const char *) __page(CORE_SEG);
void urlhost(const char *) __page(CORE_SEG);
void urlcapture(const char *) __page(CORE_SEG);
int begin_redirect(char *, char *) __page(CORE_SEG);
void send_redirect(char *) __page(CORE_SEG);
@ -672,8 +675,8 @@ void do_urlhist(COMMAND_ARGS) __page(CMD1_SEG);
#ifdef TCL
/*
LS char *tcl_var_read(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags);
LS char *tcl_var_write(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags);
char *tcl_var_read(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags);
char *tcl_var_write(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags);
*/
int tcl_timer_jump(Hook *hook);
int tcl_parse_jump(char *from, char *rest, Hook *hook);
@ -682,14 +685,14 @@ void tcl_dcc_complete(Client *client, int cps);
int tcl_hook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
#endif
/*
LS int tcl_unhook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_userlevel(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_debug(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_to_server(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_to_file(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_dcc_sendfile(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_dns_jump(char *host, char *resolved, Hook *hook);
LS int tcl_dns(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_unhook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_userlevel(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_debug(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_to_server(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_to_file(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_dcc_sendfile(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
int tcl_dns_jump(char *host, char *resolved, Hook *hook);
int tcl_dns(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
*/
void init_tcl(void);
void do_tcl(COMMAND_ARGS) __page(CMD1_SEG);

View File

@ -145,7 +145,7 @@ help_loop:
return;
}
if (STRCHR(rest,'*'))
if (stringchr(rest,'*'))
{
line[0] = 0;
ci = 0;

View File

@ -53,7 +53,7 @@ struct /* statusvalues */
const int klen;
char *valbuf;
} sv[] =
} statusvalues[] =
{
{ "VmPeak:", 7, vmpeak },
{ "VmSize:", 7, vmsize },
@ -65,55 +65,9 @@ struct /* statusvalues */
{ NULL, 0, NULL }
};
#ifdef DEBUG
struct
{
int value;
char *str;
} in2str[] =
{
{ IN_ACCESS, "IN_ACCESS" }, /* File was accessed (read) */
{ IN_ATTRIB, "IN_ATTRIB" }, /* Metadata changed, e.g., permissions, timestamps, extended attributes, link count, UID, GID, etc. */
{ IN_CLOSE_WRITE, "IN_CLOSE_WRITE" }, /* File opened for writing was closed */
{ IN_CLOSE_NOWRITE, "IN_CLOSE_NOWRITE" }, /* File not opened for writing was closed */
{ IN_CREATE, "IN_CREATE" }, /* File/directory created in watched directory */
{ IN_DELETE, "IN_DELETE" }, /* File/directory deleted from watched directory */
{ IN_DELETE_SELF, "IN_DELETE_SELF" }, /* Watched file/directory was itself deleted */
{ IN_MODIFY, "IN_MODIFY" }, /* File was modified */
{ IN_MOVE_SELF, "IN_MOVE_SELF" }, /* Watched file/directory was itself moved */
{ IN_MOVED_FROM, "IN_MOVED_FROM" }, /* Generated for the directory containing the old filename when a file is renamed */
{ IN_MOVED_TO, "IN_MOVED_TO" }, /* Generated for the directory containing the new filename when a file is renamed */
{ IN_OPEN, "IN_OPEN" }, /* File was opened */
{ 0, NULL }
};
char *inomask2str(uint32_t mask, char *dst)
{
const char *src;
int i,n = 0;
for(i=0;in2str[i].str;i++)
{
if ((mask & in2str[i].value) == in2str[i].value)
{
if (n)
dst[n++] = '|';
src = in2str[i].str;
for(;src[n];n++)
dst[n] = src[n];
}
}
dst[n] = 0;
return(dst);
}
#endif /* DEBUG */
int monitor_fs(const char *file)
{
FileMon *fmon,*fnew;
FileMon *fnew;
int ino;
if ((ino = inotify_init()) < 0)
@ -145,15 +99,15 @@ int parse_proc_status(char *line)
#endif
if (key == NULL)
return(FALSE);
for(i=0;sv[i].key;i++)
for(i=0;statusvalues[i].key;i++)
{
if (strncmp(key,sv[i].key,sv[i].klen) == 0)
if (strncmp(key,statusvalues[i].key,statusvalues[i].klen) == 0)
{
#ifdef DEBUG
debug("(parse_proc_status) key %s -> %s\n",key,line);
#endif /* DEBUG */
dest = sv[i].valbuf;
limit = sv[i].valbuf + 31;
dest = statusvalues[i].valbuf;
limit = statusvalues[i].valbuf + 31;
while(*line == ' ')
line++;
while(*line && dest <= limit)
@ -250,29 +204,41 @@ int parse_proc_cpuinfo(char *line)
return(FALSE); /* return false to continue reading lines */
}
void select_monitor()
void select_monitor(void)
{
FileMon *fmon;
for(fmon=filemonlist;fmon;fmon=fmon->next)
{
if (fmon->fd >= 0)
{
FD_SET(fmon->fd,&read_fds);
chkhigh(fmon->fd);
}
}
}
void process_monitor()
#ifdef DEBUG
extern const DEFstruct inomasks[];
#endif /* DEBUG */
void process_monitor(void)
{
FileMon *fmon;
struct inotify_event *ivent;
#ifdef DEBUG
char tmp[256];
int n,m;
int n;
#else
int n __notused__;
#endif /* DEBUG */
int m __notused__;
for(fmon=filemonlist;fmon;fmon=fmon->next)
{
if (fmon->fd >= 0 && FD_ISSET(fmon->fd,&read_fds))
{
if (fmon->fd < 0 || 0 == FD_ISSET(fmon->fd,&read_fds))
continue;
ivent = (struct inotify_event *)&globaldata;
n = read(fmon->fd,globaldata,sizeof(struct inotify_event));
@ -281,14 +247,11 @@ void process_monitor()
else
*ivent->name = 0;
#ifdef DEBUG
debug("(process_monitor) ino %i, n %i, sz %i\n",fmon->fd,n,sizeof(in2str));
debug("(process_monitor) wd %i, mask %lu, cookie %lu, len %lu, name %s\n",
ivent->wd,ivent->mask,ivent->cookie,ivent->len,ivent->name);
debug("(process_monitor) %s\n",inomask2str(ivent->mask,tmp));
debug("(process_monitor) ino %i bytes read, int wd = %i, uint32_t mask = %s (%lu), "
"uint32_t cookie = %lu, uint32_t len = %lu, char name = %s\n",
n,ivent->wd,inomask2str(ivent->mask,tmp),ivent->mask,ivent->cookie,ivent->len,ivent->name);
#endif
strflags(tmp,inomasks,ivent->mask);
debug("(process_monitor) ino {%i} %i bytes, wd = %i, mask = %s (%lu), cookie = %lu, len = %lu, name = %s\n",
fmon->fd,n,ivent->wd,tmp,ivent->mask,ivent->cookie,ivent->len,ivent->name);
#endif /* DEBUG */
if ((ivent->mask & IN_CLOSE_WRITE) == IN_CLOSE_WRITE)
return;
if (fmon->nospam > now-30)
@ -296,7 +259,6 @@ void process_monitor()
fmon->nospam = now;
send_global(SPYSTR_SYSMON,"Alert: file ``%s'' was touched",fmon->filename);
}
}
}
/*---------------------------------------------------------------------------------------------------------------------------------------------------*/
@ -346,8 +308,8 @@ void do_meminfo(COMMAND_ARGS)
p = getpid();
snprintf(fn,sizeof(fn),"/proc/%i/status",p);
for(i=0;sv[i].key;i++)
*(sv[i].valbuf) = 0;
for(i=0;statusvalues[i].key;i++)
*(statusvalues[i].valbuf) = 0;
if ((fd = open(fn,O_RDONLY)) < 0)
return;
readline(fd,&parse_proc_status); /* readline closes fd */
@ -364,18 +326,9 @@ See also: hostinfo, meminfo
void do_cpuinfo(COMMAND_ARGS)
{
char bogostr[256],cpustr[64];
char *a1,*a2,*a3,*dst;
int fd,n;
int fd;
double loads[3];
#ifdef DEVELOPING
a1 = chop(&rest);
if (a1)
sprintf(bogostr,"/home/git/cpuinfo/%s",a1);
else
stringcpy(bogostr,"/proc/cpuinfo");
if ((fd = open(bogostr,O_RDONLY)) < 0)
#endif
if ((fd = open("/proc/cpuinfo",O_RDONLY)) < 0)
#ifdef DEBUG
{

View File

@ -204,7 +204,8 @@ int SockConnect(char *host, int port, int use_vhost)
int SockAccept(int sock)
{
struct sockaddr_in sai;
int s,sz;
unsigned int sz;
int s;
sz = sizeof(sai);
s = accept(sock,(struct sockaddr*)&sai,&sz);
@ -309,7 +310,7 @@ void to_user_q(const char *target, const char *format, ...)
if (STARTUP_ECHOTOCONSOLE)
{
int n;
int n __notused__;
n = write(1,message,strlen(message));
return;
}
@ -449,6 +450,91 @@ void to_user(const char *target, const char *format, ...)
#endif /* DEBUG */
}
Strp *output_table = NULL;
void table_buffer(const char *format, ...)
{
va_list msg;
va_start(msg,format);
vsprintf(globaldata,format,msg);
va_end(msg);
set_mallocdoer(table_buffer);
append_strp(&output_table,globaldata);
}
void table_send(const char *from, const int space)
{
char message[MAXLEN];
Strp *sp,*next;
char *src,*o,*end;
int i,u,g,x,columns[16];
memset(columns,0,sizeof(columns));
for(sp=output_table;sp;sp=sp->next)
{
u = i = 0;
src = o = sp->p;
while(*src)
{
/* Dont count control codes */
if (*src == '\037' || *src == '\002')
u++;
if (*src == '\t' || *src == '\r')
{
x = (src - o) - u;
if (x > columns[i])
columns[i] = x;
i++;
o = src+1;
u = 0;
}
src++;
}
}
for(sp=output_table;sp;sp=next)
{
next = sp->next;
o = message;
src = sp->p;
g = x = i = 0;
while(*src)
{
if (g)
{
end = src;
while(*end && *end != '\t' && *end != '\r')
end++;
g -= (end - src);
while(g-- > 0)
*(o++) = ' ';
}
if (*src == '\037' || *src == '\002')
x++;
if (*src == '\t' || *src == '\r')
{
if (*src == '\r')
g = columns[i+1];
src++;
x += (columns[i++] + space);
while(o < (message + x))
*(o++) = ' ';
}
else
*(o++) = *(src++);
}
*o = 0;
to_user(from,FMT_PLAIN,message);
Free((char**)&sp);
}
output_table = NULL;
}
#endif /* ifndef GENCMD_C */
/*

View File

@ -144,8 +144,8 @@ void mech_exec(void)
exit(1);
}
LS int r_ct;
LS char r_str[MSGLEN];
int r_ct;
char r_str[MSGLEN];
int randstring_count(char *line)
{
@ -199,7 +199,7 @@ char *randstring(const char *file)
* SIGUSR2 Call run_debug() (dump `everything' to a debug file)
*/
LS struct
struct
{
uint32_t sighup:1,
sigint:1,
@ -667,7 +667,7 @@ doit_jumptonext:
if (current->ip.s_addr == 0)
{
struct sockaddr_in sai;
int sz;
unsigned int sz;
sz = sizeof(sai);
if (getsockname(current->sock,(struct sockaddr *)&sai,&sz) == 0)
@ -777,6 +777,18 @@ restart_dcc:
if (current->sock != -1)
process_server_input();
#ifdef DEBUG
if (current->inject)
{
char injection[MSGLEN];
stringcpy(injection,current->inject);
Free((char**)&current->inject);
debug("(*inject) %s\n");
parse_server_input(injection);
}
#endif /* DEBUG */
if (current->connect == CN_ONLINE)
{
/*
@ -897,7 +909,7 @@ restart_die:
const char *bad_exe = "init: Error: Improper executable name\n";
int parse_commandline(int argc, char **argv, char **envp)
void parse_commandline(int argc, char **argv, char **envp)
{
struct stat st;
char *opt;
@ -919,6 +931,11 @@ int parse_commandline(int argc, char **argv, char **envp)
stat("..",&st);
parent_inode = st.st_ino; /* used for is_safepath() */
if (stat("/proc",&st) >= 0)
{
cx.system_uptime = st.st_ctime;
}
srand(now+getpid());
/*
@ -956,6 +973,7 @@ int parse_commandline(int argc, char **argv, char **envp)
}
#ifdef DEBUG
/* memory tracking */
mrrec = calloc(sizeof(aMEA),1);
#endif /* DEBUG */
@ -964,7 +982,7 @@ int parse_commandline(int argc, char **argv, char **envp)
to_file(1,bad_exe);
_exit(1);
}
if ((opt = STRCHR(*argv,' ')) != NULL)
if ((opt = stringchr(*argv,' ')) != NULL)
{
*(opt++) = 0;
respawn = asc2int(opt);
@ -984,66 +1002,26 @@ int parse_commandline(int argc, char **argv, char **envp)
opt = *argv;
switch(opt[1])
{
case 'v':
versiononly = TRUE;
break;
case 'h':
to_file(1,TEXT_USAGE,executable);
to_file(1,
TEXT_CSWITCH
#ifdef DEBUG
TEXT_DSWITCH
#endif /* DEBUG */
TEXT_ESWITCH
TEXT_FSWITCH
TEXT_HSWITCH
#ifdef DEBUG
TEXT_OSWITCH
TEXT_PSWITCH1
TEXT_PSWITCH2
#endif /* DEBUG */
TEXT_TSWITCH
TEXT_VSWITCH
#ifdef DEBUG
TEXT_XSWITCH
#endif /* DEBUG */
);
_exit(0);
case 'c':
makecore = TRUE;
break;
#ifdef DEBUG
case 'd':
dodebug = TRUE;
do_fork = FALSE;
break;
case 'o':
if (opt[2] != 0)
do_fork = TRUE;
if (opt[2] != 0) /* -d[file] */
{
debugfile = &opt[2];
}
else
if (argv[1] && argv[1][0] != '-') /* -d [file] */
{
++argv;
if (!*argv)
{
to_file(1,"init: No debugfile specified\n");
_exit(0);
}
debugfile = *argv;
argc--;
}
do_fork = TRUE;
break;
case 'p':
++argv;
if (*argv)
to_file(1,"%s\n",makepass(*argv));
else
to_file(1,"error: Missing argument for -p <string>\n");
_exit(0);
case 'X':
debug_on_exit = TRUE;
do_fork = FALSE;
break;
#endif /* DEBUG */
case 'e': /* run a single command before exiting */
@ -1057,9 +1035,6 @@ int parse_commandline(int argc, char **argv, char **envp)
else
to_file(1,"error: Missing argument for -e <command string>\n");
_exit(0);
case 't':
startup = STARTUP_TESTRUN;
break;
case 'f':
if (opt[2] != 0)
{
@ -1078,6 +1053,43 @@ int parse_commandline(int argc, char **argv, char **envp)
}
to_file(1,INFO_USINGCONF,configfile);
break;
case 'h':
to_file(1,TEXT_USAGE,executable);
to_file(1,
TEXT_CSWITCH
#ifdef DEBUG
TEXT_DSWITCH
#endif /* DEBUG */
TEXT_ESWITCH
TEXT_FSWITCH
TEXT_HSWITCH
TEXT_PSWITCH1
TEXT_PSWITCH2
TEXT_TSWITCH
TEXT_VSWITCH
#ifdef DEBUG
TEXT_XSWITCH
#endif /* DEBUG */
);
_exit(0);
case 'p':
++argv;
if (*argv)
to_file(1,"%s\n",makepass(*argv));
else
to_file(1,"error: Missing argument for -p <string>\n");
_exit(0);
case 't':
startup = STARTUP_TESTRUN;
break;
case 'v':
versiononly = TRUE;
break;
#ifdef DEBUG
case 'x':
debug_on_exit = TRUE;
break;
#endif /* DEBUG */
default:
to_file(1,ERR_UNKNOWNOPT,opt);
_exit(1);
@ -1098,7 +1110,7 @@ int parse_commandline(int argc, char **argv, char **envp)
to_file(1,"warning: current configuration file overrides session file\n");
}
#endif /* SESSION */
if (stat(configfile,&st));
if (stat(configfile,&st))
{
if ((st.st_mode & (S_IWGRP|S_IWOTH)) != 0)
{
@ -1108,7 +1120,7 @@ int parse_commandline(int argc, char **argv, char **envp)
if ((st.st_mode & (S_IRGRP|S_IROTH)) != 0)
to_file(1,"warning: configfile is readable by others\n");
}
if (stat(".",&st));
if (stat(".",&st))
{
if ((st.st_mode & (S_IWGRP|S_IWOTH)) != 0)
{
@ -1174,7 +1186,7 @@ int parse_commandline(int argc, char **argv, char **envp)
}
#else
{
if (stat(opt,&st));
if (stat(opt,&st))
{
if ((st.st_mode & (S_IWGRP|S_IWOTH)) != 0)
{

View File

@ -46,10 +46,11 @@ const char banneropt[] = "BB%i %i PTA"
#ifdef TELNET
char *telnetprompt = TEXT_ENTERNICKNAME;
#endif /* TELNET */
/*
* this is a partial copy of the BotNet struct
*/
LS struct
struct
{
struct BotNet *next;
@ -73,7 +74,7 @@ typedef struct LinkCmd
#define RELAY_YES 1
#define RELAY_NO 0
LS const LinkCmd basicProto[] =
const LinkCmd basicProto[] =
{
{ "BA", basicAuth, RELAY_NO },
{ "BB", basicBanner, RELAY_NO },
@ -95,7 +96,7 @@ LS const LinkCmd basicProto[] =
{ "\0\0", NULL, RELAY_NO },
};
LS int deadlinks = FALSE;
int deadlinks = FALSE;
/*
*
@ -160,7 +161,6 @@ NetCfg *find_netcfg(int guid)
BotInfo *make_botinfo(int guid, int hops, char *nuh, char *server, char *version)
{
BotInfo *newbinfo;
int sn,vn;
set_mallocdoer(make_botinfo);
newbinfo = (BotInfo*)Calloc(sizeof(BotInfo) + StrlenX(nuh,server,version,NULL));
@ -168,11 +168,6 @@ BotInfo *make_botinfo(int guid, int hops, char *nuh, char *server, char *version
newbinfo->guid = guid;
newbinfo->hops = hops;
/*
sprintf(newbinfo->nuh,"%s%c%n%s%c%n%s",nuh,0,&sn,server,0,&vn,version);
newbinfo->server = newbinfo->nuh + sn;
newbinfo->version = newbinfo->nuh + vn;
*/
newbinfo->server = stringcat(newbinfo->nuh,nuh) + 1;
newbinfo->version = stringcat(newbinfo->server,server) + 1;
stringcpy(newbinfo->version,version);
@ -922,10 +917,10 @@ void partyAuth(BotNet *bn, char *rest)
{
User *user;
Strp *ump;
char *name,*userhost,*checksum;
char *userhost,*checksum;
int m;
name = chop(&rest);
chop(&rest);
userhost = chop(&rest);
if ((checksum = chop(&rest)) == NULL)
checksum = "";
@ -1337,10 +1332,8 @@ void ushareTick(BotNet *bn, char *rest)
void ushareDelete(BotNet *bn, char *rest)
{
User *user;
char *orig;
int modcount;
orig = rest;
modcount = asc2int(chop(&rest));
if (errno)
return;
@ -1779,10 +1772,9 @@ void do_cmd(COMMAND_ARGS)
Mech *backup;
char tempdata[MAXLEN];
char *target,*orig = rest;
int guid;
target = chop(&rest);
guid = asc2int(target);
asc2int(target);
if (errno)
{
unchop(orig,rest);
@ -1796,7 +1788,7 @@ void do_cmd(COMMAND_ARGS)
return;
}
if (STRCHR(from,'!'))
if (stringchr(from,'!'))
sprintf(tempdata,"%s %i %s %s",target,current->guid,from,rest);
else
sprintf(tempdata,"%s %i %s!%s %s",target,current->guid,from,CurrentUser->mask->p,rest);

View File

@ -34,7 +34,6 @@ int catch_note(char *from, char *to, char *rest)
{
User *u;
Note *n,**pp;
Strp *sp,**np;
#ifdef DEBUG
debug("(catch_note) from = %s, to = %s, rest = %s\n",from,to,rest);
@ -85,7 +84,6 @@ void do_note(COMMAND_ARGS)
{
User *u;
Note *n;
Strp *sp,**np;
char header[MSGLEN];
/*
@ -112,7 +110,7 @@ void do_note(COMMAND_ARGS)
/*
* add a note header
*/
sprintf(header,"\001%s %s",from,time2str(now));
sprintf(header,"\001%s %s",from,maketimestr(now,TFMT_FULL));
append_strp(&u->note,header);
}

112
src/ons.c
View File

@ -231,7 +231,7 @@ void on_join(Chan *chan, char *from)
*/
if (chan->setting[TOG_CTL].int_var)
{
if (STRCHR(from,'\031') || STRCHR(from,'\002') || STRCHR(from,'\022') || STRCHR(from,'\026'))
if (stringchr(from,'\031') || stringchr(from,'\002') || stringchr(from,'\022') || stringchr(from,'\026'))
{
deop_siteban(chan,cu);
send_kick(chan,CurrentNick,KICK_BAD_IDENT);
@ -639,20 +639,20 @@ recheck_alias:
Free(&current->lastcmds[LASTCMDSIZE-1]);
for(j=LASTCMDSIZE-2;j>=0;j--)
current->lastcmds[j+1] = current->lastcmds[j];
if ((pt = STRCHR(from,'@')) == NULL)
if ((pt = stringchr(from,'@')) == NULL)
pt = from;
set_mallocdoer(on_msg);
current->lastcmds[0] = (char*)Calloc(strlen(pt) + 45);
if (CurrentUser)
{
sprintf(current->lastcmds[0],"[%s] %s\r%s[%-3i]\t(*%s)",
time2medium(now),command,CurrentUser->name,
maketimestr(now,TFMT_CLOCK),command,CurrentUser->name,
(CurrentUser->x.x.access),pt);
}
else
{
sprintf(current->lastcmds[0],"[%s] %s\r%s[---]\t(*%s)",
time2medium(now),command,CurrentNick,pt);
maketimestr(now,TFMT_CLOCK),command,CurrentNick,pt);
}
}
@ -745,8 +745,11 @@ void on_mode(char *from, char *channel, char *rest)
char templimit[20];
char *nick;
char *parm,*nickuh,*mode;
int i,sign,enfm,maxprot;
int i,sign,rev,enfm,flag,maxprot,isself;
#ifdef DEBUG
debug("(on_mode) %s --> %s: %s\n",from,channel,rest);
#endif /* DEBUG */
if ((chan = find_channel_ac(channel)) == NULL)
return;
channel = chan->name;
@ -765,16 +768,6 @@ void on_mode(char *from, char *channel, char *rest)
doer = find_chanuser(chan,from);
modeloop:
if (*mode == 'o' || *mode == 'v')
{
nick = chop(&rest);
if ((victim = find_chanuser(chan,nick)) == NULL)
{
mode++;
goto modeloop;
}
}
switch(*mode)
{
case '+':
@ -783,25 +776,50 @@ modeloop:
break;
/*
*
* MODE <channel> +/-v <nick>
* MODE <channel> +/-o <nick>
*
*/
case 'v':
case 'o':
nick = chop(&rest);
victim = find_chanuser(chan,nick);
if (victim == NULL) /* Cant take action against an unknown entity */
{
mode++;
goto modeloop;
}
rev = 0;
i = (victim->user) ? victim->user->x.x.access : 0;
/*
* Can only be 'o' or 'v'
* Sign can only be '+' or '-'
* #define CU_VOICE 0x0001
* #define CU_CHANOP 0x0002
*/
flag = CU_VOICE + (*mode == 'o');
victim->flags &= ~flag;
victim->flags |= (flag & (-(sign == '+')));
if (*mode == 'v')
break;
victim->flags &= ~CU_DEOPPED;
isself = (0 == nickcmp(getbotnick(current),nick)) ? TRUE : FALSE;
/* +o */ if (sign == '+')
{
victim->flags |= CU_CHANOP;
victim->flags &= ~CU_DEOPPED;
if (!i)
if (0 == i)
{
if (victim->shit || (chan->setting[TOG_SD].int_var && !doer) ||
chan->setting[TOG_SO].int_var)
if (victim->shit || (chan->setting[TOG_SO].int_var) || (chan->setting[TOG_SD].int_var && !doer))
{
send_mode(chan,60,QM_CHANUSER,'-','o',victim);
rev = '-';
}
}
else
if (!nickcmp(getbotnick(current),nick))
if (isself)
{
/*
* wooohoooo! they gave me ops!!!
@ -815,35 +833,30 @@ modeloop:
}
check_shit();
update_modes(chan);
if (current->spy & SPYF_STATUS)
send_spy(SPYSTR_STATUS,"Given op on %s, set by %s",chan->name,nick);
}
#ifdef DEBUG
debug("(on_mode) %s!%s --> %i\n",victim->nick,victim->userhost,i);
#endif /* DEBUG */
}
/* -o */ else
{
victim->flags &= ~(CU_CHANOP|CU_DEOPPED);
if (i == BOTLEVEL)
{
if (!nickcmp(getbotnick(current),nick))
if (isself)
{
/*
* they dont love me!!! :~(
*/
chan->bot_is_op = FALSE;
}
if (current->spy & SPYF_STATUS)
send_spy(SPYSTR_STATUS,"Lost op on %s, removed by %s",chan->name,nick);
}
/*
* idiots deopping themselves
*/
if (!nickcmp(from,nick))
#ifdef DEBUG
debug("(on_mode) doer == victim: %s\n",(doer == victim) ? "TRUE" : "FALSE");
#endif /* DEBUG */
if (doer == victim)
break;
/*
* 1. Use enfm var to temporarily store users access
* 2. get_userlevel also checks is_localbot()...
*/
enfm = (doer && doer->user) ? doer->user->x.x.access : 0;
if (enfm == BOTLEVEL)
if (doer && doer->user && doer->user->x.x.access >= OWNERLEVEL)
break;
if (check_mass(chan,doer,INT_MDL))
mass_action(chan,doer);
@ -855,29 +868,14 @@ modeloop:
nickuh = get_nuh(victim);
if (get_authaccess(nickuh,channel))
{
send_mode(chan,60,QM_CHANUSER,'+','o',victim);
rev = '+';
prot_action(chan,from,doer,NULL,victim);
}
}
}
if (rev)
send_mode(chan,60,QM_CHANUSER,rev,'o',victim);
break;
/*
*
* MODE <channel> +/-v <nick>
*
*/
case 'v':
if (sign == '+')
victim->flags |= CU_VOICE;
else
victim->flags &= ~CU_VOICE;
break;
#ifdef IRCD_EXTENSIONS
/*
:joonicks!*@* MODE #emech +I *king*!*@*
:joonicks!*@* MODE #emech +e *kong*!*@*
*/
#endif /* IRCD_EXTENSIONS */
/*
*
* MODE <channel> +/-b <parm>
@ -886,6 +884,8 @@ modeloop:
#ifdef IRCD_EXTENSIONS
/*
* ircnet braindamage modes
* :joonicks!*@* MODE #emech +I *king*!*@*
* :joonicks!*@* MODE #emech +e *kong*!*@*
*/
case 'I':
case 'e':

View File

@ -816,7 +816,7 @@ void parse_317(char *from, char *rest)
}
if (when != -1)
send_pa(PA_WHOIS,nick,"Signed On: %s",time2away(when));
send_pa(PA_WHOIS,nick,"Signed On: %s",maketimestr(when,TFMT_AWAY));
send_pa(PA_WHOIS,nick,
(sec) ? "Idle: %i minute%s, %i second%s" : "Idle: %i minute%s",

View File

@ -124,7 +124,7 @@ void partyline_banner(Client *client)
sprintf(tmp,"[%s] %s[%i] has connected",
getbotnick(current),client->user->name,(int)client->user->x.x.access);
if ((to_file(client->sock,"[%s] %s\n",time2medium(now),tmp)) < 0)
if ((to_file(client->sock,"[%s] %s\n",maketimestr(now,TFMT_CLOCK),tmp)) < 0)
{
client->flags = DCC_DELETE;
return;
@ -142,9 +142,10 @@ void partyline_banner(Client *client)
void dcc_chat(char *from)
{
struct sockaddr_in sai;
unsigned int sz;
Client *client;
User *user;
int sock,sz;
int sock;
if ((user = get_authuser(from,NULL)) == NULL)
return;

View File

@ -28,6 +28,60 @@
#include "text.h"
#include "mcmd.h"
/*
* deal with undesired lusers
*/
void screwban_format(char *userhost)
{
int sz,n,pos;
#ifdef DEBUG
debug("(screwban_format) %s\n",userhost);
#endif /* DEBUG */
if ((sz = strlen(userhost)) < 8)
return;
n = RANDOM(4,sz);
while(--n)
{
pos = RANDOM(0,(sz - 1));
if (!stringchr("?!@*",userhost[pos]))
{
userhost[pos] = (RANDOM(0,3) == 0) ? '*' : '?';
}
}
}
void deop_ban(Chan *chan, ChanUser *victim, char *mask)
{
if (!mask)
mask = format_uh(get_nuh(victim),FUH_USERHOST);
send_mode(chan,85,QM_CHANUSER,'-','o',victim);
send_mode(chan,90,QM_RAWMODE,'+','b',mask);
}
void deop_siteban(Chan *chan, ChanUser *victim)
{
char *mask;
mask = format_uh(get_nuh(victim),FUH_HOST);
deop_ban(chan,victim,mask);
}
void deop_screwban(Chan *chan, ChanUser *victim)
{
char *mask;
int i;
for(i=2;--i;)
{
mask = format_uh(get_nuh(victim),FUH_USERHOST);
screwban_format(mask);
deop_ban(chan,victim,mask);
}
}
/*
*
* kicking and screaming
@ -821,7 +875,7 @@ void do_unban(COMMAND_ARGS)
if (((chan = find_channel_ac(to)) == NULL) || !chan->bot_is_op)
return;
if (nick && STRCHR(nick,'*'))
if (nick && stringchr(nick,'*'))
{
channel_massunban(chan,nick,0);
return;

View File

@ -1,7 +1,7 @@
/*
EnergyMech, IRC bot software
Copyright (c) 1997-2018 proton
Copyright (c) 1997-2025 proton
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -27,11 +27,13 @@
#include "h.h"
#ifdef TELNET
LS int client_type = DCC_ACTIVE;
int client_type = DCC_ACTIVE;
#endif /* TELNET */
#define mkaxx(x) (0x40404040 + (0x0f0f & x) + ((0xf0f0 & x) << 12))
#define getaxx(x) (((x & 0x0f0f0000) >> 12) | (x & 0x00000f0f))
#define simpleencode(x) (0x41414141 + (0x0f0f & x) + ((0xf0f0 & x) << 12))
#define simpledecode(x) ((((x - 0x41410000) & 0x0f0f0000) >> 12) | ((x - 0x4141) & 0x0f0f))
char *recover_client(char *env)
{
@ -40,17 +42,18 @@ char *recover_client(char *env)
char asc[8];
} axx;
struct sockaddr_in sai;
unsigned int sz;
Client *client;
User *user;
char *p,*handle;
int guid = 0,fd = 0,sz;
int guid = 0,fd = 0;
if (env[8] != ':')
return(env);
memcpy(axx.asc,env,8); /* compiler is not stupid and will optimize the shit out of this */
guid = getaxx(axx.num[0]);
fd = getaxx(axx.num[1]);
guid = simpledecode(axx.num[0]);
fd = simpledecode(axx.num[1]);
handle = p = (env = env + 9);
while(*p)
@ -97,7 +100,7 @@ char *recover_client(char *env)
found_user:
if (to_file(fd,"[%s] [%s] %s[%i] has connected (reset recover)\n",
time2medium(now),getbotwantnick(current),handle,user->x.x.access) < 0)
maketimestr(now,TFMT_CLOCK),getbotwantnick(current),handle,user->x.x.access) < 0)
{
close(fd);
return(p);
@ -142,16 +145,16 @@ char *recover_debug(char *env)
char asc[4];
} axx;
struct stat s;
char *d;
debug_fd = 0;
d = stringchr(env,'&');
if (env[4] != ' ' && env[4] != 0)
return(env);
/*
* get the fd number
*/
memcpy(axx.asc,env,4); /* compiler is not stupid and will optimize the shit out of this */
debug_fd = getaxx(axx.num);
debug_fd = simpledecode(axx.num);
if (fstat(debug_fd,&s) < 0)
{
@ -164,17 +167,19 @@ char *recover_debug(char *env)
dodebug = TRUE;
debug("(recover_debug) {%i} debug fd recovered\n",debug_fd);
CoreClient.sock = debug_fd;
if (d && is_safepath(d+1,FILE_MAY_EXIST) == TRUE)
{
debugfile = d+1;
debug("(recover_debug) output file = %s\n",debugfile);
}
return(env+4);
}
d = chop(&env);
return(env);
}
#endif /* DEBUG */
/*
(do_reset) mkaxx(3) = C@@@
(do_reset) ircx mkaxx(12) = L@@@
(do_reset) sock mkaxx(2) = B@@@
(do_reset) guid mkaxx(1881) = IGE@
[StS] {2} PING :OT1523818405
(do_reset) MECHRESET=dC@@@ fXIGE@B@@@L@@@ tIGE@F@@@:joo [44]
execve( ./energymech, argv = { ./energymech <NULL> <NULL> <NULL> <NULL> }, envp = { MECHRESET=dC@@@ fXIGE@B@@@L@@@ tIGE@F@@@:joo } )
@ -187,8 +192,8 @@ char *recover_server(char *env)
char asc[16];
} axx;
struct sockaddr_in sai;
char *p;
int guid = 0,fd = 0,sz;
unsigned int sz;
int guid = 0,fd = 0;
#ifdef IRCD_EXTENSIONS
int ircx = 0;
#endif /* IRCD_EXTENSIONS */
@ -209,10 +214,10 @@ char *recover_server(char *env)
memcpy(axx.asc,env,sz); /* compiler is not stupid and will optimize the shit out of this */
env += sz;
guid = getaxx(axx.num[0]);
fd = getaxx(axx.num[1]);
guid = simpledecode(axx.num[0]);
fd = simpledecode(axx.num[1]);
#ifdef IRCD_EXTENSIONS
ircx = getaxx(axx.num[2]);
ircx = simpledecode(axx.num[2]);
#ifdef DEBUG
debug("(recover_server) guid = %i; fd = %i, ircx = %i\n",guid,fd,ircx);
#endif /* DEBUG */
@ -251,7 +256,7 @@ char *recover_server(char *env)
/* if the guid changed, we cant guess which old<-->new is the matching one so */
if (fd != -1)
{
to_file(fd,"QUIT :I'm no longer wanted *cry*\n");
to_file(fd,"QUIT :Am I a figment of my own imagination?\n");
killsock(fd);
}
return(env);
@ -314,9 +319,8 @@ void do_reset(COMMAND_ARGS)
} axx;
Client *client;
Mech *backup;
char env[MSGLEN];
char *p;
int n,sz;
char *p,env[MSGLEN];
int sz;
if (current->userlist && current->ul_save)
{
@ -350,10 +354,12 @@ void do_reset(COMMAND_ARGS)
*/
if (dodebug && (debug_fd >= 0))
{
axx.num[0] = mkaxx(debug_fd);
axx.num[0] = simpleencode(debug_fd);
axx.num[1] = 0;
sprintf(p,"d%s",axx.asc);
p = STREND(p);
if (debugfile)
p += sprintf(p,"d%s&%s",axx.asc,debugfile);
else
p += sprintf(p,"d%s",axx.asc);
}
#endif /* DEBUG */
/*
@ -365,17 +371,14 @@ void do_reset(COMMAND_ARGS)
if ((current->connect == CN_ONLINE) && ((MSGLEN - (p - env)) > 25))
{
unset_closeonexec(current->sock);
axx.num[0] = mkaxx(current->guid);
axx.num[1] = mkaxx(current->sock);
#ifdef IRCD_EXTENSIONS
axx.num[2] = mkaxx(current->ircx_flags);
axx.num[3] = 0;
sprintf(p," fX%s",axx.asc);
#else /* IRCD_EXTENSIONS */
axx.num[0] = simpleencode(current->guid);
axx.num[1] = simpleencode(current->sock);
axx.num[2] = 0;
sprintf(p," fx%s",axx.asc);
axx.num[3] = 0;
#ifdef IRCD_EXTENSIONS
axx.num[2] = simpleencode(current->ircx_flags);
#endif /* IRCD_EXTENSIONS */
p = STREND(p);
p += sprintf(p," fX%s",axx.asc);
to_server("PING :OT%lu\n",current->ontime);
}
for(client=current->clientlist;client;client=client->next)
@ -391,16 +394,15 @@ void do_reset(COMMAND_ARGS)
if ((MSGLEN - (p - env)) > sz)
{
unset_closeonexec(client->sock);
axx.num[0] = mkaxx(current->guid);
axx.num[1] = mkaxx(client->sock);
axx.num[0] = simpleencode(current->guid);
axx.num[1] = simpleencode(client->sock);
axx.num[2] = 0;
#ifdef TELNET
sprintf(p,(client->flags & DCC_TELNET) ? " t%s:%s" : " c%s:%s",
p += sprintf(p,(client->flags & DCC_TELNET) ? " t%s:%s" : " c%s:%s",
axx.asc,client->user->name);
#else
sprintf(p," c%s:%s",axx.asc,client->user->name);
p += sprintf(p," c%s:%s",axx.asc,client->user->name);
#endif /* TELNET */
p = STREND(p);
}
}
}

View File

@ -44,7 +44,7 @@
#define NF_OPTIONS 7
LS const char notify_opt[NF_OPTIONS][10] =
const char notify_opt[NF_OPTIONS][10] =
{
"-ALL",
"-NOMATCH",
@ -53,9 +53,9 @@ LS const char notify_opt[NF_OPTIONS][10] =
"-SEEN",
};
LS Notify **endoflist;
LS int lock_ison = FALSE;
LS int nf_header;
Notify **endoflist;
int lock_ison = FALSE;
int nf_header;
void purge_notify(void)
{
@ -466,7 +466,7 @@ int notify_callback(char *rest)
{
nf->mask = dst + 1;
dst = stringcat(nf->mask,rest);
if (STRCHR(nf->mask,' '))
if (stringchr(nf->mask,' '))
nf->endofmask = dst;
}
if (src)
@ -565,7 +565,7 @@ void nfshow_full(Notify *nf)
for(nlog=nf->log;nlog;nlog=nlog->next)
{
opt = mem;
s = time2away(nlog->signon);
s = maketimestr(nlog->signon,TFMT_AWAY);
if (s[1] == ':')
*(opt++) = ' ';
*opt = 0;
@ -576,7 +576,7 @@ void nfshow_full(Notify *nf)
opt = stringcat(opt," -- ");
if (nlog->signoff)
{
s = time2away(nlog->signoff);
s = maketimestr(nlog->signoff,TFMT_AWAY);
if (s[1] == ':')
*(opt++) = ' ';
*opt = 0;
@ -826,12 +826,10 @@ void do_seen(COMMAND_ARGS)
{
Seen *seen;
char ago[35]; /* enought for "36500 days, 23 hours and 59 minutes" (100 years) */
const char *chan;
char *fmt,*n,*u,*c1,*c2,*c3;
time_t when;
int d,h,m,mul;
chan = get_channel(to,&rest);
mul = get_maxaccess(from);
if (!*rest)
@ -985,7 +983,7 @@ void do_notify(COMMAND_ARGS)
#ifdef DEBUG
debug("(do_notify) dumping errnames\n");
#endif /* DEBUG */
to_user(from,"User%s not found: %s",(STRCHR(message,',')) ? "s" : "",message);
to_user(from,"User%s not found: %s",(stringchr(message,',')) ? "s" : "",message);
}
if (nf_header)

View File

@ -24,7 +24,7 @@
#define DEFAULTCMDCHAR '-'
#define ZERO 0
#define ZERO .v.num=0
#define INTCAST(x) .v.num=x
#define CMDCHAR .v.chr=DEFAULTCMDCHAR
#define VNULL .v.str=NULL

View File

@ -58,7 +58,7 @@ void shit_action(Chan *chan, ChanUser *cu)
send_mode(chan,90,QM_RAWMODE,'+','b',shit->mask);
fromnick = nickcpy(NULL,shit->from);
send_kick(chan,nick,"%s %s: %s",time2small(shit->time),fromnick,
send_kick(chan,nick,"%s %s: %s",maketimestr(shit->time,TFMT_DATE),fromnick,
(shit->reason) ? shit->reason : "GET THE HELL OUT!!!");
return;
}
@ -335,7 +335,7 @@ void do_shit(COMMAND_ARGS)
add_shit(from,channel,nuh,rest,shitlevel,now + days);
to_user(from,TEXT_HASSHITTED,nuh,channel);
to_user(from,TEXT_SHITEXPIRES,time2str(now + days));
to_user(from,TEXT_SHITEXPIRES,maketimestr(now + days,TFMT_FULL));
check_shit();
}
@ -390,7 +390,7 @@ void do_shitlist(COMMAND_ARGS)
for(shit=current->shitlist;shit;shit=shit->next)
{
table_buffer(FMT_6XSTRTAB,shit->chan,shit->mask,shit_actions[shit->action],
nickcpy(NULL,shit->from),shit->reason,time2away(shit->expire));
nickcpy(NULL,shit->from),shit->reason,maketimestr(shit->expire,TFMT_AWAY));
}
table_send(from,2);
}

View File

@ -34,7 +34,7 @@
#ifdef DEBUG
LS const char SPY_DEFS[][12] =
const char SPY_DEFS[][12] =
{
"SPY_FILE",
"SPY_CHANNEL",
@ -51,7 +51,9 @@ LS const char SPY_DEFS[][12] =
#endif /* DEBUG */
#if defined(SHACRYPT) || defined(MD5CRYPT)
char *CRYPT_FUNC(const char *, const char *);
#endif
void send_spy(const char *src, const char *format, ...)
@ -62,15 +64,10 @@ void send_spy(const char *src, const char *format, ...)
va_list msg;
const char *spysrc;
const char *printmsg;
char tempdata[MAXLEN],*rnd,*dst,*end;
char tempdata[MAXLEN];
int fd;
int printed = FALSE;
if (src == SPYSTR_RAWIRC)
{
printmsg = format;
printed = TRUE;
}
printmsg = (src == SPYSTR_RAWIRC) ? format : NULL;
#ifdef DEBUG
if (src != SPYSTR_RAWIRC) /* too much debug spam */
@ -80,8 +77,16 @@ void send_spy(const char *src, const char *format, ...)
for(spy=current->spylist;spy;spy=spy->next)
{
/*
* Dont support RANDSRC unless there is a good hashing function to
* create high quality randomness.
*/
#if defined(SHACRYPT) || defined(MD5CRYPT)
if (spy->t_src == SPY_RANDSRC)
{
char mysalt[16],mydata[128];
char *rnd,*dst,*end;
if (src != SPYSTR_RAWIRC)
continue;
if (spy->data.delay > now)
@ -90,31 +95,24 @@ void send_spy(const char *src, const char *format, ...)
if (format[5] == ':')
continue;
/* create delay until next */
spy->data.delay = now + 10 + RANDOM(0,9); /* make it unpredictable which messages will be sourced */
spy->data.delay = now + 20 + RANDOM(0,29); /* make it unpredictable which messages will be sourced */
/*
* MD5 | 22 characters, $1$
* SHA-512 | 86 characters, $6$
*/
#if defined(SHACRYPT) || defined(MD5CRYPT)
sprintf(tempdata,
sprintf(mysalt,
#ifdef SHACRYPT
"$6$%04x",
#else
"$1$%04x",
#endif /* SHACRYPT */
#endif /* defined(SHACRYPT) || defined(MD5CRYPT) */
(uint32_t)(now & 0xFFFF));
rnd = CRYPT_FUNC(format,tempdata);
/* SHA512 internal returns NULL if strlen(format) > 256 */
stringcpy_n(mydata,format,120);
rnd = CRYPT_FUNC(mydata,mysalt);
dst = tempdata;
end = STREND(rnd);
#if defined(SHACRYPT) || defined(MD5CRYPT)
rnd += 8; /* skip salt */
#endif /* defined(SHACRYPT) || defined(MD5CRYPT) */
while(rnd < (end - 4))
{
@ -143,6 +141,13 @@ void send_spy(const char *src, const char *format, ...)
c = m32.b[2];
d = m32.b[3];
/*
|..aaaaaa|..bbbbbb|..cccccc|..dddddd|
| |aaaaaa..|bbbbbb..|cccccc..|
| | ddddDD|
| ddDD|dd
DD|dddd |
*/
/* base64 to bin, 4 chars to 3 */
dst[0] = (a << 2) | (b >> 4); /* aaaaaabb */
dst[1] = (b << 4) | (c >> 2); /* bbbbcccc */
@ -157,19 +162,14 @@ void send_spy(const char *src, const char *format, ...)
#endif /* DEBUG */
if ((fd = open(spy->dest,O_WRONLY|O_CREAT|O_APPEND,NEWFILEMODE)) >= 0)
{
int n;
int n __notused__;
n = write(fd,tempdata,dst - tempdata);
close(fd);
}
}
continue;
}
if (spy->t_src == SPY_STATUS)
spysrc = time2medium(now);
else
spysrc = spy->src;
#endif /* defined(SHACRYPT) || defined(MD5CRYPT) */
if ((*src == '#' || *src == '*') && spy->t_src == SPY_CHANNEL)
{
@ -187,9 +187,15 @@ void send_spy(const char *src, const char *format, ...)
if (spy->src != src)
continue;
if (!printed)
if (spy->t_src == SPY_STATUS)
{
spysrc = maketimestr(now,TFMT_CLOCK);
}
else
spysrc = spy->src;
if (printmsg == NULL)
{
printed = TRUE;
va_start(msg,format);
vsprintf(tempdata,format,msg);
va_end(msg);
@ -223,7 +229,7 @@ void send_spy(const char *src, const char *format, ...)
case SPY_FILE:
if ((fd = open(spy->dest,O_WRONLY|O_CREAT|O_APPEND,NEWFILEMODE)) >= 0)
{
to_file(fd,"[%s] %s\n",logtime(now),printmsg);
to_file(fd,"[%s] %s\n",maketimestr(now,TFMT_LOG),printmsg);
close(fd);
}
}
@ -320,7 +326,7 @@ int begin_redirect(char *from, char *args)
if (!args)
return(0);
pt = STRCHR(args,'>');
pt = stringchr(args,'>');
if (pt)
{
*pt = 0;
@ -457,10 +463,10 @@ void end_redirect(void)
#ifdef URLCAPTURE
char *urlhost(const char *url)
void urlhost(const char *url)
{
char copy[strlen(url)];
const char *end,*beg,*dst;
const char *end,*beg;
int n = 0;
beg = end = url;
@ -488,7 +494,7 @@ char *urlhost(const char *url)
void urlcapture(const char *rest)
{
Strp *sp,*nx;
Strp *sp;
char *dest,url[MSGLEN];
int n;
@ -1023,8 +1029,6 @@ void do_info(COMMAND_ARGS)
{
ChanStats *stats;
Chan *chan;
char *p;
char text[MSGLEN];
char modes[128];
uint32_t avg;

View File

@ -133,17 +133,6 @@ void stringcpy_n(char *dst, const char *src, int sz)
n++;
}
dst[n] = 0;
/*
char *stop = dst + sz - 1;
while(*src)
{
*(dst++) = *(src++);
if (dst == stop)
break;
}
*dst = 0;
*/
}
char *stringcpy(char *dst, const char *src)

View File

@ -106,12 +106,7 @@ typedef struct
typedef struct DEFstruct
{
union
{
int id;
void *func;
} v;
char *idstr;
} DEFstruct;
@ -605,6 +600,10 @@ typedef struct Mech
int ircx_flags;
#endif /* IRCD_EXTENSIONS */
#ifdef DEBUG
char *inject;
#endif /* DEBUG */
/*
* Buffers for do_die() command.
*/

View File

@ -32,7 +32,7 @@
#include <tcl.h>
LS Tcl_Interp *energymech_tcl = NULL;
Tcl_Interp *energymech_tcl = NULL;
#define tclv_READ TCL_TRACE_READS
#define tclv_WRITE TCL_TRACE_WRITES
@ -62,7 +62,7 @@ typedef struct Tcl_TVInfo
} Tcl_TVInfo;
LS Tcl_TVInfo vinfolist[] =
Tcl_TVInfo vinfolist[] =
{
{ TVINFO_pointer | TVINFO_CHAR, tclv_READ, "mech_currentnick", CurrentNick },
{ TVINFO_guid | TVINFO_INT, tclv_READ, "mech_guid" },
@ -518,7 +518,7 @@ int tcl_dns(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[])
*
*/
LS struct
struct
{
char *cmdname;
void *func;

View File

@ -72,8 +72,8 @@
#define TEXT_SERVERDELETED "Server has been deleted: %s:%i"
#define TEXT_MANYSERVMATCH "Several entries for %s exists, please specify port also"
/* do_core() */
#define TEXT_CURRNICKWANT "Current nick\t%s (Wanted: %s) [guid #%i]"
#define TEXT_CURRNICKHAS "Current nick\t%s [guid #%i]"
#define TEXT_CURRNICKWANT "Current nick\t%s%s (Wanted: %s) [guid #%i]"
#define TEXT_CURRNICKHAS "Current nick\t%s%s [guid #%i]"
#define TEXT_USERLISTSTATS "Users in userlist\t%i (%i Superuser%s, %i Bot%s)"
#define TEXT_ACTIVECHANS "Active channels\t%s"
#define TEXT_MOREACTIVECHANS "\t%s"
@ -83,11 +83,11 @@
#define TEXT_VHINACTIVE " - Inactive"
#define TEXT_CURRSERVER "Current Server\t%s:%i"
#define TEXT_CURRSERVGRP "Current Server\t%s:%i @%s"
#define TEXT_CURRSERVERNOT "Current Server\t" TEXT_NOTINSERVLIST
#define TEXT_TRYNEWSERVER "Trying new server, brb..."
#define TEXT_SWITCHSERVER "Switching servers..."
#define TEXT_SERVERONTIME "Server Ontime\t%s"
#define TEXT_BOTMODES "Mode\t+%s"
#define TEXT_CURRENTTIME "Current Time\t%s"
#define TEXT_BOTSTARTED "Started\t%s"
@ -137,7 +137,7 @@
#define TEXT_TSWITCH " -t run normal startup, but exit right before going into main loop\n"
#ifdef SHACRYPT
#define TEXT_PSWITCH1 " -p <string> encrypt <string> using the password hashing algorithm (SHA-512),\n"
#define TEXT_PSWITCH1 " -p <string> encrypt <string> using the password hashing algorithm (SHA),\n"
#elif MD5CRYPT
#define TEXT_PSWITCH1 " -p <string> encrypt <string> using the password hashing algorithm (MD5),\n"
#else
@ -145,9 +145,8 @@
#endif
#define TEXT_PSWITCH2 " output the result and then quit.\n"
#define TEXT_DSWITCH " -d start mech in debug mode\n"
#define TEXT_OSWITCH " -o <file> write debug output to <file>\n"
#define TEXT_XSWITCH " -X write a debug file before exit\n"
#define TEXT_DSWITCH " -d [file] start mech in debug mode, with an optional output file\n"
#define TEXT_XSWITCH " -x write a debug file before any exit\n"
#define TEXT_HDR_VERS "EnergyMech %s, %s\n"
#define TEXT_HDR_FEAT "Features: %s\n"

View File

@ -46,15 +46,15 @@
#define DAY_IN_SECONDS (24*60*60)
#define WEEK_IN_SECONDS (7*24*60*60)
LS TrivScore *lastwinner;
LS Chan *triv_chan = NULL;
LS Strp *triv_answers = NULL;
LS time_t triv_ask_time;
LS time_t triv_weektop10;
LS int triv_mode;
LS int triv_score;
LS int triv_streak;
LS int triv_halt_flag;
TrivScore *lastwinner;
Chan *triv_chan = NULL;
Strp *triv_answers = NULL;
time_t triv_ask_time;
time_t triv_weektop10;
int triv_mode;
int triv_score;
int triv_streak;
int triv_halt_flag;
#endif /* TRIVIA */
@ -195,6 +195,7 @@ int read_bigcharset(char *fname)
int read_ascii(char *rest)
{
to_user_q(global_from,FMT_PLAIN,rest);
return(0);
}
#ifdef TRIVIA
@ -268,7 +269,7 @@ void hint_one(void)
src = triv_answers->p;
while(*src)
{
if (STRCHR(TRIV_METACHARS,*src))
if (stringchr(TRIV_METACHARS,*src))
*(dst++) = *src;
else
*(dst++) = triv_qchar;
@ -305,7 +306,7 @@ void hint_two(void)
while(*src)
{
if (STRCHR(TRIV_METACHARS,*src))
if (stringchr(TRIV_METACHARS,*src))
*(dst++) = *src;
else
*(dst++) = triv_qchar;
@ -342,7 +343,7 @@ void hint_three(void)
while(*src)
{
if (STRCHR(TRIV_METACHARS "aeiouyAEIOUY",*src))
if (stringchr(TRIV_METACHARS "aeiouyAEIOUY",*src))
*(dst++) = *src;
else
*(dst++) = triv_qchar;
@ -480,7 +481,7 @@ char *random_question(char *triv_rand)
} entry;
if (STRCHR(triv_qfile,'/') || strlen(triv_qfile) > 100) /* really bad filenames... */
if (stringchr(triv_qfile,'/') || strlen(triv_qfile) > 100) /* really bad filenames... */
return(NULL);
stringcat(stringcpy(tmpname,"trivia/"),triv_qfile);
@ -496,7 +497,7 @@ char *random_question(char *triv_rand)
#endif /* DEBUG */
stringcpy(triv_rand,tmpname);
if ((p = STRCHR(triv_rand,'.')) == NULL)
if ((p = stringchr(triv_rand,'.')) == NULL)
p = STREND(triv_rand);
stringcpy(p,".index");
@ -733,7 +734,7 @@ void do_bigsay(COMMAND_ARGS)
if (temp[1] == '-')
; /* allow .bigsay -- -dash- */
else
if (STRCHR(temp,'/') == NULL) /* no filesystem perversions... */
if (stringchr(temp,'/') == NULL) /* no filesystem perversions... */
{
stringcat(stringcat(stringcpy(output,COMMONDIR),temp+1),".bigchars"); /* temp+1 = skip initial '-' */
}
@ -766,7 +767,7 @@ reuse_font:
}
for(bigc=fontlist;bigc;bigc=bigc->next)
{
if (STRCHR(bigc->chars,*pt))
if (stringchr(bigc->chars,*pt))
{
sp = bigc->data;
for(x=0;x<i;x++)
@ -895,7 +896,7 @@ void do_ascii(COMMAND_ARGS)
int fd;
#ifdef DEBUG
if (STRCHR(rest,'/'))
if (stringchr(rest,'/'))
{
debug("(do_ascii) '/' not permitted in filename\n");
ascii_badfile:
@ -915,7 +916,7 @@ ascii_badfile:
goto ascii_badfile;
}
#else
if (STRCHR(rest,'/'))
if (stringchr(rest,'/'))
{
ascii_badfile:
to_user_q(from,"%s","Bad filename or file does not exist");
@ -954,7 +955,11 @@ user (after eliminating all known bots) and says the nick in the channel.
If the command ``RAND luser'' is issued in a channel, the bot picks a random channel
user that has no access in the bots userlist and says the nick in the channel.
0299
*/
#define __characterisnumeric (attrtab[(uchar)*rest] & NUM)
#define characterisnumeric (*rest >= '0' && *rest <= '9')
void do_rand(COMMAND_ARGS)
{
const char *opt;
@ -964,18 +969,18 @@ void do_rand(COMMAND_ARGS)
if (!rest || *rest == 0)
goto pick_randnum;
if (attrtab[(uchar)*rest] & NUM)
if (characterisnumeric)
{
max = 0;
while(attrtab[(uchar)*rest] & NUM)
while(characterisnumeric)
max = 10 * max + (*(rest++) - '0');
if (*rest == '-' || *rest == ' ')
rest++;
if ((attrtab[(uchar)*rest] & NUM) == 0)
if (characterisnumeric == 0)
goto pick_randnum;
min = max;
max = 0;
while(attrtab[(uchar)*rest] & NUM)
while(characterisnumeric)
max = 10 * max + (*(rest++) - '0');
goto pick_randnum;
}

View File

@ -94,9 +94,8 @@ void init_uptime(void)
void send_uptime(int type)
{
PackUp upPack;
PackUp *upPack;
struct sockaddr_in sai;
struct stat st;
Server *sp;
const char *server,*nick;
int sz;
@ -128,6 +127,8 @@ void send_uptime(int type)
}
#endif /* RAWDNS */
upPack = (PackUp*)&globaldata;
/*
* update the time when we last sent packet
*/
@ -135,30 +136,19 @@ void send_uptime(int type)
uptimelast = (now & ~7) + 21600 + sz; /* 21600 seconds = 6 hours */
uptimepackets = uptimepackets + 1;
upPack.packets_sent = htonl(uptimepackets);
upPack->packets_sent = htonl(uptimepackets);
upPack.mytime = htonl(now);
upPack.regnr = uptimeregnr;
upPack.type = htonl(type);
upPack.uptime = htonl(uptime);
upPack.ontime = 0; /* set a few lines down */
upPack->mytime = htonl(now);
upPack->regnr = uptimeregnr;
upPack->type = htonl(type);
upPack->uptime = htonl(uptime);
upPack->ontime = 0; /* set a few lines down */
/*
* callouts to other functions should be done last (think compiler optimizations)
*/
upPack.pid = htonl(getpid());
/*
* this trick for most systems gets the system uptime
*/
if (stat("/proc",&st) < 0)
{
upPack.sysup = 0;
}
else
{
upPack.sysup = htonl(st.st_ctime);
}
upPack->pid = htonl(getpid());
upPack->sysup = htonl(cx.system_uptime);
server = UNKNOWN;
nick = BOTLOGIN;
@ -169,7 +159,7 @@ void send_uptime(int type)
if (botlist)
{
nick = getbotnick(botlist);
upPack.ontime = htonl(botlist->ontime);
upPack->ontime = htonl(botlist->ontime);
if ((sp = find_server(botlist->server)))
{
server = (*sp->realname) ? sp->realname : sp->name;
@ -190,14 +180,10 @@ void send_uptime(int type)
}
#endif /* ! RAWDNS */
sz = sizeof(PackStub) + 3 + StrlenX(nick,server,VERSION,NULL);
if (sz > sizeof(PackUp))
return;
sprintf(upPack.string,"%s %s %s",nick,server,VERSION);
sz = sizeof(PackStub) + snprintf(upPack->string,256,"%s %s %s",nick,server,VERSION);
#ifdef DEBUG
debug("(send_uptime) packets sent %i, my pid %i, my ident = \"%s\"\n",uptimepackets,ntohl(upPack.pid),upPack.string);
debug("(send_uptime) packets sent %i, my pid %i, my ident = \"%s\"\n",uptimepackets,ntohl(upPack->pid),upPack->string);
#endif /* DEBUG */
/*
* udp sending...
@ -207,7 +193,7 @@ void send_uptime(int type)
sai.sin_addr.s_addr = uptimeip;
sai.sin_port = htons(uptimeport);
sendto(uptimesock,(void*)&upPack,sz,0,(struct sockaddr*)&sai,sizeof(sai));
sendto(uptimesock,(void*)upPack,sz,0,(struct sockaddr*)&sai,sizeof(sai));
}
void uptime_death(int type)
@ -224,7 +210,8 @@ void uptime_death(int type)
void process_uptime(void)
{
struct sockaddr_in sai;
int res,sz;
unsigned int sz;
int res;
struct
{
int regnr;

View File

@ -26,7 +26,7 @@ typedef struct
} UsageList;
LS const UsageList ulist[] =
const UsageList ulist[] =
{
#ifdef TOYBOX
{ C_8BALL, "[text]" },

View File

@ -77,7 +77,7 @@ void cfg_chan(char *rest)
addtouser(&cfgUser->chan,rest,TRUE);
}
LS struct
struct
{
char modechar;
int modeflag;
@ -228,7 +228,7 @@ typedef struct CommandStruct
} ConfCommand;
LS const ConfCommand userlist_cmds[] =
const ConfCommand userlist_cmds[] =
{
/*
* users
@ -560,7 +560,9 @@ void mirror_user(User *user)
{
Mech *backup,*anybot;
User *newuser,*olduser;
#ifdef NOTE
Strp *notes;
#endif /* NOTE */
#ifdef BOTNET
/* dont mirror noshare users */
@ -1073,7 +1075,7 @@ void do_userlist(COMMAND_ARGS)
channel = rest;
}
else
if (STRCHR(rest,'*') != NULL)
if (stringchr(rest,'*') != NULL)
{
mask = rest;
}
@ -1180,7 +1182,6 @@ void do_user(COMMAND_ARGS)
/*
* on_msg checks: CARGS
*/
Mech *anybot;
User *user;
Strp *ump;
char *handle,*pt,*mask,*nick,*chan,*anum,*pass,*encpass;

View File

@ -187,7 +187,7 @@ static void ec_loadavg(char *from, const char *to)
void ec_time(char *from, const char *to)
{
nobo_strcpy(time2away(now));
nobo_strcpy(maketimestr(now,TFMT_AWAY));
}
void ec_set(char *from, const char *to)

View File

@ -35,9 +35,9 @@
#define WEBROOT "web/"
LS WebSock *weblist;
WebSock *weblist;
LS WebDoc docraw = { NULL, NULL, &web_raw };
WebDoc docraw = { NULL, NULL, &web_raw };
#if 0
{
@ -45,7 +45,7 @@ LS WebDoc docraw = { NULL, NULL, &web_raw };
};
#endif
LS WebDoc doclist[] =
WebDoc doclist[] =
{
{ NULL, "/internalstatus.html", &web_botstatus },
#ifdef DEBUG
@ -125,7 +125,7 @@ char *webread(int s, char *rest, char *line)
return(NULL);
}
#define NOBO if (dest == &mem[MSGLEN-2]) { int n; n = write(s,mem,dest-mem); dest = mem; }
#define NOBO if (dest == &mem[MSGLEN-2]) { int _n_ __notused__; _n_ = write(s,mem,dest-mem); dest = mem; }
void eml_fmt(WebSock *client, char *format)
{
@ -133,7 +133,7 @@ void eml_fmt(WebSock *client, char *format)
char *src,*dest,*org;
int out;
int s = client->sock;
int n;
int n __notused__;
org = NULL;
out = TRUE;
@ -241,7 +241,7 @@ void web_raw(WebSock *client, char *url)
char path[MSGLEN];
char *src,*dest;
ino_t ino;
int fd,eml,n;
int fd,eml,n __notused__;
size_t sz;
eml = (matches("*.html",url)) ? TRUE : FALSE;