Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
54
scripts/game/beta5/sale/library.inc
Normal file
54
scripts/game/beta5/sale/library.inc
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_library {
|
||||
var $index = array(
|
||||
'bid',
|
||||
'buy',
|
||||
'cancel',
|
||||
'cancelTransfer',
|
||||
'decline',
|
||||
'getDirectSales',
|
||||
'getFleetSale',
|
||||
'getPlanetSale',
|
||||
'getPublicSales',
|
||||
'getSentOffers',
|
||||
'sell'
|
||||
);
|
||||
|
||||
|
||||
function beta5_sale_library($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function getHistoryFrom($player) {
|
||||
$q = $this->db->query("SELECT * FROM sale_history WHERE from_player=$player AND end_mode IS NOT NULL ORDER BY ended DESC,started DESC");
|
||||
$rs = array();
|
||||
while ($r = dbFetchHash($q)) {
|
||||
array_push($rs,$r);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
function getHistoryTo($player) {
|
||||
$q = $this->db->query("SELECT * FROM sale_history WHERE to_player=$player AND mode<2 AND end_mode IS NOT NULL ORDER BY ended DESC,started DESC");
|
||||
$rs = array();
|
||||
while ($r = dbFetchHash($q)) {
|
||||
array_push($rs,$r);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
function isDirectOffer($pid, $oid) {
|
||||
$q = $this->db->query(
|
||||
"SELECT id FROM sale,private_offer WHERE offer=id AND to_player=$pid AND id=$oid "
|
||||
. "AND (expires IS NULL OR UNIX_TIMESTAMP(NOW())-expires<0) AND finalized IS NULL"
|
||||
);
|
||||
return $q && (dbCount($q)==1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
119
scripts/game/beta5/sale/library/bid.inc
Normal file
119
scripts/game/beta5/sale/library/bid.inc
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_bid {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_bid($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
$this->planets = $this->lib->game->getLib('beta5/planet');
|
||||
$this->fleets = $this->lib->game->getLib('beta5/fleet');
|
||||
}
|
||||
|
||||
|
||||
function run($pid, $oid, $price) {
|
||||
$q = $this->db->query(
|
||||
"SELECT id,price,player FROM sale,public_offer"
|
||||
." WHERE id=$oid AND offer=$oid AND player<>$pid AND auction"
|
||||
. " AND finalized IS NULL AND expires>UNIX_TIMESTAMP(NOW())"
|
||||
);
|
||||
if (!($q && dbCount($q))) {
|
||||
return "0";
|
||||
}
|
||||
$r = dbFetchArray($q);
|
||||
$q = $this->db->query("SELECT price FROM auction WHERE offer=$oid ORDER BY price DESC LIMIT 1");
|
||||
if ($q && dbCount($q)) {
|
||||
list($mp) = dbFetchArray($q);
|
||||
} else {
|
||||
$mp = $r[1];
|
||||
}
|
||||
if ($mp >= $price) {
|
||||
return "2#$oid#$mp";
|
||||
}
|
||||
|
||||
$q = $this->db->query("SELECT price FROM auction WHERE offer=$oid AND player=$pid ORDER BY price DESC LIMIT 1");
|
||||
if ($q && dbCount($q)) {
|
||||
list($lBid) = dbFetchArray($q);
|
||||
} else {
|
||||
$lBid = 0;
|
||||
}
|
||||
$rPrice = $price - $lBid;
|
||||
|
||||
$pi = $this->players->call('get', $pid);
|
||||
if ($pi['cash'] < $rPrice) {
|
||||
return "1";
|
||||
}
|
||||
$this->db->query("UPDATE player SET cash=cash-$rPrice WHERE id=$pid");
|
||||
$this->db->query("INSERT INTO auction VALUES ($oid,$pid,".time().",$price)");
|
||||
$this->sendOwnerBidMessage($r[2], $oid, $price, $pid);
|
||||
|
||||
$q = $this->db->query("SELECT player FROM auction WHERE offer=$oid AND price<$price ORDER BY price DESC LIMIT 1");
|
||||
if (!($q && dbCount($q))) {
|
||||
return "";
|
||||
}
|
||||
list($oldPId) = dbFetchArray($q);
|
||||
if ($oldPId == $pid) {
|
||||
return "";
|
||||
}
|
||||
$this->sendNewBidMessage($oldPId, $oid, $price);
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function sendOwnerBidMessage($player, $offer, $newPrice, $bidder) {
|
||||
$q = $this->db->query("SELECT fleet,planet FROM sale WHERE id=$offer");
|
||||
list($fid,$pid) = dbFetchArray($q);
|
||||
$qs = "$offer," . (is_null($pid)?0:1);
|
||||
|
||||
if (!is_null($fid)) {
|
||||
$fleet = $this->fleets->call('get', $fid);
|
||||
$g = $fleet['gaships']; $f = $fleet['fighters']; $c = $fleet['cruisers']; $b = $fleet['bcruisers'];
|
||||
if (is_null($pid)) {
|
||||
$pid = $fleet['location'];
|
||||
}
|
||||
} else {
|
||||
$g=$f=$c=$b=0;
|
||||
}
|
||||
$pinf = $this->planets->call('byId', $pid);
|
||||
$pname = $pinf['name'];
|
||||
|
||||
$qs .= ",'".addslashes($pname)."',$pid,$g,$f,$c,$b,$newPrice";
|
||||
|
||||
$tm = time();
|
||||
$this->db->query("INSERT INTO message(player,sent_on,mtype,ftype,is_new) VALUES($player,$tm,'bid','INT',TRUE)");
|
||||
$q = $this->db->query("SELECT id FROM message WHERE player=$player AND sent_on=$tm AND mtype='bid' ORDER BY id DESC LIMIT 1");
|
||||
list($mid) = dbFetchArray($q);
|
||||
$this->db->query("INSERT INTO msg_bid VALUES($mid,$qs,$bidder)");
|
||||
}
|
||||
|
||||
|
||||
function sendNewBidMessage($player, $offer, $newPrice) {
|
||||
$q = $this->db->query("SELECT fleet,planet FROM sale WHERE id=$offer");
|
||||
list($fid,$pid) = dbFetchArray($q);
|
||||
$qs = "$offer," . (is_null($pid)?0:1);
|
||||
|
||||
if (!is_null($fid)) {
|
||||
$fleet = $this->fleets->call('get', $fid);
|
||||
$g = $fleet['gaships']; $f = $fleet['fighters']; $c = $fleet['cruisers']; $b = $fleet['bcruisers'];
|
||||
if (is_null($pid)) {
|
||||
$pid = $fleet['location'];
|
||||
}
|
||||
} else {
|
||||
$g=$f=$c=$b=0;
|
||||
}
|
||||
$pinf = $this->planets->call('byId', $pid);
|
||||
$pname = $pinf['name'];
|
||||
|
||||
$qs .= ",'".addslashes($pname)."',$pid,$g,$f,$c,$b,$newPrice";
|
||||
|
||||
$tm = time();
|
||||
$this->db->query("INSERT INTO message(player,sent_on,mtype,ftype,is_new) VALUES($player,$tm,'bid','INT',TRUE)");
|
||||
$q = $this->db->query("SELECT id FROM message WHERE player=$player AND sent_on=$tm AND mtype='bid' ORDER BY id DESC LIMIT 1");
|
||||
list($mid) = dbFetchArray($q);
|
||||
$this->db->query("INSERT INTO msg_bid VALUES($mid,$qs,NULL)");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
61
scripts/game/beta5/sale/library/buy.inc
Normal file
61
scripts/game/beta5/sale/library/buy.inc
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_buy {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_buy($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
}
|
||||
|
||||
|
||||
function run($pid, $offer) {
|
||||
$q = $this->db->query(
|
||||
"SELECT player,fleet,planet FROM sale "
|
||||
. "WHERE id=$offer AND player<>$pid AND finalized IS NULL AND "
|
||||
. "(expires IS NULL OR expires>UNIX_TIMESTAMP(NOW()))"
|
||||
);
|
||||
if (!($q && dbCount($q))) {
|
||||
return "0";
|
||||
}
|
||||
list($seller,$flId,$plId) = dbFetchArray($q);
|
||||
|
||||
$q = $this->db->query("SELECT price FROM public_offer WHERE offer=$offer AND NOT auction UNION SELECT price FROM private_offer WHERE offer=$offer");
|
||||
if (!($q && dbCount($q))) {
|
||||
return "0";
|
||||
}
|
||||
list($price) = dbFetchArray($q);
|
||||
|
||||
$pi = $this->players->call('get', $pid);
|
||||
if ($pi['cash'] < $price) {
|
||||
return "1";
|
||||
}
|
||||
|
||||
$tm = time();
|
||||
$this->db->query("UPDATE player SET cash=cash-$price WHERE id=$pid");
|
||||
$this->db->query("UPDATE player SET cash=cash+$price WHERE id=$seller");
|
||||
$this->db->query("UPDATE sale SET finalized=$tm,sold_to=$pid WHERE id=$offer");
|
||||
|
||||
// Start owner transfer
|
||||
if (is_null($plId)) {
|
||||
$qs = "";
|
||||
} else {
|
||||
$this->db->query("UPDATE planet SET sale=3 WHERE id=$plId");
|
||||
$q = $this->db->query("SELECT pop,turrets,ifact+mfact FROM planet WHERE id=$plId");
|
||||
list($pop,$turrets,$fact) = dbFetchArray($q);
|
||||
$qs = ",p_pop=$pop,p_turrets=$turrets,p_factories=$fact";
|
||||
}
|
||||
if (!is_null($flId)) {
|
||||
$this->db->query("UPDATE fleet SET sale=3 WHERE id=$flId");
|
||||
}
|
||||
|
||||
// Update history
|
||||
$this->db->query("UPDATE sale_history SET ended=$tm,end_mode=2,sell_price=$price,to_player=$pid$qs WHERE offer=$offer");
|
||||
|
||||
// FIXME: send message
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
45
scripts/game/beta5/sale/library/cancel.inc
Normal file
45
scripts/game/beta5/sale/library/cancel.inc
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_cancel {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_cancel($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($pid,$id) {
|
||||
$q = $this->db->query("SELECT planet FROM sale WHERE player=$pid AND id=$id AND finalized IS NULL");
|
||||
if (!($q && dbCount($q))) {
|
||||
return false;
|
||||
}
|
||||
list($pl) = dbFetchArray($q);
|
||||
|
||||
// Refund auctions
|
||||
$q = $this->db->query("SELECT MAX(price),player FROM auction WHERE offer=$id GROUP BY player");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$this->db->query("UPDATE player SET cash=cash+".$r[0]." WHERE id=".$r[1]);
|
||||
// FIXME: send message
|
||||
}
|
||||
|
||||
// Insert history entry
|
||||
if (is_null($pl)) {
|
||||
$qs = "";
|
||||
} else {
|
||||
$q = $this->db->query("SELECT pop,turrets,ifact+mfact FROM planet WHERE id=$pl");
|
||||
list($pop,$turrets,$fact) = dbFetchArray($q);
|
||||
$qs = ",p_pop=$pop,p_turrets=$turrets,p_factories=$fact";
|
||||
}
|
||||
$tm = time();
|
||||
$this->db->query("UPDATE sale_history SET end_mode=0,ended=$tm$qs WHERE offer=$id");
|
||||
|
||||
// Delete offer
|
||||
$this->db->query("DELETE FROM sale WHERE id=$id");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
61
scripts/game/beta5/sale/library/cancelTransfer.inc
Normal file
61
scripts/game/beta5/sale/library/cancelTransfer.inc
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_cancelTransfer {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_cancelTransfer($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($pid,$id) {
|
||||
// Get sale details
|
||||
$q = $this->db->query("SELECT planet,fleet,sold_to FROM sale WHERE player=$pid AND id=$id AND finalized IS NOT NULL");
|
||||
if (!($q && dbCount($q))) {
|
||||
return false;
|
||||
}
|
||||
list($pl,$fl,$stid) = dbFetchArray($q);
|
||||
$q = $this->db->query("SELECT price FROM public_offer WHERE offer=$id UNION SELECT price FROM private_offer WHERE offer=$id");
|
||||
list($price) = dbFetchArray($q);
|
||||
|
||||
// Get seller cash and find out if refund is possible
|
||||
$q = $this->db->query("SELECT cash FROM player WHERE id=$pid");
|
||||
list($cSeller) = dbFetchArray($q);
|
||||
if ($cSeller < $price) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Refund
|
||||
$this->db->query("UPDATE player SET cash=cash+$price WHERE id=$stid");
|
||||
$this->db->query("UPDATE player SET cash=cash-$price WHERE id=$pid");
|
||||
|
||||
// Cancel planet & fleet sale
|
||||
if (is_null($pl)) {
|
||||
$qs = "";
|
||||
} else {
|
||||
$this->db->query("UPDATE planet SET sale=NULL WHERE id=$pl");
|
||||
$q = $this->db->query("SELECT pop,turrets,ifact+mfact FROM planet WHERE id=$pl");
|
||||
list($pop,$turrets,$fact) = dbFetchArray($q);
|
||||
$qs = ",p_pop=$pop,p_turrets=$turrets,p_factories=$fact";
|
||||
}
|
||||
if (!is_null($fl)) {
|
||||
$this->db->query("UPDATE fleet SET sale=NULL WHERE id=$fl");
|
||||
}
|
||||
|
||||
// Insert history entries
|
||||
$tm = time();
|
||||
$this->db->query("UPDATE sale_history SET end_mode=1,ended=$tm,sell_price=NULL$qs WHERE offer=$id");
|
||||
|
||||
// Send message
|
||||
// FIXME
|
||||
|
||||
// Delete offer
|
||||
$this->db->query("DELETE FROM sale WHERE id=$id");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
39
scripts/game/beta5/sale/library/decline.inc
Normal file
39
scripts/game/beta5/sale/library/decline.inc
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_decline {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_decline($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($id) {
|
||||
$q = $this->db->query("SELECT planet FROM sale WHERE id=$id");
|
||||
if (!($q&&dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($pl) = dbFetchArray($q);
|
||||
|
||||
// Update history entry
|
||||
if (is_null($pl)) {
|
||||
$qs = "";
|
||||
} else {
|
||||
$q = $this->db->query("SELECT pop,turrets,ifact+mfact FROM planet WHERE id=$pl");
|
||||
list($pop,$turrets,$fact) = dbFetchArray($q);
|
||||
$qs = ",p_pop=$pop,p_turrets=$turrets,p_factories=$fact";
|
||||
}
|
||||
$tm = time();
|
||||
$this->db->query("UPDATE sale_history SET end_mode=4,ended=$tm$qs WHERE offer=$id");
|
||||
|
||||
// Send message
|
||||
// FIXME
|
||||
|
||||
// Delete offer
|
||||
$this->db->query("DELETE FROM sale WHERE id=$id");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
56
scripts/game/beta5/sale/library/getDirectSales.inc
Normal file
56
scripts/game/beta5/sale/library/getDirectSales.inc
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_getDirectSales {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_getDirectSales($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($pid) {
|
||||
$q = $this->db->query(
|
||||
"SELECT * FROM sale,private_offer WHERE id=offer AND to_player=$pid AND finalized IS NULL AND offer=id "
|
||||
. "AND (expires IS NULL OR expires>UNIX_TIMESTAMP(NOW())) ORDER BY started DESC"
|
||||
);
|
||||
|
||||
$oList = $pList = $fList = array();
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$r['id']] = $r;
|
||||
if (!is_null($r['planet'])) {
|
||||
$pList[$r['planet']] = $r['id'];
|
||||
}
|
||||
if (!is_null($r['fleet'])) {
|
||||
$fList[$r['fleet']] = $r['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($pList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query(
|
||||
"SELECT p.id AS id,pop AS pop,p.turrets AS turrets,p.mfact+p.ifact AS fact,p.orbit AS orbit,s.x AS x,s.y AS y,p.name AS name "
|
||||
. "FROM planet p,system s WHERE p.system=s.id AND p.id IN ($l1)"
|
||||
);
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$pList[$r['id']]]['planet'] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($fList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query(
|
||||
"SELECT f.id AS id,f.gaships AS sg,f.fighters AS sf,f.cruisers AS sc,f.bcruisers AS sb,"
|
||||
."p.id AS pid,p.name AS pname,s.x AS x,s.y AS y,p.orbit AS orbit "
|
||||
. "FROM fleet f,planet p,system s WHERE f.id IN ($l1) AND p.id=f.location AND p.system=s.id"
|
||||
);
|
||||
while ($r = dbFetchHash($q))
|
||||
$oList[$fList[$r['id']]]['fleet'] = $r;
|
||||
}
|
||||
|
||||
return array_values($oList);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
49
scripts/game/beta5/sale/library/getFleetSale.inc
Normal file
49
scripts/game/beta5/sale/library/getFleetSale.inc
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_getFleetSale {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_getFleetSale($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($sId) {
|
||||
$q = $this->db->query("SELECT id,player,expires,finalized,sold_to,fleet FROM sale WHERE id=$sId AND planet IS NULL AND fleet IS NOT NULL");
|
||||
if (!($q && dbCount($q))) {
|
||||
return null;
|
||||
}
|
||||
$r = dbFetchHash($q);
|
||||
|
||||
$q = $this->db->query("SELECT sale FROM fleet WHERE id={$r['fleet']}");
|
||||
if (!($q && dbCount($q)))
|
||||
return null;
|
||||
list($r['tx_time']) = dbFetchArray($q);
|
||||
|
||||
$q = $this->db->query("SELECT price,auction FROM public_offer WHERE offer=".$r['id']);
|
||||
if ($q && dbCount($q)) {
|
||||
$r['public'] = true;
|
||||
list($r['price'],$r['is_auction']) = dbFetchArray($q);
|
||||
$r['is_auction'] = ($r['is_auction'] == 't');
|
||||
if ($r['is_auction']) {
|
||||
$q = $this->db->query("SELECT MAX(price) FROM auction WHERE offer={$r['id']}");
|
||||
if ($q && dbCount($q)) {
|
||||
list($r['max_bid']) = dbFetchArray($q);
|
||||
if (!is_null($r['max_bid'])) {
|
||||
$q = $this->db->query("SELECT player,moment FROM auction WHERE offer={$r['id']} AND price={$r['max_bid']}");
|
||||
list($r['bidder'],$r['last_bid']) = dbFetchArray($q);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
$q = $this->db->query("SELECT price,to_player FROM private_offer WHERE offer=".$r['id']);
|
||||
list($r['price'],$r['sold_to']) = dbFetchArray($q);
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
33
scripts/game/beta5/sale/library/getPlanetSale.inc
Normal file
33
scripts/game/beta5/sale/library/getPlanetSale.inc
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_getPlanetSale {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_getPlanetSale($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($id) {
|
||||
$q = $this->db->query("SELECT id,expires,finalized,sold_to FROM sale WHERE planet=$id");
|
||||
if (!($q && dbCount($q))) {
|
||||
return null;
|
||||
}
|
||||
$r = dbFetchHash($q);
|
||||
|
||||
$q = $this->db->query("SELECT price FROM public_offer WHERE offer=".$r['id']);
|
||||
if ($q && dbCount($q)) {
|
||||
$r['public'] = true;
|
||||
list($r['price']) = dbFetchArray($q);
|
||||
return $r;
|
||||
}
|
||||
|
||||
$q = $this->db->query("SELECT price,to_player FROM private_offer WHERE offer=".$r['id']);
|
||||
list($r['price'],$r['sold_to']) = dbFetchArray($q);
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
77
scripts/game/beta5/sale/library/getPublicSales.inc
Normal file
77
scripts/game/beta5/sale/library/getPublicSales.inc
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_getPublicSales {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_getPublicSales($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($pList) {
|
||||
$l1 = join(',',$pList);
|
||||
|
||||
$q = $this->db->query("SELECT id FROM fleet WHERE location IN ($l1)");
|
||||
$fList = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
array_push($fList, $r[0]);
|
||||
}
|
||||
$l2 = join(',',$fList);
|
||||
|
||||
$q = $this->db->query(
|
||||
"SELECT * FROM sale,public_offer "
|
||||
. "WHERE finalized IS NULL AND offer=id AND (expires IS NULL OR expires>UNIX_TIMESTAMP(NOW())) "
|
||||
. "AND (planet IN ($l1)" . ($l2 != '' ? " OR fleet IN ($l2)" : "") . ")"
|
||||
);
|
||||
$aList = $oList = $pList = $fList = array();
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$r['id']] = $r;
|
||||
if (!is_null($r['planet'])) {
|
||||
$pList[$r['planet']] = $r['id'];
|
||||
}
|
||||
if (!is_null($r['fleet'])) {
|
||||
$fList[$r['fleet']] = $r['id'];
|
||||
}
|
||||
if ($r['auction'] == 't') {
|
||||
$aList[$r['id']] = $r['price'];
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($aList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query("SELECT offer,MAX(price) FROM auction WHERE offer IN ($l1) GROUP BY offer");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$oList[$r[0]]['price'] = $r[1];
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($pList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query(
|
||||
"SELECT p.id AS id,pop AS pop,p.turrets AS turrets,p.mfact+p.ifact AS fact,p.orbit AS orbit,s.x AS x,s.y AS y,p.name AS name "
|
||||
. "FROM planet p,system s WHERE p.system=s.id AND p.id IN ($l1)"
|
||||
);
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$pList[$r['id']]]['planet'] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($fList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query(
|
||||
"SELECT f.id AS id,f.gaships AS sg,f.fighters AS sf,f.cruisers AS sc,f.bcruisers AS sb,"
|
||||
."p.id AS pid,p.name AS pname,s.x AS x,s.y AS y,p.orbit AS orbit "
|
||||
. "FROM fleet f,planet p,system s WHERE f.id IN ($l1) AND p.id=f.location AND p.system=s.id"
|
||||
);
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$fList[$r['id']]]['fleet'] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($oList);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
85
scripts/game/beta5/sale/library/getSentOffers.inc
Normal file
85
scripts/game/beta5/sale/library/getSentOffers.inc
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_getSentOffers {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_getSentOffers($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($pid) {
|
||||
$q = $this->db->query(
|
||||
"SELECT * FROM sale WHERE player=$pid AND finalized IS NULL "
|
||||
. "AND (expires IS NULL OR expires>UNIX_TIMESTAMP(NOW()))"
|
||||
);
|
||||
|
||||
$oList = $pList = $fList = array();
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$r['id']] = $r;
|
||||
if (!is_null($r['planet'])) {
|
||||
$pList[$r['planet']] = $r['id'];
|
||||
}
|
||||
if (!is_null($r['fleet'])) {
|
||||
$fList[$r['fleet']] = $r['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($oList));
|
||||
$aList = array();
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query("SELECT * FROM public_offer WHERE offer IN ($l1)");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$oList[$r[0]]['mode'] = ($r[2] == 1 ? 3 : 2);
|
||||
$oList[$r[0]]['price'] = $r[1];
|
||||
if ($r[2])
|
||||
array_push($aList, $r[0]);
|
||||
// FIXME: to_player for auctions
|
||||
}
|
||||
|
||||
$q = $this->db->query("SELECT * FROM private_offer WHERE offer IN ($l1)");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$oList[$r[0]]['mode'] = ($r[2] == 0 ? 0 : 1);
|
||||
$oList[$r[0]]['to_player'] = $r[1];
|
||||
$oList[$r[0]]['price'] = $r[2];
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',', $aList);
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query("SELECT offer,MAX(price) FROM auction WHERE offer IN ($l1) GROUP BY offer");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$oList[$r[0]]['price'] = $r[1];
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($pList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query(
|
||||
"SELECT p.id AS id,pop AS pop,p.turrets AS turrets,p.mfact+p.ifact AS fact,p.orbit AS orbit,s.x AS x,s.y AS y,p.name AS name "
|
||||
. "FROM planet p,system s WHERE p.system=s.id AND p.id IN ($l1)"
|
||||
);
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$pList[$r['id']]]['planet'] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
$l1 = join(',',array_keys($fList));
|
||||
if ($l1 != '') {
|
||||
$q = $this->db->query(
|
||||
"SELECT f.id AS id,f.gaships AS sg,f.fighters AS sf,f.cruisers AS sc,f.bcruisers AS sb,"
|
||||
."p.id AS pid,p.name AS pname,s.x AS x,s.y AS y,p.orbit AS orbit "
|
||||
. "FROM fleet f,planet p,system s WHERE f.id IN ($l1) AND p.id=f.location AND p.system=s.id"
|
||||
);
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$oList[$fList[$r['id']]]['fleet'] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($oList);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
69
scripts/game/beta5/sale/library/sell.inc
Normal file
69
scripts/game/beta5/sale/library/sell.inc
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
class beta5_sale_sell {
|
||||
var $index = array();
|
||||
|
||||
|
||||
function beta5_sale_sell($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->planets = $this->lib->game->getLib('beta5/planet');
|
||||
$this->fleets = $this->lib->game->getLib('beta5/fleet');
|
||||
}
|
||||
|
||||
|
||||
function run($player, $public, $auction, $expires, $price, $target, $planet, $fleet) {
|
||||
// Insert sale entry
|
||||
$tm = time();
|
||||
$exp = ($expires > 0) ? ($tm + 3600 * $expires) : 'NULL';
|
||||
$pl = is_null($planet)?'NULL':$planet;
|
||||
$plq = is_null($planet)?' IS NULL':"=$planet";
|
||||
$fl = is_null($fleet)?'NULL':$fleet;
|
||||
$flq = is_null($fleet)?' IS NULL':"=$fleet";
|
||||
$this->db->query("INSERT INTO sale(player,started,expires,planet,fleet) VALUES ($player,$tm,$exp,$pl,$fl)");
|
||||
|
||||
// Insert offer
|
||||
$q = $this->db->query("SELECT id FROM sale WHERE player=$player AND started=$tm AND planet$plq AND fleet$flq");
|
||||
list($sId) = dbFetchArray($q);
|
||||
if ($public) {
|
||||
$this->db->query("INSERT INTO public_offer VALUES($sId,$price,".dbBool($auction).")");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO private_offer VALUES($sId,$target,$price)");
|
||||
}
|
||||
|
||||
// Insert history entry
|
||||
$mode = $public ? ($auction ? 3 : 2) : ($price > 0 ? 1 : 0);
|
||||
$toPl = $public ? "NULL" : $target;
|
||||
if (is_null($planet)) {
|
||||
$finf = $this->fleets->call('get', $fleet);
|
||||
$pinf = $this->planets->call('byId', $finf['location']);
|
||||
$pName = addslashes($pinf['name']);
|
||||
$pid = $finf['location'];
|
||||
} else {
|
||||
$pinf = $this->planets->call('byId', $planet);
|
||||
$pid = $planet;
|
||||
$pName = addslashes($pinf['name']);
|
||||
}
|
||||
if (is_null($fleet)) {
|
||||
$flFields = $flValues = "";
|
||||
} else {
|
||||
if (is_null($finf)) {
|
||||
$finf = $this->fleets->call('get', $fleet);
|
||||
}
|
||||
$flFields = ",f_gaships,f_fighters,f_cruisers,f_bcruisers";
|
||||
$flValues = ",".$finf['gaships'].",".$finf['fighters'].",".$finf['cruisers'].",".$finf['bcruisers'];
|
||||
}
|
||||
$this->db->query(
|
||||
"INSERT INTO sale_history(offer,from_player,to_player,started,mode,price,p_id,p_name,is_planet$flFields) VALUES"
|
||||
. "($sId,$player,$toPl,$tm,$mode,$price,$pid,'$pName',".dbBool(!is_null($planet))."$flValues)"
|
||||
);
|
||||
|
||||
// FIXME: send messages
|
||||
|
||||
if (!is_null($fleet)) {
|
||||
$this->fleets->call('invCache', $fleet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue