Newer
Older
tuved / tuved.h
@reddawg reddawg on 18 Feb 2009 8 KB Sync
/*
  (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>
#include <mysql/mysql.h>

/* TUved Information */
#define VERSION          "v1.93"            // Current Version Of Tuved
#define NUM_THREADS      1                  // Number Of Threads In The Deamon
#define MYPORT           9999               // the port users will be connecting to
#define BACKLOG          10                 // how many pending connections queue will hold
#define LOG_FILE         "./logs/tuved.log" // Default Log File
#define PING_INTERVAL    20                 // Interval For Pings
#define MAX_PING         2                  // Maximum Number Of Missed Pings
#define MAX_COUNT        2
#define MAX_TOPIC_LEN    128                // Maximum Length For A Topic
#define MAX_CHAN_LEN     32                 // Maximum Length For A Channel Name
#define MAX_USER_LEN     32                 // Maximum Length For A Username
#define MAX_USER_AWAYMSG 128                // Maximum Length For Away Message
#define CHAN_MAX_BANS    30
#define CHAN_LIVE_LENGTH 128

/* MySQL Information */
#define MYSQL_HOST_NAME  "10.3.250.13"        // MySQL Server Hostname
#define MYSQL_USERNAME   "tuve"             // MySQL Server Username
#define MYSQL_PASSWORD   "5558585"          // MySQL Server Password
#define MYSQL_DB_NAME    "tuve"             // MySQL Server Database Name

#define VIDE_PAD_TIME    2                  // Video Padding To Ensure All Users Are In Sync
#define MIN_VER          2.7                // Minimum Client Version
#define COM_DELAY        60*20              // Amount Of Playtime Before Commercial;

/* User Modes */
#define USER_MODES    2 // Count Of User Modes
#define USER_OVERLORD 0 // User Is An Overlord
#define USER_AWAY     1 // User Is Away

/* Cannel Modes */
#define CHAN_MODES      9 // 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_SCHEDULED  7 // Channel Is In Scheduled Mode
#define CHAN_NOADS      8 // Channel Will Not Play Advertisements

typedef struct tuveUserList {
  struct tuveUserList  *prev;
  struct tuveUserList  *next;
  struct myConnections *user; 
  short  chanLevel;
  } tuveUserList_t;

/* Channel Structure */
typedef struct tuveChanList {
  struct tuveChanList  *prev;
  struct tuveChanList  *next;
  struct tuveUserList  *users;
  struct tuveUserList  *nextUser;
  long long bans[CHAN_MAX_BANS][2];     // Ban List
  char   liveStream[CHAN_LIVE_LENGTH]; // Live Stream Name
  char   modes[CHAN_MODES];            // Channel Modes Array
  char   topicSetBy[MAX_USER_LEN];     // 
  char   topic[MAX_TOPIC_LEN];
  char   channel[MAX_CHAN_LEN];
  char   videoFile[256];            // File Name Of Video
  char   videoChanTitle[256];       // Video Title Displayed In The Channel w/ Links
  char   videoTitle[256];           // Video Title w/o Links
  int    videoEnd;                  // Time At Which The Server Considers The Video Has Ended
  int    videoTime;                 // Video Length In Seconds
  int    userCount;                 // Channels User Count
  int    vid;                       // Video ID
  int    comTime;                   // Total Ad Time
  int    comDelay;                  // Video Play Counter For Next Ad
  int    oid;                       // Channels OID 
  short  count;                     // Counter For Querying A User For A Video
  short  maxTime;                   // Maximum Length For A Video
  short  vidClass;                  // Video Class - For Skip Protection
  time_t topicSet;
  } 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;
  short     queue;
  float     version;
  long long uid;
  time_t    pong;
  time_t    idle;
  char      modes[USER_MODES];
  char      username[MAX_USER_LEN];
  char      awayMsg[MAX_USER_AWAYMSG];
  tuveUserChans_t *chans;
  } tuveUser_t;


typedef struct myConnections {
  struct myConnections *prev;
  struct myConnections *next;
  int    fd;
  int    recLen;
  char   data[1024];
  char   host[128];
  tuveUser_t userInfo;
  time_t signedOn;
  } myConnections_t;

/*
  Global variables very not safe
 */

extern int songCount;
extern int playCount;
extern int channelCount;
extern int userCount;
extern int listenerFD;
extern int highSock;
extern myConnections_t *connections;
extern FILE *logFile;
extern tuveChanList_t *channels;
extern pthread_mutex_t chanMutex;
extern time_t startTime;
extern char logFileName[64];

/* 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);                                                // Sends Ping To All Sockets
int sCleanConnections();                                              // Cleans Up The Dead Connections
int sSendData(myConnections_t *con,char const * __restrict fmt, ...); // Sends Data To A Socket
int sRemoveConnection(int socketFD);
int tuveGetData(myConnections_t *userConnection);
/*
 * End Socket functions
 */

/* Log Functions */
int writeLog(int level,char const * __restrict, ...);

/* Channel Functions */
int tuveChanList(myConnections_t *userConnection);                     // Sends Channel List To Provided Users
int tuveChanPart(const char *channel,myConnections_t *userConnection); // Parts A User From A Channel
int tuveChanResume(const char *channel);                               // Resumes Streaming In A Channel
int tuveChanLive(const char *channel,const char *stream,const char *location);              // Starts Live Mode In A Channel
int tuveChanJoin(const char *channel,myConnections_t *userConnection); // Joins A Users To A Channel
int tuveAddChanToUser(const char *channel,myConnections_t *userConnection); // Adds Chan To User
int tuveAddToChanList(const char *channel,myConnections_t *userConnection);
int tuveSendAllInChan(const char *channel,myConnections_t *userConnection,char const * __restrict fmt, ...);
int tuveFindChanLevel(const char *channel,myConnections_t *userConnection,int eo); // Returns Users Channel Level
int tuveChanOp(const char *channel,const char *nick,int level);             // Sets Channel Opperator Status
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(myConnections_t *byConnection,char *chan,char *nick,char *msg);
tuveChanList_t *findChan(const char *);
int tuveBan(myConnections_t *byConnection,const char *channel,const char *nick,int length);
int tuveUnBan(const char *channel,const char *nick);
int tuveVerifyBan(const char *channel,const char *nick);
myConnections_t *findNickOnChan(const char *nick,const char *channel);
/*
 * End Channel Functions
 */

/* Bot Functions */
void *tuveCMD_Thread(void *threadid);
int tuveCMD_CMD(myConnections_t *userConnection,char *chan,char *data);
int tuveBotSetSong(char *channel,char *nick,char *artist,char *title,int length,char *file,int class,int rating,int vid);
int tuveBotSetVideo(char *chan,char *nick,int vid);
/*
 * End Bot Functions
 */

/* Nick Functions */
int tuveVerifyNick(char *nick);
myConnections_t *findNick(const char *);
int tuveWhois(myConnections_t *userConnection,char *nick);
/*
 * End Nick Functions
 */

/* Server Functions */
int tuveStatus(myConnections_t *userConnection);
/*
 * End Server Functions
 */

/* Database Functions */
int dbInit();
MYSQL_RES *dbQuery(const char *query,short store);
/*
 * End Database Functions
 */

/* Lib Functions */
int formatTime(time_t sTime,char *output);
/*
 * End Lib Functions
 */