Skip to content
Permalink
Browse files

added strip_companion($stringname_or_array) to core to safely remove …

…companions

which is currently hard because you need to fix the global var and the session-user var
  • Loading branch information...
NB-Core committed Jun 29, 2019
1 parent 4e6f839 commit 1b7c3d63a569e6a45daabd0d94b868cef54e6257
Showing with 31 additions and 0 deletions.
  1. +2 −0 CHANGELOG.txt
  2. +29 −0 lib/buffs.php
@@ -1,4 +1,6 @@
Changes to 1.2.6 +nb
[CHANGES]
*lib/buffs.php -> added strip_companion($name) which removes one or more companions safely
[FIXES]
*lib/all_tables.php and several --> 0000-00-00 00:00:00 is not valid DATETIME since MySQL 5.7 anymore. Hence, new constants DATETIME_DATEMIN and _DATEMAX have been introduced in lib/constants.php. Default is set to 1970-01-01 ... and 2159-01-01 ... - max could be 9999-12-31, but if I get older than 160 years, I'll fix that for you
*motd.php --> critical SQL injection attack fix. Month in httppost was not escaped and directly patched into an SQL query!
@@ -151,6 +151,35 @@ function apply_buff($name,$buff){
calculate_buff_fields();
}
//not only add but also strip companions
//why? because in add_companion the session['user']['companions'] is ignored (!) if the global var is used.
//hence it can (and will) happen if you try to remove a companion and then add one, that you forget
//to remove it from the global var, and then it still persists -> awkward
//let's give ppl for companions (who are permanent by default!) an option to strip them safely
function strip_companion($name){
global $session, $companions;
//$name can be an array of companions you want to remove, too
$remove_result = false;
if (!is_array($companions)) {
$companions = @unserialize($session['user']['companions']);
}
if (is_array($name)) {
foreach ($name as $remove_comp_name) {
if (in_array($remove_comp_name,array_keys($companions))) {
unset($companions[$remove_comp_name]);
$remove_result=true;
}
}
} else {
$remove_comp_name = $name;
if (in_array($remove_comp_name,array_keys($companions))) {
unset($companions[$remove_comp_name]);
$remove_result=true;
}
}
return $remove_result;
}
function apply_companion($name,$companion,$ignorelimit=false){
global $session, $companions;
if (!is_array($companions)) {

0 comments on commit 1b7c3d6

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