Файл: system/v37_features.php
Строк: 34
<?php
declare(strict_types=1);
/* Стабилизация состояния: by Метриум (Стэлп) */
function game_v37_user_has_column(string $name): bool {
static $cols=null;
if($cols===null){
$cols=[];
try{
$q=db_query('SHOW COLUMNS FROM `users`');
while($r=db_fetch_assoc($q)){ $f=(string)($r['Field']??''); if($f!=='')$cols[$f]=true; }
}catch(Throwable $e){ error_log('[USER_SCHEMA] '.$e->getMessage()); }
}
return isset($cols[$name]);
}
function game_v37_repair_saved_state(array &$user): void {
if(empty($user['id'])) return;
// `new` есть не во всех production-схемах. Не даём этому legacy-полю ломать вход/сохранение.
if((int)($user['save']??0)===1 && game_v37_user_has_column('new') && (int)($user['new']??0)===0){
try{ db_execute('UPDATE `users` SET `new`=1 WHERE `id`=:u',['u'=>(int)$user['id']]); $user['new']=1; }
catch(Throwable $e){ error_log('[SAVED_STATE] '.$e->getMessage()); }
}
$maxHp=max(1,(int)($user['vit']??1)*2);
$maxMp=max(0,(int)($user['mana']??0));
$hp=min(max(0,(int)($user['hp']??0)),$maxHp);
$mp=min(max(0,(int)($user['mp']??0)),$maxMp);
if($hp!==(int)($user['hp']??0)||$mp!==(int)($user['mp']??0)){
try{ db_execute('UPDATE `users` SET `hp`=:hp,`mp`=:mp WHERE `id`=:u',['hp'=>$hp,'mp'=>$mp,'u'=>(int)$user['id']]); }
catch(Throwable $e){ error_log('[HP_MP_REPAIR] '.$e->getMessage()); }
$user['hp']=$hp; $user['mp']=$mp;
}
}