Exemplo n.º 1
0
function sgang_vault_give()
{
    global $gvars;
    if (!gang_auth_all($gvars->userid, array('pres', 'vice'))) {
        echo "<h3>You are not authorized to access this portion of the staff panel.</h3>";
        gang_go_back('yourgang.php?action=sgang_home');
        return;
    }
    if (!isset($_REQUEST['them_id']) or intval($_REQUEST['them_id']) < 1) {
        echo "<h3>Please select a {$gvars->name_sl} member.</h3>";
        gang_go_back('yourgang.php?action=sgang_vault');
        return;
    }
    $them_id = intval($_REQUEST['them_id']);
    $q_check = sprintf('select username, gang from users where userid = %d', $them_id);
    $q_check = mysql_query($q_check);
    if (!$q_check or mysql_num_rows($q_check) < 1) {
        echo "<h3>The player you selected could not be found.</h3>";
        gang_go_back('yourgang.php?action=sgang_vault');
        return;
    }
    list($them_name, $them_gang) = mysql_fetch_row($q_check);
    if ($them_gang != $gvars->ir['gang']) {
        echo "<h3>The player you selected is not in your {$gvars->name_sl}.</h3>";
        gang_go_back('yourgang.php?action=sgang_vault');
        return;
    }
    if (!isset($_REQUEST['money']) or floatval($_REQUEST['money']) < 1) {
        $money = 0;
    } else {
        $money = floatval($_REQUEST['money']);
    }
    if (!isset($_REQUEST['crystals']) or floatval($_REQUEST['crystals']) < 1) {
        $crystals = 0;
    } else {
        $crystals = floatval($_REQUEST['crystals']);
    }
    if ($money < 1 and $crystals < 1) {
        echo "<h3>Please select an amount of {$gvars->money_name} or {$gvars->crystals_name} to give.</h3>";
        gang_go_back('yourgang.php?action=sgang_vault');
        return;
    }
    $money_l = strtolower($gvars->money_name);
    $crystals_l = strtolower($gvars->crystals_name);
    if ($money > 0) {
        if (!gang_take_gang_money($gvars->ir['gang'], $money)) {
            echo "<h3>The {$gvars->name_sl} doesn't have enough {$money_l} to cover this transaction.</h3>";
            gang_go_back('yourgang.php?action=sgang_vault');
            return;
        }
    }
    if ($crystals > 0) {
        if (!gang_take_gang_money($gvars->ir['gang'], $crystals, 'gangCRYSTALS')) {
            if ($money > 0) {
                gang_give_gang_money($gvars->ir['gang'], $money);
            }
            echo "<h3>The {$gvars->name_sl} doesn't have enough {$crystals_l} to cover this transaction.</h3>";
            gang_go_back('yourgang.php?action=sgang_vault');
            return;
        }
    }
    if ($money > 0) {
        gang_give_money($them_id, $money);
    }
    if ($crystals > 0) {
        gang_give_money($them_id, $crystals, 'crystals');
    }
    if ($money > 0 and $crystals > 0) {
        $gang_event = '%1$s sent %2$s and %3$s %4$s to %5$s';
        $player_event = '%1$s sent %2$s and %3$s %4$s to you from the %5$s';
        $msg = '<h3>You sent %1$s and %2$s %3$s to %4$s</h3>';
    } else {
        if ($money > 0) {
            $gang_event = '%1$s sent %2$s to %5$s';
            $player_event = '%1$s sent %2$s to you from the %5$s';
            $msg = '<h3>You sent %1$s to %4$s</h3>';
        } else {
            if ($crystals > 0) {
                $gang_event = '%1$s sent %3$s %4$s to %5$s';
                $player_event = '%1$s sent %3$s %4$s to you from the %5$s';
                $msg = '<h3>You sent %2$s %3$s to %4$s</h3>';
            }
        }
    }
    $us_p = gang_get_profile_link($gvars->userid, $gvars->ir['username']);
    $them_p = gang_get_profile_link($them_id, $them_name);
    gang_new_event($gvars->ir['gang'], sprintf($gang_event, $us_p, gang_money_format($money), number_format($crystals), $crystals_l, $them_p), 'escape');
    event_add($them_id, sprintf($player_event, $us_p, gang_money_format($money), number_format($crystals), $crystals_l, $gvars->name_sl), $gvars->c);
    printf($msg, gang_money_format($money), number_format($crystals), $crystals_l, $them_p);
    gang_go_back('yourgang.php?action=sgang_vault');
    return;
}
Exemplo n.º 2
0
/**
 * Make multiple attempts to give money to a user (in cases where there is
 * a high likely hood of failure -- rare...)
 *
 * @param int $userid
 * @param int $amount
 * @param string $field
 * @param int $num_attempts
 * @return bool
 */
function gang_give_money_loop($userid, $amount, $field = 'money', $num_attempts = 5)
{
    for ($x = 1; $x <= $num_attempts; $x++) {
        $result = gang_give_money($userid, $amount, $field);
        if ($result) {
            break;
        }
    }
    return $result;
}
Exemplo n.º 3
0
function ygang_donate2()
{
    global $gvars;
    if (!isset($_REQUEST['money']) or floatval($_REQUEST['money']) < 1) {
        $money = 0;
    } else {
        $money = floatval($_REQUEST['money']);
    }
    if (!isset($_REQUEST['crystals']) or floatval($_REQUEST['crystals']) < 1) {
        $crystals = 0;
    } else {
        $crystals = floatval($_REQUEST['crystals']);
    }
    if ($money < 1 and $crystals < 1) {
        echo "<h3>You haven't donated anything. Please try again.</h3>";
        gang_go_back('yourgang.php?action=ygang_donate');
        return;
    }
    $money_l = strtolower($gvars->money_name);
    $crystals_l = strtolower($gvars->crystals_name);
    if ($money > 0) {
        if (!gang_take_money($gvars->userid, $money)) {
            echo "<h3>You don't have enough {$money_l} to cover your donation.</h3>";
            gang_go_back('yourgang.php?action=ygang_donate');
            return;
        }
    }
    if ($crystals > 0) {
        if (!gang_take_money($gvars->userid, $crystals, 'crystals')) {
            if ($money > 0) {
                gang_give_money($gvars->userid, $money);
            }
            echo "<h3>You don't have enough {$crystals_l} to cover your donation.</h3>";
            gang_go_back('yourgang.php?action=ygang_donate');
            return;
        }
    }
    if ($money > 0) {
        $result = gang_give_gang_money($gvars->ir['gang'], $money);
        if (!$result) {
            echo 'error';
        }
    }
    if ($crystals > 0) {
        gang_give_gang_money($gvars->ir['gang'], $crystals, 'gangCRYSTALS');
    }
    if (mysql_affected_rows() < 1) {
        echo "<h3>The donation failed.</h3>";
    } else {
        echo "<h3>Your donation has been received.</h3>";
        $us_p = gang_get_profile_link($gvars->ir['userid'], $gvars->ir['username']);
        if ($money > 1 and $crystals > 1) {
            $ev_msg = '%4$s donated %1$s and %2$s %3$s.';
        } else {
            if ($money > 1) {
                $ev_msg = '%4$s donated %1$s.';
            } else {
                $ev_msg = '%4$s donated %2$s %3$s.';
            }
        }
        gang_new_event($gvars->ir['gang'], sprintf($ev_msg, gang_money_format($money), number_format($crystals), $gvars->crystals_name, $us_p), 'escape');
        gang_go_back('yourgang.php?action=ygang_donate');
    }
}