Skip to content
Permalink
Browse files

Weight Scales/Presets:

 * moved wt_presets to DB
 * scales are now saved sensibly instead of just being dumped as is (also, tables have now constrains)
 * added admin=weight-presets to edit presets
 * added an internal user on id:0 who 'owns' the wt-presets and the +1 rates on new comments
 * consequently added constraints to comment-related tables

Misc:
 * Util::toJSON() priorizes its flags over CFG_DEBUG, wich fixes the modelviewer-redButton
 * moved terrible javascript-dump from admin-page to template
  • Loading branch information...
Sarjuuk committed Feb 27, 2016
1 parent 71e44e5 commit e80015a7cd01a214cc5e2502318d2a82ec8963fc

This file was deleted.

@@ -50,19 +50,34 @@ protected function handleWeightscales()
if (!$this->_post['scale'])
return 0;
if (!$this->_post['id'])
$id = 0;
if ($id = $this->_post['id'])
{
$res = DB::Aowow()->selectRow('SELECT MAX(id) AS max, count(id) AS num FROM ?_account_weightscales WHERE userId = ?d', User::$id);
if ($res['num'] < 5) // more or less hard-defined in LANG.message_weightscalesaveerror
$this->_post['id'] = ++$res['max'];
else
if (!DB::Aowow()->selectCell('SELECT 1 FROM ?_account_weightscales WHERE userId = ?d AND id = ?d', User::$id, $id))
return 0;
}
if (DB::Aowow()->query('REPLACE INTO ?_account_weightscales VALUES (?d, ?d, ?, ?)', $this->_post['id'], User::$id, $this->_post['name'], $this->_post['scale']))
return $this->_post['id'];
else
return 0;
{
$nScales = DB::Aowow()->selectCell('SELECT COUNT(id) FROM ?_account_weightscales WHERE userId = ?d', User::$id);
if ($nScales >= 5) // more or less hard-defined in LANG.message_weightscalesaveerror
return 0;
$id = DB::Aowow()->query('INSERT INTO ?_account_weightscales (`userId`, `name`) VALUES (?d, ?)', User::$id, $this->_post['name']);
}
DB::Aowow()->query('DELETE FROM ?_account_weightscale_data WHERE id = ?d', $id);
foreach (explode(',', $this->_post['scale']) as $s)
{
list($k, $v) = explode(':', $s);
if (!in_array($k, Util::$weightScales) || $v < 1)
continue;
DB::Aowow()->query('INSERT INTO ?_account_weightscale_data VALUES (?d, ?, ?d)', $id, $k, $v);
}
return $id;
}
else if ($this->_post['delete'] && $this->_post['id'])
DB::Aowow()->query('DELETE FROM ?_account_weightscales WHERE id = ?d AND userId = ?d', $this->_post['id'], User::$id);
@@ -77,4 +92,4 @@ protected function checkScale($val)
return null;
}
}
}
@@ -5,7 +5,7 @@
class AjaxAdmin extends AjaxHandler
{
protected $validParams = ['screenshots', 'siteconfig'];
protected $validParams = ['screenshots', 'siteconfig', 'weight-presets'];
protected $_get = array(
'action' => [FILTER_SANITIZE_STRING, 0xC], // FILTER_FLAG_STRIP_LOW | *_HIGH
'id' => [FILTER_CALLBACK, ['options' => 'AjaxAdmin::checkId']],
@@ -17,7 +17,10 @@ class AjaxAdmin extends AjaxHandler
'val' => [FILTER_UNSAFE_RAW, null]
);
protected $_post = array(
'alt' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
'alt' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
'id' => [FILTER_SANITIZE_NUMBER_INT, null],
'scale' => [FILTER_CALLBACK, ['options' => 'AjaxAccount::checkScale']],
'__icon' => [FILTER_CALLBACK, ['options' => 'AjaxAdmin::checkKey']],
);
public function __construct(array $params)
@@ -30,7 +33,7 @@ public function __construct(array $params)
if ($this->params[0] == 'screenshots')
{
if (!User::isInGroup(U_GROUP_STAFF | U_GROUP_SCREENSHOT)) // comment_mod, handleSSmod, vi_mod ?
if (!User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_SCREENSHOT))
return;
if ($this->_get['action'] == 'list')
@@ -60,6 +63,14 @@ public function __construct(array $params)
else if ($this->_get['action'] == 'update')
$this->handler = 'confUpdate';
}
else if ($this->params[0] == 'weight-presets')
{
if (!User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_BUREAU))
return;
if ($this->_get['action'] == 'save')
$this->handler = 'wtSave';
}
}
// get all => null (optional)
@@ -304,6 +315,74 @@ protected function confUpdate()
return '';
}
protected function wtSave()
{
if (!$this->_post['id'] || !$this->_post['__icon'])
return 3;
$writeFile = function($file, $content)
{
$success = false;
if ($handle = @fOpen($file, "w"))
{
if (fWrite($handle, $content))
$success = true;
fClose($handle);
}
else
die('me no file');
if ($success)
@chmod($file, Util::FILE_ACCESS);
return $success;
};
// save to db
DB::Aowow()->query('DELETE FROM ?_account_weightscale_data WHERE id = ?d', $this->_post['id']);
DB::Aowow()->query('UPDATE ?_account_weightscales SET `icon`= ? WHERE `id` = ?d', $this->_post['__icon'], $this->_post['id']);
foreach (explode(',', $this->_post['scale']) as $s)
{
list($k, $v) = explode(':', $s);
if (!in_array($k, Util::$weightScales) || $v < 1)
continue;
if (DB::Aowow()->query('INSERT INTO ?_account_weightscale_data VALUES (?d, ?, ?d)', $this->_post['id'], $k, $v) === null)
return 1;
}
// write dataset
$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)
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 (!$writeFile($file, $toFile))
return 2;
// all done
return 0;
}
protected function checkId($val)
{
// expecting id-list
@@ -331,4 +410,12 @@ protected function checkUser($val)
return null;
}
protected function checkScale($val)
{
if (preg_match('/^((\w+:\d+)(,\w+:\d+)*)$/', $val))
return $val;
return null;
}
}
@@ -1,6 +1,6 @@
<?php
define('AOWOW_REVISION', 18);
define('AOWOW_REVISION', 19);
define('CLI', PHP_SAPI === 'cli');
@@ -521,31 +521,17 @@ public static function getUserGlobals()
public static function getWeightScales()
{
$data = [];
$result = [];
$res = DB::Aowow()->select('SELECT * FROM ?_account_weightscales WHERE userId = ?d', self::$id);
foreach ($res as $i)
{
$set = array (
'name' => $i['name'],
'id' => $i['id']
);
$res = DB::Aowow()->selectCol('SELECT id AS ARRAY_KEY, name FROM ?_account_weightscales WHERE userId = ?d', self::$id);
if (!$res)
return $result;
$weights = explode(',', $i['weights']);
foreach ($weights as $weight)
{
$w = explode(':', $weight);
$weights = DB::Aowow()->selectCol('SELECT id AS ARRAY_KEY, `field` AS ARRAY_KEY2, val FROM ?_account_weightscale_data WHERE id IN (?a)', array_keys($res));
foreach ($weights as $id => $data)
$result[] = array_merge(['name' => $res[$id], 'id' => $id], $data);
if ($w[1] === 'undefined')
$w[1] = 0;
$set[$w[0]] = $w[1];
}
$data[] = $set;
}
return $data;
return $result;
}
public static function getCharacters()
@@ -174,6 +174,18 @@ class Util
'clothChestArmor', 'leatherChestArmor', 'mailChestArmor', 'plateChestArmor'
);
public static $weightScales = array(
'agi', 'int', 'sta', 'spi', 'str', 'health', 'mana', 'healthrgn', 'manargn',
'armor', 'blockrtng', 'block', 'defrtng', 'dodgertng', 'parryrtng', 'resirtng',
'atkpwr', 'feratkpwr', 'armorpenrtng', 'critstrkrtng', 'exprtng', 'hastertng', 'hitrtng', 'splpen',
'splpwr', 'arcsplpwr', 'firsplpwr', 'frosplpwr', 'holsplpwr', 'natsplpwr', 'shasplpwr',
'dmg', 'mledps', 'rgddps', 'mledmgmin', 'rgddmgmin', 'mledmgmax', 'rgddmgmax', 'mlespeed', 'rgdspeed',
'arcres', 'firres', 'frores', 'holres', 'natres', 'shares',
'mleatkpwr', 'mlecritstrkrtng', 'mlehastertng', 'mlehitrtng', 'rgdatkpwr', 'rgdcritstrkrtng', 'rgdhastertng', 'rgdhitrtng',
'splcritstrkrtng', 'splhastertng', 'splhitrtng', 'spldmg', 'splheal',
'nsockets'
);
public static $dateFormatInternal = "Y/m/d H:i:s";
public static $changeLevelString = '<a href="javascript:;" onmousedown="return false" class="tip" style="color: white; cursor: pointer" onclick="$WH.g_staticTooltipLevelClick(this, null, 0)" onmouseover="$WH.Tooltip.showAtCursor(event, \'<span class=\\\'q2\\\'>\' + LANG.tooltip_changelevel + \'</span>\')" onmousemove="$WH.Tooltip.cursorUpdate(event)" onmouseout="$WH.Tooltip.hide()"><!--lvl-->%s</a>';
@@ -1573,7 +1585,7 @@ public static function toJSON($data, $forceFlags = 0)
{
$flags = $forceFlags ?: (JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);
if (CFG_DEBUG)
if (CFG_DEBUG && !$forceFlags)
$flags |= JSON_PRETTY_PRINT;
$json = json_encode($data, $flags);

0 comments on commit e80015a

Please sign in to comment.
You can’t perform that action at this time.