one thing cant never be beaten easily:
q3 dont accept multiple occourrences of the same map within 1 file.
this means running a *non-weighted playlist*
the first map in the 2 lists will be played unbelievable often, some days i go and re-sort maps manually.
the lines in the mapcycle files are php-shuffeled...
thats the way it runs:
- Code: Select all
<?php
// (c) 2012 Blinky
mysql_connect("333.444.555.666", "user", "***") or die("sql verbindung gescheitert");
mysql_select_db("dbname");
$votesettings = mysql_query("SELECT nextvote,intervall,reg,cus FROM map_vote_admin LIMIT 0, 1");
$settings = mysql_fetch_row($votesettings);
$nextcycdate = $settings[0];
$cycleinterval = $settings[1];
$numberreg = $settings[2];
$numbercus = $settings[3];
$totalvotes = "0";
$todaysdate = date("Y-m-d");
// Datum ueberpfuefen ...
if ($nextcycdate == $todaysdate) {
// infos zum neuen cycle
$nextregmaps = mysql_query("SELECT name,votes FROM map_vote_maps WHERE reg='1' && votes!='0' && size<'3' ORDER BY votes DESC LIMIT 0, $numberreg");
$nextregnumber = mysql_num_rows($nextregmaps);
$nextcusmaps = mysql_query("SELECT name,votes FROM map_vote_maps WHERE reg='0' && votes!='0' && size<'3' ORDER BY votes DESC LIMIT 0, $numbercus");
$nextcusnumber = mysql_num_rows($nextcusmaps);
$usersvoted = mysql_query("SELECT voted_for_maps FROM phpbb_users WHERE voted_for_maps='1'");
$usersvotednumber = mysql_num_rows($usersvoted);
$totalmapvotes = mysql_query("SELECT votes FROM map_vote_maps WHERE votes!='0' && size<'3'");
if (mysql_num_rows($totalmapvotes) != "0") {
while ($mapvotes = mysql_fetch_row($totalmapvotes)) {
$totalvotes = $totalvotes + $mapvotes[0];
}
}
if ($nextregnumber == "0" && $nextcusnumber == "0") die("keine votes in der datenbank");
////////////
$nextregmaps2 = mysql_query("SELECT name,votes FROM map_vote_maps WHERE reg='1' && votes!='0' && size>'1' ORDER BY votes DESC LIMIT 0, $numberreg");
$nextregnumber2 = mysql_num_rows($nextregmaps2);
$nextcusmaps2 = mysql_query("SELECT name,votes FROM map_vote_maps WHERE reg='0' && votes!='0' && size>'1' ORDER BY votes DESC LIMIT 0, $numbercus");
$nextcusnumber2 = mysql_num_rows($nextcusmaps2);
$usersvoted2 = mysql_query("SELECT voted_for_maps FROM phpbb_users WHERE voted_for_maps='1'");
$usersvotednumber2 = mysql_num_rows($usersvoted2);
$totalmapvotes2 = mysql_query("SELECT votes FROM map_vote_maps WHERE votes!='0' && size>'1'");
if (mysql_num_rows($totalmapvotes2) != "0") {
while ($mapvotes2 = mysql_fetch_row($totalmapvotes2)) {
$totalvotes2 = $totalvotes2 + $mapvotes2[0];
}
}
if ($nextregnumber2 == "0" && $nextcusnumber2 == "0") die("keine votes in der datenbank");
// mapcycle_arrays erstellen
$mapcycle_array = array();
$votes_array = array();
if ($nextregnumber != "0") {
while ($nextregs = mysql_fetch_row($nextregmaps)) {
$mapcycle_array[] = $nextregs[0];
$votes_array[] = $nextregs[1];
}
}
if ($nextcusnumber != "0") {
while ($nextcuss = mysql_fetch_row($nextcusmaps)) {
$mapcycle_array[] = $nextcuss[0];
$votes_array[] = $nextcuss[1];
}
}
////////////
$mapcycle_array2 = array();
$votes_array2 = array();
if ($nextregnumber2 != "0") {
while ($nextregs2 = mysql_fetch_row($nextregmaps2)) {
$mapcycle_array2[] = $nextregs2[0];
$votes_array2[] = $nextregs2[1];
}
}
if ($nextcusnumber2 != "0") {
while ($nextcuss2 = mysql_fetch_row($nextcusmaps2)) {
$mapcycle_array2[] = $nextcuss2[0];
$votes_array2[] = $nextcuss2[1];
}
}
// mapcycle_array shuffeln
shuffle($mapcycle_array);
////////////
shuffle($mapcycle_array2);
// neue mapcycle.temp.txt anlegen
if (file_exists("mapcycle.temp.txt")) unlink("mapcycle.temp.txt");
$file = fopen("mapcycle.temp.txt", "a");
for ($i = 0; $i<count($mapcycle_array); $i++) {
fputs($file, $mapcycle_array[$i]);
if ($i < (count($mapcycle_array) - 1)) fputs($file, "\n");
}
fclose($file);
////////////
if (file_exists("mapcycle2.temp.txt")) unlink("mapcycle2.temp.txt");
$file2 = fopen("mapcycle2.temp.txt", "a");
for ($i = 0; $i<count($mapcycle_array2); $i++) {
fputs($file2, $mapcycle_array2[$i]);
if ($i < (count($mapcycle_array2) - 1)) fputs($file2, "\n");
}
fclose($file2);
// file uppen
$conn_id = ftp_connect("666.555.444.333");
$login_result = ftp_login($conn_id, "user", "***");
if ((!$conn_id) || (!$login_result)) die("ftp verbindung gescheitert");
ftp_delete($conn_id, "mapcycle.old.txt");
ftp_rename($conn_id, "mapcycle.txt", "mapcycle.old.txt");
////////////
ftp_delete($conn_id, "mapcycle2.old.txt");
ftp_rename($conn_id, "mapcycle2.txt", "mapcycle2.old.txt");
$upload = ftp_put($conn_id, "mapcycle.txt", "mapcycle.temp.txt", FTP_ASCII);
if (!$upload) {
ftp_close($conn_id);
die("upload gescheitert");
}
////////////
$upload = ftp_put($conn_id, "mapcycle2.txt", "mapcycle2.temp.txt", FTP_ASCII);
if (!$upload) {
ftp_close($conn_id);
die("upload gescheitert");
}
ftp_close($conn_id);
////////////
// db stuff
// cycle in db eintragen
mysql_query("INSERT INTO map_vote_cycles (allvotes,electors) VALUES ('$totalvotes','$usersvotednumber')");
// map_voted for users auf 0
mysql_query("UPDATE phpbb_users SET voted_for_maps='0'");
// map_vote_maps votes auf 0
mysql_query("UPDATE map_vote_maps SET votes='0'");
// neuen termin festlegen
$nextcycdatearray = explode("-", $nextcycdate);
$nextcycdateime = mktime(0, 0, 0, $nextcycdatearray[1], $nextcycdatearray[2], $nextcycdatearray[0]);
$newnextcycdatetime = $nextcycdateime + ($cycleinterval*7*24*60*60);
$newnextcycdate = date("Y-m-d", $newnextcycdatetime);
mysql_query("UPDATE map_vote_admin SET nextvote='$newnextcycdate'");
// server restart
//$fp = fsockopen('udp://192.168.9.1', 22222, $errno, $error, 1);
//fwrite($fp, "\xFF\xFF\xFF\xFFrcon *** exec server.cfg\x00");
// post a new topic, post, edit forums
$small_cycle = file_get_contents('mapcycle.temp.txt');
$big_cycle = file_get_contents('mapcycle2.temp.txt');
$new_cyc_time = time();
// new post
mysql_query("INSERT INTO phpbb_posts (forum_id,poster_id,post_time,post_subject,post_text,bbcode_bitfield,bbcode_uid)
VALUES ('29','857','$new_cyc_time','MapCycle from $todaysdate','small cycle:\[code:ua744a8e\]$small_cycle\[/code:ua744a8e\]big cycle:\[code:ua744a8e\]$big_cycle\[/code:ua744a8e\]',
'AIA=','ua744a8e')");
$cyc_postid = mysql_insert_id();
// new topic
mysql_query("INSERT INTO phpbb_topics (forum_id,topic_title,topic_poster,topic_time,topic_first_post_id,
topic_first_poster_name,topic_first_poster_colour,topic_last_post_id,topic_last_poster_id,topic_last_poster_name,
topic_last_poster_colour,topic_last_post_subject,topic_last_post_time)
VALUES ('29','MapCycle from $todaysdate','857','$new_cyc_time','$cyc_postid','MapCycle [Cron]','9E8DA7',
'$cyc_postid','857','MapCycle [Cron]','9E8DA7','MapCycle from $todaysdate','$new_cyc_time')");
$cyc_topicid = mysql_insert_id();
// topic_id into post
mysql_query("UPDATE phpbb_posts SET topic_id=$cyc_topicid WHERE post_id=$cyc_postid");
// edit forum
mysql_query("UPDATE phpbb_forums SET forum_posts=forum_posts+1,forum_topics=forum_topics+1,
forum_topics_real=forum_topics_real+1,forum_last_post_id='$cyc_postid',forum_last_poster_id='867',
forum_last_post_subject='MapCycle from $todaysdate',forum_last_post_time='$new_cyc_time',
forum_last_poster_name='MapCycle [Cron]',forum_last_poster_colour='9E8DA7' WHERE forum_id='29'");
// +1 post for bot
mysql_query("UPDATE phpbb_users SET user_posts=user_posts+1 WHERE user_id=857");
}
?>