load("GLOBAL,START,WORDFINDER"); $wfconfig = $db->query_first("SELECT * FROM bb".$n."_wordfinder_config"); require("./wordfinder_functions.php"); require("./wordfinder_global.php"); require("./wordfinder_styles.php"); /* INIT */ $minChars = 3; $maxChars = 15; $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $minRows = $wfconfig['minrows']; // 15 $minCols = $wfconfig['mincols']; // 15 $maxRows = $wfconfig['maxrows']; // 54 $maxCols = $wfconfig['maxcols']; // 54 $gamebonus = $wfconfig['bonus']; $minChars = $wfconfig['minchars']; $maxChars = $wfconfig['maxchars']; $lettertime = $wfconfig['lettertime']; $defaultRows = 20; $defaultCols = 20; $maxCharsLimit = 10200; $retries = 55; $mistakes = 0; $puzzleTitleSize = 20; $borf = $wfconfig['borf']; $diag = $wfconfig['diag']; $upanddown = $wfconfig['upanddown']; if ($wfconfig['bgcolor'] == "") { $bgc = $db->query_first("SELECT * FROM bb".$n."_designelements WHERE designpackid='$wbbuserdata[designpackid]' AND element='tableabgcolor'"); $backgroundColor = $bgc['value']; } else $backgroundColor = $wfconfig['bgcolor']; if ($wfconfig['hlcolor'] == "") { $hlc = $db->query_first("SELECT * FROM bb".$n."_designelements WHERE designpackid='$wbbuserdata[designpackid]' AND element='tablebbgcolor'"); $highlightColor = $hlc['value']; } else $highlightColor = $wfconfig['hlcolor']; $ficolor = $wfconfig['ficolor']; /* INIT */ // get the levels $minSize = $minRows * $minCols; $maxSize = $maxRows * $maxCols; $addWords = round(($maxSize - $minSize) / 10, 0); $gameLevels = $minLevel = $maxLevel = array(); $lvlsize = $minSize; for ($x=0;$x < 10;$x++) { $lvl = $x + 1; $gameLevels[$x] = $lvl; $minLevel[$x] = $lvlsize; $lvlsize += $addWords; if ($x == 9 AND $lvlsize > $maxSize) $lvlsize = $maxSize; $maxLevel[$x] = $lvlsize; $lvlsize++; } $minLevel[0] = 0; $currenttime = formatdate($wbbuserdata['timeformat'],time()); $toffset = (($wbbuserdata['timezoneoffset']>=0) ? ("+") : ("")).$wbbuserdata['timezoneoffset']; if(class_exists(get4eval)){ eval ("\$lang->items['LANG_START_TIMEZONE'] = \"".$lang->get4eval("LANG_START_TIMEZONE")."\";"); } else { eval ("\$lang->items['LANG_START_TIMEZONE'] = \"".$lang->get("LANG_START_TIMEZONE", array('$toffset' => $toffset))."\";"); } $lastvisitdate = formatdate($wbbuserdata['dateformat'],$wbbuserdata['lastvisit']); $lastvisittime = formatdate($wbbuserdata['timeformat'],$wbbuserdata['lastvisit']); $usergame = $db->query_first("SELECT * FROM bb".$n."_wordfinder_user WHERE userid='$wbbuserdata[userid]'"); if (!$usergame['gameid']) { $action = ""; $countInserted = 0; $gomenu = 1; if (isset($_REQUEST['action'])) $action = $_REQUEST['action']; if ($action == "goga") { $gomenu = 0; if ($_POST['send'] == "send") { if ($_POST['selgame'] != 0) { if ($wfconfig['guthaben'] == 1) { $mg = $db->query_first("SELECT userid FROM bb".$n."_wordfinder_games WHERE gameid='".$_POST['selgame']."'"); if ($mg['userid'] != $wbbuserdata['userid'] && $wfconfig['pay'] > 0) { $table = "_kontoauszug"; $tablename = "uhrzeit"; $koto = check_guthaben($table, $tablename); $ginsert = "{$lang->items['LANG_WORDFINDER_TEXT43']}"; if ($koto[0] == 1 && $koto[1] == 1) { $db->query("UPDATE bb".$n."_users set guthaben=guthaben-'$wfconfig[pay]' where userid='$wbbuserdata[userid]'"); $db->query("INSERT INTO bb".$n."_kontoauszug (kid,userid,datum,uhrzeit,info,betrag,art) VALUES ('','$wbbuserdata[userid]','".date("d.m.y")."','".date("H:i")."','".addslashes($ginsert)."','$wfconfig[pay]','minus')"); } elseif ($koto[0] == 1 && $koto[1] == 2) { $db->query("UPDATE bb".$n."_users set guthaben=guthaben-'$wfconfig[pay]' where userid='$wbbuserdata[userid]'"); $db->query("INSERT INTO bb".$n."_kontoauszug (kid,userid,datum,info,betrag,art) VALUES ('','$wbbuserdata[userid]','".time()."','".addslashes($ginsert)."','$wfconfig[pay]','minus')"); } } } $db->query("UPDATE bb".$n."_wordfinder_user SET gameid='".$_POST['selgame']."', mistakes='0' WHERE userid='$wbbuserdata[userid]'"); } header ("location: wordfinder.php?sid=$session[hash]", TRUE); exit(); } if (!$gomenu) eval ("\$gametemplate .= \"".$tpl->get("wordfinder_getgame")."\";"); } elseif ($action == "rules") { $bonustext = ""; if ($gamebonus != "" AND $gamebonus > 0) { $bonustext = "
{$lang->items['LANG_WORDFINDER_TEXT45']} {$lang->items['LANG_WORDFINDER_TEXT46']} ".$gamebonus." {$lang->items['LANG_WORDFINDER_TEXT47']}
"; $bonustext .= "{$lang->items['LANG_WORDFINDER_TEXT44']}
"; } eval ("\$gametemplate .= \"".$tpl->get("wordfinder_rules")."\";"); eval("\$tpl->output(\"".$tpl->get("wordfinder")."\");"); exit(); } elseif ($action == "create") { if ($_POST['send'] == "send") { $errormessage = ""; if ($_POST['title']) $title = ereg_replace("[^0-9A-Za-zÄÖÜäöü ]","",$_POST['title']); else $title = ""; $gridstyle = $_POST['gridstyle']; $rows = ereg_replace("[^0-9]","",$_POST['rows']); $cols = ereg_replace("[^0-9]","",$_POST['cols']); if ($rows < $minRows) $rows = $minRows; elseif ($rows > $maxRows) $rows = $maxRows; if ($cols < $minCols) $cols = $minCols; elseif ($cols > $maxCols) $cols = $maxCols; $gS = ""; if ($gridstyle != "square") { foreach ($gridStyleOptions as $t) { if ($t == $gridstyle) { $gS = $gridstyle; break; } } if (!empty($gS)) { $rows = ${$gS}[2]; $cols = ${$gS}[3]; $v = 0; for($t=1;$t <= $rows;$t++) { for($u=1;$u <= $cols;$u++,$v++) { if(${$gS}[0][$v] == 0) $grid[$t][$u] = " "; else $grid[$t][$u] = ""; } } } } else { for($t=1;$t <= $rows;$t++) { for($u=1;$u <= $cols;$u++,$v++) { $grid[$t][$u] = ""; ${$gS}[0][$v] = 1; } } } $grsno = $$gS; $maxGridSize = ($rows * $cols) + $rows + $cols; $maxGridSizeCounter = 0; $rc = ($rows >= $cols) ? $rows + 1 : $cols + 1; if ($counter) { for ($a=0;$a < $counter;$a++) mt_rand(0,1); } $tempWords = str_replace("\r\n", ",", $_POST['words']); $tempWords = str_replace("\n", ",", $tempWords); $tempWords = str_replace("\r", ",", $tempWords); $tempWords = strtoupper($tempWords); $tempWords = str_replace("Ä", "AE", $tempWords); $tempWords = str_replace("Ö", "OE", $tempWords); $tempWords = str_replace("Ü", "UE", $tempWords); $tempWords = str_replace("ä", "AE", $tempWords); $tempWords = str_replace("ö", "OE", $tempWords); $tempWords = str_replace("ü", "UE", $tempWords); $tempWords = str_replace(" ", ",", $tempWords); $tempWords = ereg_replace("^[,]*", "", $tempWords); $tempWords = ereg_replace("[^".$chars.",]", "", $tempWords); $temp = $words = array(); $temp = explode(",", $tempWords); $numWords = count($temp); if ($numWords) { for ($x=0,$y=0,$z=0;$z < $numWords;$y++,$z++) { $tmp = strlen($temp[$y]); if($tmp >= $minChars && $tmp <= $maxChars && $tmp < $rc) { $words[$x] = $temp[$y]; $maxGridSizeCounter += $tmp; $x++; } if ($maxGridSizeCounter > $maxGridSize) break; } } if ($words[0] == "") { $errormessage .= "{$lang->items['LANG_WORDFINDER_TEXT48']} ".$minChars." {$lang->items['LANG_WORDFINDER_TEXT49']} ".$maxChars." {$lang->items['LANG_WORDFINDER_TEXT50']}"; eval ("\$gametemplate .= \"".$tpl->get("wordfinder_error")."\";"); eval("\$tpl->output(\"".$tpl->get("wordfinder")."\");"); exit(); } $words = array_values(array_unique($words)); $unsortedWords = $words; usort($words,"cmp"); $wcount = 0; $mywords = ""; foreach($words as $key => $val) { if ($val) { $wcount++; $mywords .= $val.","; } } $mywords = substr($mywords, 0, strlen($myword) - 1); $output = create_the_grid($grsno, $mywords, $chars, $maxChars, $maxGridSizeCounter, $minchars, $maxchars, $retries); $error = $output[4]; if ($error) { $errormessage .= "{$lang->items['LANG_WORDFINDER_TEXT51']}"; eval ("\$gametemplate .= \"".$tpl->get("wordfinder_error")."\";"); eval("\$tpl->output(\"".$tpl->get("wordfinder")."\");"); exit(); } $db->query("INSERT INTO bb".$n."_wordfinder_games (userid, username, gamerows, gamecols, style, maxwords, gamewords, title) VALUES ('$wbbuserdata[userid]', '".addslashes($wbbuserdata['username'])."', '$rows', '$cols', '$gridstyle', '$wcount', '".addslashes($mywords)."', '".addslashes($title)."') "); header ("location: wordfinder.php?sid=$session[hash]", TRUE); exit(); } $gomenu = 0; $gridoptions = ""; foreach ($gridStyleOptions as $key => $gSo) { if ($gSo) { $gridoptions .= "\n"; } } $minsize = $minCols." x ".$minRows; $maxsize = $maxCols." x ".$maxRows; eval ("\$gametemplate .= \"".$tpl->get("wordfinder_create")."\";"); } elseif ($action == "high") { require("./wordfinder_high.php"); } elseif ($action == "endit") { header ("location: wordfinder.php?sid=$session[hash]", TRUE); exit(); } if ($gomenu) eval ("\$gametemplate .= \"".$tpl->get("wordfinder_main")."\";"); eval("\$tpl->output(\"".$tpl->get("wordfinder")."\");"); exit(); } else{ if (isset($_REQUEST['action']) AND $_REQUEST['action'] == "endgame") { $bonus = 0; $countInserted = 0; $endTime = time() - $usergame['starttime']; $mistakes = $usergame['mistakes']; $mygame = $db->query_first("SELECT * FROM bb".$n."_wordfinder_games WHERE gameid='$usergame[gameid]'"); $gstyle = $mygame['style']; $usedRows = $mygame['gamerows']; $usedCols = $mygame['gamecols']; $usedWords = $mygame['maxwords']; $usedLetters = strlen(str_replace(",", "", $mygame['gamewords'])); $gamesize = $usedRows * $usedCols; $fieldsize = $usedRows." x ".$usedCols." / ".$gamesize; if ($gstyle != "square") { foreach ($gridStyleOptions as $t) { if ($t == $gstyle) { $gS = $gstyle; break; } } if (!empty($gS)) { $charCount = 0; $chars = ${$gS}[0]; for($d=0;$d < strlen($chars);$d++) { if ($chars[$d] == "1") $charCount++; } $gamesize = $charCount; $fieldsize = ${$gS}[2]." x ".${$gS}[3]." / ".$gamesize; } } if ($_REQUEST['send'] == "sent") { $gamebonus = 0; $endTime = $usedLetters * $lettertime; $mistakes = $gamesize; } if ($endTime <= ($usedLetters * $lettertime)) $bonus += $gamebonus; $chance = round($gamesize / $usedLetters, 2); $epercent = round(($mistakes * 100) / $gamesize, 2); $errorperc = round($epercent, 0); $score = round(($gamesize / 100) * (100 - $errorperc), 0); $score = $score - $mistakes; $timeScore = round($endTime / $lettertime, 0); if ($timeScore < $score) $score = $score - $timeScore; else $score = 0; $singlescore = $score; $score += $bonus; if ($bonus) $singlescore .= " + ".$bonus." = ".$score; $tstamp = return_time($endTime); $usedtime = ""; if ($tstamp[0]) $usedtime .= ($tstamp[0] == 1) ? $tstamp[0]." {$lang->items['LANG_WORDFINDER_TEXT52']}, " : $tstamp[0]." {$lang->items['LANG_WORDFINDER_TEXT53']}, "; if ($tstamp[1]) $usedtime .= $tstamp[1].":"; else $usedtime .= "00:"; if ($tstamp[2]) $usedtime .= $tstamp[2].":"; else $usedtime .= "00:"; if ($tstamp[3]) $usedtime .= $tstamp[3]; else $usedtime .= "00"; // change: 25*50/98 = 1:12 | rows*cols/strlen(words) // epercent: 125*100/1250 | (mistakes*100)/gamesize if ($wfconfig['guthaben'] == 1) { $mg = $db->query_first("SELECT userid FROM bb".$n."_wordfinder_games WHERE gameid='$usergame[gameid]'"); if ($mg['userid'] != $wbbuserdata['userid']) { $table ="_kontoauszug"; $tablename = "uhrzeit"; $koto = check_guthaben($table, $tablename); $ginsert = "{$lang->items['LANG_WORDFINDER_TEXT54']}"; $money = $wfconfig['betrag']; if ($money == -1) $money = $score; if ($koto[0] == 1 && $koto[1] == 1) { $db->query("UPDATE bb".$n."_users set guthaben=guthaben+'$money' where userid='$wbbuserdata[userid]'"); $db->query("INSERT INTO bb".$n."_kontoauszug (kid,userid,datum,uhrzeit,info,betrag,art) VALUES ('','$wbbuserdata[userid]','".date("d.m.y")."','".date("H:i")."','".addslashes($ginsert)."','$money','plus')"); } elseif ($koto[0] == 1 && $koto[1] == 2) { $db->query("UPDATE bb".$n."_users set guthaben=guthaben+'$money' where userid='$wbbuserdata[userid]'"); $db->query("INSERT INTO bb".$n."_kontoauszug (kid,userid,datum,info,betrag,art) VALUES ('','$wbbuserdata[userid]','".time()."','".addslashes($ginsert)."','$money','plus')"); } } } $db->query("INSERT INTO bb".$n."_wordfinder_finished (userid, username, gameid, taketime, mistakes, gchance, epercent, month, year, rows, cols, score, style) VALUES ('$wbbuserdata[userid]', '".addslashes($wbbuserdata['username'])."', '$usergame[gameid]', '$endTime', '$mistakes', '".addslashes($chance)."', '".addslashes($epercent)."', '".date("m", time())."', '".date("Y", time())."', '$mygame[gamerows]', '$mygame[gamecols]', '$score', '".addslashes($gstyle)."') "); $db->query("UPDATE bb".$n."_wordfinder_user SET gameid='0', mistakes='0', starttime='0' WHERE userid='$wbbuserdata[userid]'"); $db->query("OPTIMIZE TABLE bb".$n."_wordfinder_user"); eval ("\$gametemplate .= \"".$tpl->get("wordfinder_endgame")."\";"); eval("\$tpl->output(\"".$tpl->get("wordfinder")."\");"); exit(); } require("./wordfinder_game.php"); } ?>