$temp_avatar_size = $temp_avatar_size * 2; list($temp_background_kind, $temp_background_token) = explode('/', $temp_background_path); $temp_avatar_class = 'avatar avatar_80x80 float float_' . ($is_personal_message_creator ? 'left' : 'right') . ' '; $temp_avatar_colour = !empty($this_thread_info['user_colour_token']) ? $this_thread_info['user_colour_token'] : 'none'; $temp_sprite_class = 'sprite sprite_' . $temp_avatar_size . 'x' . $temp_avatar_size . ' sprite_' . $temp_avatar_size . 'x' . $temp_avatar_size . '_' . $temp_avatar_frame; $temp_sprite_path = 'images/sprites/' . $temp_avatar_kind . '/' . $temp_avatar_token . '/sprite_' . ($is_personal_message_creator ? 'right' : 'left') . '_' . $temp_avatar_size . 'x' . $temp_avatar_size . '.png?' . MMRPG_CONFIG_CACHE_DATE; $temp_background_path = 'images/sprites/' . $temp_background_kind . '/' . $temp_background_token . '/battle-field_avatar.png?' . MMRPG_CONFIG_CACHE_DATE; $temp_is_contributor = in_array($this_thread_info['role_token'], array('developer', 'administrator', 'contributor', 'moderator')) ? true : false; if ($temp_is_contributor) { $temp_item_class = 'sprite sprite_80x80 sprite_80x80_00'; $temp_item_path = 'images/sprites/items/' . (!empty($this_thread_info['role_icon']) ? $this_thread_info['role_icon'] : 'energy-pellet') . '/icon_left_80x80.png?' . MMRPG_CONFIG_CACHE_DATE; $temp_item_title = !empty($this_thread_info['role_name']) ? $this_thread_info['role_name'] : 'Contributor'; } // Check if the thread creator is currently online $temp_is_online = false; $temp_leaderboard_online = rpg_prototype::leaderboard_online(); foreach ($temp_leaderboard_online as $key => $info) { if ($info['id'] == $this_thread_info['user_id']) { $temp_is_online = true; break; } } // Collect the thread count for this user if ($this_thread_info['user_id'] != MMRPG_SETTINGS_GUEST_ID) { $this_thread_info['thread_count'] = !empty($this_user_countindex[$this_thread_info['user_id']]['thread_count']) ? $this_user_countindex[$this_thread_info['user_id']]['thread_count'] : 0; } else { $this_thread_info['thread_count'] = false; } // Collect the thread count for this user if ($this_thread_info['user_id'] != MMRPG_SETTINGS_GUEST_ID) { $this_thread_info['post_count'] = !empty($this_user_countindex[$this_thread_info['user_id']]['post_count']) ? $this_user_countindex[$this_thread_info['user_id']]['post_count'] : 0;
public static function print_online($this_leaderboard_online_players = array(), $filter_userids = array()) { if (empty($this_leaderboard_online_players)) { $this_leaderboard_online_players = rpg_prototype::leaderboard_online(); } ob_start(); foreach ($this_leaderboard_online_players as $key => $info) { if (!empty($filter_userids) && !in_array($info['id'], $filter_userids)) { continue; } if (empty($info['image'])) { $info['image'] = 'robots/mega-man/40'; } list($path, $token, $size) = explode('/', $info['image']); $frame = $info['placeint'] <= 3 ? 'victory' : 'base'; //if ($key > 0 && $key % 5 == 0){ echo '<br />'; } echo ' <a data-playerid="' . $info['id'] . '" class="player_type player_type_' . $info['colour'] . '" href="leaderboard/' . $info['token'] . '/">'; echo '<span class="sprite_wrap"><span class="sprite sprite_' . $size . 'x' . $size . ' sprite_' . $size . 'x' . $size . '_' . $frame . '" style="left: ' . ($size == 40 ? -4 : -26) . 'px; background-image: url(images/sprites/' . $path . '/' . $token . '/sprite_left_' . $size . 'x' . $size . '.png?' . MMRPG_CONFIG_CACHE_DATE . ');"></span></span>'; echo '<span class="name_wrap">' . strip_tags($info['place']) . ' : ' . $info['name'] . '</span>'; echo '</a>'; } $temp_markup = ob_get_clean(); return $temp_markup; }
$_SESSION['GAME']['DEMO'] = 1; $_SESSION['GAME']['USER'] = $this_user; $_SESSION['GAME']['counters']['battle_points'] = 0; // Reset the game session and reload the page rpg_game::reset_session(); // Exit on success exit('success'); } // Cache the currently online players if (!isset($_SESSION['LEADERBOARD']['online_timestamp']) || (time() - $_SESSION['LEADERBOARD']['online_timestamp']) > 1){ // 600sec = 10min $_SESSION['LEADERBOARD']['online_players'] = rpg_prototype::leaderboard_online(); $_SESSION['LEADERBOARD']['online_timestamp'] = time(); } // Require the prototype data file require_once('includes/prototype.php'); /* * PASSWORD PROCESSING */ // Collect the game flags for easier password processing $temp_flags = !empty($_SESSION['GAME']['flags']) ? $_SESSION['GAME']['flags'] : array();
public static function leaderboard_targets($this_userid, $player_limit = 12, $player_sort = '', $player_campaign = '') { global $db; // Check to see if the leaderboard targets have already been pulled or not if (!empty($db->INDEX['LEADERBOARD']['targets'])) { $this_leaderboard_target_players = $db->INDEX['LEADERBOARD']['targets']; } else { // Collect the leaderboard index and online players for ranking $this_leaderboard_index = rpg_prototype::leaderboard_index(); $this_leaderboard_targets = array(); $this_leaderboard_targets_ids = array(); $this_leaderboard_targets['custom'] = rpg_prototype::leaderboard_custom($player_campaign, $this_userid); $this_leaderboard_targets['online'] = rpg_prototype::leaderboard_online(); $this_leaderboard_targets['rival'] = rpg_prototype::leaderboard_rivals($this_leaderboard_index, $this_userid, 10); $this_leaderboard_targets_ids['custom'] = array(); $this_leaderboard_targets_ids['online'] = array(); $this_leaderboard_targets_ids['rival'] = array(); if (!empty($this_leaderboard_targets['custom'])) { shuffle($this_leaderboard_targets['custom']); } if (!empty($this_leaderboard_targets['online'])) { shuffle($this_leaderboard_targets['online']); } if (!empty($this_leaderboard_targets['rival'])) { shuffle($this_leaderboard_targets['rival']); } //die('<pre>$this_leaderboard_targets(this:'.$player_campaign.'/target:'.$player_sort.') = '.print_r($this_leaderboard_targets, true).'</pre>'); //$this_leaderboard_include_players = array_merge($this_leaderboard_targets['online'], $this_leaderboard_targets['rival']); //$this_leaderboard_include_players = array_slice($this_leaderboard_include_players, 0, $player_limit); //shuffle($this_leaderboard_include_players); // Generate the custom username tokens for adding to the condition list $temp_include_raw = array(); $temp_include_userids = array(); $temp_include_usernames = array(); $temp_include_usernames_count = 0; $temp_include_usernames_string = array(); // Add the include data to the raw array if (!empty($this_leaderboard_targets)) { foreach ($this_leaderboard_targets as $kind => $players) { if (!empty($players)) { if (!isset($this_leaderboard_targets_ids[$kind])) { $this_leaderboard_targets_ids[$kind] = array(); } foreach ($players as $key => $info) { $id = isset($info['user_id']) ? $info['user_id'] : $info['id']; $this_leaderboard_targets_ids[$kind][] = $id; if (!isset($temp_include_raw[$id])) { $temp_include_raw[$id] = $info; } else { continue; } } } } } //die('<pre>$this_leaderboard_targets_ids(this:'.$player_campaign.'/target:'.$player_sort.') = '.print_r($this_leaderboard_targets_ids, true).'</pre>'); // Re-key the array to prevent looping errors $temp_include_raw = array_values($temp_include_raw); // Loop thrugh the raw array and collect filter variables if (!empty($temp_include_raw)) { foreach ($temp_include_raw as $info) { if (isset($info['id']) && $info['id'] != $this_userid) { $temp_include_usernames[] = $info['token']; $temp_include_userids[] = $info['id']; } elseif (isset($info['user_id']) && $info['user_id'] != $this_userid) { $temp_include_usernames[] = $info['user_name_clean']; $temp_include_userids[] = $info['user_id']; } } $temp_include_usernames_count = count($temp_include_usernames); if (!empty($temp_include_usernames)) { foreach ($temp_include_usernames as $token) { $temp_include_usernames_string[] = "'{$token}'"; } $temp_include_usernames_string = implode(',', $temp_include_usernames_string); } else { $temp_include_usernames_string = ''; } } else { $temp_include_usernames_string = ''; } //die('<pre>$temp_include_raw(this:'.$player_campaign.'/target:'.$player_sort.') = '.print_r($temp_include_raw, true).'</pre>'); // Define the array for pulling all the leaderboard data $temp_leaderboard_query = 'SELECT mmrpg_leaderboard.user_id, mmrpg_leaderboard.board_points, mmrpg_users.user_name, mmrpg_users.user_name_clean, mmrpg_users.user_name_public, mmrpg_users.user_gender, mmrpg_saves.save_values_battle_rewards AS player_rewards, mmrpg_saves.save_values_battle_settings AS player_settings, mmrpg_saves.save_values AS player_values, mmrpg_saves.save_counters AS player_counters FROM mmrpg_leaderboard LEFT JOIN mmrpg_users ON mmrpg_users.user_id = mmrpg_leaderboard.user_id LEFT JOIN mmrpg_saves ON mmrpg_users.user_id = mmrpg_saves.user_id WHERE board_points > 0 AND mmrpg_leaderboard.user_id != ' . $this_userid . ' ' . (!empty($temp_include_usernames_string) ? 'AND mmrpg_users.user_name_clean IN (' . $temp_include_usernames_string . ') ' : '') . ' ORDER BY board_points DESC '; //AND board_points >= '.$this_player_points_min.' AND board_points <= '.$this_player_points_max.' //'.(!empty($temp_online_usernames_string) ? ' FIELD(user_name_clean, '.$temp_online_usernames_string.') DESC, ' : '').' //LIMIT '.$player_limit.' // Query the database and collect the array list of all online players //die('<pre>$temp_leaderboard_query(this:'.$player_campaign.'/target:'.$player_sort.') = '.print_r($temp_leaderboard_query, true).'</pre>'); $this_leaderboard_target_players = $db->get_array_list($temp_leaderboard_query); //die('<pre>$this_leaderboard_target_players(this:'.$player_campaign.'/target:'.$player_sort.') = '.print_r($this_leaderboard_target_players, true).'</pre>'); // Sort the target players based on position in userid array usort($this_leaderboard_target_players, function ($u1, $u2) use($temp_include_userids) { $id1 = isset($u1['user_id']) ? $u1['user_id'] : $u1['id']; $id2 = isset($u2['user_id']) ? $u2['user_id'] : $u2['id']; $pos1 = array_search($id1, $temp_include_userids); $pos2 = array_search($id2, $temp_include_userids); if ($pos1 > $pos2) { return 1; } elseif ($pos1 < $pos2) { return -1; } else { return 0; } }); //die('<pre>$this_leaderboard_target_players(this:'.$player_campaign.'/target:'.$player_sort.') = '.print_r($this_leaderboard_target_players, true).'</pre>'); //die('<pre>(this:'.$player_campaign.'/target:'.$player_sort.')'."\n\n".'$temp_leaderboard_query = '.print_r($temp_leaderboard_query, true).''."\n\n".'$this_leaderboard_target_players = '.print_r($this_leaderboard_target_players, true).'</pre>'); // Loop through and decode any fields that require it if (!empty($this_leaderboard_target_players)) { foreach ($this_leaderboard_target_players as $key => $player) { $player['player_rewards'] = !empty($player['player_rewards']) ? json_decode($player['player_rewards'], true) : array(); $player['player_settings'] = !empty($player['player_settings']) ? json_decode($player['player_settings'], true) : array(); $player['values'] = !empty($player['player_values']) ? json_decode($player['player_values'], true) : array(); $player['counters'] = !empty($player['player_counters']) ? json_decode($player['player_counters'], true) : array(); unset($player['player_values']); unset($player['player_counters']); $player['player_favourites'] = !empty($player['values']['robot_favourites']) ? $player['values']['robot_favourites'] : array(); $player['player_starforce'] = !empty($player['values']['star_force']) ? $player['values']['star_force'] : array(); if (!empty($player_sort)) { $player['counters']['player_robots_count'] = !empty($player['player_rewards'][$player_sort]['player_robots']) ? count($player['player_rewards'][$player_sort]['player_robots']) : 0; } $player['values']['flag_custom'] = in_array($player['user_id'], $this_leaderboard_targets_ids['custom']) ? 1 : 0; $player['values']['flag_online'] = in_array($player['user_id'], $this_leaderboard_targets_ids['online']) ? 1 : 0; $player['values']['flag_rival'] = in_array($player['user_id'], $this_leaderboard_targets_ids['rival']) ? 1 : 0; $this_leaderboard_target_players[$key] = $player; } } // Update the database index cache //if (!empty($player_sort)){ uasort($this_leaderboard_target_players, 'mmrpg_prototype_leaderboard_targets_sort'); } $db->INDEX['LEADERBOARD']['targets'] = $this_leaderboard_target_players; //die($temp_leaderboard_query); } // Return the collected online players if any return $this_leaderboard_target_players; }