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,32 @@
<?php
class main_getTick {
function main_getTick($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($name, $lang = null) {
$tInst = $this->lib->game->ticks[$name];
if (is_null($tInst)) {
return null;
}
$tick = array(
"game" => $tInst->definition->public,
"first" => $tInst->first,
"last" => $tInst->last,
"interval" => $tInst->interval
);
if (!is_null($lang)) {
$tick['name'] = $tInst->definition->getName($lang);
$tick['description'] = $tInst->definition->getDescription($lang);
}
return $tick;
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
class main_getTicks {
function main_getTicks($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($lang = null) {
$ticks = array();
foreach ($this->lib->game->ticks as $script => $tInst) {
$tick = array(
"script" => $script,
"game" => $tInst->definition->public,
"first" => $tInst->first,
"last" => $tInst->last,
"interval" => $tInst->interval
);
if (!is_null($lang)) {
$tick['name'] = $tInst->definition->getName($lang);
$tick['description'] = $tInst->definition->getDescription($lang);
}
array_push($ticks, $tick);
}
return $ticks;
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
class main_isGameRunning {
function main_isGameRunning($lib) {
$this->lib = $lib;
}
function run($game) {
$g = config::getGame($game);
if (!$g) {
return false;
}
$lib = $g->getLib();
if ($lib->call('isFinished')) {
return false;
}
$now = time();
foreach ($g->ticks as $td => $tick) {
if ($tick->first <= $now && $tick->definition->public) {
return true;
}
}
return false;
}
}
?>

View file

@ -0,0 +1,49 @@
<?php
//-----------------------------------------------------------------------
// LegacyWorlds Beta 5
// Game libraries
//
// main/library/preJoin.inc
//
// This function lets a player who had registered into the game
//
// Copyright(C) 2004-2008, DeepClone Development
//-----------------------------------------------------------------------
class main_preJoin {
public function __construct($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
public function run($account) {
// Get the game's ID
$q = $this->db->query("SELECT game FROM reg_queue WHERE account = $account");
if (!($q && dbCount($q))) {
$this->db->end(false);
return null;
}
list($gameID) = dbFetchArray($q);
// Get the game library on call its preJoin() function
$game = config::getGame($gameID);
if (!$game) {
$this->db->end(false);
return null;
}
if (!$game->getLib()->call('preJoin', $account)) {
return null;
}
// Delete the queue entry
$this->db->query("DELETE FROM reg_queue WHERE account = $account");
return $gameID;
}
}
?>

View file

@ -0,0 +1,29 @@
<?php
class main_requestGenPlanets {
function main_requestGenPlanets($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($first, $amount) {
$dir = config::getParam('pgenreq');
$game = $this->lib->game->name;
if (!is_dir($dir)) {
$base = dirname($dir);
if (!(is_dir($base) && is_writable($base) && @mkdir($dir))) {
logText("main::requestGenPlanets($game,$first,$amount): unable to create directory '$dir'", LOG_WARNING);
return false;
}
}
$r = @touch("$dir/req-$game-$first-$amount");
if (!$r) {
logText("main::requestGenPlanets($game,$first,$amount): unable to create file 'req-$game-$first-$amount'", LOG_WARNING);
}
return $r;
}
}
?>

View file

@ -0,0 +1,48 @@
<?php
class main_sendMail {
function main_sendMail($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($file, $to, $vars) {
if (! config::$main['sendmails']) {
return true;
}
// Read the file
$mail = @file_get_contents("{$this->lib->game->dir}/mail/$file");
if (is_bool($mail)) {
logText("Mail '$file' to $to failed: file not found", LOG_WARNING);
return false;
}
// Generate the substitution arrays from the variables
$vals = array_values($vars);
$subst = array();
foreach (array_keys($vars) as $name) {
array_push($subst, "/_{$name}_/");
}
$mail = preg_replace($subst, $vals, $mail);
$tmp = explode("\n", $mail);
$subject = array_shift($tmp);
$mail = join("\n", $tmp);
$header = "From: webmaster@legacyworlds.com\r\n"
. "Reply-To: webmaster@legacyworlds.com\r\n"
. "X-Mailer: LegacyWorlds\r\n"
. "Mime-Version: 1.0\r\n"
. "Content-Type: text/plain; charset=iso-8859-1";
if (!mail($to, $subject, $mail, $header)) {
logText("Mail '$file' to $to failed: unable to send", LOG_WARNING);
return false;
}
return true;
}
}
?>