/* (c) 2007 Christopher Olsen $Id: tuvebot.h,v 1.18 2009/02/18 19:53:46 reddawg Exp $ */ #include <sys/types.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <unistd.h> #include <time.h> #include <netdb.h> #include <mysql/mysql.h> #define SERVER_HOST "127.0.0.1" //"Ivorytower.UbixOnline.com" #define SERVER_PORT 2007 #define NUM_THREADS 2 #define MYPORT 2007 // the port users will be connecting to #define BACKLOG 10 // how many pending connections queue will hold #define LOG_FILE "./logs/tuvebot.log" #define PING_INTERVAL 20 #define MAX_PING 2 #define MAX_COUNT 2 #define MAX_TOPIC_LEN 128 #define MAX_CHAN_LEN 32 #define VERSION "v0.40" #define MYSQL_HOST_NAME "SPBX-DB002.SpherePBX.com" #define MYSQL_USERNAME "tuve" #define MYSQL_PASSWORD "5558585" #define MYSQL_DB_NAME "tuve" /* Cannel Modes */ #define CHAN_MODES 8 // Count Of Channel Modes #define CHAN_RANDOM 0 // Random Videos #define CHAN_QUEUE 1 // Users Queues #define CHAN_TIME 2 // Video Time Limit #define CHAN_RATING 3 // Video Parental Rating #define CHAN_CLASS 4 // Video Classs #define CHAN_LIVE 5 // Channel Is In Live Stream Mode #define CHAN_EXCLUSIVE 6 // Channel Is In Exclusive Mode #define CHAN_NOADS 7 // Channel Has No Advertisements typedef struct botChanList { struct botChanList *prev; struct botChanList *next; int modes[CHAN_MODES]; char topic[MAX_TOPIC_LEN]; char channel[MAX_CHAN_LEN]; short updated; short sM; unsigned int schedule[10][3]; int sCount; int sCur; int cid; } botChanList_t; typedef struct myConnections { struct myConnections *prev; struct myConnections *next; int fd; int recLen; char data[1024]; char host[128]; time_t signedOn; } myConnections_t; /* Global variables very not safe */ extern int mySocket; extern int connected; extern pthread_mutex_t chanMutex; extern botChanList_t *chans; extern int highSock; extern FILE *logFile; extern time_t startTime; extern int joinChan; /* Socket Functions */ int sConnect(const char *host,int port); ssize_t sReadSocket(void *buffer,size_t length); int sGetConnections(fd_set *readset); int sWriteSocket(char const * __restrict fmt, ...); /* Log Functions */ int writeLog(int level,char const * __restrict, ...); /* Channel Functions */ int tuveChanList(myConnections_t *userConnection); 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); int tuveBan(const char *channel,const char *nick); int tuveUnBan(const char *channel,const char *nick); int tuveVerifyBan(const char *channel,const char *nick); /* 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); /* Database Functions */ int dbInit(); MYSQL_RES *dbQuery(const char *query,short type); /* Bot Functions */ int botJoinChans(); int botStoreTopic(char *data); void *botCMD_Thread(void *threadid); void *botSCHD_Thread(void *threadid); botChanList_t *botFindChan(char *channel); botChanList_t *botAddChan(char *channel); int botDoLogin(char *cmdData);