<?php
/****************************************************************************
* Copyright (C) 2000 Bryan Brunton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
****************************************************************************/
page_open(array("sess" => "ME_Session_Uncached", "auth" => "ME_Auth", "user" => "ME_User"));
$sess->register("player_id");
include("./lib/player.php");
include("./lib/ship.php");
include("./merchantempiresdefines.php");
include("./lib/player_redirect.php");
$error = 0;
$player = new ME_Player;
$player->get_player($player_id);
$game_id = $player->f("game_id");
$ship = new ME_Ship;
$ship->get_ship($player_id);
$sector_id = $ship->f("sector_id");
$db_u = new ME_DB;
$db_u->query("SELECT * from locations where sector_id = '$sector_id' and type='Underground'");
$db_u->next_record();
// Check if there was a submission
while (is_array($HTTP_POST_VARS)
&& list($key, $val) = each($HTTP_POST_VARS)) {
switch ($key) {
case "criminalize":
$returnto = "underground";
if ( $player->f("deputy_or_underground") == 't' or $player->f("alignment") >= 100 ) {
$error = 1;
break;
}
if ( $db_u->nf() == 0 ) {
$error = 6;
break;
}
$db = new ME_DB;
$query = "update players set deputy_or_underground = 't', alignment = -150 where
player_id = '$player_id'";
$db->query($query);
break;
case "place_bounty":
$merchant_id = (int) $merchant_id;
$amount = (int) $amount;
$returnto = "underground";
if ( $player->f("credits") < $amount ) {
$error = 2;
break;
}
if ( $db_u->nf() == 0 ) {
$error = 6;
break;
}
$db_p = new ME_DB;
$db_p->query("select player_id, public_player_id, game_id, name, experience
from players where public_player_id = '$merchant_id' and game_id = '$game_id'");
$db_p->next_record();
if ( $db_p->nf() == 0 ) {
$returnto = "underground_place";
$error = 1;
break;
}
if ( $db_p->f("experience") < 1000 ) {
$returnto = "underground_place";
$error = 7;
break;
}
if ( $amount < 10000 ) {
$returnto = "underground_place";
$error = 2;
break;
}
if ( $amount > 10000000 ) {
$returnto = "underground_place";
$error = 3;
break;
}
$new_credits = $player->f("credits") - $amount;
$db = new ME_DB;
$player_place_id = $player->f("player_id");
$player_place_name = addslashes($player->f("name"));
if ( $db_p->f("experience") > 10000 and $db_p->f("experience") < 100000) {
$amount = $amount + ($amount * .2);
}
if ( $db_p->f("experience") >= 100000 ) {
$amount = $amount + ($amount * .5);
}
$player_target_id = $db_p->f("player_id");
$player_target_name = addslashes($db_p->f("name"));
if ( $player_target_id == $player_place_id ) {
$returnto = "underground_place";
$error = 4;
break;
}
$query = "select * from underground_bounties where player_target_id = '$player_target_id'";
$db->query($query);
$db->next_record();
if ( $db->nf() > 0 ) {
$new_amount = $db->f("amount") + $amount;
$underground_bounty_id = $db->f("underground_bounty_id");
$query = "update underground_bounties set amount = '$new_amount' where underground_bounty_id = '$underground_bounty_id'";
$db->query($query);
} else {
$query = "insert into underground_bounties (game_id, player_place_id, player_place_name, amount,
player_target_id, player_target_name) values ('$game_id', '$player_place_id',
'$player_place_name', '$amount', '$player_target_id', '$player_target_name')";
$db->query($query);
}
$player->set_credits($new_credits);
$player->save();
break;
case "claim_bounty":
$returnto = "underground";
if ( $db_u->nf() == 0 ) {
$error = 6;
break;
}
$bounties = array();
$bounties = explode(",", $player->f("unclaimed_ug_bounties"));
if ( ! $bounties[0] > 0 ) {
$returnto = "underground";
$error = 4;
break;
} else {
$new_credits = 0;
while (list($key, $val) = each($bounties)) {
$val = (int) $val;
$db = new ME_DB;
$db->query("select * from underground_bounties where underground_bounty_id = '$val'");
while ( $db->next_record() ) {
$new_credits = $new_credits + $db->f("amount");
$db_2 = new ME_DB;
$db_2->query("delete from underground_bounties where underground_bounty_id = '$val'");
}
}
$new_credits = $new_credits + $player->f("credits");
$player->set_credits($new_credits);
$player->set_unclaimed_ug_bounties('');
$player->save();
}
break;
case "post_bulletin":
$returnto = "underground_bulletins";
if ( $db_u->nf() == 0 ) {
$error = 6;
break;
}
if (strlen($bulletin) > 800) {
$error = 2;
break;
}
if (stristr($bulletin, ';') ) {
$error = 3;
break;
}
if (stristr($bulletin, 'fuck') ) {
$error = 3;
break;
}
$db = new ME_DB;
$db->query("select * from bulletins where player_id = '$player_id' and sector_id = '$sector_id'");
if ( $db->nf() > 0 ) {
$error = 4;
break;
}
$query = "select * from bulletins where sector_id = '$sector_id' order by bulletin_id";
$db->query($query);
$db->next_record();
if ( $db->nf() > 10 ) {
$bulletin_id = $db->f("bulletin_id");
$query = "delete from bulletins where bulletin_id = '$bulletin_id'";
$db->query($query);
}
$public_player_id = $player->f("public_player_id");
$player_name = addslashes($player->f("name"));
$bulletin = addslashes($bulletin);
$db->query("insert into bulletins (player_id, public_player_id, player_name, sector_id, bulletin)
values ('$player_id', '$public_player_id', '$player_name', '$sector_id', '$bulletin')");
break;
}
}
if ( $error ) {
if ($returnto == "underground") {
$newurl = $sess->url(URL . "underground.php?error=$error");
header("Location: $newurl");
} elseif ($returnto == "underground_place") {
$newurl = $sess->url(URL . "underground_place.php?error=$error");
header("Location: $newurl");
} elseif ($returnto == "underground_bulletins") {
$newurl = $sess->url(URL . "underground_bulletins.php?error=$error");
header("Location: $newurl");
}
} else {
if ($returnto == "underground") {
$newurl = $sess->url(URL . "underground.php");
header("Location: $newurl");
} elseif ($returnto == "underground_place") {
$newurl = $sess->url(URL . "underground_place.php");
header("Location: $newurl");
} elseif ($returnto == "underground_bulletins") {
$newurl = $sess->url(URL . "underground_bulletins.php");
header("Location: $newurl");
}
}
page_close();
?>