Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
120
scripts/game/beta5/actions/addTrustedAlly.inc
Normal file
120
scripts/game/beta5/actions/addTrustedAlly.inc
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/addTrustedAlly.inc
|
||||
//
|
||||
// This action adds a player to another player's trusted allies list.
|
||||
//
|
||||
// Parameters:
|
||||
// $player Identifier of the player whose list must be
|
||||
// changed
|
||||
// $allyName Name of the new trusted ally
|
||||
//
|
||||
// Possible return values:
|
||||
// an array The trusted allies data for the player; see
|
||||
// documentation for getTrustedAllies
|
||||
// an integer Error; check the error codes.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_addTrustedAlly
|
||||
extends game_action {
|
||||
|
||||
|
||||
/* ERROR CODES */
|
||||
const playerNotFound = 0; // Player not found
|
||||
const playerOnVacation = 1; // Player is on vacation
|
||||
const noAllyName = 2; // No ally name
|
||||
const invalidAllyName = 3; // Invalid ally name
|
||||
const allyNotFound = 4; // Ally not found
|
||||
const allyIsPlayer = 5; // Ally and player are the same
|
||||
const allyIsEnemy = 6; // New ally is on enemy list
|
||||
const playerBlacklisted = 7; // Player is banned from the new ally's reverse list
|
||||
const allyAlreadyListed = 8; // Ally already in the player's list
|
||||
const maxPlayerTrust = 9; // Player already has 5 trusted allies
|
||||
const maxAllyTrust = 10; // Ally already is trusted by 5 players
|
||||
/***************/
|
||||
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"players" => "beta5/player"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player, $allyName) {
|
||||
// Check if the player ID is not null
|
||||
if (is_null($player)) {
|
||||
return self::playerNotFound;
|
||||
}
|
||||
$player = (int) $player;
|
||||
|
||||
// Check if the player is valid
|
||||
$playerRecord = $this->players->call('get', $player);
|
||||
if (is_null($playerRecord)) {
|
||||
return self::playerNotFound;
|
||||
}
|
||||
|
||||
// Check if the player is on vacation
|
||||
if ($this->players->call('isOnVacation', $player)) {
|
||||
return self::playerOnVacation;
|
||||
}
|
||||
|
||||
// Check the ally's name
|
||||
$allyName = preg_replace('/\s+/', ' ', trim($allyName));
|
||||
if ($allyName == "") {
|
||||
return self::noAllyName;
|
||||
} elseif (strlen($allyName) > 15) {
|
||||
return self::invalidAllyName;
|
||||
}
|
||||
|
||||
// Check the ally's record
|
||||
$ally = $this->players->call('getPlayerId', $allyName);
|
||||
if (is_null($ally)) {
|
||||
return self::allyNotFound;
|
||||
} elseif ($ally == $player) {
|
||||
return self::allyIsPlayer;
|
||||
}
|
||||
|
||||
// Check the enemy list
|
||||
if ($this->players->call('isEnemy', $player, $ally)) {
|
||||
return self::allyIsEnemy;
|
||||
}
|
||||
|
||||
// Check the blacklist
|
||||
if ($this->players->call('checkTAListBan', $ally, $player)) {
|
||||
return self::playerBlacklisted;
|
||||
}
|
||||
|
||||
// Check the player's current TA list
|
||||
$taList = $this->players->call('getAllies', $player);
|
||||
if (count($taList) == 5) {
|
||||
return self::maxPlayerTrust;
|
||||
}
|
||||
foreach ($taList as $id => $data) {
|
||||
if ($data['id'] == $ally) {
|
||||
return self::allyAlreadyListed;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the reverse TA list
|
||||
$taList = $this->players->call('isAllyOf', $ally);
|
||||
if (count($taList) == 5) {
|
||||
return self::maxAllyTrust;
|
||||
}
|
||||
|
||||
// Add to the player's list
|
||||
$this->players->call('addAlly', $player, $ally);
|
||||
|
||||
// Return all trusted allies data
|
||||
return $this->game->action('getTrustedAllies', $player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
101
scripts/game/beta5/actions/banTrustingAlly.inc
Normal file
101
scripts/game/beta5/actions/banTrustingAlly.inc
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/banTrustingAlly.inc
|
||||
//
|
||||
// This action removes a player from other players' trusted allies
|
||||
// lists.
|
||||
//
|
||||
// Parameters:
|
||||
// $player The player to remove from others' lists.
|
||||
// $removeList An array of the player IDs from whose lists
|
||||
// the player must be removed
|
||||
//
|
||||
// Possible return values:
|
||||
// an array The trusted allies data for the player; see
|
||||
// documentation for getTrustedAllies
|
||||
// an integer Error; check the error codes.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_banTrustingAlly
|
||||
extends game_action {
|
||||
|
||||
/* ERROR CODES */
|
||||
const playerNotFound = 0; // Player not found
|
||||
const playerOnVacation = 1; // Player is on vacation
|
||||
const emptyName = 2; // The name of the player to ban is empty
|
||||
const invalidName = 3; // The name of the player to ban is invalid
|
||||
const targetNotFound = 4; // The player to ban could not be found
|
||||
const targetIsPlayer = 5; // The player is trying to ban himself
|
||||
const alreadyBanned = 6; // This player has already been banned
|
||||
/***************/
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"players" => "beta5/player"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player, $name) {
|
||||
// Check if the player ID is not null
|
||||
if (is_null($player)) {
|
||||
return self::playerNotFound;
|
||||
}
|
||||
$player = (int) $player;
|
||||
|
||||
// Check if the player is valid
|
||||
$playerRecord = $this->players->call('get', $player);
|
||||
if (is_null($playerRecord)) {
|
||||
return self::playerNotFound;
|
||||
}
|
||||
|
||||
if ($this->players->call('isOnVacation', $player)) {
|
||||
return self::playerOnVacation;
|
||||
}
|
||||
|
||||
// Check the name of the player to ban
|
||||
$name = preg_replace('/\s+/', ' ', trim($name));
|
||||
if ($name == "") {
|
||||
return self::emptyName;
|
||||
} elseif (strlen($name) > 15) {
|
||||
return self::invalidName;
|
||||
}
|
||||
|
||||
// Examine the player to ban
|
||||
$toBan = $this->players->call("getPlayerId", $name);
|
||||
if (is_null($toBan)) {
|
||||
return self::targetNotFound;
|
||||
} elseif ($toBan == $player) {
|
||||
return self::targetIsPlayer;
|
||||
}
|
||||
|
||||
// Check if the target player is already banned
|
||||
if ($this->players->call('checkTAListBan', $toBan, $player)) {
|
||||
return self::alreadyBanned;
|
||||
}
|
||||
|
||||
// Remove the current player from the banned player's TA list
|
||||
$reverseList = $this->players->call('isAllyOf', $player);
|
||||
foreach ($reverseList as $id => $data) {
|
||||
if ($id == $toBan) {
|
||||
$this->players->call('removeAlly', $toBan, $reverseList[$toBan]['level']);
|
||||
$this->players->call('reorderAllies', $toBan);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the ban
|
||||
$this->players->call('addTAListBan', $player, $toBan);
|
||||
|
||||
return $this->game->action("getTrustedAllies", $player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
91
scripts/game/beta5/actions/getCommsOverview.inc
Normal file
91
scripts/game/beta5/actions/getCommsOverview.inc
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/getCommsOverview.inc
|
||||
//
|
||||
// This action fetches data associated with the overview of a player's
|
||||
// communication channels.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_getCommsOverview
|
||||
extends game_action {
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"forums" => "beta5/forums",
|
||||
"msgs" => "beta5/msg"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player) {
|
||||
if (is_null($player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Messages in default folders
|
||||
$folders = array();
|
||||
$dfld = array('IN', 'INT', 'OUT');
|
||||
foreach ($dfld as $f) {
|
||||
$pm = $this->msgs->call('getAll', $player, $f);
|
||||
$pmn = $this->msgs->call('getNew', $player, $f);
|
||||
$folders[$f] = array($pm, $pmn);
|
||||
}
|
||||
|
||||
// Custom folders
|
||||
$folders["CUS"] = array();
|
||||
$cFold = $this->msgs->call('getCustomFolders', $player);
|
||||
foreach ($cFold as $cfid => $cfn) {
|
||||
$pm = $this->msgs->call('getAll', $player, 'CUS', $cfid);
|
||||
$pmn = $this->msgs->call('getNew', $player, 'CUS', $cfid);
|
||||
$folders["CUS"][$cfid] = array($pm, $pmn, $cfn);
|
||||
}
|
||||
|
||||
// Forums
|
||||
$cats = $this->forums->call('getStructure', $player);
|
||||
$forums = array(
|
||||
"general" => array(),
|
||||
"alliance" => array()
|
||||
);
|
||||
foreach ($cats as $c) {
|
||||
if (!count($c['forums'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($c['type'] == 'A') {
|
||||
$forums['allianceID'] = $c['id'];
|
||||
foreach ($c['forums'] as $f) {
|
||||
array_push($forums['alliance'], array(
|
||||
$f['id'], $f['topics'], $f['unread'], $f['title']
|
||||
));
|
||||
}
|
||||
} else {
|
||||
$gCat = array(
|
||||
"id" => $c['id'],
|
||||
"type" => $c['type'],
|
||||
"title" => $c['title'],
|
||||
"forums" => array()
|
||||
);
|
||||
foreach ($c['forums'] as $f) {
|
||||
array_push($gCat['forums'], array(
|
||||
$f['id'], $f['topics'], $f['unread'], $f['title']
|
||||
));
|
||||
}
|
||||
array_push($forums['general'], $gCat);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
"folders" => $folders,
|
||||
"forums" => $forums
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
69
scripts/game/beta5/actions/getEmpireOverview.inc
Normal file
69
scripts/game/beta5/actions/getEmpireOverview.inc
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/getEmpireOverview.inc
|
||||
//
|
||||
// This action fetches data associated with an empire's overview.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_getEmpireOverview
|
||||
extends game_action {
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"planets" => "beta5/planet",
|
||||
"players" => "beta5/player",
|
||||
"fleets" => "beta5/fleet",
|
||||
"techs" => "beta5/tech"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player) {
|
||||
if (is_null($player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get general statistics
|
||||
$genStats = $this->planets->call('getStats', $player);
|
||||
$fleetStats = $this->fleets->call('getStats', $player);
|
||||
$planets = $this->players->call('getPlanets', $player);
|
||||
|
||||
// Additional planet data
|
||||
$income = 0;
|
||||
foreach ($planets as $id => $name) {
|
||||
$pInfo = $this->planets->call('byId', $id);
|
||||
$pIncome = $this->planets->call('getIncome', $pInfo);
|
||||
$income += $pIncome[0];
|
||||
}
|
||||
|
||||
// Get research data
|
||||
$rPoints = $this->techs->call('getPoints', $player);
|
||||
$rBudget = $this->techs->call('getBudget', $player);
|
||||
$nNew = count($this->techs->call('getTopics', $player, 0));
|
||||
$nForeseen = count($this->techs->call('getTopics', $player, -1)) / 2;
|
||||
|
||||
// Return data
|
||||
return array(
|
||||
"planetStats" => $genStats,
|
||||
"planets" => $planets,
|
||||
"fleetStats" => $fleetStats,
|
||||
"techStats" => array(
|
||||
"points" => $rPoints,
|
||||
"budget" => $rBudget,
|
||||
"new" => $nNew,
|
||||
"foreseen" => $nForeseen
|
||||
),
|
||||
"income" => $income,
|
||||
"profit" => $income - $fleetStats['upkeep']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
38
scripts/game/beta5/actions/getOverview.inc
Normal file
38
scripts/game/beta5/actions/getOverview.inc
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/getOverview.inc
|
||||
//
|
||||
// This action fetches data associated with the complete overview.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_getOverview
|
||||
extends game_action {
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
'players' => 'beta5/player'
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player, $language) {
|
||||
if (is_null($player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
"protection" => $this->players->call('getProtectionLevel', $player),
|
||||
"comms" => $this->game->action('getCommsOverview', $player),
|
||||
"universe" => $this->game->action('getUniverseOverview', $player, $language),
|
||||
"empire" => $this->game->action('getEmpireOverview', $player)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
54
scripts/game/beta5/actions/getTrustedAllies.inc
Normal file
54
scripts/game/beta5/actions/getTrustedAllies.inc
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/getTrustedAllies.inc
|
||||
//
|
||||
// This action returns all data associated with the trusted allies list.
|
||||
//
|
||||
// Parameters:
|
||||
// $player Identifier of the player
|
||||
//
|
||||
// Possible return values:
|
||||
// an array The trusted allies data for the player
|
||||
// NULL Error, player not found
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_getTrustedAllies
|
||||
extends game_action {
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"players" => "beta5/player"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player) {
|
||||
// Check if the player ID is not null
|
||||
if (is_null($player)) {
|
||||
return null;
|
||||
}
|
||||
$player = (int) $player;
|
||||
|
||||
// Check if the player is valid
|
||||
$playerRecord = $this->players->call('get', $player);
|
||||
if (is_null($playerRecord)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return data
|
||||
return array(
|
||||
"allies" => $this->players->call('getAllies', $player),
|
||||
"reverse" => $this->players->call('isAllyOf', $player),
|
||||
"blacklist" => $this->players->call('getTAListBans', $player)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
80
scripts/game/beta5/actions/getUniverseOverview.inc
Normal file
80
scripts/game/beta5/actions/getUniverseOverview.inc
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/getUniverseOverview.inc
|
||||
//
|
||||
// This action fetches data associated with the universe's overview.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_getUniverseOverview
|
||||
extends game_action {
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"main" => "main",
|
||||
"beta5" => "beta5",
|
||||
"map" => "beta5/map",
|
||||
"players" => "beta5/player",
|
||||
"rankings" => "main/rankings"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player, $language) {
|
||||
if (is_null($player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
"summary" => $this->map->call('getUniverse'),
|
||||
"ticks" => $this->getTicks($language),
|
||||
"rankings" => $this->getPlayerRankings($player)
|
||||
);
|
||||
}
|
||||
|
||||
private function getTicks($language) {
|
||||
$ticks = array();
|
||||
$info = $this->main->call('getTicks', $language);
|
||||
foreach ($info as $tid => $td) {
|
||||
if (! $td['game']) {
|
||||
continue;
|
||||
}
|
||||
array_push($ticks, array($tid, $td['first'], $td['interval'], $td['last'], $td['name']));
|
||||
}
|
||||
return $ticks;
|
||||
}
|
||||
|
||||
private function getRanking($type, $name) {
|
||||
$rt = $this->rankings->call('getType', $type);
|
||||
$r = $this->rankings->call('get', $rt, $name);
|
||||
if (!$r) {
|
||||
$r = array('','');
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
private function getPlayerRankings($pid) {
|
||||
$pc = $this->beta5->call('getPlayerCount');
|
||||
|
||||
$pName = $this->players->call('getName', $pid);
|
||||
$gr = $this->getRanking('p_general', $pName);
|
||||
$cr = $this->getRanking('p_civ', $pName);
|
||||
$mr = $this->getRanking('p_financial', $pName);
|
||||
$fr = $this->getRanking('p_military', $pName);
|
||||
$or = $this->getRanking('p_round', $pName);
|
||||
$ir = $this->getRanking('p_idr', $pName);
|
||||
|
||||
return array(
|
||||
$pc, $gr['points'], $gr['ranking'], $cr['points'], $cr['ranking'],
|
||||
$mr['points'], $mr['ranking'], $fr['points'], $fr['ranking'],
|
||||
$or['points'], $or['ranking'], $ir['points'], $ir['ranking']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
79
scripts/game/beta5/actions/removeTrustingAllies.inc
Normal file
79
scripts/game/beta5/actions/removeTrustingAllies.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// LegacyWorlds Beta 5
|
||||
// Game actions
|
||||
//
|
||||
// beta5/actions/removeTrustingAllies.inc
|
||||
//
|
||||
// This action removes a player from other players' trusted allies
|
||||
// lists.
|
||||
//
|
||||
// Parameters:
|
||||
// $player The player to remove from others' lists.
|
||||
// $removeList An array of the player IDs from whose lists
|
||||
// the player must be removed
|
||||
//
|
||||
// Possible return values:
|
||||
// an array The trusted allies data for the player; see
|
||||
// documentation for getTrustedAllies
|
||||
// an integer Error; check the error codes.
|
||||
//
|
||||
// Copyright(C) 2004-2008, DeepClone Development
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
class beta5_removeTrustingAllies
|
||||
extends game_action {
|
||||
|
||||
/* ERROR CODES */
|
||||
const playerNotFound = 0; // Player not found
|
||||
const playerOnVacation = 1; // Player is on vacation
|
||||
const trustingPlayerNotFound = 2; // One of the allies to remove wasn't found
|
||||
/***************/
|
||||
|
||||
public function __construct($game) {
|
||||
parent::__construct($game, array(
|
||||
"players" => "beta5/player"
|
||||
));
|
||||
}
|
||||
|
||||
public function run($player, $removeList) {
|
||||
// Check if the player ID is not null
|
||||
if (is_null($player)) {
|
||||
return self::playerNotFound;
|
||||
}
|
||||
$player = (int) $player;
|
||||
|
||||
// Check if the player is valid
|
||||
$playerRecord = $this->players->call('get', $player);
|
||||
if (is_null($playerRecord)) {
|
||||
return self::playerNotFound;
|
||||
}
|
||||
|
||||
if ($this->players->call('isOnVacation', $player)) {
|
||||
return self::playerOnVacation;
|
||||
}
|
||||
|
||||
// Check if the player is listed as an ally for these players
|
||||
$trustedBy = $this->players->call('isAllyOf', $player);
|
||||
$removeList = array_unique($removeList);
|
||||
foreach ($removeList as $removePlayer) {
|
||||
if (!array_key_exists((int) $removePlayer, $trustedBy)) {
|
||||
return self::trustingPlayerNotFound;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the player from their lists and reorder
|
||||
foreach ($removeList as $removePlayer) {
|
||||
$this->players->call('removeAlly', (int) $removePlayer,
|
||||
$trustedBy[(int) $removePlayer]['level']);
|
||||
$this->players->call('reorderAllies', $removePlayer);
|
||||
}
|
||||
|
||||
return $this->game->action("getTrustedAllies", $player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue