function weightPresets() { // check directory-structure if (!CLISetup::writeDir('datasets/')) { return false; } $wtPresets = []; $scales = DB::Aowow()->select('SELECT id, name, icon, class FROM ?_account_weightscales WHERE userId = 0 ORDER BY class, id ASC'); foreach ($scales as $s) { $weights = DB::Aowow()->selectCol('SELECT field AS ARRAY_KEY, val FROM ?_account_weightscale_data WHERE id = ?d', $s['id']); if (!$weights) { CLISetup::log('WeightScale \'' . CLISetup::bold($s['name']) . '\' has no data set. Skipping...', CLISetup::LOG_WARN); continue; } $wtPresets[$s['class']]['pve'][$s['name']] = array_merge(['__icon' => $s['icon']], $weights); } $toFile = "var wt_presets = " . Util::toJSON($wtPresets) . ";"; $file = 'datasets/weight-presets'; if (!CLISetup::writeFile($file, $toFile)) { return false; } return true; }
function spawns() { $alphaMapCache = []; $alphaMapCheck = function ($areaId, array &$set) use(&$alphaMapCache) { $file = 'setup/generated/alphaMaps/' . $areaId . '.png'; if (!file_exists($file)) { // file does not exist (probably instanced area) return false; } // invalid and corner cases (literally) if (!is_array($set) || empty($set['posX']) || empty($set['posY']) || $set['posX'] >= 100 || $set['posY'] >= 100) { $set = null; return true; } if (empty($alphaMapCache[$areaId])) { $alphaMapCache[$areaId] = imagecreatefrompng($file); } // alphaMaps are 1000 x 1000, adapt points [black => valid point] if (!imagecolorat($alphaMapCache[$areaId], $set['posX'] * 10, $set['posY'] * 10)) { $set = null; } return true; }; $checkCoords = function ($points) use($alphaMapCheck) { $result = []; $capitals = array(1497, 1637, 1638, 3487, 1519, 1537, 1657, 3557, 3703, 4395); foreach ($points as $res) { if ($alphaMapCheck($res['areaId'], $res)) { if (!$res) { continue; } // some rough measure how central the spawn is on the map (the lower the number, the better) // 0: perfect center; 1: touches a border $q = abs(($res['posX'] - 50) / 50 * (($res['posY'] - 50) / 50)); if (empty($result) || $result[0] > $q) { $result = [$q, $res]; } } else { if (in_array($res['areaId'], $capitals)) { // capitals (auto-discovered) and no hand-made alphaMap available return $res; } else { if (empty($result)) { // add with lowest quality if alpha map is missing $result = [1.0, $res]; } } } } // spawn does not really match on a map, but we need at least one result if (!$result) { usort($points, function ($a, $b) { return $a['quality'] < $b['quality'] ? -1 : 1; }); $result = [1.0, $points[0]]; } return $result[1]; }; $query[1] = ['SELECT c.guid, 1 AS "type", c.id AS typeId, c.spawntimesecs AS respawn, c.phaseMask, c.zoneId AS areaId, c.map, IFNULL(ca.path_id, 0) AS pathId, c.position_y AS `posX`, c.position_x AS `posY` ' . 'FROM creature c LEFT JOIN creature_addon ca ON ca.guid = c.guid', ' - assembling ' . CLISetup::bold('creature') . ' spawns']; $query[2] = ['SELECT c.guid, 2 AS "type", c.id AS typeId, ABS(c.spawntimesecs) AS respawn, c.phaseMask, c.zoneId AS areaId, c.map, 0 as pathId, c.position_y AS `posX`, c.position_x AS `posY` ' . 'FROM gameobject c', ' - assembling ' . CLISetup::bold('gameobject') . ' spawns']; $query[3] = ['SELECT c.guid, w.entry AS "npcOrPath", w.pointId AS "point", c.zoneId AS areaId, c.map, w.waittime AS "wait", w.location_y AS `posX`, w.location_x AS `posY` ' . 'FROM creature c JOIN script_waypoint w ON c.id = w.entry', ' - assembling waypoints from ' . CLISetup::bold('script_waypoint')]; $query[4] = ['SELECT c.guid, w.entry AS "npcOrPath", w.pointId AS "point", c.zoneId AS areaId, c.map, 0 AS "wait", w.position_y AS `posX`, w.position_x AS `posY` ' . 'FROM creature c JOIN waypoints w ON c.id = w.entry', ' - assembling waypoints from ' . CLISetup::bold('waypoints')]; $query[5] = ['SELECT c.guid, -w.id AS "npcOrPath", w.point, c.zoneId AS areaId, c.map, w.delay AS "wait", w.position_y AS `posX`, w.position_x AS `posY` ' . 'FROM creature c JOIN creature_addon ca ON ca.guid = c.guid JOIN waypoint_data w ON w.id = ca.path_id', ' - assembling waypoints from ' . CLISetup::bold('waypoint_data')]; $queryPost = 'SELECT dm.Id, wma.areaId, IFNULL(dm.floor, 0) AS floor, ' . '100 - ROUND(IF(dm.Id IS NOT NULL, (?f - dm.minY) * 100 / (dm.maxY - dm.minY), (?f - wma.right) * 100 / (wma.left - wma.right)), 1) AS `posX`, ' . '100 - ROUND(IF(dm.Id IS NOT NULL, (?f - dm.minX) * 100 / (dm.maxX - dm.minX), (?f - wma.bottom) * 100 / (wma.top - wma.bottom)), 1) AS `posY`, ' . '((abs(IF(dm.Id IS NOT NULL, (?f - dm.minY) * 100 / (dm.maxY - dm.minY), (?f - wma.right) * 100 / (wma.left - wma.right)) - 50) / 50) * ' . ' (abs(IF(dm.Id IS NOT NULL, (?f - dm.minX) * 100 / (dm.maxX - dm.minX), (?f - wma.bottom) * 100 / (wma.top - wma.bottom)) - 50) / 50)) AS quality ' . 'FROM dbc_worldmaparea wma ' . 'LEFT JOIN dbc_dungeonmap dm ON dm.mapId = IF(?d AND wma.mapId NOT IN (0, 1, 530), wma.mapId, -1) ' . 'WHERE wma.mapId = ?d AND IF(?d, wma.areaId = ?d, wma.areaId <> 0) ' . 'HAVING (`posX` BETWEEN 0.1 AND 99.9 AND `posY` BETWEEN 0.1 AND 99.9) AND (dm.Id IS NULL OR ?d) ' . 'ORDER BY quality ASC'; /*********************/ /* truncate old data */ /*********************/ DB::Aowow()->query('TRUNCATE TABLE ?_spawns'); DB::Aowow()->query('TRUNCATE TABLE ?_creature_waypoints'); /**************************/ /* offsets for transports */ /**************************/ $transports = DB::World()->selectCol('SELECT Data0 AS pathId, Data6 AS ARRAY_KEY FROM gameobject_template WHERE type = 15 AND Data6 <> 0'); foreach ($transports as &$t) { $t = DB::Aowow()->selectRow('SELECT posX, posY, mapId FROM dbc_taxipathnode tpn WHERE tpn.pathId = ?d AND nodeIdx = 0', $t); } /**************/ /* perform... */ /**************/ foreach ($query as $idx => $q) { CLISetup::log($q[1]); $n = 0; $sum = 0; foreach (DB::World()->select($q[0]) as $spawn) { if (!$n) { CLISetup::log(' * sets ' . ($sum + 1) . ' - ' . ($sum += SqlGen::$stepSize)); } if ($n++ > SqlGen::$stepSize) { $n = 0; } // npc/object is on a transport -> apply offsets to path of transport // note, that the coordinates are mixed up .. again // also note, that transport DO spawn outside of displayable area maps .. another todo i guess.. if (isset($transports[$spawn['map']])) { $spawn['posX'] += $transports[$spawn['map']]['posY']; $spawn['posY'] += $transports[$spawn['map']]['posX']; $spawn['map'] = $transports[$spawn['map']]['mapId']; } $points = DB::Aowow()->select($queryPost, $spawn['posX'], $spawn['posX'], $spawn['posY'], $spawn['posY'], $spawn['posX'], $spawn['posX'], $spawn['posY'], $spawn['posY'], 1, $spawn['map'], $spawn['areaId'], $spawn['areaId'], $spawn['areaId'] ? 1 : 0); if (!$points) { // retry: TC counts pre-instance subareas as instance-maps .. which have no map file $points = DB::Aowow()->select($queryPost, $spawn['posX'], $spawn['posX'], $spawn['posY'], $spawn['posY'], $spawn['posX'], $spawn['posX'], $spawn['posY'], $spawn['posY'], 0, $spawn['map'], 0, 0, 1); } if (!$points) { CLISetup::log('GUID ' . $spawn['guid'] . ($idx < 3 ? '' : ' on path/point ' . $spawn['npcOrPath'] . '/' . $spawn['point']) . ' could not be matched to displayable area [A:' . $spawn['areaId'] . '; X:' . $spawn['posY'] . '; Y:' . $spawn['posX'] . ']', CLISetup::LOG_WARN); continue; } // if areaId is set, area was determined by TC .. we're fine .. mostly $final = $spawn['areaId'] ? $points[0] : $checkCoords($points); if ($idx < 3) { $set = array('guid' => $spawn['guid'], 'type' => $spawn['type'], 'typeId' => $spawn['typeId'], 'respawn' => $spawn['respawn'], 'phaseMask' => $spawn['phaseMask'], 'pathId' => $spawn['pathId'], 'areaId' => $final['areaId'], 'floor' => $final['floor'], 'posX' => $final['posX'], 'posY' => $final['posY']); DB::Aowow()->query('REPLACE INTO ?_spawns (?#) VALUES (?a)', array_keys($set), array_values($set)); } else { $set = array('creatureOrPath' => $spawn['npcOrPath'], 'point' => $spawn['point'], 'wait' => $spawn['wait'], 'areaId' => $final['areaId'], 'floor' => $final['floor'], 'posX' => $final['posX'], 'posY' => $final['posY']); DB::Aowow()->query('REPLACE INTO ?_creature_waypoints (?#) VALUES (?a)', array_keys($set), array_values($set)); } } } /*****************************/ /* spawn vehicle accessories */ /*****************************/ // get vehicle template accessories $accessories = DB::World()->select(' SELECT vta.accessory_entry AS typeId, c.guid, vta.entry, count(1) AS nSeats FROM vehicle_template_accessory vta LEFT JOIN creature c ON c.id = vta.entry GROUP BY accessory_entry, c.guid UNION SELECT va.accessory_entry AS typeId, va.guid, 0 AS entry, count(1) AS nSeats FROM vehicle_accessory va GROUP BY accessory_entry, va.guid'); // accessories may also be vehicles (e.g. "Kor'kron Infiltrator" is seated on "Kor'kron Suppression Turret" is seated on "Kor'kron Troop Transport") // so we will retry finding a spawned vehicle if none were found on the previous pass and a change occured $vGuid = 0; // not really used, but we need some kind of index $n = 0; $matches = -1; while ($matches) { $matches = 0; foreach ($accessories as $idx => $data) { $vehicles = []; if ($data['guid']) { // vehicle already spawned $vehicles = DB::Aowow()->select('SELECT s.areaId, s.posX, s.posY, s.floor FROM ?_spawns s WHERE s.guid = ?d AND s.type = ?d', $data['guid'], TYPE_NPC); } else { if ($data['entry']) { // vehicle on unspawned vehicle action $vehicles = DB::Aowow()->select('SELECT s.areaId, s.posX, s.posY, s.floor FROM ?_spawns s WHERE s.typeId = ?d AND s.type = ?d', $data['entry'], TYPE_NPC); } } if ($vehicles) { $matches++; foreach ($vehicles as $v) { // if there is more than one vehicle, its probably due to overlapping zones for ($i = 0; $i < $data['nSeats']; $i++) { DB::Aowow()->query(' REPLACE INTO ?_spawns (`guid`, `type`, `typeId`, `respawn`, `spawnMask`, `phaseMask`, `areaId`, `floor`, `posX`, `posY`, `pathId`) VALUES (?d, ?d, ?d, 0, 0, 1, ?d, ?d, ?d, ?d, 0)', --$vGuid, TYPE_NPC, $data['typeId'], $v['areaId'], $v['floor'], $v['posX'], $v['posY']); } } unset($accessories[$idx]); } } if ($matches) { CLISetup::log(' * assigned ' . $matches . ' accessories on ' . ++$n . '. pass on vehicle accessories'); } } if ($accessories) { CLISetup::log(count($accessories) . ' accessories could not be fitted onto a spawned vehicle.', CLISetup::LOG_WARN); } /********************************/ /* restrict difficulty displays */ /********************************/ DB::Aowow()->query('UPDATE ?_spawns s, dbc_worldmaparea wma, dbc_map m SET s.spawnMask = 0 WHERE s.areaId = wma.areaId AND wma.mapId = m.Id AND m.areaType IN (0, 3, 4)'); return true; }
function dbconfig() { $databases = ['aowow', 'world', 'auth', 'characters']; $AoWoWconf = []; $dbFields = array('host' => ['Server Host', false], 'user' => ['User', false], 'pass' => ['Password', true], 'db' => ['Database Name', false], 'prefix' => ['Table prefix', false]); $testDB = function ($idx, $name, $dbInfo) { $buff = '[' . CLISetup::bold($idx) . '] ' . str_pad($name, 17); $errStr = ''; if ($dbInfo['host']) { // test DB if ($link = @mysqli_connect($dbInfo['host'], $dbInfo['user'], $dbInfo['pass'], $dbInfo['db'])) { mysqli_close($link); } else { $errStr = '[' . mysqli_connect_errno() . '] ' . mysqli_connect_error(); } $buff .= $errStr ? CLISetup::red('ERR ') : CLISetup::green('OK '); $buff .= 'mysqli://' . $dbInfo['user'] . ':' . str_pad('', strlen($dbInfo['pass']), '*') . '@' . $dbInfo['host'] . '/' . $dbInfo['db']; $buff .= ($dbInfo['prefix'] ? ' table prefix: ' . $dbInfo['prefix'] : null) . ' ' . $errStr; } else { $buff .= ' ' . CLISetup::bold('<empty>'); } return $buff; }; if (file_exists('config/config.php')) { require 'config/config.php'; } foreach ($databases as $idx => $name) { if (empty($AoWoWconf[$name]) && $name != 'characters') { $AoWoWconf[$name] = array_combine(array_keys($dbFields), ['', '', '', '', '']); } } while (true) { CLISetup::log(); CLISetup::log("select a numerical index to use the corresponding entry"); $nCharDBs = 0; foreach ($databases as $idx => $name) { if ($idx != 3) { CLISetup::log($testDB($idx, $name, $AoWoWconf[$name])); } else { if (!empty($AoWoWconf[$name])) { foreach ($AoWoWconf[$name] as $charIdx => $dbInfo) { CLISetup::log($testDB($idx + $nCharDBs++, $name . ' [' . $charIdx . ']', $AoWoWconf[$name][$charIdx])); } } } } CLISetup::log("[" . CLISetup::bold(3 + $nCharDBs) . "] add an additional Character DB"); while (true) { $inp = ['idx' => ['', true, '/\\d/']]; if (CLISetup::readInput($inp, true) && $inp) { if ($inp['idx'] >= 0 && $inp['idx'] <= 3 + $nCharDBs) { $curFields = $dbFields; if ($inp['idx'] == 3 + $nCharDBs) { // add new realmDB $curFields['realmId'] = ['Realm Id', false, '/[1-9][0-9]*/']; } if (CLISetup::readInput($curFields)) { // auth, world or aowow if ($inp['idx'] < 3) { $AoWoWconf[$databases[$inp['idx']]] = $curFields ?: array_combine(array_keys($dbFields), ['', '', '', '', '']); } else { if ($inp['idx'] == 3 + $nCharDBs) { if ($curFields) { $_ = $curFields['realmId']; unset($curFields['realmId']); $AoWoWconf[$databases[3]][$_] = $curFields; } } else { $i = 0; foreach ($AoWoWconf[$databases[3]] as $realmId => &$dbInfo) { if ($inp['idx'] - 3 != $i++) { continue; } if ($curFields) { $dbInfo = $curFields; } else { unset($AoWoWconf[$databases[3]][$realmId]); } } } } // write config file $buff = "<?php\n\nif (!defined('AOWOW_REVISION'))\n die('illegal access');\n\n\n"; foreach ($databases as $db) { if ($db != 'characters') { $buff .= '$AoWoWconf[\'' . $db . '\'] = ' . var_export($AoWoWconf[$db], true) . ";\n\n"; } else { foreach ($AoWoWconf[$db] as $idx => $charInfo) { $buff .= '$AoWoWconf[\'' . $db . '\'][\'' . $idx . '\'] = ' . var_export($AoWoWconf[$db][$idx], true) . ";\n\n"; } } } $buff .= "?>\n"; CLISetup::log(); CLISetup::writeFile('config/config.php', $buff); continue 2; } else { CLISetup::log(); CLISetup::log("edit canceled! returning to list...", CLISetup::LOG_WARN); sleep(1); continue 2; } } } else { CLISetup::log(); CLISetup::log("db setup aborted", CLISetup::LOG_WARN); break 2; } } } }
function firstrun($resume) { require_once 'setup/tools/sqlGen.class.php'; require_once 'setup/tools/fileGen.class.php'; SqlGen::init(true); FileGen::init(true); /****************/ /* define steps */ /****************/ $steps = array(['dbconfig', null, 'testDB', 'Please enter your database credentials.', 'could not establish connection to:'], ['siteconfig', null, 'testSelf', 'SITE_HOST and STATIC_HOST ' . CLISetup::bold('must') . ' be set. Also enable FORCE_SSL if needed. You may also want to change other variables such as NAME, NAME_SHORT OR LOCALES.', 'could not access:'], ['SqlGen::generate', 'achievementcategory', null, null, null], ['SqlGen::generate', 'achievementcriteria', null, null, null], ['SqlGen::generate', 'glyphproperties', null, null, null], ['SqlGen::generate', 'itemenchantment', null, null, null], ['SqlGen::generate', 'itemenchantmentcondition', null, null, null], ['SqlGen::generate', 'itemextendedcost', null, null, null], ['SqlGen::generate', 'itemlimitcategory', null, null, null], ['SqlGen::generate', 'itemrandomproppoints', null, null, null], ['SqlGen::generate', 'lock', null, null, null], ['SqlGen::generate', 'mailtemplate', null, null, null], ['SqlGen::generate', 'scalingstatdistribution', null, null, null], ['SqlGen::generate', 'scalingstatvalues', null, null, null], ['SqlGen::generate', 'spellfocusobject', null, null, null], ['SqlGen::generate', 'spellrange', null, null, null], ['SqlGen::generate', 'spellvariables', null, null, null], ['SqlGen::generate', 'totemcategory', null, null, null], ['SqlGen::generate', 'classes', null, null, null], ['SqlGen::generate', 'factions', null, null, null], ['SqlGen::generate', 'factiontemplate', null, null, null], ['SqlGen::generate', 'holidays', null, null, null], ['SqlGen::generate', 'icons', null, null, null], ['SqlGen::generate', 'itemrandomenchant', null, null, null], ['SqlGen::generate', 'races', null, null, null], ['SqlGen::generate', 'shapeshiftforms', null, null, null], ['SqlGen::generate', 'skillline', null, null, null], ['SqlGen::generate', 'achievement', null, null, null], ['SqlGen::generate', 'creature', null, null, null], ['SqlGen::generate', 'currencies', null, null, null], ['SqlGen::generate', 'events', null, null, null], ['SqlGen::generate', 'objects', null, null, null], ['SqlGen::generate', 'pet', null, null, null], ['SqlGen::generate', 'quests', null, null, null], ['SqlGen::generate', 'quests_startend', null, null, null], ['SqlGen::generate', 'spell', null, null, null], ['SqlGen::generate', 'spelldifficulty', null, null, null], ['SqlGen::generate', 'taxi', null, null, null], ['SqlGen::generate', 'titles', null, null, null], ['SqlGen::generate', 'items', null, null, null], ['FileGen::generate', 'complexImg', null, null, null], ['SqlGen::generate', 'spawns', null, null, null], ['SqlGen::generate', 'zones', null, null, null], ['SqlGen::generate', 'itemset', null, null, null], ['SqlGen::generate', 'item_stats', null, null, null], ['SqlGen::generate', 'source', null, null, null], ['FileGen::generate', 'searchplugin', null, null, null], ['FileGen::generate', 'power', null, null, null], ['FileGen::generate', 'searchboxScript', null, null, null], ['FileGen::generate', 'demo', null, null, null], ['FileGen::generate', 'searchboxBody', null, null, null], ['FileGen::generate', 'realmMenu', null, null, null], ['FileGen::generate', 'locales', null, null, null], ['FileGen::generate', 'itemScaling', null, null, null], ['FileGen::generate', 'realms', null, null, null], ['FileGen::generate', 'statistics', null, null, null], ['FileGen::generate', 'simpleImg', null, null, null], ['FileGen::generate', 'talents', null, null, null], ['FileGen::generate', 'pets', null, null, null], ['FileGen::generate', 'talentIcons', null, null, null], ['FileGen::generate', 'glyphs', null, null, null], ['FileGen::generate', 'itemsets', null, null, null], ['FileGen::generate', 'enchants', null, null, null], ['FileGen::generate', 'gems', null, null, null], ['FileGen::generate', 'profiler', null, null, null], ['FileGen::generate', 'statistics', null, null, null], ['FileGen::generate', 'statistics', null, null, null], ['update', null, null, null, null], ['account', null, 'testAcc', 'Please create your admin account.', 'There is no user with administrator priviledges in the DB.'], ['endSetup', null, null, null, null]); /**********/ /* helper */ /**********/ $saveProgress = function ($nStep) { $h = fopen('cache/firstrun', 'w'); fwrite($h, AOWOW_REVISION . "\n" . ($nStep + 1) . "\n"); fclose($h); }; $testDB = function (&$error) { require 'config/config.php'; $error = []; foreach (['world', 'aowow', 'auth'] as $what) { if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host']))) { continue; } if ($link = @mysqli_connect($AoWoWconf[$what]['host'], $AoWoWconf[$what]['user'], $AoWoWconf[$what]['pass'], $AoWoWconf[$what]['db'])) { mysqli_close($link); } else { $error[] = ' * ' . $what . ': ' . '[' . mysqli_connect_errno() . '] ' . mysqli_connect_error(); } } return empty($error); }; $testSelf = function (&$error) { $error = []; $test = function ($url, &$rCode) { $res = get_headers($url, true); if (preg_match("/HTTP\\/[0-9\\.]+\\s+([0-9]+)/", $res[0], $m)) { $rCode = $m[1]; return $m[1] == 200; } $rCode = 0; return false; }; $res = DB::Aowow()->selectCol('SELECT `key` AS ARRAY_KEY, value FROM ?_config WHERE `key` IN ("site_host", "static_host", "force_ssl")'); $prot = $res['force_ssl'] ? 'https://' : 'http://'; if ($res['site_host']) { if (!$test($prot . $res['site_host'] . '/README', $resp)) { $error[] = ' * could not access ' . $prot . $res['site_host'] . '/README [' . $resp . ']'; } } else { $error[] = ' * SITE_HOST is empty'; } if ($res['static_host']) { if (!$test($prot . $res['static_host'] . '/css/aowow.css', $resp)) { $error[] = ' * could not access ' . $prot . $res['static_host'] . '/css/aowow.css [' . $resp . ']'; } } else { $error[] = ' * STATIC_HOST is empty'; } return empty($error); }; $testAcc = function (&$error) { $error = []; return !!DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE userPerms = 1'); }; function endSetup() { return DB::Aowow()->query('UPDATE ?_config SET value = 0 WHERE `key` = "maintenance"'); } /********************/ /* get current step */ /********************/ $startStep = 0; if ($resume) { if (file_exists('cache/firstrun')) { $rows = file('cache/firstrun'); if ((int) $rows[0] == AOWOW_REVISION) { $startStep = (int) $rows[1]; } else { CLISetup::log('firstrun info is outdated! Starting from scratch.', CLISetup::LOG_WARN); } } if (!$startStep) { CLISetup::log('no usable info found.', CLISetup::LOG_WARN); $inp = ['x' => ['start from scratch? (y/n)', true, '/y|n/i']]; if (!CLISetup::readInput($inp, true) || !$inp || strtolower($inp['x']) == 'n') { CLISetup::log(); return; } CLISetup::log(); } else { CLISetup::log('Resuming setup from step ' . $startStep); sleep(1); } } /*******/ /* run */ /*******/ foreach ($steps as $idx => $step) { if ($startStep > $idx) { continue; } if (!strpos($step[0], '::') && !is_callable($step[0])) { require_once 'setup/tools/clisetup/' . $step[0] . '.func.php'; } if ($step[3]) { CLISetup::log($step[3]); $inp = ['x' => ['Press any key to continue', true]]; if (!CLISetup::readInput($inp, true)) { // we don't actually care about the input return; } } while (true) { $res = call_user_func($step[0], $step[1]); // check script result if ($step[2]) { if (!${$step}[2]($errors)) { CLISetup::log($step[4], CLISetup::LOG_ERROR); foreach ($errors as $e) { CLISetup::log($e); } } else { $saveProgress($idx); break; } } else { if ($res !== false) { $saveProgress($idx); break; } } $inp = ['x' => ['[' . CLISetup::bold('c') . ']ontinue anyway? [' . CLISetup::bold('r') . ']etry? [' . CLISetup::bold('a') . ']bort?', true, '/c|r|a/i']]; if (CLISetup::readInput($inp, true) && $inp) { switch (strtolower($inp['x'])) { case 'c': $saveProgress($idx); break 2; case 'r': CLISetup::log(); break; case 'a': CLISetup::log(); return; } } else { CLISetup::log(); return; } } } unlink('cache/firstrun'); CLISetup::log('setup finished', CLISetup::LOG_OK); }
public static function generate($key, array $updateIds = []) { $success = false; $reqDBC = []; if (file_exists('setup/tools/filegen/' . $key . '.func.php')) { require_once 'setup/tools/filegen/' . $key . '.func.php'; } else { if (empty(self::$tplFiles[$key])) { CLISetup::log(sprintf(ERR_MISSING_INCL, $key, 'setup/tools/filegen/' . $key . '.func.php', CLISetup::LOG_ERROR)); return false; } } CLISetup::log('FileGen::generate() - gathering data for ' . $key); if (!empty(self::$tplFiles[$key])) { list($file, $destPath, $deps) = self::$tplFiles[$key]; if ($content = file_get_contents(FileGen::$tplPath . $file . '.in')) { if ($dest = @fOpen($destPath . $file, "w")) { // replace constants $content = strtr($content, FileGen::$txtConstants); // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { continue 2; } } // must generate content // PH format: /*setup:<setupFunc>*/ $funcOK = true; if (preg_match_all('/\\/\\*setup:([\\w\\-_]+)\\*\\//i', $content, $m)) { foreach ($m[1] as $func) { if (function_exists($func)) { $content = str_replace('/*setup:' . $func . '*/', $func(), $content); } else { $funcOK = false; CLISetup::log('No function for was registered for placeholder ' . $func . '().', CLISetup::LOG_ERROR); if (!array_reduce(get_included_files(), function ($inArray, $itr) use($func) { return $inArray || false !== strpos($itr, $func); }, false)) { CLISetup::log('Also, expected include setup/tools/filegen/' . $name . '.func.php was not found.'); } } } } if (fWrite($dest, $content)) { CLISetup::log(sprintf(ERR_NONE, CLISetup::bold($destPath . $file)), CLISetup::LOG_OK); if ($content && $funcOK) { $success = true; } } else { CLISetup::log(sprintf(ERR_WRITE_FILE, CLISetup::bold($destPath . $file)), CLISetup::LOG_ERROR); } fClose($dest); } else { CLISetup::log(sprintf(ERR_CREATE_FILE, CLISetup::bold($destPath . $file)), CLISetup::LOG_ERROR); } } else { CLISetup::log(sprintf(ERR_READ_FILE, CLISetup::bold(FileGen::$tplPath . $file . '.in')), CLISetup::LOG_ERROR); } } else { if (!empty(self::$datasets[$key])) { if (function_exists($key)) { // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { return false; } } $success = $key($updateIds); } else { CLISetup::log(' - subscript \'' . $key . '\' not defined in included file', CLISetup::LOG_ERROR); } } } set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script return $success; }
function siteconfig() { if (!DB::isConnected(DB_AOWOW)) { CLISetup::log(); CLISetup::log("database not yet set up!\n Please use --dbconfig for setup", CLISetup::LOG_WARN); return; } while (true) { CLISetup::log(); CLISetup::log('select a numerical index to use the corresponding entry'); $results = DB::Aowow()->select('SELECT *, (flags & ?d) AS php FROM ?_config ORDER BY php ASC', CON_FLAG_PHP); $hasEmpty = false; foreach ($results as $idx => $data) { if (!($data['flags'] & CON_FLAG_PHP) && $data['value'] === '') { $hasEmpty = true; } $php = $data['flags'] & CON_FLAG_PHP; $buff = "[" . CLISetup::bold($idx) . "] " . ($idx > 9 ? '' : ' ') . ($php ? ' PHP ' : ' AOWOW '); $buff .= str_pad($php ? strtolower($data['key']) : strtoupper('cfg_' . $data['key']), 35); if ($data['value'] === '') { $buff .= CLISetup::red('<empty>'); } else { $info = explode(' - ', $data['comment']); if ($data['flags'] & CON_FLAG_TYPE_BOOL) { $buff .= '[bool] ' . ($data['value'] ? '<Enabled>' : '<Disabled>'); } else { if ($data['flags'] & CON_FLAG_OPT_LIST && !empty($info[2])) { $buff .= "[opt] "; foreach (explode(', ', $info[2]) as $option) { $opt = explode(':', $option); $buff .= '[' . ($data['value'] == $opt[0] ? 'x' : ' ') . ']' . $opt[1] . ' '; } } else { if ($data['flags'] & CON_FLAG_BITMASK && !empty($info[2])) { $buff .= "[mask] "; foreach (explode(', ', $info[2]) as $option) { $opt = explode(':', $option); $buff .= '[' . ($data['value'] & 1 << $opt[0] ? 'x' : ' ') . ']' . $opt[1] . ' '; } } else { if ($data['flags'] & CON_FLAG_TYPE_STRING) { $buff .= "[str] " . $data['value']; } else { if ($data['flags'] & CON_FLAG_TYPE_FLOAT) { $buff .= "[float] " . floatVal($data['value']); } else { /* if ($data['flags'] & CON_FLAG_TYPE_INT) */ $buff .= "[int] " . intVal($data['value']); } } } } } } CLISetup::log($buff); } CLISetup::log(str_pad("[" . CLISetup::bold(count($results)) . "]", 21) . "add another php configuration"); if ($hasEmpty) { CLISetup::log(); CLISetup::log("please configure the required empty setings", CLISetup::LOG_WARN); } $inp = ['idx' => ['', false, '/\\d/']]; if (CLISetup::readInput($inp) && $inp && $inp['idx'] !== '') { // add new php setting if ($inp['idx'] == count($results)) { CLISetup::log(); CLISetup::log("Adding additional php configuration."); while (true) { $setting = array('key' => ['option name', false, '/[\\w_\\.\\-]/i'], 'val' => ['value']); if (CLISetup::readInput($setting) && $setting) { CLISetup::log(); $key = strtolower($setting['key']); if (ini_get($key) === false || ini_set($key, $setting['val']) === false) { CLISetup::log("this configuration option cannot be set", CLISetup::LOG_ERROR); sleep(1); } else { if (DB::Aowow()->selectCell('SELECT 1 FROM ?_config WHERE `flags` & ?d AND `key` = ?', CON_FLAG_PHP, $key)) { CLISetup::log("this configuration option is already in use", CLISetup::LOG_ERROR); sleep(1); } else { DB::Aowow()->query('INSERT IGNORE INTO ?_config (`key`, `value`, `flags`) VALUES (?, ?, ?d)', $key, $setting['val'], CON_FLAG_TYPE_STRING | CON_FLAG_PHP); CLISetup::log("new php configuration added", CLISetup::LOG_OK); sleep(1); } } break; } else { CLISetup::log(); CLISetup::log("edit canceled! returning to list...", CLISetup::LOG_WARN); sleep(1); break; } } } else { if ($inp['idx'] >= 0 && $inp['idx'] < count($results)) { $conf = $results[$inp['idx']]; $info = explode(' - ', $conf['comment']); $buff = ''; CLISetup::log(); $buff .= $conf['flags'] & CON_FLAG_PHP ? " PHP: " : "AOWOW: "; $buff .= $conf['flags'] & CON_FLAG_PHP ? strtolower($conf['key']) : strtoupper('cfg_' . $conf['key']); if (!empty($info[1])) { $buff .= " - " . $info[1]; } CLISetup::log($buff); $buff = "VALUE: "; if ($conf['flags'] & CON_FLAG_TYPE_BOOL) { $buff .= $conf['value'] ? '<Enabled>' : '<Disabled>'; } else { if ($conf['flags'] & CON_FLAG_OPT_LIST && !empty($info[2])) { foreach (explode(', ', $info[2]) as $option) { $opt = explode(':', $option); $buff .= '[' . ($conf['value'] == $opt[0] ? 'x' : ' ') . '] ' . $opt[1] . ' '; } } else { if ($conf['flags'] & CON_FLAG_BITMASK && !empty($info[2])) { foreach (explode(', ', $info[2]) as $option) { $opt = explode(':', $option); $buff .= '[' . ($conf['value'] & 1 << $opt[0] ? 'x' : ' ') . '] ' . $opt[1] . ' '; } } else { if ($conf['flags'] & CON_FLAG_TYPE_STRING) { $buff .= $conf['value']; } else { if ($conf['flags'] & CON_FLAG_TYPE_FLOAT) { $buff .= floatVal($conf['value']); } else { /* if ($conf['flags'] & CON_FLAG_TYPE_INT) */ $buff .= intVal($conf['value']); } } } } } CLISetup::log($buff); CLISetup::log(); CLISetup::log("[" . CLISetup::bold('E') . "]dit"); if (!($conf['flags'] & CON_FLAG_PERSISTENT)) { CLISetup::log("[" . CLISetup::bold('D') . "]elete"); } if (strstr($info[0], 'default:')) { CLISetup::log("[" . CLISetup::bold('R') . "]estore Default - " . trim(explode('default:', $info[0])[1])); } while (true) { $action = ['idx' => ['', true, '/[edr]/i']]; if (CLISetup::readInput($action, true) && $action) { switch (strtoupper($action['idx'])) { case 'E': // edit value $pattern = false; $single = false; $value = ['idx' => ['Select new value', false, &$pattern]]; if ($conf['flags'] & CON_FLAG_OPT_LIST) { $_valid = []; foreach (explode(', ', $info[2]) as $option) { $opt = explode(':', $option); $_valid[] = $opt[0]; CLISetup::log('[' . CLISetup::bold($opt[0]) . '] ' . $opt[1]); } $single = true; $pattern = '/\\d/'; $validate = function ($v) use($_valid) { return in_array($v, $_valid); }; } else { if ($conf['flags'] & CON_FLAG_BITMASK) { CLISetup::log('Bitmask: sum fields to select multiple options'); $_valid = 0x0; foreach (explode(', ', $info[2]) as $option) { $opt = explode(':', $option); $_valid |= 1 << $opt[0]; CLISetup::log('[' . CLISetup::bold(1 << $opt[0]) . ']' . str_pad('', 4 - strlen(1 << $opt[0])) . $opt[1]); } $pattern = '/\\d+/'; $validate = function ($v) use($_valid) { $v = $v & $_valid; return $v; }; } else { if ($conf['flags'] & CON_FLAG_TYPE_BOOL) { CLISetup::log('[' . CLISetup::bold(0) . '] Disabled'); CLISetup::log('[' . CLISetup::bold(1) . '] Enabled'); $single = true; $pattern = '/[01]/'; $validate = function ($v) { return true; }; } else { if ($conf['flags'] & CON_FLAG_TYPE_INT) { $validate = function ($v) { return preg_match('/^-?\\d+$/i', $v); }; } else { if ($conf['flags'] & CON_FLAG_TYPE_FLOAT) { $validate = function ($v) { return preg_match('/^-?\\d*(,|.)?\\d+$/i', $v); }; } else { // string $validate = function ($v) { return true; }; } } } } } while (true) { $use = $value; if (CLISetup::readInput($use, $single) && $use) { CLISetup::log(); if (!$validate($use['idx'])) { CLISetup::log("value not in range", CLISetup::LOG_ERROR); sleep(1); continue; } else { DB::Aowow()->query('UPDATE ?_config SET `value` = ? WHERE `key` = ?', $use['idx'], strtolower($conf['key'])); CLISetup::log("setting updated", CLISetup::LOG_OK); sleep(1); break 3; } } else { CLISetup::log("edit canceled! returning to selection...", CLISetup::LOG_WARN); sleep(1); break; } } break 2; case 'R': // restore default if (!strstr($info[0], 'default:')) { continue 2; } // @eval .. some dafault values are supplied as bitmask or the likes if (DB::Aowow()->query('UPDATE ?_config SET `value` = ? WHERE `key` = ?', @eval('return (' . trim(explode('default:', $info[0])[1]) . ');'), strtolower($conf['key']))) { CLISetup::log("default value restored", CLISetup::LOG_OK); sleep(1); } break 2; case 'D': // delete config pair if ($conf['flags'] & CON_FLAG_PERSISTENT) { continue 2; } if (DB::Aowow()->query('DELETE FROM ?_config WHERE `key` = ? AND (`flags` & ?d) = 0', strtolower($conf['key']), CON_FLAG_PERSISTENT)) { CLISetup::log("php setting deleted ['" . $conf['key'] . "': '" . $conf['value'] . "']", CLISetup::LOG_OK); sleep(1); } break 2; } } else { CLISetup::log(); CLISetup::log("edit canceled! returning to list...", CLISetup::LOG_WARN); sleep(1); break; } } } else { CLISetup::log(); CLISetup::log("invalid selection", CLISetup::LOG_ERROR); sleep(1); } } } else { CLISetup::log(); CLISetup::log("site configuration aborted", CLISetup::LOG_WARN); break; } } }
function emotes() { $globStrPath = CLISetup::$srcDir . '%sInterface/FrameXML/GlobalStrings.lua'; $allOK = true; $locPath = []; DB::Aowow()->query('TRUNCATE ?_emotes_aliasses'); foreach (CLISetup::$localeIds as $lId) { foreach (CLISetup::$expectedPaths as $xp => $locId) { if ($lId != $locId) { continue; } if ($xp) { // if in subDir add trailing slash $xp .= '/'; } $path = sprintf($globStrPath, $xp); if (CLISetup::fileExists($path)) { $locPath[$lId] = $path; continue 2; } } CLISetup::log('GlobalStrings.lua not found for selected locale ' . CLISetup::bold(Util::$localeStrings[$lId]), CLISetup::LOG_WARN); $allOK = false; } $_ = DB::Aowow()->query('REPLACE INTO ?_emotes SELECT et.Id, LOWER(et.command), IF(e.animationId, 1, 0), 0, -- cuFlags etdT.text_loc0, etdT.text_loc2, etdT.text_loc3, etdT.text_loc6, etdT.text_loc8, etdNT.text_loc0, etdNT.text_loc2, etdNT.text_loc3, etdNT.text_loc6, etdNT.text_loc8, etdS.text_loc0, etdS.text_loc2, etdS.text_loc3, etdS.text_loc6, etdS.text_loc8 FROM dbc_emotestext et LEFT JOIN dbc_emotes e ON e.Id = et.emoteId LEFT JOIN dbc_emotestextdata etdT ON etdT.Id = et.targetId LEFT JOIN dbc_emotestextdata etdNT ON etdNT.Id = et.noTargetId LEFT JOIN dbc_emotestextdata etdS ON etdS.Id = et.selfId'); if (!$_) { $allOK = false; } // i have no idea, how the indexing in this file works. // sometimes the \d+ after EMOTE is the emoteTextId, but not nearly often enough $aliasses = []; foreach ($locPath as $lId => $path) { foreach (file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { if (preg_match('/^EMOTE(\\d+)_CMD\\d+\\s=\\s\\"\\/([^"]+)\\";$/', $line, $m)) { $aliasses[$m[1]][] = [$lId, $m[2]]; } } } $emotes = DB::Aowow()->selectCol('SELECT id AS ARRAY_KEY, cmd FROM ?_emotes'); foreach ($emotes as $eId => $cmd) { foreach ($aliasses as $gsId => $data) { if (in_array($cmd, array_column($data, 1))) { foreach ($data as $d) { DB::Aowow()->query('INSERT IGNORE INTO ?_emotes_aliasses VALUES (?d, ?d, ?) ON DUPLICATE KEY UPDATE locales = locales | ?d', $eId, 1 << $d[0], strtolower($d[1]), 1 << $d[0]); } break; } } } return $allOK; }
function talentIcons() { $success = true; $query = 'SELECT ic.iconString FROM ?_icons ic JOIN dbc_spell s ON s.iconId = ic.Id JOIN dbc_talent t ON t.rank1 = s.Id JOIN dbc_talenttab tt ON tt.Id = t.tabId WHERE tt.?# = ?d AND tt.tabNumber = ?d ORDER BY t.row, t.column, t.petCategory1 ASC'; $dims = 36; //v-pets $filenames = ['icons', 'warrior', 'paladin', 'hunter', 'rogue', 'priest', 'deathknight', 'shaman', 'mage', 'warlock', null, 'druid']; // create directory if missing if (!CLISetup::writeDir('static/images/wow/talents/icons')) { $success = false; } if (!CLISetup::writeDir('static/images/wow/hunterpettalents')) { $success = false; } foreach ($filenames as $k => $v) { if (!$v) { continue; } set_time_limit(10); for ($tree = 0; $tree < 3; $tree++) { $what = $k ? 'classMask' : 'creatureFamilyMask'; $set = $k ? 1 << $k - 1 : 1 << $tree; $subset = $k ? $tree : 0; $path = $k ? 'talents/icons' : 'hunterpettalents'; $outFile = 'static/images/wow/' . $path . '/' . $v . '_' . ($tree + 1) . '.jpg'; $icons = DB::Aowow()->SelectCol($query, $what, $set, $subset); if (empty($icons)) { CLISetup::log('talentIcons - query for ' . $v . ' tree: ' . $k . ' returned empty', CLISetup::LOG_ERROR); $success = false; continue; } if ($res = imageCreateTrueColor(count($icons) * $dims, 2 * $dims)) { for ($i = 0; $i < count($icons); $i++) { $imgFile = 'static/images/wow/icons/medium/' . strtolower($icons[$i]) . '.jpg'; if (!file_exists($imgFile)) { CLISetup::log('talentIcons - raw image ' . CLISetup::bold($imgFile) . ' not found', CLISetup::LOG_ERROR); $success = false; break; } $im = imagecreatefromjpeg($imgFile); // colored imagecopymerge($res, $im, $i * $dims, 0, 0, 0, imageSX($im), imageSY($im), 100); // grayscale if (imageistruecolor($im)) { imagetruecolortopalette($im, false, 256); } for ($j = 0; $j < imagecolorstotal($im); $j++) { $color = imagecolorsforindex($im, $j); $gray = round(0.299 * $color['red'] + 0.587 * $color['green'] + 0.114 * $color['blue']); imagecolorset($im, $j, $gray, $gray, $gray); } imagecopymerge($res, $im, $i * $dims, $dims, 0, 0, imageSX($im), imageSY($im), 100); } if (@imagejpeg($res, $outFile)) { CLISetup::log(sprintf(ERR_NONE, CLISetup::bold($outFile)), CLISetup::LOG_OK); } else { $success = false; CLISetup::log('talentIcons - ' . CLISetup::bold($outFile . '.jpg') . ' could not be written', CLISetup::LOG_ERROR); } } else { $success = false; CLISetup::log('talentIcons - image resource not created', CLISetup::LOG_ERROR); continue; } } } return $success; }