AAC Deathlist PHP bug

bury

Excellent OT User
Joined
Jul 27, 2008
Messages
373
Reaction score
8
Hello, I've a problem in my server with the "last kills" and !deathlist talkaction. Some random monsters appear when someone dies.


Example: I've gone Edron with my player "Goku" and I died by a Priestess, Monk and a Ghoul. Any other monster touched me until I died and it was a character that was logged out since lot of days. This is what deathlist say:

Goku slain at level 135 by a dragon lord, a juggernaut, a monk, a hellhound, minishabaal, minishabaal, a priestess, a dragon lord and a minotaur guard.

I'm using TFS 0.4 and Gesior Acc.

Last kills subtopic PHP code:

PHP:
<?php
if(!defined('INITIALIZED'))
    exit;

$players_deaths = $SQL->query('SELECT ' . $SQL->tableName('player_deaths') . '.' . $SQL->fieldName('id') . ', ' . $SQL->tableName('player_deaths') . '.' . $SQL->fieldName('date') . ', ' . $SQL->tableName('player_deaths') . '.' . $SQL->fieldName('level') . ', ' . $SQL->tableName('players') . '.' . $SQL->fieldName('name') . ', ' . $SQL->tableName('players') . '.' . $SQL->fieldName('world_id') . ' FROM ' . $SQL->tableName('player_deaths') . ' LEFT JOIN ' . $SQL->tableName('players') . ' ON ' . $SQL->tableName('player_deaths') . '.' . $SQL->fieldName('player_id') . ' = ' . $SQL->tableName('players') . '.' . $SQL->fieldName('id') . ' ORDER BY ' . $SQL->fieldName('date') . ' DESC LIMIT '.$config['site']['last_deaths_limit']);
$players_deaths_count = 0;
if(!empty($players_deaths))
{
    foreach($players_deaths as $death)
    {
        $bgcolor = (($players_deaths_count++ % 2 == 1) ?  $config['site']['darkborder'] : $config['site']['lightborder']);

        $players_rows .= '<TR BGCOLOR="'.$bgcolor.'"><TD WIDTH="30"><center>'.$players_deaths_count.'.</center></TD><TD WIDTH="125"><small>'.date("j.m.Y, G:i:s",$death['date']).'</small></TD><TD><a href="?subtopic=characters&name='.urlencode($death['name']).'"><b>'.htmlspecialchars($death['name']).'</b></a> ';

        $killers = $SQL->query('SELECT ' . $SQL->tableName('environment_killers') . '.' . $SQL->fieldName('name') . ' AS monster_name, ' . $SQL->tableName('players') . '.' . $SQL->fieldName('name') . ' AS player_name, ' . $SQL->tableName('players') . '.' . $SQL->tableName('deleted') . ' AS player_exists FROM ' . $SQL->tableName('killers') . ' LEFT JOIN ' . $SQL->tableName('environment_killers') . ' ON ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('id') . ' = ' . $SQL->tableName('environment_killers') . '.' . $SQL->fieldName('kill_id') . ' LEFT JOIN ' . $SQL->tableName('player_killers') . ' ON ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('id') . ' = ' . $SQL->tableName('player_killers') . '.' . $SQL->fieldName('kill_id') . ' LEFT JOIN ' . $SQL->tableName('players') . ' ON ' . $SQL->tableName('players') . '.' . $SQL->fieldName('id') . ' = ' . $SQL->tableName('player_killers') . '.' . $SQL->fieldName('player_id') . ' WHERE ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('death_id') . ' = ' . $SQL->quote($death['id']) . ' ORDER BY ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('final_hit') . ' DESC, ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('id') . ' ASC')->fetchAll();

        $i = 0;
        $count = count($killers);
        foreach($killers as $killer)
        {
            $i++;
            if($i == 1)
            {
                if($count <= 4)
                    $players_rows .= "killed at level <b>".$death['level']."</b> by ";
                elseif($count > 4 and $count < 10)
                    $players_rows .= "slain at level <b>".$death['level']."</b> by ";
                elseif($count > 9 and $count < 15)
                    $players_rows .= "crushed at level <b>".$death['level']."</b> by ";
                elseif($count > 14 and $count < 20)
                    $players_rows .= "eliminated at level <b>".$death['level']."</b> by ";
                elseif($count > 19)
                    $players_rows .= "annihilated at level <b>".$death['level']."</b> by ";
            }
            elseif($i == $count)
                $players_rows .= " and ";
            else
                $players_rows .= ", ";

            if($killer['player_name'] != "")
            {
                if($killer['monster_name'] != "")
                    $players_rows .= htmlspecialchars($killer['monster_name'])." summoned by ";

                if($killer['player_exists'] == 0)
                    $players_rows .= "<a href=\"index.php?subtopic=characters&name=".urlencode($killer['player_name'])."\">";

                $players_rows .= htmlspecialchars($killer['player_name']);
                if($killer['player_exists'] == 0)
                    $players_rows .= "</a>";
            }
            else
                $players_rows .= htmlspecialchars($killer['monster_name']);
        }

        $players_rows .= '</TD><TD>'.htmlspecialchars($config['site']['worlds'][(int)$death['world_id']]).'</TD></TR>';
    }
}

if($players_deaths_count == 0)
    $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><B>Last Deaths</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1><TR><TD>No one died on '.htmlspecialchars($config['server']['serverName']).'.</TD></TR></TABLE></TD></TR></TABLE><BR>';
else
    $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><B>Last Deaths</B></TD></TR></TABLE><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>'.$players_rows.'</TABLE>';
 

Jacobs

Webdev, mapper
Joined
Jun 22, 2014
Messages
401
Reaction score
273
Location
Slovakia
This just takes players each death, cycles through it, gets killers' names.
Based on killer count, it shows a message.

This is not a php problem. GesiorAAC, or any AAC in general, doesn't populate `environment_killers` & `player_deaths` tables afaik.
Those tables are populated by the game server, website just takes data from it.
You should rather take a loot at tfs, the issue is there, somewhere.

//edited
 
OP
bury

bury

Excellent OT User
Joined
Jul 27, 2008
Messages
373
Reaction score
8
This just takes players each death, cycles through it, gets killers' names.
Based on killer count, it shows a message.

This is not a php problem. GesiorAAC, or any AAC in general, doesn't populate `environment_killers` & `player_deaths` tables afaik.
Those tables are populated by the game server, website just takes data from it.
You should rather take a loot at tfs, the issue is there, somewhere.

//edited
I know this php file just take the data from db but I thought somebody already would have had this problem. I've never had this problem before, I've opened my server some other times and this is the first time this happens. I had a problem with azerus that apparently nobody knows how to solve too, server crashed when this happened, and all this maybe is related because sometimes one of the random monster is azerus or his summons:

Wolverin slain at level 147 by a rift brood, a hellfire fighter, a hellfire fighter, a rift scythe, a juggernaut and a hellhound.

Wolverin slain at level 111 by a stone golem, a rift worm, demodras, a fire elemental, a demon, a rift worm and a behemoth.

If it's a TFS problem and the issue is there somewhere, where can I start looking at? Im trying to check everything...

(After the crash, I removed azerus.lua line from actions.xml so the quest is not working, until I fix it.).
 
Last edited:
OP
bury

bury

Excellent OT User
Joined
Jul 27, 2008
Messages
373
Reaction score
8
Hello. I can't edit last post idk why. I have solved the issue. Is a database problem, I couldn't add a constraint when I imported db. I received this error:

Code:
ALTER TABLE `environment_killers` ADD CONSTRAINT `environment_killers_ibfk_1` FOREIGN KEY (`kill_id`) REFERENCES `killers` (`id`) ON DELETE CASCADE

MySQL error: #1452

#1452 - Cannot add or update a child row: a foreign key constraint fails (`test1`.`#sql-71ea_c2b`, CONSTRAINT `environment_killers_ibfk_1` FOREIGN KEY (`kill_id`) REFERENCES `killers` (`id`) ON DELETE CASCADE)
If you have receive this error, to solve it you should make this SQL query:

Code:
DELETE FROM environment_killers WHERE kill_id NOT IN (SELECT id FROM killers);
After this, run the constraint again and should be solved. System won't add any random monsters to the deathlist of the players.
 
Top