AutoMatic Quiz

Started on the old forum in August 2012 · view the original in the archive · old links redirect here

2 replies · 660 views · started 14 years ago · 1 min read

2 participants
wap-ruler Developer · 143 posts #1

I Wanna make a automatic quiz room for my site...frm ilichat script i have borrowed the method.... i used bot.php made db ri8....nd included that file for a value of $rid but it doesnt work....smone plz help...here is the bot.php

<?
//BOT FOR QUIZ

//GET TIME
$fd = fopen("bots/time.dat", "r");
if(!$fd) return;
$buff_time = intval(fgets($fd));
fclose($fd);

//GET ACTION
$fd = fopen("bots/action.dat", "r");
if(!$fd) $buff_action = "unknown";
else $buff_action = fgets($fd);
fclose($fd);

if($buff_time < time() && $buff_action != 0)
{
if($buff_action != 0) $action = 3;
}
else
{
if($buff_action == 0 && ($buff_time - time() < 0)) $action = 0;
if($buff_action == 1 && ($buff_time - time() < 135)) $action = 1;
if($buff_action == 2 && ($buff_time - time() < 75)) $action = 2;
if($buff_action == 3 && ($buff_time - time() < 15)) $action = 3;
}

//FIRST START
if($buff_time == 0) $action = 0;

switch($action)
{
//NEW QUESTION
case '0':
$sql = mysql_query("SELECT * FROM `chat_questions` ORDER BY RAND() LIMIT 1;");
$ques_arr = mysql_fetch_array($sql);
$question = $ques_arr['question'];
$answer = $ques_arr['answer'];
$tran_answer = $ques_arr['translit'];
$answer = iconv('utf-8', 'windows-1251', $answer);
$length = strlen($answer);
$answer = iconv('windows-1251', 'utf-8', $answer);

$question = "$question ($length букв)";

mysql_query("INSERT INTO `chat".$rid."` VALUES(0, '2', '".$bots[0]."', '".$question."', '0', '".date("H:i")."',".time().",0);");
mysql_query("UPDATE `chat_users` SET `posts` = `posts` + 1 WHERE `id` = 2;");

$fd = fopen("bots/question.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, $question);
flock($fd, LOCK_UN);
fclose($fd);

$fd = fopen("bots/answer.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, $answer);
flock($fd, LOCK_UN);
fclose($fd);

$fd = fopen("bots/translit.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, $tran_answer);
flock($fd, LOCK_UN);
fclose($fd);

$fd = fopen("bots/action.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, "1");
flock($fd, LOCK_UN);
fclose($fd);

$fd = fopen("bots/time.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, (time() + 180 + $intervals[0])); //TIME FOR ANSWER - 15
flock($fd, LOCK_UN);
fclose($fd);
break;

//FIRST HELP
case '1':
$fd = fopen("bots/answer.dat", "r");
$answer = fgets($fd);
fclose($fd);

$answer = iconv('utf-8', 'windows-1251', $answer);
$help = substr($answer, 0, 1);
$answer = iconv('windows-1251', 'utf-8', $answer);
$help = iconv('windows-1251', 'utf-8', $help);
$help = "Подсказка: $help...";

mysql_query("INSERT INTO `chat".$rid."` VALUES(0, '2', '".$bots[0]."', '".$help."', '0', '".date("H:i")."',".time().",0);");
mysql_query("UPDATE `chat_users` SET `posts` = `posts` + 1 WHERE `id` = 2;");

$fd = fopen("bots/action.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, "2");
flock($fd, LOCK_UN);
fclose($fd);
break;

//SECOND HELP
case '2':
$fd = fopen("bots/answer.dat", "r");
$answer = fgets($fd);
fclose($fd);

$answer = iconv('utf-8', 'windows-1251', $answer);
$help = substr($answer, 0, 2);
$answer = iconv('windows-1251', 'utf-8', $answer);
$help = iconv('windows-1251', 'utf-8', $help);
$help = "Подсказка: $help...";

mysql_query("INSERT INTO `chat".$rid."` VALUES(0, '2', '".$bots[0]."', '".$help."', '0', '".date("H:i")."', ".time().",0);");
mysql_query("UPDATE `chat_users` SET `posts` = `posts` + 1 WHERE `id` = 2;");

$fd = fopen("bots/action.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, "3");
flock($fd, LOCK_UN);
fclose($fd);
break;

//NO ANSWER
case '3':
$fd = fopen("bots/answer.dat", "r");
$answer = fgets($fd);
fclose($fd);
$message = "Время истекло! Правильный ответ был: <b>$answer</b>. Следующий вопрос через ".$intervals[0]." секунд.";
mysql_query("INSERT INTO `chat".$rid."` VALUES(0, '2', '".$bots[0]."', '".$message."', '0', '".date("H:i")."', ".time().",0);");
mysql_query("UPDATE `chat_users` SET `posts` = `posts` + 1 WHERE `id` = 2;");

$fd = fopen("bots/time.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, (time() + $intervals[0])); //NEXT QUESTION
flock($fd, LOCK_UN);
fclose($fd);

$fd = fopen("bots/action.dat", "w");
flock($fd, LOCK_EX);
$puts = fputs($fd, "0");
flock($fd, LOCK_UN);
fclose($fd);
break;
}
?>

ImPoSsIbLe iS nOthInG aS ImPoSsible ItSelF SaYs "I M POSSIBLE"

wap-ruler Developer · 143 posts #2

thank u guyz for nt helping me!!!! i made it myself... lolz

ImPoSsIbLe iS nOthInG aS ImPoSsible ItSelF SaYs "I M POSSIBLE"

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close