Example #1
0
function sn_contact_view($template = null)
{
    global $template_result, $lang;
    $template = gettemplate('contact', $template);
    $query = db_user_list("`authlevel` > 0 ORDER BY `authlevel` ASC");
    // while($row = db_fetch($query))
    foreach ($query as $row) {
        $template_result['.']['contact'][] = array('NAME' => $row['username'], 'LEVEL' => $lang['user_level'][$row['authlevel']], 'EMAIL' => $row['email']);
    }
    $template_result['PAGE_HEADER'] = $lang['ctc_title'];
    return $template;
}
/**
* SendSimpleMessage.php
*
* @version 1.3
* @copyright 2008 by Chlorel for XNova
  Revision history :
  1.0 - Initial release (mise en fonction generique)
  1.1 - Ajout gestion des messages par type pour le module de messages
  1.2 - Correction bug (addslashes pour les zone texte pouvant contenir une apostrophe)
  1.3 - Correction bug (integration de la variable $Time pour afficher l'heure exacte de l'evenement pour les flottes)
  1.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
        [+] Ability to mass-send emails. Mass-sending done via two queries - one for messages table, one for users table
  1.5 - copyright (c) 2010-2011 by Gorlum for http://supernova.ws
        [+] SuperMassMailing - authlevel=3 player can send messages to whole server ('*' as $owners)
*/
function msg_ali_send($message, $subject, $ally_rank_id = 0, $ally_id = 0)
{
    global $user;
    $ally_id = $ally_id ? $ally_id : $user['ally_id'];
    $list = '';
    $query = db_user_list("ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''), false, 'id, username');
    // while ($u = db_fetch($query))
    foreach ($query as $u) {
        $sendList[] = $u['id'];
        $list .= "<br>{$u['username']} ";
    }
    msg_send_simple_message($sendList, $user['id'], SN_TIME_NOW, MSG_TYPE_ALLIANCE, $user['username'], $subject, $message, true);
    return $list;
}
Example #3
0
function sys_stat_calculate()
{
    global $config, $sta_update_step;
    ini_set('memory_limit', $config->stats_php_memory ? $config->stats_php_memory : '1024M');
    $user_skip_list = sys_stat_get_user_skip_list();
    // $sn_groups_resources_loot = sn_get_groups('resources_loot');
    $rate[RES_METAL] = $config->rpg_exchange_metal;
    $rate[RES_CRYSTAL] = $config->rpg_exchange_crystal / $config->rpg_exchange_metal;
    $rate[RES_DEUTERIUM] = $config->rpg_exchange_deuterium / $config->rpg_exchange_metal;
    $rate[RES_DARK_MATTER] = $config->rpg_exchange_darkMatter / $config->rpg_exchange_metal;
    $sta_update_step = -1;
    sta_set_time_limit('starting update');
    $counts = $points = $unit_cost_cache = $user_allies = array();
    sn_db_transaction_start();
    sta_set_time_limit('calculating players stats');
    $i = 0;
    // Блокируем всех пользователей
    classSupernova::db_lock_tables('users');
    $user_list = db_user_list('', true, 'id, dark_matter, metal, crystal, deuterium, user_as_ally, ally_id');
    $row_num = count($user_list);
    // while($player = db_fetch($query))
    foreach ($user_list as $player) {
        if ($i++ % 100 == 0) {
            sta_set_time_limit("calculating players stats (player {$i}/{$row_num})", false);
        }
        if (array_key_exists($user_id = $player['id'], $user_skip_list)) {
            continue;
        }
        $resources = $player['metal'] * $rate[RES_METAL] + $player['crystal'] * $rate[RES_CRYSTAL] + $player['deuterium'] * $rate[RES_DEUTERIUM] + $player['dark_matter'] * $rate[RES_DARK_MATTER];
        $counts[$user_id][UNIT_RESOURCES] += $resources;
        // $points[$user_id][UNIT_RESOURCES] += $resources;
        // А здесь мы фильтруем пользователей по $user_skip_list - далее не нужно этого делать, потому что
        if (!isset($user_skip_list[$user_id])) {
            $user_allies[$user_id] = $player['ally_id'];
        }
    }
    unset($user_list);
    classSupernova::cache_clear(LOC_USER, true);
    //pdump(classSupernova::$data[LOC_USER]);
    //pdump(classSupernova::$locks[LOC_USER]);
    sta_set_time_limit('calculating planets stats');
    $i = 0;
    $query = db_planet_list_resources_by_owner();
    $row_num = db_num_rows($query);
    while ($planet = db_fetch($query)) {
        if ($i++ % 100 == 0) {
            sta_set_time_limit("calculating planets stats (planet {$i}/{$row_num})", false);
        }
        if (array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) {
            continue;
        }
        $resources = $planet['metal'] * $rate[RES_METAL] + $planet['crystal'] * $rate[RES_CRYSTAL] + $planet['deuterium'] * $rate[RES_DEUTERIUM];
        $counts[$user_id][UNIT_RESOURCES] += $resources;
        // $points[$user_id][UNIT_RESOURCES] += $resources;
    }
    // Calculation of Fleet-In-Flight
    sta_set_time_limit('calculating flying fleets stats');
    $i = 0;
    $query = doquery("SELECT fleet_owner, fleet_array, fleet_resource_metal, fleet_resource_crystal, fleet_resource_deuterium FROM {{fleets}};");
    $row_num = db_num_rows($query);
    while ($fleet_row = db_fetch($query)) {
        if ($i++ % 100 == 0) {
            sta_set_time_limit("calculating flying fleets stats (fleet {$i}/{$row_num})", false);
        }
        if (array_key_exists($user_id = $fleet_row['fleet_owner'], $user_skip_list)) {
            continue;
        }
        $fleet = sys_unit_str2arr($fleet_row['fleet_array']);
        foreach ($fleet as $unit_id => $unit_amount) {
            $counts[$user_id][UNIT_SHIPS] += $unit_amount;
            if (!isset($unit_cost_cache[$unit_id][0])) {
                $unit_cost_cache[$unit_id][0] = get_unit_param($unit_id, P_COST);
            }
            $unit_cost_data =& $unit_cost_cache[$unit_id][0];
            $points[$user_id][UNIT_SHIPS] += ($unit_cost_data[RES_METAL] * $rate[RES_METAL] + $unit_cost_data[RES_CRYSTAL] * $rate[RES_CRYSTAL] + $unit_cost_data[RES_DEUTERIUM] * $rate[RES_DEUTERIUM]) * $unit_amount;
        }
        $resources = $fleet_row['fleet_resource_metal'] * $rate[RES_METAL] + $fleet_row['fleet_resource_crystal'] * $rate[RES_CRYSTAL] + $fleet_row['fleet_resource_deuterium'] * $rate[RES_DEUTERIUM];
        $counts[$user_id][UNIT_RESOURCES] += $resources;
        // $points[$user_id][UNIT_RESOURCES] += $resources;
    }
    sta_set_time_limit('calculating unit stats');
    $i = 0;
    $query = db_unit_list_stat_calculate();
    $row_num = db_num_rows($query);
    while ($unit = db_fetch($query)) {
        if ($i++ % 100 == 0) {
            sta_set_time_limit("calculating unit stats (unit {$i}/{$row_num})", false);
        }
        if (array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) {
            continue;
        }
        $counts[$user_id][$unit['unit_type']] += $unit['unit_level'] * $unit['unit_amount'];
        $total_cost = eco_get_total_cost($unit['unit_snid'], $unit['unit_level']);
        $points[$user_id][$unit['unit_type']] += (isset($total_cost['total']) ? $total_cost['total'] : 0) * $unit['unit_amount'];
    }
    sta_set_time_limit('calculating ques stats');
    $i = 0;
    $query = db_que_list_stat();
    $row_num = db_num_rows($query);
    while ($que_item = db_fetch($query)) {
        if ($i++ % 100 == 0) {
            sta_set_time_limit("calculating ques stats (que item {$i}/{$row_num})", false);
        }
        if (array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) {
            continue;
        }
        $que_unit_amount = $que_item['que_unit_amount'];
        $que_item = sys_unit_str2arr($que_item['que_unit_price']);
        $resources = ($que_item[RES_METAL] * $rate[RES_METAL] + $que_item[RES_CRYSTAL] * $rate[RES_CRYSTAL] + $que_item[RES_DEUTERIUM] * $rate[RES_DEUTERIUM]) * $que_unit_amount;
        $counts[$user_id][UNIT_RESOURCES] += $resources;
        // $points[$user_id][UNIT_RESOURCES] += $resources;
    }
    sta_set_time_limit('archiving old statistic');
    // Statistic rotation
    // doquery("DELETE FROM {{statpoints}} WHERE `stat_code` >= 14;");
    doquery("DELETE FROM {{statpoints}} WHERE `stat_date` < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL {$config->stats_history_days} DAY));");
    doquery("UPDATE {{statpoints}} SET `stat_code` = `stat_code` + 1;");
    sta_set_time_limit('posting new user stats to DB');
    $data = array();
    foreach ($user_allies as $user_id => $ally_id) {
        // $counts[UNIT_RESOURCES] дублирует $points[UNIT_RESOURCES], поэтому $points не заполняем, а берем $counts и делим на 1000
        $points[$user_id][UNIT_RESOURCES] = $counts[$user_id][UNIT_RESOURCES] / 1000;
        $points[$user_id] = array_map('floor', $points[$user_id]);
        $counts[$user_id] = array_map('floor', $counts[$user_id]);
        $ally_id = $ally_id ? $ally_id : 'NULL';
        $user_defence_points = $points[$user_id][UNIT_DEFENCE] + $points[$user_id][UNIT_DEF_MISSILES];
        $user_defence_counts = $counts[$user_id][UNIT_DEFENCE] + $counts[$user_id][UNIT_DEF_MISSILES];
        $user_points = array_sum($points[$user_id]);
        $user_counts = array_sum($counts[$user_id]);
        $data[] = $q = "({$user_id},{$ally_id},1,1,'{$points[$user_id][UNIT_TECHNOLOGIES]}','{$counts[$user_id][UNIT_TECHNOLOGIES]}'," . "'{$points[$user_id][UNIT_STRUCTURES]}','{$counts[$user_id][UNIT_STRUCTURES]}','{$user_defence_points}','{$user_defence_counts}'," . "'{$points[$user_id][UNIT_SHIPS]}','{$counts[$user_id][UNIT_SHIPS]}','{$points[$user_id][UNIT_RESOURCES]}','{$counts[$user_id][UNIT_RESOURCES]}'," . "{$user_points},{$user_counts}," . SN_TIME_NOW . ")";
        sys_stat_calculate_flush($data);
    }
    sys_stat_calculate_flush($data, true);
    // Updating Allie's stats
    sta_set_time_limit('posting new Alliance stats to DB');
    doquery("INSERT INTO {{statpoints}}\n      (`tech_points`, `tech_count`, `build_points`, `build_count`, `defs_points`, `defs_count`,\n        `fleet_points`, `fleet_count`, `res_points`, `res_count`, `total_points`, `total_count`,\n        `stat_date`, `id_owner`, `id_ally`, `stat_type`, `stat_code`,\n        `tech_old_rank`, `build_old_rank`, `defs_old_rank`, `fleet_old_rank`, `res_old_rank`, `total_old_rank`\n      )\n      SELECT\n        SUM(u.`tech_points`)+aus.`tech_points`, SUM(u.`tech_count`)+aus.`tech_count`, SUM(u.`build_points`)+aus.`build_points`, SUM(u.`build_count`)+aus.`build_count`,\n        SUM(u.`defs_points`)+aus.`defs_points`, SUM(u.`defs_count`)+aus.`defs_count`, SUM(u.`fleet_points`)+aus.`fleet_points`, SUM(u.`fleet_count`)+aus.`fleet_count`,\n        SUM(u.`res_points`)+aus.`res_points`, SUM(u.`res_count`)+aus.`res_count`, SUM(u.`total_points`)+aus.`total_points`, SUM(u.`total_count`)+aus.`total_count`,\n        " . SN_TIME_NOW . ", NULL, u.`id_ally`, 2, 1,\n        a.tech_rank, a.build_rank, a.defs_rank, a.fleet_rank, a.res_rank, a.total_rank\n      FROM {{statpoints}} as u\n        join {{alliance}} as al on al.id = u.id_ally\n        left join {{statpoints}} as aus on aus.id_owner = al.ally_user_id and aus.stat_type = 1 AND aus.stat_code = 1\n        LEFT JOIN {{statpoints}} as a ON a.id_ally = u.id_ally AND a.stat_code = 2 AND a.stat_type = 2\n      WHERE u.`stat_type` = 1 AND u.stat_code = 1 AND u.id_ally<>0\n      GROUP BY u.`id_ally`");
    // Удаляем больше не нужные записи о достижении игрока-альянса
    db_stat_list_delete_ally_player();
    // Some variables we need to update ranks
    $qryResetRowNum = 'SET @rownum=0;';
    $qryFormat = 'UPDATE {{statpoints}} SET `%1$s_rank` = (SELECT @rownum:=@rownum+1) WHERE `stat_type` = %2$d AND `stat_code` = 1 ORDER BY `%1$s_points` DESC, `id_owner` ASC, `id_ally` ASC;';
    $rankNames = array('tech', 'build', 'defs', 'fleet', 'res', 'total');
    // Updating player's ranks
    sta_set_time_limit("updating ranks for players");
    foreach ($rankNames as $rankName) {
        sta_set_time_limit("updating player rank '{$rankName}'", false);
        doquery($qryResetRowNum);
        doquery(sprintf($qryFormat, $rankName, 1));
    }
    sta_set_time_limit("updating ranks for Alliances");
    // --- Updating Allie's ranks
    foreach ($rankNames as $rankName) {
        sta_set_time_limit("updating Alliances rank '{$rankName}'", false);
        doquery($qryResetRowNum);
        doquery(sprintf($qryFormat, $rankName, 2));
    }
    sta_set_time_limit('setting previous user stats from archive');
    doquery("UPDATE {{statpoints}} as new\n      LEFT JOIN {{statpoints}} as old ON old.id_owner = new.id_owner AND old.stat_code = 2 AND old.stat_type = new.stat_type\n    SET\n      new.tech_old_rank = old.tech_rank,\n      new.build_old_rank = old.build_rank,\n      new.defs_old_rank  = old.defs_rank ,\n      new.fleet_old_rank = old.fleet_rank,\n      new.res_old_rank = old.res_rank,\n      new.total_old_rank = old.total_rank\n    WHERE\n      new.stat_type = 1 AND new.stat_code = 1;");
    sta_set_time_limit('setting previous allies stats from archive');
    doquery("UPDATE {{statpoints}} as new\n      LEFT JOIN {{statpoints}} as old ON old.id_ally = new.id_ally AND old.stat_code = 2 AND old.stat_type = new.stat_type\n    SET\n      new.tech_old_rank = old.tech_rank,\n      new.build_old_rank = old.build_rank,\n      new.defs_old_rank  = old.defs_rank ,\n      new.fleet_old_rank = old.fleet_rank,\n      new.res_old_rank = old.res_rank,\n      new.total_old_rank = old.total_rank\n    WHERE\n      new.stat_type = 2 AND new.stat_code = 1;");
    sta_set_time_limit('updating players current rank and points');
    db_stat_list_update_user_stats();
    sta_set_time_limit('updating Allys current rank and points');
    db_stat_list_update_ally_stats();
    // Counting real user count and updating values
    $config->db_saveItem('users_amount', db_user_count());
    sn_db_transaction_commit();
}
Example #4
0
        case 'usr_level':
            # only for admins
            if ($user['authlevel'] < 3 || $NewLevel >= $user['authlevel']) {
                message($lang['sys_noalloaw'], $lang['sys_noaccess']);
                die;
            }
            $selected_user = db_user_by_username($Pattern, false, 'id');
            $QryUpdate = db_user_set_by_id($selected_user['id'], "`authlevel` = '{$NewLvl}'");
            $Message = $lang['adm_mess_lvl1'] . " " . $Pattern . " " . $lang['adm_mess_lvl2'];
            $Message .= "<font color=\"red\">" . $lang['adm_usr_level'][$NewLvl] . "</font>!";
            AdminMessage($Message, $lang['adm_mod_level']);
            break;
        case 'ip_search':
            $bloc = $lang;
            $bloc['adm_this_ip'] = $ip;
            $SelUser = db_user_list("`user_lastip` = '{$ip}'");
            //while ( $Usr = db_fetch($SelUser) ) {
            foreach ($SelUser as $Usr) {
                $UsrMain = db_planet_by_id($Usr['id_planet'], false, 'name');
                $bloc['adm_plyer_lst'] .= "<tr><th>" . $Usr['username'] . "</th><th>[" . $Usr['galaxy'] . ":" . $Usr['system'] . ":" . $Usr['planet'] . "] " . $UsrMain['name'] . "</th></tr>";
            }
            $SubPanelTPL = gettemplate('admin/admin_panel_asw2');
            $parse['adm_sub_form2'] = parsetemplate($SubPanelTPL, $bloc);
            break;
        default:
            break;
    }
}
// Traiter les reponses aux formulaires
if (isset($GET_action)) {
    $bloc = $lang;
Example #5
0
function sys_stat_get_user_skip_list()
{
    global $config;
    $result = array();
    $user_skip_list = array();
    if ($config->stats_hide_admins) {
        $user_skip_list[] = '`authlevel` > 0';
    }
    if ($config->stats_hide_player_list) {
        $temp = explode(',', $config->stats_hide_player_list);
        foreach ($temp as $user_id) {
            $user_id = floatval($user_id);
            if ($user_id) {
                $user_skip_list[] = '`id` = ' . $user_id;
            }
        }
    }
    if (!empty($user_skip_list)) {
        $user_skip_list = implode(' OR ', $user_skip_list);
        $user_skip_query = db_user_list($user_skip_list);
        if (!empty($user_skip_query)) {
            foreach ($user_skip_query as $user_skip_row) {
                $result[$user_skip_row['id']] = $user_skip_row['id'];
            }
        }
    }
    return $result;
}
Example #6
0
function dashboard_userman()
{
    list($section, $st, $delete) = GET('section, st, delete');
    list($user_name, $user_pass, $user_confirm, $user_nick, $user_email, $user_acl) = GET('user_name, user_pass, user_confirm, user_nick, user_email, user_acl');
    $per_page = 100;
    $section = intval($section);
    $st = intval($st);
    $grp = getoption('#grp');
    $is_edit = FALSE;
    //visability Edit btton
    if (request_type('POST')) {
        cn_dsi_check();
        // Do Delete
        if ($delete) {
            db_user_delete($user_name);
            cn_throw_message('User [' . cn_htmlspecialchars($user_name) . '] deleted');
            $user_name = $user_nick = $user_email = $user_acl = '';
        } else {
            $user_data = db_user_by_name($user_name);
            if (REQ('edit')) {
                if ($user_data === null) {
                    $is_edit = FALSE;
                    cn_throw_message("User not exists", 'e');
                }
            } else {
                // Check user
                if (!$user_name) {
                    cn_throw_message("Fill required field: username", 'e');
                }
                if (!$user_pass) {
                    cn_throw_message("Fill required field: password", 'e');
                }
                if ($user_data !== null) {
                    cn_throw_message("Username already exist", 'e');
                }
                if ($user_confirm != $user_pass) {
                    cn_throw_message('Confirm not match', 'e');
                }
                // Invalid email
                if (!check_email($user_email)) {
                    cn_throw_message("Email not valid", "e");
                } elseif (db_user_by($user_email, 'email')) {
                    cn_throw_message('Email already exists', 'e');
                }
            }
            // Must be correct all
            if (cn_get_message('e', 'c') == 0) {
                // Edit user [user exist]
                if (REQ('edit')) {
                    db_user_update($user_name, "email={$user_email}", "nick={$user_nick}", "acl={$user_acl}");
                    // Update exists (change password)
                    if ($user_pass) {
                        if ($user_confirm == $user_pass) {
                            db_user_update($user_name, 'pass='******'User password / user info updated');
                        } else {
                            cn_throw_message('Confirm not match', 'e');
                        }
                    } else {
                        cn_throw_message('User info updated');
                    }
                } else {
                    if ($user_id = db_user_add($user_name, $user_acl)) {
                        if (db_user_update($user_name, "email={$user_email}", "nick={$user_nick}", 'pass='******'t update user", 'e');
                        }
                    } else {
                        cn_throw_message("User not added: internal error", 'e');
                    }
                }
            }
        }
    }
    // ----
    $userlist = db_user_list();
    // Get users by ACL from index
    if ($section) {
        foreach ($userlist as $id => $dt) {
            if ($dt['acl'] != $section) {
                unset($userlist[$id]);
            }
        }
    }
    // Sort by latest & make pagination
    krsort($userlist);
    $userlist = array_slice($userlist, $st, $per_page, TRUE);
    // Fetch estimate user list
    foreach ($userlist as $id => $data) {
        $user = db_user_by($id);
        $userlist[$id] = $user;
    }
    // Retrieve info about user
    if ($user = db_user_by_name($user_name)) {
        $user_nick = isset($user['nick']) ? $user['nick'] : '';
        $user_email = isset($user['email']) ? $user['email'] : '';
        $user_acl = isset($user['acl']) ? $user['acl'] : '';
        $is_edit = TRUE;
    }
    // By default for section
    if (!$user_acl) {
        $user_acl = $section;
    }
    cn_assign('users, section, st, per_page, grp', $userlist, $section, $st, $per_page, $grp);
    cn_assign('user_name, user_nick, user_email, user_acl, is_edit', $user_name, $user_nick, $user_email, $user_acl, $is_edit);
    echoheader('-@dashboard/style.css', "Users manager");
    echo exec_tpl('dashboard/users');
    echofooter();
}
Example #7
0
 function user_lookup($username)
 {
     $users = db_user_list();
     foreach ($users as $uid => $acl) {
         $user = db_user_by($uid);
         if (isset($user['name']) && $user['name'] == $username) {
             return $user;
         }
     }
     return null;
 }
Example #8
0
    }
    if (isset($_POST["temat"]) && $_POST["temat"] != '') {
        $config->temat = $_POST['temat'];
    }
    if ($user['authlevel'] == 3) {
        $kolor = 'red';
        $ranga = 'Administrator';
    } elseif ($user['authlevel'] == 4) {
        $kolor = 'skyblue';
        $ranga = 'GameOperator';
    } elseif ($user['authlevel'] == 5) {
        $kolor = 'yellow';
        $ranga = 'SuperGameOperator';
    }
    if ($config->tresc != '' and $config->temat) {
        $Time = time();
        $From = '<font color="' . $kolor . '">' . $ranga . " " . $user['username'] . "</font>";
        $Subject = '<font color="' . $kolor . '">' . $config->temat . "</font>";
        $Message = '<font color="' . $kolor . '"><b>' . $config->tresc . "</b></font>";
        $sq = db_user_list('', false, 'id');
        foreach ($sq as $u) {
            msg_send_simple_message($u['id'], $user['id'], $Time, MSG_TYPE_ADMIN, $From, $Subject, $Message);
        }
        message("<font color=\"lime\">Херня на польском</font>", "Complete", "../overview." . PHP_EX, 3);
    }
} else {
    $parse['dpath'] = $dpath;
    $parse['debug'] = $config->debug == 1 ? " checked='checked'/" : '';
    $page .= parsetemplate(gettemplate('admin/messall_body'), $parse);
    display($page, '', false, '', true);
}