Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4060806
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
48 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/beta/source/parse.c b/beta/source/parse.c
index 078fae3..3cf3605 100755
--- a/beta/source/parse.c
+++ b/beta/source/parse.c
@@ -1,508 +1,505 @@
#include "defines.h"
#include "vars.h"
#include "prototypes.h"
/**
* TODO: No function should ever be this long...move to the Command Pattern
*/
void
parse (char *line)
{
char *s = NULL, *s1 = NULL, *s2 = NULL, *s3 = NULL, *cmd = NULL, *ptr = NULL;
#if BAN_BY_HOST == ON
char *s4 = NULL;
#endif
long TOG = 0, seen_value = 0;
LastInput = 0;
if (DebuG == 1)
printf ("IN :%s\n", line);
#ifdef DEBUG2
db_log ("darkbot_debug.log", "IN :%s\n", line);
#endif
stripline (line);
s = strtok (line, " ");
if (strcasecmp (s, "PING") == 0)
{
s1 = strtok (NULL, " ");
Snow ("PONG %s\n", s1);
}
else if (strcasecmp (s, "ERROR") == 0)
{
s1 = strtok (NULL, "");
if (s1 != NULL)
{
if (strstr (s1, "Excess Flood") != NULL)
{
prepare_bot ();
register_bot ();
}
else if (strstr (s1, "throttled") != NULL)
{
prepare_bot ();
register_bot ();
}
else if (strstr (s1, "oo many c") != NULL)
{
prepare_bot ();
register_bot ();
}
else if (strstr (s1, "o more c") != NULL)
{
prepare_bot ();
register_bot ();
}
else
{
S ("QUIT :Caught ERROR from %s :(\n", BS);
db_sleep (5);
prepare_bot ();
register_bot ();
}
}
}
else if (strstr (s, "!") == NULL)
{ /* From Server */
cmd = strtok (NULL, " ");
if (strcasecmp (cmd, "004") == 0)
{ /* Connected! */
save_changes ();
s2 = strtok (NULL, " "); /* Copy the current nick */
strncpy (Mynick, s2, sizeof (Mynick));
snprintf (NICK_COMMA, sizeof (NICK_COMMA), "%s,", Mynick);
snprintf (COLON_NICK, sizeof (COLON_NICK), "%s:", Mynick);
snprintf (BCOLON_NICK, sizeof (BCOLON_NICK), "%s\2:\2", Mynick);
s2 = strtok (NULL, " "); /* Got server name */
}
else if (strcasecmp (cmd, "315") == 0)
{
#if DISPLAY_SYNC == 1
s2 = strtok (NULL, " "); /*mynick */
strncpy (Mynick, s2, sizeof (Mynick));
s2 = strtok (NULL, " "); /* chan */
S ("PRIVMSG %s :Sync with %s completed.\n", s2, s2);
#endif
}
else if (strcasecmp (cmd, "311") == 0)
{
s1 = strtok (NULL, " ");
s1 = strtok (NULL, " ");
s1 = strtok (NULL, " ");
s1 = strtok (NULL, " ");
strncpy (g_host, s1, sizeof (g_host));
}
else if (strcasecmp (cmd, "319") == 0)
{
s1 = strtok (NULL, " ");
s1 = strtok (NULL, " ");
s2 = strtok (NULL, "");
if (*s2 == ':')
s2++;
strlwr (s2);
if (strstr (s2, "arez") != NULL)
TOG = 1;
if (strstr (s2, "kidd") != NULL)
TOG = 1;
if (strstr (s2, "hack") != NULL)
TOG = 1;
if (strstr (s2, "sex") != NULL)
TOG = 1;
if (strstr (s2, "fuck") != NULL)
TOG = 1;
if (strstr (s2, "porn") != NULL)
TOG = 1;
if (strstr (s2, "pic") != NULL)
TOG = 1;
if (TOG == 1)
{
S ("NOTICE @%s :%s is on \2%s\2\n", g_chan, s1, s2);
return;
}
}
else if (strcasecmp (cmd, "432") == 0 || strcasecmp (cmd, "468") == 0)
{ /* Invalid nick/user */
s2 = strtok (NULL, "");
printf ("Server Reported error %s\n\nDarkbot exiting.\n", s2);
db_sleep (2);
exit (0);
}
else if ((strcasecmp (cmd, "376") == 0) || (strcasecmp(cmd, "422") == 0))
{
/* Set default umodes */
S ("MODE %s %s\n", Mynick, DEFAULT_UMODE);
run_perform (); /* Run performs */
S ("JOIN %s\n", CHAN);
}
else if (strcasecmp (cmd, "482") == 0)
{
#if BITCH_ABOUT_DEOP == 1
s2 = strtok (NULL, " "); /* mynick */
strncpy (Mynick, s2, sizeof (Mynick));
s2 = strtok (NULL, " "); /* chan */
/* We used to run the DEOP.INI here */
#endif
}
else if (strcasecmp (cmd, "352") == 0)
{
s2 = strtok (NULL, "");
parse_who (s2);
#ifdef ENABLE_STATUS
}
else if (strcasecmp (cmd, "252") == 0)
{
s2 = strtok (NULL, "");
parse_252 (s2);
}
else if (strcasecmp (cmd, "404") == 0
|| strcasecmp (cmd, "475") == 0
|| strcasecmp (cmd, "474") == 0 || strcasecmp (cmd, "473") == 0)
{ /* Can't join? */
s2 = strtok (NULL, " ");
s2 = strtok (NULL, " ");
db_sleep (5);
S ("JOIN %s\n", s2);
}
else if (strcasecmp (cmd, "251") == 0)
{
s2 = strtok (NULL, "");
parse_251 (s2);
}
else if (strcasecmp (cmd, "255") == 0)
{
s2 = strtok (NULL, "");
parse_255 (s2);
#endif
}
else if (strcasecmp (cmd, "433") == 0)
{
s2 = strtok (NULL, " ");
if (*s2 != '*')
{
strncpy (Mynick, s2, sizeof (Mynick));
snprintf (NICK_COMMA, sizeof (NICK_COMMA), "%s,", Mynick);
snprintf (COLON_NICK, sizeof (COLON_NICK), "%s:", Mynick);
snprintf (BCOLON_NICK, sizeof (BCOLON_NICK), "%s\2:\2", Mynick);
s3 = strtok (NULL, " ");
}
else
{
Snow ("NICK %s%d\n", Mynick, xtried);
xtried++;
if (xtried > 15)
Snow ("NICK _`^%s%d\n", Mynick, xtried);
if (xtried > 5)
Snow ("NICK _%s%d\n", Mynick, xtried);
}
}
}
else
{ /* Info from user */
if (*s == ':') /* Remove the colon prefix */
s++;
cmd = strtok (NULL, " "); /* Read in command */
if (strcasecmp (cmd, "NOTICE") == 0)
{
s2 = strtok (NULL, " "); /* target */
#if KICK_ON_CHANNEL_NOTICE == ON
if (*s2 == '#')
{
s3 = strtok (s, "!");
#if BAN_ON_CHANNEL_NOTICE == ON
#if BAN_BY_HOST == ON
s4 = strtok (NULL, "@");
s4 = strtok (NULL, "");
S ("MODE %s +b *!*@%s\n", s2, s4);
#else /* ban just by u@h */
S ("MODE %s +b *%s\n", s2, strtok (NULL, ""));
#endif
#endif
S ("KICK %s %s :Punt\n", s2, s3);
}
#endif
}
else if (strcasecmp (cmd, "PRIVMSG") == 0)
{ /* PRIVMSG */
s1 = strtok (NULL, " "); /* Target */
s2 = strtok (NULL, ""); /* Rest */
-#if LOG_PRIVMSG == 1
+#if LOG_PRIVMSG == 1
if (*s1 != '#' && *s1 != '&')
{
db_log (privmsg_log, "[%s] %s %s %s\n", date (), s, s1, s2);
}
#endif
if (*s1 == '#' || *s1 == '&' || *s1 == '+')
if (do_lastcomm (s, s1, s2) == 1)
return;
chanserv (s, s1, s2); /* Process PRIVMSG commands */
}
else if (strcasecmp (cmd, "KILL") == 0)
{
s1 = strtok (NULL, " "); /* Kill nick */
if (strcasecmp (s1, Mynick) == 0)
{
do_quit (s1, 3); /* delete all users from ram since I'm gone */
prepare_bot ();
register_bot ();
}
}
else if (strcasecmp (cmd, "KICK") == 0)
{
s1 = strtok (NULL, " "); /* #chan */
s2 = strtok (NULL, " "); /* Who got kicked? */
if (strcasecmp (s2, Mynick) == 0)
{ /* Rejoin if I was
* kicked */
do_quit (s1, 2);
db_sleep (5);
S ("JOIN %s\n", s1);
S ("PRIVMSG %s :%s\n", s1, COMPLAIN_REASON);
}
else
delete_user (s2, s1);
}
else if (strcasecmp (cmd, "INVITE") == 0)
{
s1 = strtok (NULL, " "); /* Mynick */
s2 = strtok (NULL, " "); /* Target */
if (*s2 == ':')
s2++;
if (strcasecmp (s2, CHAN) == 0)
S ("JOIN %s\n", s2);
}
else if (strcasecmp (cmd, "PART") == 0)
{
if ((ptr = strchr (s, '!')) != NULL)
*ptr++ = '\0';
// Channel
s1 = strtok (NULL, " ");
// Make sure the first character in the target operative is not a :.
if (*s1 == ':')
s1++;
/*
* If we are parting the channel, remove all users in that channel from
* memory. If someone else is parting, only remove them from memory.
*/
if (strcasecmp (s, Mynick) != 0)
delete_user (s, s1);
else
do_quit (s1, 2);
}
else if (strcasecmp (cmd, "QUIT") == 0)
{
if ((ptr = strchr (s, '!')) != NULL)
*ptr++ = '\0';
do_quit (s, 1);
}
else if (strcasecmp (cmd, "MODE") == 0)
{
do_modes (s, strtok (NULL, ""));
}
else if (strcasecmp (cmd, "NICK") == 0)
{
if ((ptr = strchr (s, '!')) != NULL)
*ptr++ = '\0';
s1 = strtok (NULL, " ");
process_nick (s, s1);
}
else if (strcasecmp (cmd, "JOIN") == 0)
{
JOINs++;
s1 = strtok (NULL, " "); /* TARGET */
if (*s1 == ':')
s1++;
if ((ptr = strchr (s, '!')) != NULL)
*ptr++ = '\0';
strlwr (ptr);
if (SeeN == 1 && *s1 == '#')
seen_value = save_seen (s, ptr, s1);
if (strcasecmp (s, Mynick) != 0)
{
if (check_permban (ptr, s1, s) == 1)
return;
add_user (s1, s, ptr, 1);
#if AUTOHELP_GUESTS == 1
if (strstr (s, "Guest") != NULL)
S ("PRIVMSG %s :hello %s. need any help?\n", s);
#endif
#ifdef ENABLE_WHOIS
strncpy (g_chan, s1, sizeof (g_chan));
S ("WHOIS %s\n", s);
#endif
if (check_access (ptr, s1, 0, s) >= 4)
{
S ("MODE %s +o %s\n", s1, s);
}
else if (check_access (ptr, s1, 1, s) >= 1)
{
#if VOICE_USERS_ON_JOIN == 1
S ("MODE %s +v %s\n", s1, s);
#endif
#if HELP_GREET == 1
}
else if (check_access (ptr, s1, 0, s) >= 1)
{
return; /* don't greet if the guy has
* access (and no setinfo) */
}
else if (strcasecmp (s1, CHAN) == 0)
{
if (SeeN == 1)
{
if (seen_value == 0) /* don't show people the
* notice every join */
if (setinfo_lastcomm (s1) == 0) /* don't do it if you just did it! */
L102 (s, s1, s, *CMDCHAR);
}
else
{
if (setinfo_lastcomm (s1) == 0)
L102 (s, s1, s, *CMDCHAR);
}
}
#else
}
#endif
}
else
S ("WHO %s\n", s1); /* Check who is in the
* chan */
} /* JOIN */
}
}
void
parse_who (char *data)
{
char *chan = NULL, *nick = NULL, *ptr = NULL, *flags = NULL, b[STRING_SHORT] = { 0 };
nick = strtok (data, " "); /* botnick */
strncpy (Mynick, nick, sizeof (Mynick));
chan = strtok (NULL, " ");
ptr = strtok (NULL, " ");
snprintf (b, sizeof (b), "%s@%s", ptr, strtok (NULL, " "));
nick = strtok (NULL, " "); /* server */
nick = strtok (NULL, " ");
flags = strtok (NULL, " ");
add_user (chan, nick, b, 1);
if (strstr (flags, "@") != NULL)
do_op(nick, chan, 1);
}
#ifdef ENABLE_STATUS
void
parse_252 (char *s)
{
char *tmp = NULL;
int numb = 0;
tmp = strtok (s, " ");
tmp = strtok (NULL, " ");
sscanf (tmp, "%d", &numb);
IRCOPS = numb;
}
-#endif
-#ifdef ENABLE_STATUS
void
parse_251 (char *s)
{
char *tmp = NULL;
int numb = 0, r = 0, i = 0;
/*- Read and chuck useless data from line 'b' -*/
tmp = strtok (s, " ");
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
sscanf (tmp, "%d", &r);
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
sscanf (tmp, "%d", &i);
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
sscanf (tmp, "%d", &numb);
NUM_SERV = numb;
G_USERS = r + i;
}
-#endif
-#ifdef ENABLE_STATUS
void
parse_255 (char *s)
{
char *tmp = NULL, Stat[1] = { 0 };
int numb = 0, pre_CLIENTS = 0;
/* test321 :I have 1313 clients and 1 servers */
strlwr (s);
tmp = strtok (s, " ");
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
tmp = strtok (NULL, " ");
numb = atoi (tmp);
pre_CLIENTS = L_CLIENTS;
L_CLIENTS = numb;
if (L_CLIENTS < pre_CLIENTS)
{
strncpy (Stat, "-", sizeof (Stat));
pre_CLIENTS = pre_CLIENTS - L_CLIENTS;
}
else
{
strncpy (Stat, "+", sizeof (Stat));
pre_CLIENTS = L_CLIENTS - pre_CLIENTS;
}
snprintf (tmp, sizeof (tmp), "%3.2f", (float) (((float) L_CLIENTS / (float) G_USERS) * 100));
+/* FIXME: I don't see PLAY defined anywhere, is it left over from something else? */
#if PLAY == 1
if (pre_CLIENTS == 0 || pre_CLIENTS == L_CLIENTS)
{
S ("PRIVMSG %s :!SENDQ %d srvs, %d ops, %d users (%s%% of %d, %ld avg)\n", PBOT, NUM_SERV,
IRCOPS, L_CLIENTS, tmp, G_USERS, G_USERS / NUM_SERV);
}
else
S ("PRIVMSG %s :!SENDQ %d srvs, %d ops, %d users [%c%2d] (%s%% of %d, %ld avg)\37\n", PBOT,
NUM_SERV, IRCOPS, L_CLIENTS, Stat[0], pre_CLIENTS, tmp, G_USERS, G_USERS / NUM_SERV);
db_log (".ubcount", "%d\n%d\n0\n0\n", L_CLIENTS, L_CLIENTS);
rename (".ubcount", "/usr/local/apache/htdocs/usage/userbase/userbase.dat");
db_log (".glcount", "%d\n%d\n0\n0\n", G_USERS, G_USERS);
rename (".glcount", "/usr/local/apache/htdocs/usage/global/global.dat");
#else
if (pre_CLIENTS == 0 || pre_CLIENTS == L_CLIENTS)
{
S ("PRIVMSG %s :\1ACTION \37(\37%2d servers\37)\37: %2d opers + \2%4d\2 users \37(\37%s%% %5d global \2!\2 %3ld avg\37)\37\1\n", CHAN, NUM_SERV, IRCOPS, L_CLIENTS, tmp, G_USERS, G_USERS / NUM_SERV);
}
else
S ("PRIVMSG %s :\1ACTION \37(\37%2d servers\37)\37: %2d opers + \2%4d\2 users [\37%c%2d\37] \37(\37%s%% %5d global \2!\2 %3ld avg\37)\37\1\n", CHAN, NUM_SERV, IRCOPS, L_CLIENTS, Stat[0], pre_CLIENTS, tmp, G_USERS, G_USERS / NUM_SERV);
#endif
}
#endif
void
parse_server_msg (fd_set * read_fds)
{
if (FD_ISSET (socketfd, read_fds))
{
if (readln () > 0)
{
NUMLINESSEEN++;
parse (L);
}
else
{
close (socketfd);
}
}
}
diff --git a/beta/source/permbans.c b/beta/source/permbans.c
index af597ce..f7a4415 100755
--- a/beta/source/permbans.c
+++ b/beta/source/permbans.c
@@ -1,222 +1,219 @@
#include "defines.h"
#include "vars.h"
#include "prototypes.h"
/**
* Add a permban to the permban list.
* 6/23/00 Dan:
* - Both pointer variables are now received as pointer to const data
* - Changed counter to type size_t, this should be an unsigned type
* - Initialiazed n to 0 on declaration
* - Added support for dynamically allocated uh and reason fields
* in the struct permban list
* - Did some extra memory leak prevention
*/
void
add_permban (const char *uh, size_t counter, const char *reason)
{
struct permbanlist *n = 0;
n = malloc (sizeof (struct permbanlist));
if (n == NULL)
{
db_log ("error.log", "AHHH! no ram left! in add_permban!\n");
return;
}
memset (n, 0, sizeof (struct permbanlist));
n->uh = strndup (uh, STRING_SHORT);
if (NULL == n->uh)
{
db_log ("error.log", "add_permban> Memory allocation failure\n");
/* Prevent memory leaks */
free (n);
return;
}
n->reason = strndup (reason, STRING_SHORT);
if (NULL == n->reason)
{
db_log ("error.log", "add_permban> Memory allocation failure\n");
/* Prevent memory leaks */
free (n->uh);
free (n);
return;
}
strlwr (n->uh);
n->counter = counter;
PERMBAN_counter++;
n->next = permbanhead;
permbanhead = n;
}
/**
* Check if a permban exists for a given uh/channel/nick set.
* 6/23/00 Dan:
* - Changed all method arguments to be pointers to const data
* - Return type is now bool, returns true if ban is found,
* false otherwise
*/
bool
check_permban (const char *uh, const char *chan, const char *nick)
{
char tmpBuf[STRING_SHORT + 1] = { 0 };
struct permbanlist *c = permbanhead;
size_t len = 0;
len = MIN(STRING_SHORT, strlen(uh));
strncpy (tmpBuf, uh, len);
tmpBuf[len] = '\0';
strlwr (tmpBuf);
for (; c != NULL; c = c->next)
{
if (!match_wild (c->uh, tmpBuf) == 0)
{
c->counter++;
S ("MODE %s +b %s\n", chan, c->uh);
S ("KICK %s %s :\2[\2%d\2]\2: %s\n", chan, nick, c->counter, c->reason);
return true;
}
}
return false;
}
#ifdef ENABLE_CHANNEL
/**
* Remove a permban based on nickname and user@host.
* 6/23/00 Dan:
* - Both arguments are now pointers to const data
* - Added free() for both pNode->uh and pNode->reason now
* that the permbanlist has dynamically allocated fields
* - Changed type of toggle from long to bool
* - Changed name of toggle variable to (foundBan)
* - permbanlist pointers are now initialized when declared
* - Added if statement at end of method, this will only save
* the bans if a ban was removed
*/
int
del_permban (const char *nick, const char *uh)
{
bool foundBan = false;
struct permbanlist *pNode = permbanhead, *pPrev = 0;
int i = 0;
while (pNode)
{
if (strcasecmp (pNode->uh, uh) == 0)
{
L002 (nick, PERMBAN_counter, uh);
PERMBAN_counter--;
if (pPrev != NULL)
{
pPrev->next = pNode->next;
}
else
{
permbanhead = pNode->next;
}
free (pNode->uh);
free (pNode->reason);
free (pNode);
foundBan = true;
pNode = NULL;
break;
}
pPrev = pNode;
pNode = pNode->next;
}
if (foundBan)
{
/* Only need to save bans if ban list has changed */
save_permbans ();
}
return foundBan;
}
-#endif
-#ifdef ENABLE_CHANNEL
/**
* Save the permban list to file.
* 6/23/00 Dan:
* - the permbanlist pointer (c) is now pointer to const, because
* this is a read only method, and that is a read only variable
* - Initialized c when it is declared
*/
void
save_permbans (void)
{
const struct permbanlist *c = permbanhead;
remove (TMP_FILE);
printf ("*** Writing permbans: %s (%s)\n", PERMBAN, date ());
for (; c != NULL; c = c->next)
{
db_log (TMP_FILE, "%s %d %s\n", c->uh, c->counter, c->reason);
}
rename (TMP_FILE, PERMBAN);
if (PERMBAN_counter == 0)
remove (PERMBAN);
}
#endif
/**
* 6/22 Dan
* - Changed DATA to be 512 bytes, a power of 2
* - DATA now initialized properly
* - c is now a pointer to const, this is a read only method
* - c is now initialized where declared
* - Changed type of i, x to size_t, these variables should be
* unsigned.
* - Changed while loop to for loop.
* - Changed reinitialization of DATA to use memset()
*/
void
show_banlist (const char *nick)
{
char DATA[STRING_SHORT * 7] = { 0 };
char tmp [STRING_SHORT * 7] = { 0 };
size_t i = 0, x = 0;
const struct permbanlist *c = 0;
for (c = permbanhead; c != NULL; c = c->next)
{
i++;
++x;
snprintf (tmp, sizeof (tmp), "%s", DATA);
snprintf (DATA, sizeof(DATA), "%s %s:%u",
tmp, c->uh, c->counter);
memset (tmp, 0, sizeof (tmp));
/* Only show at max 6 bans per message sent. */
if (i >= 6)
{
S ("NOTICE %s :%s\n", nick, DATA);
i = 0;
memset (DATA, 0, sizeof (DATA));
}
}
/* If 'i' never reaches 6 on the last pass through the while loop,
* and there are bans yet to be shown, act accordingly.
*/
if (i > 0)
{
S ("NOTICE %s :%s\n", nick, DATA);
}
S ("NOTICE %s :End of PERMBAN list; %d ban%s found.\n", nick, x, (x == 1) ? "" : "s");
}
-
diff --git a/beta/source/random.c b/beta/source/random.c
index d2d51fe..1ccc390 100755
--- a/beta/source/random.c
+++ b/beta/source/random.c
@@ -1,685 +1,684 @@
#include "defines.h"
#include "vars.h"
#include "prototypes.h"
#ifdef RANDOM_STUFF
void add_randomstuff (char *source, char *target, char *data)
{
char *ptr = NULL;
char file [STRING_LONG] = {0};
size_t nLines = 0;
int toggle = 1;
#ifdef BACKUP_RANDOMSTUFF
# ifndef WIN32
// Backup randomstuff file to a temporary file.
unlink(RAND_BACKUP_FILE);
snprintf(file, sizeof(file), "cp %s %s\n", RAND_FILE, RAND_BACKUP_FILE);
system(file);
# endif
#endif
if(*data == '~')
{
data++;
ptr = strtok(data, " ");
if(ptr != NULL)
strlwr(ptr);
if(strspn(ptr, LEGAL_TEXT) != strlen(ptr))
{
S("privmsg %s :%s, rdb files must be made up of letters and or numbers, no other text is accepted.\n",
target, source);
return;
}
snprintf(file, sizeof(file), "%s/%s.rdb", RDB_DIR, ptr);
data = strtok(NULL, "");
toggle = 0;
}
else
{
snprintf(file, sizeof(file), "%s", RAND_FILE);
nRandStuffs++;
}
db_log(file, "%s\n", data);
nLines = count_lines(file);
L011(target, source, nLines);
}
void get_rand_stuff_time (void)
{
Rand_Stuff = rand () % RAND_STUFF_TIME + 2;
if (Rand_Stuff < RAND_STUFF_TIME / 2)
Rand_Stuff = RAND_STUFF_TIME;
}
void do_random_stuff (void)
{
FILE *fp = 0;
size_t nLine = 0, nLength = 0, nIndex = 0;
int nIsAction = 0;
char temp [STRING_SHORT] = {0};
char szBuffer [STRING_LONG] = {0};
char *b2 = NULL;
// Count the randomstuffs.
if ((nRandStuffs = count_lines(RAND_FILE)) < 1)
return;
// Get a random line number to display. If nLine is more than the number of RandStuffs,
// nLine becomes equal to the number of RandStuffs.
if ((nLine = 1 + (size_t) ((float)nRandStuffs * rand() / (RAND_MAX + 1.0))) > nRandStuffs)
nLine = nRandStuffs;
// If nLine is less than 1, nLine becomes equal to 1
if(nLine < 1)
nLine = 1;
// Complain if we can't open the randomstuff file.
if((fp = fopen(RAND_FILE, "r")) == NULL)
{
S("privmsg %s :Unable to open %s for reading in do_random_stuff()\n",
CHAN, RAND_FILE);
return;
}
while(fgets(szBuffer, STRING_LONG, fp))
{
// Ignore comments that start with a /, treat as comments.
if((*szBuffer != '/') && (*szBuffer != '\n'))
nIndex++;
else
continue;
stripline(szBuffer);
if(nIndex == nLine)
{
nLength = strlen(szBuffer);
nIndex = 0;
memset(data, 0, sizeof(data));
nIsAction = (*szBuffer == '+' ? 1 : 0);
while(nLength > 0)
{
nIndex++;
nLength--;
// Parse data for channel name variable. replace accordingly.
if(szBuffer[nLength] == '~')
snprintf(temp, sizeof(temp), "%s%s", CHAN, data);
else
snprintf(temp, sizeof(temp), "%c%s", szBuffer[nLength], data);
strncpy(data, temp, sizeof(data));
}
// Make sure the file is closed!
fclose (fp);
if(nIsAction == 1)
{
b2 = data;
b2++;
S("privmsg %s :\1ACTION %s\1\n", CHAN, b2);
return;
}
else
{
S("privmsg %s :%s\n", CHAN, data);
return;
}
}
}
fclose(fp);
}
#endif
void do_randomtopic (int type, char *target, char *file, char *nick, char *topic)
{
FILE *fp = 0;
char file2 [FILENAME_MAX] = {0};
char szBuffer2 [STRING_LONG] = {0};
char Data [STRING_LONG] = {0};
char temp [STRING_LONG] = {0};
char crm1 [STRING_LONG] = {0};
char crm2 [STRING_LONG] = {0};
char bFirst = 1;
char *pBuffer = NULL, *ptr = NULL, *pDefault = NULL;
size_t nLength = 0, nRandTopics = 0, nLine = 0,
nIndex = 0;
int toggle = 0, nType = 0, F = 0;
// This ends up being the response, if we're doing a dunno, or whut reply, and the file
// containing the random responses can't be opened.
pDefault = (type == DUNNOR ? DONNO_Q : WHUT);
if(file != NULL)
snprintf(file2, sizeof(file2), "%s/%s.rdb", RDB_DIR, file);
if ((nRandTopics = count_lines(file2)) < 1)
{
S("privmsg %s :Sorry, I cannot answer that topic because "
"darkbot random text file (rdb) \"%s\" has no lines in it.\n",
target, file2);
return;
}
if ((fp = fopen(file2, "r")) == NULL)
{
// If this is a dunno, or whut response, instead we say our default reply.
if (type == NORMALR)
{
S("privmsg %s :Sorry, I cannot answer that topic because "
"darkbot random text file (rdb) \"%s\" was not found.\n",
target, file2);
}
else
{
S ("privmsg %s :%s\n", target, pDefault);
}
return;
}
/* db_sleep(1) */
// Get line number that we are searching for in the file. If it ends up less than
// 1, for some reason, set it to 1.
if ((nLine = (size_t) ((float)nRandTopics * rand() / (RAND_MAX+1.0))) < 1)
nLine = 1;
if(nLine > nRandTopics)
nLine = nRandTopics;
while(fgets(szBuffer2, STRING_LONG, fp))
{
if((*szBuffer2 != '/') && (*szBuffer2 != '\n'))
nIndex++;
else
continue;
stripline(szBuffer2);
// This is our line!
if(nIndex == nLine)
{
nIndex = 0;
pBuffer = szBuffer2;
/* if ((*pBuffer == '+') || (*pBuffer == '-'))
{
pBuffer++;
nType = ((*pBuffer == '+') ? RDB_ACTION : RDB_RAW);
}
else
nType = RDB_NORMAL;
*/
if (*pBuffer == '+')
{
pBuffer++;
nType = RDB_ACTION;
}
else if (*pBuffer == '-')
{
pBuffer++;
nType = RDB_RAW;
}
else
{
nType = RDB_NORMAL;
}
nLength = (size_t) strlen(pBuffer);
while(nLength > 0)
{
nLength--;
if (toggle == 1)
{
toggle = 0;
// Support for tokens
if (pBuffer[nLength] == '1' || pBuffer[nLength] == '2' || pBuffer[nLength] == '3' ||
pBuffer[nLength] == '4' || pBuffer[nLength] == '5' || pBuffer[nLength] == '6' ||
pBuffer[nLength] == '7' || pBuffer[nLength] == '8' || pBuffer[nLength] == '9')
{
/* The first time around, we just store the topic in a "safe place" */
if (bFirst == 1)
{
strncpy (crm1, topic, sizeof(crm1));
bFirst = 0;
}
/* Each time around, get a new copy from the "safe place". */
strncpy (crm2, crm1, sizeof(crm2));
snprintf (temp, sizeof(temp), "%s%s", get_word (pBuffer[nLength], crm2, "+"), Data);
}
else if(pBuffer[nLength] == 'N')
{ // nick
snprintf(temp, sizeof(temp), "%s%s", nick, Data);
}
else if ((pBuffer[nLength] == 'H') && (*target == '#'))
{ /* u@h of user */
snprintf (temp, sizeof (temp), "%s%s", mask_from_nick (nick, target), Data);
}
else if ((pBuffer[nLength] == 'C') && (*target == '#'))
{ // channel or nick.
snprintf(temp, sizeof(temp), "%s%s", target, Data);
}
else if (pBuffer[nLength] == 'T')
{ // time
snprintf(temp, sizeof(temp), "%s%s", date(), Data);
}
else if (pBuffer[nLength] == 't')
{ /* unixtime */
snprintf (temp, sizeof (temp), "%ld%s", (long) time (NULL), Data);
}
else if ((pBuffer[nLength] == 'R') && (*target == '#'))
{ // Random nick (not if this is not a channel
snprintf(temp, sizeof(temp), "%s%s",
get_rand_nick(target), Data);
}
else if (pBuffer[nLength] == 'S')
{ // Server
snprintf(temp, sizeof(temp), "%s%s", BS, Data);
}
else if (pBuffer[nLength] == 'P')
{ // Port
snprintf(temp, sizeof(temp), "%d%s", (int) BP, Data);
}
else if(pBuffer[nLength] == 'Q')
{ // Question
snprintf(temp, sizeof(temp), "%s%s", revert_topic(topic), Data);
}
else if(pBuffer[nLength] == 'W')
{ // WWW page
snprintf(temp, sizeof(temp), "http://darkbot.org%s", Data);
}
else if(pBuffer[nLength] == '!')
{ // cmdchar
snprintf(temp, sizeof(temp), "%c%s", *CMDCHAR, Data);
}
else if(pBuffer[nLength] == 'V')
{ // Version
snprintf(temp, sizeof(temp), "%s%s", dbVersion, Data);
}
else if(pBuffer[nLength] == 'B')
{ // Mynick
snprintf(temp, sizeof(temp), "%s%s", Mynick, Data);
}
else
{
snprintf(temp, sizeof(temp), "%c~%s", pBuffer[nLength], Data);
}
}
else if(pBuffer[nLength] == '~')
{
toggle = 1;
}
else
{
snprintf(temp, sizeof(temp), "%c%s", pBuffer[nLength], Data);
}
strncpy(Data, temp, sizeof(Data));
}
switch (nType)
{
case RDB_ACTION:
S ("privmsg %s :\1ACTION %s\1\n", target, Data);
break;
case RDB_NORMAL:
S ("privmsg %s :%s\n", target, Data);
break;
case RDB_RAW:
ptr = strtok (Data, "|");
while (ptr != NULL)
{
if (ptr[0] == ' ')
ptr++;
if (ptr[0] == 'B' && ptr[1] == 'A' && ptr[2] == 'N')
{ // Ban the user, if the target is a channel.
if (*target == '#')
S ("mode %s +b *%s\n", target, mask_from_nick (nick, target));
else
S ("privmsg %s :Sorry, %s, I can't respond to that topic in private.\n",
target, nick);
}
if (ptr[0] == 'T' && ptr[1] == 'E' && ptr[2] == 'M' && ptr[3] == 'P' &&
ptr[4] == 'B' && ptr[5] == 'A' && ptr[6] == 'N')
{ // Ban user for 60 seconds, if the target is a channel.
if (*target == '#')
{
S ("mode %s +b *%s\n", target, mask_from_nick (nick, target));
snprintf (temp, sizeof (temp), "%s/%ld", DBTIMERS_PATH, (long) time (NULL) + 60);
db_log (temp, "MODE %s -b *%s\n", target, mask_from_nick (nick, target));
}
else
S ("privmsg %s :Sorry, %s, I can't respond to that topic in private.\n",
target, nick);
}
ptr[0] = tolower (ptr[0]);
ptr[1] = tolower (ptr[1]);
if (ptr[0] == 'p' && ptr[1] == 'r')
F = 1;
if (ptr[0] == 'k' && ptr[1] == 'i')
F = 1;
if (ptr[0] == 'n' && ptr[1] == 'o')
F = 1;
if (ptr[0] == 't' && ptr[1] == 'o')
F = 1;
if (F == 1)
{
S ("%s\n", ptr);
F = 0;
}
ptr = strtok (NULL, "|");
}
break;
} // End switch.
fclose (fp);
return;
}
}
fclose(fp);
}
/**
* 05/27/02 Ron
* - Recoded this function, random.ini no longer needs a number
* at the top.
* 6/22/00 Dan
* - Function argument is now pointer to const
* - Fixed a problem where the file was never closed
* - All variables are now initialized when declared
* - Removed an unused variable
* - Changed long variables to type size_t, they should be
* unsigned
* - Changed reinitialization of data
* - Moved the big if/else structure to a switch
*/
char *rand_reply (const char *nick)
{
FILE *fp = 0;
char temp [STRING_SHORT] = {0};
size_t nIndex = 0, nRandTopics = 0, nLine = 0,
- nLength = 0;
-
+ nLength = 0;
// Count how many lines are in the RAND_SAY file, if can't be
// counted, just return.
if((nRandTopics = count_lines(RAND_SAY)) < 1)
return(0);
// set nLine to be a random number between 1 and nRandTopics.
nLine = 1 + (size_t) ((float)nRandTopics * rand() / (RAND_MAX+1.0));
// If the RAND_SAY file can't be opened, just return.
if((fp = fopen(RAND_SAY, "r")) == NULL)
return(0);
while(fgets(r_reply, STRING_SHORT, fp))
{
// Ignore comments
if((*r_reply != '/' ) && (*r_reply != '\n'))
nIndex++;
else
continue;
stripline(r_reply);
if(nIndex != nLine)
continue;
else
{
// This is our line.
fclose(fp);
nLength = (size_t) strlen(r_reply);
nIndex = 0;
data[0] = 0;
while(nLength > 0)
{
nIndex++;
nLength--;
switch(r_reply[nLength])
{
case '^':
snprintf(temp, sizeof(temp), "%s%s", nick, data);
break;
case '%':
snprintf(temp, sizeof(temp), "\2%s", data);
break;
case '&':
snprintf(temp, sizeof(temp), "\37%s", data);
break;
case '~':
snprintf(temp, sizeof(temp), "\26%s", data);
break;
default:
snprintf(temp, sizeof(temp), "%c%s", r_reply[nLength], data);
break;
}
strncpy(data, temp, sizeof(data));
}
// Return our fully parsed line.
return(data);
}
}
// Unable to find a match
fclose(fp);
// A space is returned to prevent crashing
return(" ");
}
-#if RANDQ == ON
+#if RANDQ == ON
/*
* do_randq():
*
* Types = RANDQ_NORMAL, RANDQ_CASE, RANDQ_RAND
*/
void do_randq (char *text, const int type, const char *target, const char *nick)
{
FILE *fp = 0;
size_t nLine = 0, length = 0, nNumMatches = 0,
nIndex2 = 0, nIndex3 = 0;
int nIsAction = 0;
char *b2 = NULL;
char temp [STRING_SHORT] = { 0 };
char szBuffer[STRING_LONG] = { 0 };
/*
* Check for RANDQ_RAND, and just do_random_stuff() if it's specified.
*/
if (type == RANDQ_RAND)
{
do_random_stuff ();
return;
}
if (text == NULL)
{
if(((nNumMatches = count_lines(RAND_FILE)) == -1) ||
(nNumMatches == 0))
{
S ("privmsg %s :%s, There are no randomstuffs, or %s cannot be accessed.\n",
target, nick, RAND_FILE);
return;
}
S("privmsg %s :%s, there %s %d randomstuff%s\n",
target,
nick,
nNumMatches == 1 ? "is" : "are",
nNumMatches,
nNumMatches == 1 ? "." : "s."
);
return;
}
/* Remove the temporary file. */
remove(RANDQ_TEMPFILE);
if((fp = fopen(RAND_FILE, "r")) == NULL)
{
S("privmsg %s :%s, I was unable to open %s for reading.\n",
target, nick, RAND_FILE);
return;
}
while(!feof(fp))
{
while(fgets(szBuffer, STRING_LONG, fp))
{
if(*szBuffer == '/')
continue;
stripline(szBuffer);
/*
* If type is specified as being case sensitive, use strstr,
* otherwise, use strcasestr
*/
if (type == RANDQ_CASE)
{
if (strstr(szBuffer, text))
{
nNumMatches++;
db_log(RANDQ_TEMPFILE, "%s\n", szBuffer);
}
}
else /* if (type == RANDQ_NORMAL) */
{
if (strcasestr(szBuffer, text) != 0)
{
nNumMatches++;
db_log(RANDQ_TEMPFILE, "%s\n", szBuffer);
}
}
}
}
// Close randomstuff file.
fclose(fp);
// If no matches are present, return that.
if(nNumMatches == 0)
{
S("privmsg %s :%s, I didn't find any matches for your search.\n",
target, nick);
return;
}
nLine = 1 + (size_t) ((float)nNumMatches * rand() / (RAND_MAX + 1.0));
// If we can't open the temporary file, complain about it.
if((fp = fopen(RANDQ_TEMPFILE, "r")) == 0)
{
S("privmsg %s :%s, I was unable to open %s for reading.\n",
target, nick, RANDQ_TEMPFILE);
return;
}
while(!feof(fp))
{
while(fgets(szBuffer, STRING_LONG, fp))
{
if((*szBuffer != '/' ) || (*szBuffer != '\n'))
nIndex2++;
else
continue;
stripline(szBuffer);
// This is the line we have chosen.
if(nIndex2 == nLine)
{
// Check if this is an action.
nIsAction = (*szBuffer == '+' ? 1 : 0);
length = strlen(szBuffer);
nIndex3 = 0;
memset(data, 0, sizeof(data));
while(length > 0)
{
nIndex3++;
length--;
if(szBuffer[length] == '~')
{
// Replace occurance of this char with chan name
snprintf(temp, sizeof(temp), "%s%s", target, data);
}
else
{
snprintf(temp, sizeof(temp), "%c%s", szBuffer[length], data);
}
strncpy(data, temp, sizeof(data));
}
// Make sure the file is closed.
fclose (fp);
if(nIsAction == 1)
{
b2 = data;
b2++;
S("privmsg %s :\1ACTION %s (%d/%d)\1\n",
target, b2, nLine, nNumMatches);
return;
}
else
{
S("privmsg %s :(%d/%d): %s\n",
target, nLine, nNumMatches, data);
return;
}
}
}
}
fclose(fp);
}
#endif
diff --git a/beta/source/url.c b/beta/source/url.c
index c4c8205..e478395 100755
--- a/beta/source/url.c
+++ b/beta/source/url.c
@@ -1,643 +1,643 @@
#include "defines.h"
#include "vars.h"
#include "prototypes.h"
int
check_existing_url (const char *source, char *topic, char *target)
{
FILE *fp;
char b[STRING_LONG] = { 0 }, *subj = NULL;
if ((fp = fopen (URL2, "r")) == NULL)
{
L003 (source, URL2);
return 0;
}
while (fgets (b, STRING_LONG, fp))
{
stripline (b);
subj = strtok (b, " ");
if (strcasecmp (subj, topic) == 0)
{
fclose (fp);
return 1;
}
}
fclose (fp);
return 0;
}
void
find_url (const char *nick, char *topic, char *target)
{
FILE *fp = NULL;
long i = 0, FOUND = 0, x = 0;
char b [STRING_LONG] = {0}, DATA [STRING_SHORT] = {0};
char *subj = NULL, *ptr2 = NULL;
if (strlen (topic) > MAX_TOPIC_SIZE)
topic[MAX_TOPIC_SIZE] = '\0';
strlwr (topic);
if ((fp = fopen (URL2, "r")) == NULL)
{
L003 (nick, URL2);
return;
}
while (fgets (b, STRING_LONG, fp))
{
x++;
if (*b == '\n')
continue; /* Just pass over empty lines */
stripline (b);
subj = strtok (b, " ");
strlwr (subj);
ptr2 = strstr (subj, topic);
if (ptr2 != NULL)
{
i++;
FOUND = 1;
sprintf (DATA, "%s %s", DATA, subj);
if (strlen (DATA) >= MAX_SEARCH_LENGTH)
break;
}
}
fclose (fp);
if (FOUND == 0)
{
L021 (target, NO_TOPIC, topic, x);
}
else if (i > 19)
{
L022 (target, i, DATA);
}
else if (i == 1)
{
L023 (target, nick, DATA);
}
else
L024 (target, i, nick, DATA);
}
void
display_url (char *target, char *nick, char *topic)
{
FILE *fp;
long x = 0;
char b[STRING_LONG] = { 0 }, *subj = NULL, *ptr = NULL;
strlwr (topic);
if ((fp = fopen (URL2, "r")) == NULL)
{
S ("%s %s :%s, there was an error displaying data for \"%s\".\n",
(target == nick) ? "notice" : "privmsg", target,
nick, topic);
return;
}
while (fgets (b, STRING_LONG, fp))
{
x++;
stripline (b);
subj = strtok (b, " ");
ptr = strtok (NULL, "");
if (strcasecmp (subj, topic) == 0 || !match_wild (subj, topic) == 0)
{
QUESTIONS++;
S ("PRIVMSG %s :Raw data for %s is: %s\n", target, topic, ptr);
fclose (fp);
return;
} /* Subject match */
}
fclose (fp);
S ("PRIVMSG %s :%s, I do not know of any topic named %s\n", target, nick, topic);
}
void
delete_url (const char *nick, char *topic, char *target)
{
FILE *fp = 0;
size_t i = 0;
size_t FOUND = 0;
char b [STRING_LONG] = { 0 };
char DATA [STRING_SHORT] = { 0 };
char *subj = NULL;
char *ptr = NULL;
if (*topic == '~')
{
topic++;
if (topic != NULL)
strlwr (topic);
snprintf (DATA, sizeof (DATA), "%s/%s.rdb", RDB_DIR, topic);
if (strspn (topic, LEGAL_TEXT) != strlen (topic))
{
if (strcasecmp (nick, target) == 0)
S ("NOTICE %s :%s, rdb files are made up of letters and or numbers, no other text is accepted.\n", nick, nick);
else
S ("PRIVMSG %s :%s, rdb files are made up of letters and or numbers, no other text is accepted.\n", target, nick);
return;
}
if ((fp = fopen (DATA, "r")) == NULL)
{
if (strcasecmp (nick, target) == 0)
S ("NOTICE %s :%s, %s.rdb does not exist.\n", nick, nick, topic);
else
S ("PRIVMSG %s :%s, %s.rdb does not exist.\n", target, nick, topic);
return;
}
fclose (fp);
remove(DATA);
if (strcasecmp (nick, target) == 0)
S ("NOTICE %s :I have unlinked %s.\n", nick, DATA);
else
S ("PRIVMSG %s :I have unlinked %s.\n", target, DATA);
return;
}
if ((fp = fopen (TMP_URL, "w")) == NULL) /* fixes the 'must have at least 1 topic' problem. */
{
L003 (nick, TMP_URL);
return;
}
fclose (fp);
if ((fp = fopen (URL2, "r")) == NULL)
{
L003 (nick, URL2);
return;
}
while (fgets (b, STRING_LONG, fp))
{
stripline (b);
subj = strtok (b, " ");
ptr = strtok (NULL, "");
i++;
if (strcasecmp (subj, topic) == 0)
{
FOUND = 1;
DELETIONS++;
if (strcasecmp (nick, target) == 0)
L029n (nick, nick, i, topic);
else
L029 (target, nick, i, topic);
}
else if (strstr (subj, " ") == NULL)
db_log (TMP_URL, "%s %s\n", subj, ptr);
}
fclose (fp);
remove(URL2);
rename(TMP_URL, URL2);
if (FOUND == 0)
{
if (strcasecmp (nick, target) == 0)
L030n (nick, nick, topic);
else
L030 (target, nick, topic);
}
}
void
show_url (char *nick, char *topic, char *target, long donno, long floodpro, char *uh, long no_pipe)
{
FILE *fp;
long x = 0, length = 0, toggle = 0, A = 0, gotit = 0, D = 0, F = 0, Tog = 0;
char b[STRING_LONG] = { 0 }, *subj = NULL, *ptr = NULL;
char temp[STRING_LONG] = { 0 };
char Data[STRING_LONG] = { 0 }, *ptr8 = NULL;
char crm1[STRING_LONG] = { 0 };
char crm2[STRING_LONG] = { 0 }, bFirst = 1;
strlwr (topic);
/* removes the question mark */
if ((ptr = strchr (topic, '?')) != NULL)
memmove (ptr, ptr + 1, strlen (ptr + 1) + 1);
if ((fp = fopen (URL2, "r")) == NULL)
{
if (donno == 1)
L003 (nick, URL2);
return;
}
while (fgets (b, STRING_LONG, fp))
{
x++;
stripline (b);
subj = strtok (b, " ");
if (subj == NULL)
continue;
ptr = strtok (NULL, "");
if (ptr == NULL)
continue;
if (strcasecmp (subj, topic) == 0 || !match_wild (subj, topic) == 0)
{
QUESTIONS++;
if (floodpro == 1)
if (cf (uh, nick, nick))
{
fclose (fp);
return;
}
gotit = 1;
if (*ptr == '+')
{
ptr++;
A = 1;
}
else if (*ptr == '-')
{
if (strstr (nick, "|") != NULL)
return;
if (no_pipe == 1)
{
fclose (fp);
return;
}
ptr++;
D = 1;
}
else if (*ptr == '~')
{
ptr++;
fclose (fp);
do_randomtopic (NORMALR, target, ptr, nick, topic);
return;
}
length = strlen (ptr);
if (length > 3)
{
if (ptr[0] == 'i' && ptr[1] == 'l' && ptr[2] == 'c')
{
toggle++;
}
}
while (length > 0)
{
length--;
if (Tog == 1)
{
Tog = 0;
if (ptr[length] == 'N')
{ /* nick */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", nick, Data);
}
else if (ptr[length] == 'C')
{ /* chan */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", target, Data);
}
else if (ptr[length] == '1'
|| ptr[length] == '2'
|| ptr[length] == '3'
|| ptr[length] == '4'
|| ptr[length] == '5'
|| ptr[length] == '6'
|| ptr[length] == '7' || ptr[length] == '8' || ptr[length] == '9')
{
toggle++;
/* The first time around, we just store the topic in a
"safe place" */
if (bFirst == 1)
{
strncpy (crm1, topic, sizeof (crm1));
bFirst = 0;
}
/* Each time around, get a new copy from the "safe place." */
strncpy (crm2, crm1, sizeof (crm2));
snprintf (temp, sizeof (temp), "%s%s", get_word (ptr[length], crm2, "+"), Data);
}
else if (ptr[length] == 'H')
{ /* u@h of user */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", uh, Data);
}
else if (ptr[length] == 'h')
{ /* u@h (no ident) */
toggle++;
if (*uh == '~')
{
uh++;
}
snprintf (temp, sizeof (temp), "%s%s", uh, Data);
}
else if (ptr[length] == 'T')
{ /* time */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", date (), Data);
}
else if (ptr[length] == 't')
{ /* unixtime */
toggle++;
snprintf (temp, sizeof (temp), "%ld%s", (long)time (NULL), Data);
}
else if (ptr[length] == 'W')
{ /* WWW page */
toggle++;
snprintf (temp, sizeof (temp), "http://darkbot.org%s", Data);
}
else if (ptr[length] == 'S')
{ /* server */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", BS, Data);
}
else if (ptr[length] == 'R')
{ /* rand */
toggle++;
/* The first time around, we just store the topic in a
"safe place" */
if (bFirst == 1)
{
strncpy (crm1, topic, sizeof (crm1));
bFirst = 0;
}
// Don't do random nicknames if the target isn't a channel!!
snprintf (temp, sizeof (temp), "%s%s",
((*target != '#') ? "R~" : get_rand_nick (target)),
Data);
}
else if (ptr[length] == 'P')
{ /* port */
toggle++;
snprintf (temp, sizeof (temp), "%ld%s", BP, Data);
}
else if (ptr[length] == 'Q')
{ /* question */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", revert_topic (topic), Data);
}
else if (ptr[length] == 'V')
{ /* version */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", dbVersion, Data);
}
else if (ptr[length] == '!')
{ /* cmdchar */
toggle++;
snprintf (temp, sizeof (temp), "%c%s", *CMDCHAR, Data);
}
else if (ptr[length] == 'B')
{ /* mynick */
toggle++;
snprintf (temp, sizeof (temp), "%s%s", Mynick, Data);
}
else
snprintf (temp, sizeof (temp), "%c~%s", ptr[length], Data);
}
else if (ptr[length] == '~')
{
Tog = 1;
}
else
snprintf (temp, sizeof (temp), "%c%s", ptr[length], Data);
strncpy (Data, temp, sizeof (Data));
} /* While */
if (D == 1)
{
ptr8 = strtok (Data, "|");
while (ptr8 != NULL)
{
if (ptr8[0] == ' ')
ptr8++;
if (ptr8[0] == 'B' && ptr8[1] == 'A' && ptr8[2] == 'N')
{ /* ban user */
S ("MODE %s +b *%s\n", target, uh);
}
if (ptr8[0] == 'T' && ptr8[1] == 'E' && ptr8[2] == 'M' &&
ptr8[3] == 'P' && ptr8[4] == 'B' && ptr8[5] == 'A' && ptr8[6] == 'N')
{ /* temp ban user for 60 sec */
S ("MODE %s +b *%s\n", target, uh);
snprintf (temp, sizeof (temp), "%s/%ld", DBTIMERS_PATH, (long)time (NULL) + 60);
db_log (temp, "MODE %s -b *%s\n", target, uh);
}
ptr8[0] = tolower (ptr8[0]);
ptr8[1] = tolower (ptr8[1]);
if (ptr8[0] == 'p' && ptr8[1] == 'r')
F = 1;
if (ptr8[0] == 'k' && ptr8[1] == 'i' && !is_op(nick, target))
F = 1;
if (ptr8[0] == 'n' && ptr8[1] == 'o')
F = 1;
if (ptr8[0] == 't' && ptr8[1] == 'o')
F = 1;
if (F == 1)
S ("%s\n", ptr8);
F = 0;
ptr8 = strtok (NULL, "|");
}
fclose (fp);
return;
}
if (toggle == 0)
{
add_stats (nick, uh, 1, time (NULL), time (NULL));
if (A == 0)
{
if ((*target == '#') || (*target == '+') || (*target == '&'))
S ("PRIVMSG %s :%s%s\n", target, rand_reply (nick), Data);
else
{
S ("NOTICE %s :%s%s\n", target, rand_reply(target), temp, Data);
}
}
else if ((*target == '#') || (*target == '+') || (*target == '&'))
S ("PRIVMSG %s :\1ACTION %s\1\n", target, Data);
else
{
S ("NOTICE %s :%s%s\n", target, rand_reply(target), Data);
}
}
else if (A == 0)
{
add_stats (nick, uh, 1, time (NULL), time (NULL));
if ((*target == '#') || (*target == '+') || (*target == '&'))
S ("PRIVMSG %s :%s\n", target, Data);
else
{
S ("NOTICE %s :%s\n", target, Data);
}
}
else if ((*target == '#') || (*target == '+') || (*target == '&'))
{
add_stats (nick, uh, 1, time (NULL), time (NULL));
S ("PRIVMSG %s :\1ACTION %s\1\n", target, Data);
}
-#if MSG_RESPONSES == ON
+#if MSG_RESPONSES == ON
else
{
add_stats (nick, uh, 1, time (NULL), time (NULL));
S ("NOTICE %s :%s\n", target, Data);
}
#endif
fclose (fp);
return;
} /* Subject match */
}
fclose (fp);
if (donno == 1)
{
if (strlen (topic) > 3)
{
strlwr (topic);
if (topic[0] == 'i' && topic[1] == 'l' && topic[2] == 'c')
{
if ((*target == '#') || (*target == '+') || (*target == '&'))
S ("PRIVMSG %s :%s, I found no matching ILC for that channel.\n", target, nick);
return;
}
}
if ((*target == '#') || (*target == '+') || (*target == '&'))
-#if RANDOM_DUNNO == 1
+#if RANDOM_DUNNO == 1
do_randomtopic (DUNNOR, target, DUNNO_FILE, nick, topic);
#else
S ("PRIVMSG %s :%s, %s\n", target, nick, DONNO_Q);
#endif
else
S ("NOTICE %s :%s, %s\n", nick, nick, DONNO_Q);
}
}
char *
get_multiword_topic (char *first)
{
char *tmp2 = NULL;
tmp2 = strtok (NULL, " ");
if (tmp2 != NULL)
{
sprintf (f_tmp, "%s", first);
while (tmp2 != NULL)
{
sprintf (f_tmp, "%s+%s", f_tmp, tmp2);
tmp2 = strtok (NULL, " ");
}
return f_tmp;
}
else
return first;
}
void
datasearch (const char *nick, char *topic, char *target)
{
FILE *fp = NULL;
size_t i = 0, FOUND = 0, x = 0;
char b[STRING_LONG] = { 0 }, *dorf = NULL, *subj = NULL, *ptr2 = NULL, DATA[STRING_SHORT] =
{
0};
/* Make sure topic is not NULL.*/
if (topic == NULL)
{
return;
}
if (strlen (topic) > MAX_TOPIC_SIZE)
topic[MAX_TOPIC_SIZE] = '\0';
strlwr (topic);
if ((fp = fopen (URL2, "r")) == NULL)
{
L003 (nick, URL2);
return;
}
while (fgets (b, STRING_LONG, fp))
{
x++;
if (*b == '\n')
continue; /* Just pass over blank lines */
stripline (b);
strlwr (b);
subj = strtok (b, " ");
dorf = strtok (NULL, "");
ptr2 = strstr (dorf, topic);
if (ptr2 != NULL)
{
i++;
FOUND = 1;
sprintf (DATA, "%s %s", DATA, subj);
if (strlen (DATA) >= MAX_SEARCH_LENGTH)
break;
}
}
fclose (fp);
if (FOUND == 0)
{
L021 (target, NO_TOPIC, topic, x);
}
else if (i > 19)
{
L022 (target, i, DATA);
}
else if (i == 1)
{
L023 (target, nick, DATA);
}
else
L024 (target, i, nick, DATA);
}
char *
get_word (long number, char *string, char *seperator)
{ /* gets a specific word requested */
long i = 0;
char *ptr = NULL;
number = number - 49;
ptr = strtok (string, "+");
strncpy (f_tmp, ptr, sizeof (f_tmp));
if (ptr != NULL)
{
while (ptr != NULL)
{
i++; /* word number */
ptr = strtok (NULL, seperator);
if (ptr != NULL)
{
if (i == number)
{
snprintf (f_tmp, sizeof (f_tmp), "%s", ptr);
return f_tmp;
}
}
}
return f_tmp;
}
else
{ /* only one word */
if (number == 1)
{
return f_tmp;
}
else
return ""; /* no match */
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jan 28, 07:55 (5 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2378651
Default Alt Text
(48 KB)
Attached To
Mode
rDARKBOT Darkbot
Attached
Detach File
Event Timeline
Log In to Comment