Added full source code

This commit is contained in:
Emmanuel BENOîT 2016-01-10 11:01:49 +01:00
commit 33f8586698
1377 changed files with 123808 additions and 0 deletions

View file

@ -0,0 +1,23 @@
<?php
class beta5_player_addEnemyAlliance {
function beta5_player_addEnemyAlliance($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Adds an alliance to the enemy list
function run($pid, $eid) {
$this->db->query("INSERT INTO enemy_alliance VALUES($pid,$eid)");
$q = $this->db->query("SELECT id FROM player WHERE alliance=$eid AND a_status='IN'");
$al = array();
while ($r = dbFetchArray($q)) {
array_push($al, $r[0]);
}
$this->lib->call('makeEnemies', $pid, $al);
}
}
?>

View file

@ -0,0 +1,53 @@
<?php
class beta5_player_assign {
function beta5_player_assign($lib) {
$this->lib = $lib;
$this->game = $this->lib->game;
$this->db = $this->game->db;
$this->planets = $this->game->getLib('beta5/planet');
}
// Assign a planet to a player
function run($pid, $planet) {
$q = $this->db->query("SELECT id FROM system WHERE NOT assigned ORDER BY RANDOM() LIMIT 1");
list($sid) = dbFetchArray($q);
$npl = 6;
$porb = rand(0, $npl - 1);
$tm = time();
$pQuery = "";
if ($this->game->params['victory'] == 0) {
$fTick = $this->game->ticks['day']->first;
$this->db->query("DELETE FROM pk_enemy WHERE until < UNIX_TIMESTAMP(NOW())");
$q = $this->db->query("SELECT * FROM pk_enemy WHERE player = $pid");
if ($tm - $fTick >= $this->game->params['prot_after'] * 86400 && dbCount($q) == 0) {
$pQuery = ",prot = " . $this->game->params['prot_duration'];
}
}
$p = addslashes($planet);
$this->db->query(
"UPDATE planet SET name = '$p', owner = $pid, renamed = $tm,mod_check = FALSE "
. "WHERE system = $sid AND orbit = $porb"
);
$this->db->query("UPDATE system SET assigned = TRUE$pQuery WHERE id=$sid");
$q = $this->db->query("SELECT id,pop FROM planet WHERE system=$sid AND orbit=$porb FOR UPDATE");
list($plid, $cPop) = dbFetchArray($q);
$this->planets->call('updateHappiness', $plid);
$this->planets->call('updateMaxPopulation', $plid, null, $pid);
$this->db->query(
"INSERT INTO planet_abandon_time (id, time_required) "
. "VALUES ($plid, 6)"
);
return $plid;
}
}
?>

View file

@ -0,0 +1,54 @@
<?php
//-----------------------------------------------------------------------
// LegacyWorlds Beta 5
// Game libraries
//
// beta5/player/library/breakProtection.inc
//
// This function causes a player to break from protection by the
// Peacekeepers.
//
// Parameters:
// $playerID ID of the player
// $breakType Either 'ACT' or 'BRK'
//
// Copyright(C) 2004-2008, DeepClone Development
//-----------------------------------------------------------------------
class beta5_player_breakProtection {
public function __construct($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->msgs = $this->lib->game->getLib('beta5/msg');
}
public function run($playerID, $breakType) {
// Get protection level and system ID
$q = $this->db->query(
"SELECT s.id, s.prot FROM system s "
. "WHERE s.id IN (SELECT DISTINCT p.system FROM planet p WHERE p.owner = $playerID) "
. "FOR UPDATE"
);
if (dbCount($q) != 1) {
return 0;
}
list($systemID, $protLevel) = dbFetchArray($q);
if ($protLevel == 0) {
return;
}
// Set the system's protection level to 0
$this->db->query("UPDATE system SET prot = 0 WHERE id = $systemID");
$this->db->query("DELETE FROM pk_sys_status WHERE system = $systemID");
// Send message
$this->msgs->call('send', $playerID, 'endprotection', array(
'end_type' => $breakType
));
}
}
?>

View file

@ -0,0 +1,35 @@
<?php
class beta5_player_checkAllies {
function beta5_player_checkAllies($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Checks players that have set a player as trusted allies in order to know whether the player can control their fleets
function run($pid) {
$allies = $this->lib->call('isAllyOf', $pid);
$res = array();
foreach ($allies as $ally => $crap) {
if ($this->lib->call('isOnline', $ally) || $this->lib->call('isOnVacation', $ally)) {
continue;
}
$aList = $this->lib->call('getAllies', $ally);
foreach ($aList as $aa) {
if ($aa['id'] == $pid) {
array_push($res, $ally);
break;
}
if ($this->lib->call('isOnline', $aa['id'])) {
break;
}
}
}
return $res;
}
}
?>

View file

@ -0,0 +1,73 @@
<?php
class beta5_player_get {
function beta5_player_get($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($id, $quitOk = false) {
if (is_null($id)) {
l::warn("****** BUG: beta5::player::get(null)");
if (config::$main['debug'] == 2) {
l::backtrace();
}
return null;
}
if (is_array($this->lib->mainClass->players[$id])) {
if (!$quitOk && $this->lib->mainClass->players[$id]["quit"] == "1") {
return null;
}
return $this->lib->mainClass->players[$id];
}
$s = $quitOk ? "" : "AND (p.quit IS NULL OR UNIX_TIMESTAMP(NOW()) - p.quit < 86400)";
$q = $this->db->query(
"SELECT u.id,u.name,p.name,p.cash,p.alliance,TRIM(p.a_status),p.a_vote,p.a_grade,"
. "(p.quit IS NOT NULL AND UNIX_TIMESTAMP(NOW()) - p.quit >= 86400),p.quit,"
. "(u.status='VAC') "
. "FROM account u, player p "
. "WHERE p.id=$id $s AND u.id=p.userid"
);
if (!($q && dbCount($q))) {
return null;
}
$a = dbFetchArray($q);
$pinf = array(
"uid" => $a[0],
"pid" => $id,
"name" => ($a[2] != "")?$a[2]:$a[1],
"cash" => $a[3],
"quit" => $a[8] == 't',
"qts" => $a[9],
"vac" => ($a[10] == 't'),
);
if (is_null($this->lib->mainClass->pNames[$id])) {
$this->lib->mainClass->pNames[$id] = $pinf['name'];
}
if ($a[5] == "IN") {
$q = $this->db->query("SELECT tag, name FROM alliance WHERE id=".$a[4]);
$pinf['aid'] = $a[4];
$pinf['vote'] = $a[6];
$pinf['a_grade'] = $a[7];
list($pinf['alliance'], $pinf['aname']) = dbFetchArray($q);
} elseif ($a[5] == "REQ") {
$q = $this->db->query("SELECT tag, name FROM alliance WHERE id=".$a[4]);
$pinf['arid'] = $a[4];
list($pinf['alliance_req'], $pinf['aname']) = dbFetchArray($q);
}
$q = $this->db->query("SELECT COUNT(*) FROM planet WHERE owner=$id");
list($pinf["planets"]) = dbFetchArray($q);
$this->lib->mainClass->players[$id] = $pinf;
return $pinf;
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_getAllies {
function beta5_player_getAllies($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Get the list of a player's trusted allies
function run($pid) {
$q = $this->db->query(
"SELECT l.friend,p.name,u.name FROM trusted l,player p,account u "
. "WHERE l.player=$pid AND p.id=l.friend AND u.id=p.userid "
. "ORDER BY level ASC"
);
$al = array();
while ($r = dbFetchArray($q)) {
array_push($al, array('id' => $r[0], 'name' => is_null($r[1]) ? $r[2] : $r[1]));
}
return $al;
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_getDiploSummary {
function beta5_player_getDiploSummary($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Returns a summary of the player's diplomatic relations
function run($pid) {
$q = $this->db->query("SELECT COUNT(*) FROM enemy_player WHERE player=$pid");
list($c0) = dbFetchArray($q);
$q = $this->db->query("SELECT COUNT(*) FROM enemy_alliance WHERE player=$pid");
list($c1) = dbFetchArray($q);
$q = $this->db->query("SELECT COUNT(*) FROM trusted WHERE player=$pid");
list($c2) = dbFetchArray($q);
$q = $this->db->query("SELECT COUNT(*) FROM trusted WHERE friend=$pid");
list($c3) = dbFetchArray($q);
return array($c0,$c1,$c2,$c3);
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_getEnemies {
function beta5_player_getEnemies($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Get the list of enemy players
function run($pid) {
$q = $this->db->query(
"SELECT p.id,p.name,u.name FROM enemy_player e,player p,account u "
. "WHERE e.player=$pid AND e.enemy=p.id AND u.id=p.userid"
);
$rs = array();
while ($r = dbFetchArray($q)) {
$rs[$r[0]] = is_null($r[1]) ? $r[2] : $r[1];
}
return $rs;
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_getEnemyAlliances {
function beta5_player_getEnemyAlliances($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Get the list of enemy alliances
function run($pid) {
$q = $this->db->query(
"SELECT a.id,a.tag FROM enemy_alliance e,alliance a "
. "WHERE e.player=$pid AND e.alliance=a.id"
);
$rs = array();
while ($r = dbFetchArray($q)) {
$rs[$r[0]] = is_null($r[1]) ? $r[2] : $r[1];
}
return $rs;
}
}
?>

View file

@ -0,0 +1,22 @@
<?php
class beta5_player_getFleets {
function beta5_player_getFleets($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Returns the list of a player's fleets
function run($pid) {
$q = $this->db->query("SELECT id,name FROM fleet WHERE owner = $pid");
$a = array();
while ($r = dbFetchArray($q)) {
$a[$r[0]] = $r[1];
}
return $a;
}
}
?>

View file

@ -0,0 +1,29 @@
<?php
class beta5_player_getName {
function beta5_player_getName($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Returns the name of a player
function run($id) {
if (is_null($id)) {
logText("****** BUG: beta5::player::getName(null) called");
l::backtrace();
return null;
}
if (!is_null($this->lib->mainClass->pNames[$id])) {
return $this->lib->mainClass->pNames[$id];
}
$q = $this->db->query(
"SELECT u.name,p.name FROM account u, player p WHERE p.id=$id AND u.id=p.userid"
);
list($an,$pn) = dbFetchArray($q);
return ($this->lib->mainClass->pNames[$id] = is_null($pn) ? $an : $pn);
}
}
?>

View file

@ -0,0 +1,26 @@
<?php
class beta5_player_getPlanetCount {
var $pPlanets = array();
function beta5_player_getPlanetCount($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Returns the amount of planets a player controls
function run($pl) {
if (is_null($pl)) {
return 1;
}
if (!is_null($this->pPlanets[$pl])) {
return $this->pPlanets[$pl];
}
$q = $this->db->query("SELECT COUNT(*) FROM planet WHERE owner=$pl");
list($this->pPlanets[$pl]) = dbFetchArray($q);
return $this->pPlanets[$pl];
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_getPlanets {
function beta5_player_getPlanets($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Returns the list of a player's planets
function run($pid) {
$q = $this->db->query(
"SELECT p.id, p.name FROM planet p, system s "
. "WHERE p.owner = $pid AND s.id = p.system "
. "ORDER BY s.x, s.y, p.orbit");
$a = array();
while ($r = dbFetchArray($q)) {
$a[$r[0]] = $r[1];
}
return $a;
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
class beta5_player_getPlayerId {
var $players = array();
function beta5_player_getPlayerId($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
/** Returns a player's ID using his name to locate him. */
function run($name) {
$n = strtolower($name);
if (is_null($this->players[$n])) {
$n2 = addslashes($n);
$q = $this->db->query(
"SELECT p.id FROM account u, player p "
. "WHERE (p.quit IS NULL OR UNIX_TIMESTAMP(NOW())-p.quit<86400)"
. " AND u.id=p.userid AND ((p.name IS NULL AND LOWER(u.name)='$n2') OR LOWER(p.name)='$n2')"
);
if (!($q && dbCount($q) == 1)) {
return null;
}
list($this->players[$n]) = dbFetchArray($q);
}
return $this->players[$n];
}
}
?>

View file

@ -0,0 +1,24 @@
<?php
class beta5_player_getPower {
var $pFleets = array();
function beta5_player_getPower($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->fleets = $this->lib->game->getLib('beta5/fleet');
}
// Returns a player's total fleet power
function run($pid) {
if (!is_null($this->pFleets[$pid])) {
return $this->pFleets[$pid];
}
$q = $this->db->query("SELECT SUM(gaships),SUM(fighters),SUM(cruisers),SUM(bcruisers) FROM fleet WHERE owner = $pid");
list($g,$f,$c,$b) = dbFetchArray($q);
return ($this->pFleets[$pid] = $this->fleets->call('getPower', $pid, $g, $f, $c, $b));
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_getProtectionLevel {
function beta5_player_getProtectionLevel($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Returns a player's protection level
function run($pid) {
$q = $this->db->query(
"SELECT s.prot FROM system s "
. "WHERE s.id IN (SELECT DISTINCT p.system FROM planet p WHERE p.owner = $pid)"
);
if (dbCount($q) != 1) {
return 0;
}
list($prot) = dbFetchArray($q);
return $prot;
}
}
?>

View file

@ -0,0 +1,21 @@
<?php
class beta5_player_getRealPlanetCount {
function beta5_player_getRealPlanetCount($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($id) {
$c = $this->lib->call('getPlanetCount', $id);
$q = $this->db->query("SELECT COUNT(*) FROM sale WHERE player=$id AND planet IS NOT NULL");
list($scount) = dbFetchArray($q);
$q = $this->db->query("SELECT COUNT(*) FROM planet WHERE owner=$id AND (abandon<>0 OR bh_prep<>0)");
list($acount) = dbFetchArray($q);
return $c - ($scount + $acount);
}
}
?>

View file

@ -0,0 +1,27 @@
<?php
class beta5_player_getTAListBans {
function beta5_player_getTAListBans($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Get the list of players in a player's T.A. blacklist
function run($pid) {
$q = $this->db->query(
"SELECT l.ban_player,p.name,u.name FROM trusted_ban l,player p,account u "
. "WHERE l.player=$pid AND p.id=l.ban_player AND u.id=p.userid"
. " AND (p.quit IS NULL OR UNIX_TIMESTAMP(NOW())-p.quit<86400)"
);
$al = array();
while ($r = dbFetchArray($q)) {
logText(join(' - ', $r));
$al[$r[0]] = is_null($r[1]) ? $r[2] : $r[1];
}
return $al;
}
}
?>

View file

@ -0,0 +1,25 @@
<?php
class beta5_player_isAllyOf {
function beta5_player_isAllyOf($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Get the list of players who have a player as a trusted ally
function run($pid) {
$q = $this->db->query(
"SELECT l.player,l.level,p.name,u.name FROM trusted l,player p,account u "
. "WHERE l.friend=$pid AND p.id=l.player AND u.id=p.userid"
);
$al = array();
while ($r = dbFetchArray($q)) {
$al[$r[0]] = array('name' => is_null($r[2]) ? $r[3] : $r[2], "level" => $r[1]);
}
return $al;
}
}
?>

View file

@ -0,0 +1,32 @@
<?php
class beta5_player_isOnVacation {
function beta5_player_isOnVacation($lib) {
$this->lib = $lib;
$this->game = $this->lib->game;
$this->db = $this->game->getDBAccess();
$this->main = $this->game->getLib();
$this->vac = $this->game->getLib('main/vacation');
}
// Checks whether a player is currently on vacation
function run($pid) {
if ($this->main->call('isFinished')) {
return true;
}
if ($this->lib->game->params['novacation'] == 1) {
return false;
}
$p = $this->lib->call('get', $pid);
if (is_null($p)) {
return false;
}
return $this->vac->call('isOnVacation', $p['uid']);
}
}
?>

View file

@ -0,0 +1,22 @@
<?php
class beta5_player_isOnline {
function beta5_player_isOnline($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->main = $this->lib->game->getLib('main/account');
}
// Checks whether a player is currently online
function run($pid) {
$p = $this->lib->call('get', $pid);
if (is_null($p)) {
return false;
}
return $this->main->call('isOnline', $p['uid']);
}
}
?>

View file

@ -0,0 +1,22 @@
<?php
class beta5_player_isRestrained {
function beta5_player_isRestrained($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Checks whether a player is restrained or not
function run($pid) {
$q = $this->db->query("SELECT restrain FROM player WHERE id = $pid");
if (!($q || dbCount($q))) {
return 666;
}
list($r) = dbFetchArray($q);
return $r;
}
}
?>

View file

@ -0,0 +1,24 @@
<?php
class beta5_player_lastOnline {
function beta5_player_lastOnline($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->main = $this->lib->game->getLib('main/account');
}
// Returns the timestamp at which the player last logged out,
// or 0 if the player is online at the moment
function run($playerID) {
$player = $this->lib->call('get', $playerID, true);
if (is_null($player)) {
return 0;
}
return $this->main->call('lastOnline', $player['uid']);
}
}
?>

View file

@ -0,0 +1,53 @@
<?php
class beta5_player_makeEnemies {
function beta5_player_makeEnemies($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');
}
// Sets players' fleets to attack mode when they're added to an enemy list
function run($pid, $elist) {
$lmsg = array();
$q = $this->db->query(
"SELECT f.id,p.id,f.owner FROM fleet f,planet p "
. "WHERE p.owner=$pid AND f.location=p.id AND NOT f.attacking AND f.owner IN (".join(',',$elist).")"
);
while ($r = dbFetchArray($q)) {
$this->db->query("UPDATE fleet SET attacking=".dbBool(1).",can_move='B' WHERE id=".$r[0]);
if (!is_array($lmsg[$r[1]])) {
$lmsg[$r[1]] = array();
}
if (!is_array($lmsg[$r[1]][$r[2]])) {
$lmsg[$r[1]][$r[2]] = array();
}
array_push($lmsg[$r[1]][$r[2]], $r[0]);
}
$pids = array_keys($lmsg);
$tm = time();
foreach ($pids as $pl) {
$this->planets->call('updateMilStatus', $pl);
$pinf = $this->planets->call('byId', $pl);
$pn = addslashes($pinf['name']);
foreach ($lmsg[$pl] AS $plid => $fl) {
$q = $this->db->query("SELECT COUNT(*),SUM(gaships),SUM(fighters),SUM(cruisers),SUM(bcruisers) FROM fleet"
. " WHERE id IN (".join(',',$fl).")");
list($nf,$g,$f,$c,$b) = dbFetchArray($q);
$fp = $this->fleets->call('getPower', $plid, $g,$f,$c,$b);
$this->db->query("INSERT INTO message(player,sent_on,mtype,ftype,is_new) VALUES($plid,$tm,'flswitch','INT',TRUE)");
$q = $this->db->query("SELECT id FROM message WHERE player=$plid AND sent_on=$tm AND mtype='flswitch' ORDER BY id DESC LIMIT 1");
list($mid) = dbFetchArray($q);
$this->db->query("INSERT INTO msg_flswitch VALUES($mid,$pl,'$pn',$nf,$fp)");
}
}
}
}
?>

View file

@ -0,0 +1,22 @@
<?php
class beta5_player_moveAllyDown {
function beta5_player_moveAllyDown($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Move an ally down the list
function run($pid, $it) {
$q = $this->db->query("SELECT COUNT(*) FROM trusted WHERE player=$pid");
list($all) = dbFetchArray($q);
$np = $it + 1;
$this->db->query("UPDATE trusted SET level=$all WHERE player=$pid AND level=$it");
$this->db->query("UPDATE trusted SET level=$it WHERE player=$pid AND level=$np");
$this->db->query("UPDATE trusted SET level=$np WHERE player=$pid AND level=$all");
}
}
?>

View file

@ -0,0 +1,22 @@
<?php
class beta5_player_moveAllyUp {
function beta5_player_moveAllyUp($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Move an ally up the list
function run($pid, $it) {
$q = $this->db->query("SELECT COUNT(*) FROM trusted WHERE player=$pid");
list($all) = dbFetchArray($q);
$np = $it - 1;
$this->db->query("UPDATE trusted SET level=$all WHERE player=$pid AND level=$it");
$this->db->query("UPDATE trusted SET level=$it WHERE player=$pid AND level=$np");
$this->db->query("UPDATE trusted SET level=$np WHERE player=$pid AND level=$all");
}
}
?>

View file

@ -0,0 +1,54 @@
<?php
class beta5_player_reassign {
function beta5_player_reassign($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->fleets = $this->lib->game->getLib('beta5/fleet');
$this->sales = $this->lib->game->getLib('beta5/sale');
}
// Assigns the player a new planet after he loses all of his
function run($player, $name) {
// Delete fleets
$list = array_keys($this->lib->call('getFleets', $player));
foreach ($list as $fId) {
$this->fleets->call('disband', $fId, true);
}
// Cancel all sales from this player
$q = $this->db->query("SELECT id,player,finalized,sold_to FROM sale WHERE player=$player OR sold_to=$player");
while ($r = dbFetchArray($q)) {
list($sid,$seller,$fin,$buyer) = $r;
if (is_null($fin)) {
$ga = 'cancel';
} else {
$ga = 'cancelTransfer';
if ($seller == $id) {
$tInc = 0;
$fInc = 1;
$t = $buyer;
} else {
$tInc = 1;
$fInc = 0;
$t = $seller;
}
}
$this->sales->call($ga, $seller, $sid);
}
// Delete probes
// FIXME
// Assign new planet
$n = addslashes($name);
$plid = $this->lib->call('assign', $player, $n);
$this->db->query("UPDATE player SET first_planet=$plid WHERE id=$player");
return $plid;
}
}
?>

View file

@ -0,0 +1,24 @@
<?php
class beta5_player_reorderAllies {
function beta5_player_reorderAllies($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Reorders the list of allies after it's been modified
function run($pid) {
$q = $this->db->query("SELECT level FROM trusted WHERE player=$pid ORDER BY level ASC");
$i = 0;
while ($r = dbFetchArray($q)) {
if ($r[0] != $i) {
$this->db->query("UPDATE trusted SET level=$i WHERE player=$pid AND level=".$r[0]);
}
$i ++;
}
}
}
?>

View file

@ -0,0 +1,27 @@
<?php
class beta5_player_transferFunds {
function beta5_player_transferFunds($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Transfers cash from an account to another
function run($s, $d, $a) {
// Transfer cash
$this->db->query("UPDATE player SET cash=cash-$a WHERE id=$s");
$this->db->query("UPDATE player SET cash=cash+$a WHERE id=$d");
$this->db->query("INSERT INTO donation_log VALUES(" . time() . ",$s,$d,$a)");
// Send a message to the recipient
$tm = time();
$this->db->query("INSERT INTO message(player,sent_on,mtype,ftype,is_new) VALUES($d,$tm,'cash','INT',TRUE)");
$q = $this->db->query("SELECT id FROM message WHERE player=$d AND sent_on=$tm AND mtype='cash' ORDER BY id DESC LIMIT 1");
list($mid) = dbFetchArray($q);
$this->db->query("INSERT INTO msg_cash VALUES($mid,$s,$a)");
}
}
?>