/*
(c) 2007 Christopher Olsen
$Id$
*/
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <netdb.h>
#define NUM_THREADS 1
#define MYPORT 9999 // the port users will be connecting to
#define BACKLOG 10 // how many pending connections queue will hold
#define LOG_FILE "./tuved.log"
#define PING_INTERVAL 20
#define MAX_PING 2
#define MAX_COUNT 2
typedef struct tuveUserList {
struct tuveUserList *prev;
struct tuveUserList *next;
struct myConnections *user;
} tuveUserList_t;
typedef struct tuveChanList {
struct tuveChanList *prev;
struct tuveChanList *next;
struct tuveUserList *users;
struct tuveUserList *nextUser;
char topic[128];
char channel[32];
char curSong[256];
char songTitle[256];
int songEnd;
int songTime;
short count;
} tuveChanList_t;
typedef struct tuveUserChans {
struct tuveUserChans *prev;
struct tuveUserChans *next;
char channel[32];
} tuveUserChans_t;
typedef struct tuveUser {
short ident;
short pfailed;
short status;
int uid;
time_t pong;
char username[32];
tuveUserChans_t *chans;
} podz_t;
typedef struct myConnections {
struct myConnections *prev;
struct myConnections *next;
int fd;
int recLen;
char data[1024];
char host[128];
podz_t userInfo;
time_t signedOn;
} myConnections_t;
/*
Global variables very not safe
*/
extern int listenerFD;
extern int highSock;
extern myConnections_t *connections;
extern FILE *logFile;
extern tuveChanList_t *channels;
pthread_mutex_t chanMutex;
/* Socket Functions */
ssize_t sReadSocket(int socketFD,void *buffer,size_t length);
myConnections_t *sFindConnection(int fd);
int sStartListener();
int sAddConnection(int,char *host);
int sGetConnections(fd_set *);
int sProcessConnections(fd_set *);
int sSendPing(time_t);
int sCleanConnections();
int sSendData(myConnections_t *con,char const *data);
/* Podz Fucntions */
int podzGetData(myConnections_t *);
int podzProcessData(myConnections_t *);
int podzSendAll(char *,int);
/* Log Functions */
int writeLog(int level,char const * __restrict, ...);
/* Channel Functions */
int tuveChanPart(const char *channel,myConnections_t *userConnection);
int tuveChanJoin(const char *channel,myConnections_t *userConnection);
int tuveAddChan(const char *channel,myConnections_t *userConnection);
int tuveAddToChanList(const char *channel,myConnections_t *userConnection);
int tuveSendAllInChan(const char *channel,myConnections_t *userConnection,char *output);
int tuveDelUserChans(myConnections_t *userConnection,char *msg);
int tuveRemoveFromChanList(const char *channel,myConnections_t *userConnection);
int tuveSetTopic(myConnections_t *userConnection,char *chan,char *topic);
int tuveSendAllInUsersChans(myConnections_t *userConnection,char *output);
int tuveDelChan(const char *channel,myConnections_t *userConnection);
int tuveKick(char *by,char *chan,char *nick,char *msg);
tuveChanList_t *findChan(const char *);
/* Bot Functions */
void *tuveBotThread(void *threadid);
int tuveBotCMD(myConnections_t *userConnection,char *chan,char *data);
int tuveBotSetSong(char *chan,char *playTime,char *file,char *title);
int tuveBotNoSong(char *chan);
/* Nick Functions */
int tuveVerifyNick(char *nick);
myConnections_t *findNick(char *);
int tuveWhois(myConnections_t *userConnection,char *nick);