diff --git a/botthread.c b/botthread.c index bf3c2f1..e8c2d0f 100644 --- a/botthread.c +++ b/botthread.c @@ -346,61 +346,64 @@ tmpUser = tmpChans->nextUser; findUser: + if (tmpChans->modes[CHAN_QUEUE] == 0x0) /* If Channel Has Queues Disabled Jump Right To Random */ - goto getRandom; - if (tmpChans->nextUser != 0x0) { - writeLog(3,"User: [%s:%s](%i)\n",tmpChans->nextUser->user->userInfo.username,tmpChans->channel,tmpChans->count); - if (tmpChans->count == MAX_COUNT) { + goto getRandom; + + if (tmpChans->count != MAX_COUNT) { + lC = 0; + while (lC < 2) { + /* Reset Chan Counter */ + tmpChans->count = 0x0; + tmpChans->nextUser = tmpChans->nextUser->next; + + /* Make sure we didn't go beyond the list */ if (tmpChans->nextUser == 0x0) tmpChans->nextUser = tmpChans->users; - tmpChans->count = 0x0; - if (tmpChans->nextUser != 0x0) + + if (tmpChans->nextUser->user->userInfo.queue == 0x1) goto gotUser; + + lC++; + } + } + /* Find A Random Song */ + getRandom: + if (tmpChans->modes[CHAN_RANDOM] == 0x1) { + sprintf(output,"SELECT artist,title,file,length,vid,classification,rating,count FROM videos WHERE rating <= %i AND classification = %i AND count <= %i",tmpChans->modes[CHAN_RATING],tmpChans->modes[CHAN_CLASS],playCnt); + res = dbQuery(output,1); + if (res == 0x0) { + sprintf(output,"MSG:TUveD:%s:Sorry I'm Have SQL Troubles Today.",tmpChans->channel); + tuveSendAllInChan(tmpChans->channel,0x0,output); + } + else if (mysql_num_rows(res) == 0x0) { + playCnt++; + goto getRandom; } else { - gotUser: - if (tmpChans->nextUser->user->userInfo.queue == 0x1) { - sSendData(tmpChans->nextUser->user,"GETVIDEO"); - writeLog(0,"Need To Find Next Song For: %s, From User: %s\n",tmpChans->channel,tmpChans->nextUser->user->userInfo.username); - tmpChans->count++; - } - else { - if (tmpUser == tmpChans->nextUser) { - if (tmpChans->count != MAX_COUNT) { - tmpChans->count = MAX_COUNT; - //goto findUser; - } - } - else { - tmpChans->count = MAX_COUNT; - goto findUser; - } - - /* Find A Random Song */ - getRandom: - if (tmpChans->modes[CHAN_RANDOM] == 0x1) { - sprintf(output,"SELECT artist,title,file,length,vid,classification,rating,count FROM videos WHERE rating <= %i AND classification = %i AND count <= %i",tmpChans->modes[CHAN_RATING],tmpChans->modes[CHAN_CLASS],playCnt); - res = dbQuery(output,1); - if (res == 0x0) { - sprintf(output,"MSG:TUveD:%s:Sorry I'm Have SQL Troubles Today.",tmpChans->channel); - tuveSendAllInChan(tmpChans->channel,0x0,output); - } - else if (mysql_num_rows(res) == 0x0) { - playCnt++; - goto getRandom; - } - else { - mysql_data_seek(res,(random() % mysql_num_rows(res))); - row = mysql_fetch_row(res); - sprintf(output,"UPDATE videos SET count = %i WHERE vid = %s\n",atoi(row[7])+1,row[4]); - dbQuery(output,0); - tmpChans->count = MAX_COUNT; - tuveBotSetSong(tmpChans->channel,"TUveD",row[0],row[1],atoi(row[3]),row[2],atoi(row[5]),atoi(row[6]),atoi(row[4])); - } - } - /* End Of Finding A Random Song */ - } + mysql_data_seek(res,(random() % mysql_num_rows(res))); + row = mysql_fetch_row(res); + sprintf(output,"UPDATE videos SET count = %i WHERE vid = %s\n",atoi(row[7])+1,row[4]); + dbQuery(output,0); + tmpChans->count = MAX_COUNT; + tuveBotSetSong(tmpChans->channel,"TUveD",row[0],row[1],atoi(row[3]),row[2],atoi(row[5]),atoi(row[6]),atoi(row[4])); + } + } + goto sE: + + gotUser: + if (tmpChans->nextUser->user->userInfo.queue == 0x1) { + sSendData(tmpChans->nextUser->user,"GETVIDEO"); + writeLog(0,"Need To Find Next Song For: %s, From User: %s\n",tmpChans->channel,tmpChans->nextUser->user->userInfo.username); + tmpChans->count++; + } + else { + tmpChans->count = MAX_COUNT; + goto findUser; + } + sE: + } } } else