#include <stdio.h>
#include "tuvebot.h"
void *botCMD_Thread(void *threadid) {
int tid = 0x0;
int i = 0;
int tmpVal = 0;
short lC = 0x0;
char qryStr[256];
MYSQL_RES *res = 0x0;
MYSQL_ROW row;
tid = (int)threadid;
writeLog(0,"Starting Bot's CMD Thread: [%d]\n", tid);
while (1) {
if (connected == 0) {
sleep(5);
if (joinChan == 1) {
joinChan = 0;
connected = 1;
botJoinChans();
}
}
else {
sleep(30);
res = dbQuery("SELECT channel,rating,classification FROM channels WHERE updated = 1",1);
if (mysql_num_rows(res) > 0) {
for (i = 0;i < mysql_num_rows(res);i++) {
row = mysql_fetch_row(res);
/* Set Access Level */
tmpVal = atoi(row[1]);
if (tmpVal > 0)
sWriteSocket("MSG %s:.tv mode +A %i"row[0],tmpVal);
else
sWriteSocket("MSG %s:.tv mode -A",row[0]);
/* Set Classification */
tmpVal = atoi(row[2]);
if (tmpVal > 0)
sWriteSocket("MSG %s:.tv mode +C %i"row[0],tmpVal);
else
sWriteSocket("MSG %s:.tv mode -C",row[0]);
sprintf(qryStr,"UPDATE channels SET updated = 0 WHERE channel = '%s'",row[0]);
dbQuery(qryStr,0);
}
}
if (lC == 6) {
lC = 0;
sWriteSocket("STATUS");
}
lC++;
}
}
pthread_exit(NULL);
} /* End tuveCMD_Thread() */