function commitFleets() { if ($_POST["conf"]) { $conf = $_POST["conf"]; } if ($conf) { foreach ($conf as $confkey => $confval) { if ($confval["faultid"]) { updateFleet($confval); } else { createFleet($confval); } } } goHere("index.php?mode=maxine/index&action=editfleets"); }
<?php use App\Battleships\Exceptions\Exception; // Default home route $app->get('/', function () use($app) { $fleet = getFleet(); // flag to backdoor cheats $debug = isset($_GET['debug']) ? true : false; $flash_messages = getFlashMessage(); $app->view->setData('fleet', $fleet); $app->render('layout.php', ['grid' => $fleet->getGridCoordinates(), 'hits' => $fleet->getShotCoordinates(), 'debug' => $debug, 'hit' => 'X', 'miss' => '--', 'no_shot' => '.', 'flash_messages' => $flash_messages]); }); // Handle post request $app->post('/', function () use($app) { if (empty($_POST['co-ordinates'])) { $app->redirect('/'); } $coordinates = $_POST['co-ordinates']; $row = strtolower(substr($coordinates, 0, 1)); $column = intval(substr($coordinates, 1)); $fleet = getFleet(); try { $status = $fleet->fire($row, $column); $status ? setFlashMessage('hit') : setFlashMessage('miss'); updateFleet($fleet); } catch (Exception $e) { setFlashMessage($e->getMessage()); } $app->redirect('/'); }); return $app;
function updateScan($scan) { $logger =& LoggerManager::getLogger("db.scans"); $logger->debug(array("function" => "updateScan", "scan" => $scan)); if (!is_numeric($scan['gala']) || !is_numeric($scan['pos'])) { return; } #scan exists $dbscan = existScan($scan['gala'], $scan['pos']); if (!$dbscan) { $sid = insertsql(" insert into scans (gala,pos,nick) values (" . $scan['gala'] . "," . $scan['pos'] . ",'" . addslashes($scan['nick']) . "')"); if (!$sid) { return; } $dbscan = array("sid" => $sid, "gala" => $scan['gala'], "pos" => $scan['pos']); } #sektorscan if ($scan['type'] == "sector") { #existiert schon -> update $val = array("sector_punkte" => $scan['punkte'], "sector_kristall" => $scan['kristall'], "sector_metall" => $scan['metall'], "sector_roids" => $scan['roids'], "sector_ships" => $scan['ships'], "sector_deff" => $scan['deff'], "sector_prec" => $scan['prec'], "sector_svs" => $scan['svs'], "sector_scanner" => $scan['scanner'], "sector_time" => time()); } if ($scan['type'] == "unit") { if ($dbscan['hasunit'] && $dbscan['unit_fid']) { updateFleet($dbscan['unit_fid'], $scan['kleptoren'], $scan['cancris'], $scan['fregatten'], $scan['zerstoerer'], $scan['kreuzer'], $scan['schlachter'], $scan['traeger'], $scan['jaeger'], $scan['bomber']); $fid = $dbscan['unit_fid']; } else { $fid = addFleet($scan['kleptoren'], $scan['cancris'], $scan['fregatten'], $scan['zerstoerer'], $scan['kreuzer'], $scan['schlachter'], $scan['traeger'], $scan['jaeger'], $scan['bomber']); if (!$fid) { return; } } $val = array("unit_prec" => $scan['prec'], "unit_svs" => $scan['svs'], "unit_scanner" => $scan['scanner'], "unit_fid" => $fid, "unit_time" => time()); } if ($scan['type'] == "gscan") { $val = array("gscan_prec" => $scan['prec'], "gscan_svs" => $scan['svs'], "gscan_scanner" => $scan['scanner'], "gscan_horus" => $scan['horus'], "gscan_rubium" => $scan['rubium'], "gscan_coon" => $scan['coon'], "gscan_pulsar" => $scan['pulsar'], "gscan_centurion" => $scan['centurion'], "gscan_time" => time()); } // miliscan updaten if ($scan['type'] == "mili") { if (miliscan_fleet_get($dbscan['sid'])) { $fleetlist = selectsql("select * from scanmili_fleet where sid = " . $dbscan['sid'] . " order by num ASC"); for ($i = 0; $i < 3; $i++) { miliscan_fleet_update($fleetlist[$i]['fid'], $scan['fleets'][$i]); } } else { for ($i = 0; $i < 3; $i++) { miliscan_fleet_add($dbscan['sid'], $i, $scan['fleets'][$i]); } } // 100% scan und user ist tic member // if($scan['prec'] == "100" && ($user = user_get_bypos($scan['gala'],$scan['pos']))) { // // } $val = array("mili_prec" => $scan['prec'], "mili_svs" => $scan['svs'], "mili_scanner" => $scan['scanner'], "mili_time" => time()); $logger->debug(array("message" => "mili update done", "vals" => $val)); } if ($scan['type'] == "news") { $val = array("news_prec" => $scan['prec'], "news_svs" => $scan['svs'], "news_scanner" => $scan['scanner'], "news_newsdata" => $scan['newsdata'], "news_time" => time()); } if (!$dbscan['nick'] || strtolower($dbscan['nick']) != strtolower($scan['nick'])) { $val['nick'] = $scan['nick']; } if (strtolower($dbscan['nick']) != strtolower($scan['nick'])) { query("update scans set nick = null where lower(nick) = lower('" . mysql_escape_string($scan['nick']) . "')"); } if (count($val)) { $updates = array(); foreach ($val as $key => $value) { if (!isset($value)) { $value = "NULL"; } else { if (!is_numeric($value)) { $value = "'" . mysql_escape_string($value) . "'"; } } $updates[] = "{$key} = {$value}"; } $logger->debug(array("function" => "updateScan", "message" => "before update scans", "vals" => $vals, "updates" => $updates)); query("update scans set " . join(",", $updates) . " where sid = " . $dbscan['sid']); } $logger->debug("update scan done"); return $dbscan['sid']; }