diff --git a/Lua/TFS_10/revscriptsys/player_history.lua b/Lua/TFS_10/revscriptsys/player_history.lua new file mode 100644 index 0000000..1673f0f --- /dev/null +++ b/Lua/TFS_10/revscriptsys/player_history.lua @@ -0,0 +1,229 @@ +-- Auto install tables if we dont got them yet (first install) +db.query([[ + CREATE TABLE IF NOT EXISTS `player_history_skill` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `player_id` int(11) NOT NULL, + `lastlogin` bigint(20) unsigned NOT NULL, + `lastlogout` bigint(20) unsigned NOT NULL, + `town_id` int(11) NOT NULL, + `lastip` int(10) unsigned NOT NULL, + `skull` tinyint(1) NOT NULL, + `blessings` tinyint(2) NOT NULL, + `onlinetime` int(11) NOT NULL, + `balance` bigint(20) unsigned NOT NULL, + `level` int(11) NOT NULL, + `experience` bigint(20) NOT NULL, + `maglevel` int(11) NOT NULL, + `skill_fist` int(10) unsigned NOT NULL, + `skill_club` int(10) unsigned NOT NULL, + `skill_sword` int(10) unsigned NOT NULL, + `skill_axe` int(10) unsigned NOT NULL, + `skill_dist` int(10) unsigned NOT NULL, + `skill_shielding` int(10) unsigned NOT NULL, + `skill_fishing` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`player_id`) REFERENCES `players` (`id`) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; +]]) + + +-- Auto populate table if it is empty +local resultId = db.storeQuery("SELECT `id` FROM `player_history_skill` LIMIT 1;") +if resultId == false then + db.asyncQuery([[ + INSERT INTO `player_history_skill` ( + `player_id`, + `lastlogin`, + `lastlogout`, + `town_id`, + `lastip`, + `skull`, + `blessings`, + `onlinetime`, + `balance`, + `level`, + `experience`, + `maglevel`, + `skill_fist`, + `skill_club`, + `skill_sword`, + `skill_axe`, + `skill_dist`, + `skill_shielding`, + `skill_fishing` + ) + SELECT + `p`.`id` AS `player_id`, + `zp`.`created` AS `lastlogin`, + CASE WHEN `p`.`lastlogout` > 0 + THEN `p`.`lastlogout` + ELSE `zp`.`created` + END AS `lastlogout`, + `p`.`town_id`, + `p`.`lastip`, + `p`.`skull`, + `p`.`blessings`, + `p`.`onlinetime`, + `p`.`balance`, + `p`.`level`, + `p`.`experience`, + `p`.`maglevel`, + `p`.`skill_fist`, + `p`.`skill_club`, + `p`.`skill_sword`, + `p`.`skill_axe`, + `p`.`skill_dist`, + `p`.`skill_shielding`, + `p`.`skill_fishing` + FROM `players` AS `p` + INNER JOIN `znote_players` AS `zp` + ON `p`.`id` = `zp`.`player_id` + ORDER BY `zp`.`created` + ]]) +else + result.free(resultId) +end + + +-- Logout event, triggered by logout, and death +function historyLogoutEvent(player) + local blessdec = 0 + local i = 0 + while player:hasBlessing(i+1) do + blessdec = blessdec+2^i + i = i+1 + end + + local playerGuid = player:getGuid() + db.query([[ + INSERT INTO `player_history_skill` ( + `player_id`, + `lastlogin`, + `lastlogout`, + `town_id`, + `lastip`, + `skull`, + `blessings`, + `onlinetime`, + `balance`, + `level`, + `experience`, + `maglevel`, + `skill_fist`, + `skill_club`, + `skill_sword`, + `skill_axe`, + `skill_dist`, + `skill_shielding`, + `skill_fishing` + ) VALUES ( + ]]..table.concat({ + playerGuid, + player:getLastLoginSaved(), + os.time(), + player:getTown():getId(), + player:getIp(), + player:getSkull(), + blessdec, + "(SELECT `onlinetime` FROM `players` WHERE `id`='"..playerGuid.."') + ".. os.time() - player:getLastLoginSaved(), + player:getBankBalance(), + player:getLevel(), + player:getExperience(), + player:getMagicLevel(), + player:getSkillLevel(SKILL_FIST), + player:getSkillLevel(SKILL_CLUB), + player:getSkillLevel(SKILL_SWORD), + player:getSkillLevel(SKILL_AXE), + player:getSkillLevel(SKILL_DISTANCE), + player:getSkillLevel(SKILL_SHIELD), + player:getSkillLevel(SKILL_FISHING) + }, ",")..[[ + ); + ]]) +end + + +-- Log player state on logout +local player_history_skill = CreatureEvent("player_history_skill") +function player_history_skill.onLogout(player) + --print("2-logout["..player:getName().."]") + historyLogoutEvent(player) + return true +end +player_history_skill:register() + + +-- And on death +local player_history_skill_death = CreatureEvent("player_history_skill_death") +function player_history_skill_death.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified) + --print("3-death["..creature:getName().."]") + historyLogoutEvent(Player(creature)) +end +player_history_skill_death:register() + + +-- If this is first login, insert current progress +local player_history_skill_login = CreatureEvent("player_history_skill_login") +function player_history_skill_login.onLogin(player) + --print("1-login["..player:getName().."]") + player:registerEvent("player_history_skill_death") + + local playerGuid = player:getGuid() + local resultId = db.storeQuery("SELECT `id` FROM `player_history_skill` WHERE `player_id`="..playerGuid.." LIMIT 1;") + if resultId == false then + db.query([[ + INSERT INTO `player_history_skill` ( + `player_id`, + `lastlogin`, + `lastlogout`, + `town_id`, + `lastip`, + `skull`, + `blessings`, + `onlinetime`, + `balance`, + `level`, + `experience`, + `maglevel`, + `skill_fist`, + `skill_club`, + `skill_sword`, + `skill_axe`, + `skill_dist`, + `skill_shielding`, + `skill_fishing` + ) + SELECT + `p`.`id` AS `player_id`, + `zp`.`created` AS `lastlogin`, + CASE WHEN `p`.`lastlogout` > 0 + THEN `p`.`lastlogout` + ELSE `zp`.`created` + END AS `lastlogout`, + `p`.`town_id`, + `p`.`lastip`, + `p`.`skull`, + `p`.`blessings`, + `p`.`onlinetime`, + `p`.`balance`, + `p`.`level`, + `p`.`experience`, + `p`.`maglevel`, + `p`.`skill_fist`, + `p`.`skill_club`, + `p`.`skill_sword`, + `p`.`skill_axe`, + `p`.`skill_dist`, + `p`.`skill_shielding`, + `p`.`skill_fishing` + FROM `players` AS `p` + INNER JOIN `znote_players` AS `zp` + ON `p`.`id` = `zp`.`player_id` + WHERE `p`.`id` = ]]..playerGuid..[[ + ]]) + else + result.free(resultId) + end + return true +end +player_history_skill_login:register() diff --git a/layout/aside.php b/layout/aside.php index cc07d98..25fa56c 100644 --- a/layout/aside.php +++ b/layout/aside.php @@ -11,6 +11,7 @@ include 'layout/widgets/charactersearch.php'; include 'layout/widgets/topplayers.php'; include 'layout/widgets/highscore.php'; + if ($config['powergamers']['enabled']) include 'layout/widgets/powergamers.php'; include 'layout/widgets/serverinfo.php'; if ($config['ServerEngine'] !== 'TFS_02') include 'layout/widgets/houses.php'; if ($follow["enabled"]): ?> diff --git a/layout/menu.php b/layout/menu.php index 07c864a..516ffdc 100644 --- a/layout/menu.php +++ b/layout/menu.php @@ -22,6 +22,7 @@
  • Forum
  • Guilds
  • Highscores
  • +
  • Powergamers
  • Houses
  • Killstatistics
  • Latest deaths
  • diff --git a/layout/widgets/powergamers.php b/layout/widgets/powergamers.php new file mode 100644 index 0000000..a5eb2db --- /dev/null +++ b/layout/widgets/powergamers.php @@ -0,0 +1,63 @@ +
    +
    + Top 5 Powergamers +
    +
    + + hasExpired()) { + $players = mysql_select_multi(" + SELECT + `h`.`player_id`, + `p`.`name`, + `p`.`level`, + CAST(`p`.`experience` as signed) - CAST(`f`.`experience` as signed) AS `diff_experience` + FROM ( + SELECT + `i`.`player_id`, + IFNULL(`o`.`id`, `i`.`id`) AS `from_id` + FROM `player_history_skill` AS `i` + LEFT JOIN ( + SELECT + `x`.`player_id`, + MAX(`x`.`id`) AS `id` + FROM `player_history_skill` AS `x` + WHERE + `x`.`lastlogout` < UNIX_TIMESTAMP() - 7 * 24 * 60 * 60 + GROUP BY + `x`.`player_id` + ) AS `o` + ON `i`.`player_id` = `o`.`player_id` + WHERE + `i`.`lastlogout` >= UNIX_TIMESTAMP() - 7 * 24 * 60 * 60 + GROUP BY + `i`.`player_id` + ) AS `h` + INNER JOIN `player_history_skill` AS `f` + ON `h`.`from_id` = `f`.`id` + INNER JOIN `players` AS `p` + ON `h`.`player_id` = `p`.`id` + WHERE CAST(`p`.`experience` as signed) - CAST(`f`.`experience` as signed) > 0 + ORDER BY CAST(`p`.`experience` as signed) - CAST(`f`.`experience` as signed) DESC + LIMIT 5 + "); + + $cache->setContent($players); + $cache->save(); + } else { + $players = $cache->load(); + } + + if ($players) { + foreach($players as $count => $player) { + $nr = $count+1; + $kexp = $player['diff_experience'] / 1000; + $kexp = number_format($kexp, 0, '', ' '); + echo ""; + } + } + ?> +
    {$nr}{$player['name']} ({$player['level']}) {$kexp} K exp
    +
    +
    diff --git a/powergamers.php b/powergamers.php index f6f5fdb..ce802aa 100644 --- a/powergamers.php +++ b/powergamers.php @@ -1,92 +1,162 @@ -hasExpired()) { + $players = mysql_select_multi($query_CTE." + SELECT + `p`.`name`, + IFNULL(`p`.`experience`, 0) - CASE WHEN `h7b`.`experience` IS NULL + THEN `hfb`.`experience` + ELSE `h7b`.`experience` + END AS `diff_exp`, + `p`.`experience` - IFNULL(`h1b`.`experience`, 0) AS `diff_0`, + IFNULL(`h1b`.`experience`, 0) - IFNULL(`h2b`.`experience`, 0) AS `diff_1`, + IFNULL(`h2b`.`experience`, 0) - IFNULL(`h3b`.`experience`, 0) AS `diff_2`, + IFNULL(`h3b`.`experience`, 0) - IFNULL(`h4b`.`experience`, 0) AS `diff_3`, + IFNULL(`h4b`.`experience`, 0) - IFNULL(`h5b`.`experience`, 0) AS `diff_4`, + IFNULL(`h5b`.`experience`, 0) - IFNULL(`h6b`.`experience`, 0) AS `diff_5`, + IFNULL(`h6b`.`experience`, 0) - IFNULL(`h7b`.`experience`, 0) AS `diff_6` + FROM `players` AS `p` + LEFT JOIN CTE_first AS `first` ON `p`.`id` = `first`.`player_id` + LEFT JOIN CTE_1b AS `d1b` ON `p`.`id` = `d1b`.`player_id` + LEFT JOIN CTE_2b AS `d2b` ON `p`.`id` = `d2b`.`player_id` + LEFT JOIN CTE_3b AS `d3b` ON `p`.`id` = `d3b`.`player_id` + LEFT JOIN CTE_4b AS `d4b` ON `p`.`id` = `d4b`.`player_id` + LEFT JOIN CTE_5b AS `d5b` ON `p`.`id` = `d5b`.`player_id` + LEFT JOIN CTE_6b AS `d6b` ON `p`.`id` = `d6b`.`player_id` + LEFT JOIN CTE_7b AS `d7b` ON `p`.`id` = `d7b`.`player_id` + LEFT JOIN CTE_history AS `hfb` ON `first`.`id` = `hfb`.`id` + LEFT JOIN CTE_history AS `h1b` ON `d1b`.`id` = `h1b`.`id` + LEFT JOIN CTE_history AS `h2b` ON `d2b`.`id` = `h2b`.`id` + LEFT JOIN CTE_history AS `h3b` ON `d3b`.`id` = `h3b`.`id` + LEFT JOIN CTE_history AS `h4b` ON `d4b`.`id` = `h4b`.`id` + LEFT JOIN CTE_history AS `h5b` ON `d5b`.`id` = `h5b`.`id` + LEFT JOIN CTE_history AS `h6b` ON `d6b`.`id` = `h6b`.`id` + LEFT JOIN CTE_history AS `h7b` ON `d7b`.`id` = `h7b`.`id` + WHERE IFNULL(`p`.`experience`, 0) - CASE WHEN `h7b`.`experience` IS NULL THEN `hfb`.`experience` ELSE `h7b`.`experience` END != 0 + ORDER BY IFNULL(`p`.`experience`, 0) - CASE WHEN `h7b`.`experience` IS NULL THEN `hfb`.`experience` ELSE `h7b`.`experience` END DESC + "); + $cache->setContent($players); + $cache->save(); +} else { + $players = $cache->load(); +} + +$dates = mysql_select_single(" + SELECT + FROM_UNIXTIME(UNIX_TIMESTAMP() - 7 * 24 * 60 * 60, '%d %b') AS `d7ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP() - 6 * 24 * 60 * 60, '%d %b') AS `d6ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP() - 5 * 24 * 60 * 60, '%d %b') AS `d5ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP() - 4 * 24 * 60 * 60, '%d %b') AS `d4ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP() - 3 * 24 * 60 * 60, '%d %b') AS `d3ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP() - 2 * 24 * 60 * 60, '%d %b') AS `d2ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP() - 1 * 24 * 60 * 60, '%d %b') AS `d1ago`, + FROM_UNIXTIME(UNIX_TIMESTAMP(), '%d %b') AS `d0ago` +"); ?> -
    - - 0) - $today = false; - } else { - $znotePlayers = mysql_select_multi('SELECT `a`.`id`, `b`.`player_id`, `a`.`name`, `a`.`vocation`, `a`.`level`, `a`.`group_id`, `a`.`experience`, `b`.`exphist_lastexp`, `b`.`exphist1`, `b`.`exphist2`, `b`.`exphist3`, `b`.`exphist4`, `b`.`exphist5`, `b`.`exphist6`, `b`.`exphist7`, (`a`.`experience` - `b`.`exphist_lastexp`) AS `expdiff` FROM `players` `a` JOIN `znote_players` `b` ON `a`.`id` = `b`.`player_id` WHERE `a`.`group_id` < 2 ORDER BY `expdiff` DESC LIMIT '.$limit); + + + + + + + + + + + + + + + + + + + $player): ?> + + + + + + + + + + + + + +

    Powergamers

    Namek Diff
    +