#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define __need_timer_t
#include <time.h>
#include <pwd.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <signal.h>
//epoch's libraries.
#include <irc.h>
#include <hashtable.h>
#define RECURSE_LIMIT 10
//#define free(a) do{printf("freeing %p line:%d\n",(void *)a,__LINE__);if(a) free(a);}while(0);
/*// just in case your system doesn't have strndup
char *strndup(char *s,int l) {
char *r=strdup(s);
r[l]=0;
return r;
}
*/
//might want to change some of these.
#define TSIZE 65535
#define SERVER "127.0.0.1"
#define PORT "6667"
#define NICK "SegFault" //override with argv[1]
#define MYUSER "segfault"
#define LINES_SENT_LIMIT 1
#define LINELEN 400
#define SEGHOMELEN 1024
#define RAWLOG "./files/rawlog"
#define LOG "./files/log"
#define BS 4096
// !c uses 56 for its tail.
// 56 == 32 + 16 + 8 == 0x38 == 0x20+0x10+0x8 == SPAM | BEGIN | MSG
#define TAILO_RAW 1 // r output gets sent directly to server
#define TAILO_EVAL 2 // e interpret the lines read from the tail as if they were messages to segfault
#define TAILO_CLOSE 4 // c close the file at EOF, default is to leave it open.
#define TAILO_MSG 8 // m output gets sent as a PM to the place the tail was made.
#define TAILO_BEGIN 16 // b start the tail at the beginning of the file instead of the end.
#define TAILO_SPAM 32 // s Spam control is enabled for this stream.
#define TAILO_ENDMSG 64 // n show a message when the tail reaches the end of a chunk
#define TAILO_FORMAT 128// f formatting?
#define TAILO_Q_EVAL (TAILO_EVAL|TAILO_CLOSE|TAILO_BEGIN) //0x2+0x4+0x10 = 2+4+16 = 22
#define TAILO_Q_COUT (TAILO_SPAM|TAILO_BEGIN|TAILO_MSG) //0x20+0x10+0x8 = 32+16+8 = 56
#define PRIVMSG_LINE_LIMIT 0
struct user *myuser;
char pid[6];
char mode_magic;
char snooty;
int start_time;
char *redo;
int redirect_to_fd;
int line_limit;
int debug;
timer_t timer;
int lines_sent;
unsigned long oldtime;
int maxtails;
int currentmaxtails;
char seghome[SEGHOMELEN];
struct hashtable alias;
struct hashtable builtin;
union hack {
void (*func)(int,...);
void *data;
};
void (*func)(int fd,...);
struct tail {
FILE *fp;
char *file;
char *to;
char *args;
struct user *user;
unsigned short opt;
unsigned int inode;
int lines;
} *tailf;
char *shitlist[] = { 0 };
void message_handler(int fd,char *from,struct user *user,char *msg,int redones);
void c_leetuntail(int fd,char *from,char *line,...);
//this function isn't with the rest of them because... meh.
char *tailmode_to_txt(int mode) {
char *modes="recmbsnf";
int i,j=0;
char *m=malloc(strlen(modes));
for(i=0;i<strlen(modes);i++)
if(mode & 1<<i)
m[j++]=modes[i];
m[j]=0;
return m;
}
void mywrite(int fd,char *b) {
int r;
if(!b || fd <0) return;
r=write(fd,b,strlen(b));
if(r == -1) exit(1);
if(r != strlen(b)) exit(2);
lines_sent++;
}
void irc_mode(int fd,char *channel,char *mode,char *nick) {
int sz=5+strlen(channel)+1+strlen(mode)+1+strlen(nick)+3;//"MODE ", " ", " ","\r\n\0"
char *hrm;
if(!(hrm=malloc(sz+1))) {
mywrite(fd,"QUIT :malloc error 1! holy shit!\r\n");
return;
}
snprintf(hrm,sz,"MODE %s %s %s\r\n",channel,mode,nick);
write(fd,hrm,strlen(hrm));
free(hrm);
}
void irc_nick(int fd,char *nick) {
int sz=5+strlen(nick)+3;//"NICK ","\r\n\0"
char *hrm;
if(!(hrm=malloc(sz+1))) {
mywrite(fd,"QUIT :malloc error 1.5! holy shit!\r\n");
return;
}
snprintf(hrm,sz,"NICK %s\r\n",nick);
write(fd,hrm,strlen(hrm));
free(hrm);
}
void privmsg(
|