Newer
Older
tuved / botthread.c
@reddawg reddawg on 22 Oct 2007 1 KB Sync
#include <stdio.h>

#include "tuved.h"

char nextSong[256];

int botNextSong();

int tuveBotCMD(char *chan,char *data) {
  char output[512];
  char *cmd     = 0x0;
  char *cmdData = 0x0;

  cmd = strtok(data," ");
  cmdData = strtok(NULL,"\n");

  if (strcasecmp(cmd,"setvid") == 0x0) {
    sprintf(output,"CURPOS:1:%s\n",cmdData);
    tuveSendAllInChan(chan,0x0,output);
    }
  else if (strcasecmp(cmd,"echo") == 0x0) {
    sprintf(output,"CHANMSG:TUveBOT:%s:%s\n",chan,cmdData);
    tuveSendAllInChan(chan,0x0,output);
    }

  return(0x0);
  }

void *tuveBotThread(void *threadid) {
  int tid;
  char output[512];
  
  tid = (int)threadid;
  writeLog(0,"Starting Bot Thread: [%d]\n", tid);
  while (1) {
    sleep(5);
    botNextSong();
    }
  pthread_exit(NULL);
  }

int botNextSong() {
  tuveChanList_t *tmpChans;
  
  for (tmpChans = channels;tmpChans != 0x0;tmpChans = tmpChans->next) {
  	if (tmpChans->songEnd < time(NULL)) {
  	  writeLog(0,"Need To Find Next Song For: %s\n",tmpChans->channel);
      }
    }
  }

void *PrintHello(void *threadid) {
   int tid;
   tid = (int)threadid;
   printf("Hello World! It's me, thread #%d!\n", tid);
   pthread_exit(NULL);
  }

/*
int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc, t;
   for(t=0; t<NUM_THREADS; t++){
      printf("In main: creating thread %d\n", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}
*/