Skip to content

Commit

Permalink
TFS 1.3+ version - new PACC column, config.lua stages error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gesior committed Jan 26, 2021
1 parent b7d7036 commit 5288b3f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 100 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -3,12 +3,13 @@ Gesior2012

Gesior 2012 - Account Maker (website) for OTSes

Version for TFS 1.2+ engine ( https://github.com/otland/forgottenserver/tree/1.2 ).
Version for TFS 1.3+ engine ( https://github.com/otland/forgottenserver/tree/1.3 ).

Tested on PHP 7.0-7.4 and 8.0 with MariaDB.

PHP extensions required:
```
bcmath
dom
gd
xml
Expand Down
4 changes: 2 additions & 2 deletions README.txt
@@ -1,6 +1,6 @@
##### CREDITS #####
Version 1.0.3 for TFS 1.2+
Version 1.0.3 for TFS 1.3+
Acc. script:
*Gesior - e-mail: phoowned@wp.pl
Layouts:
*CipSoft Gmbh - www.tibia.com
*CipSoft Gmbh - www.tibia.com
68 changes: 11 additions & 57 deletions classes/account.php
Expand Up @@ -8,11 +8,9 @@ class Account extends ObjectData
const LOADTYPE_NAME = 'name';
const LOADTYPE_MAIL = 'email';
public static $table = 'accounts';
public $data = array('name' => null, 'password' => null, 'premdays' => 0, 'lastday' => 0, 'email' => '', 'key' => '', 'create_ip' => 0, 'creation' => 0, 'premium_points' => 0, 'page_access' => 0, 'location' => '', 'rlname' => '', 'email_new' => '', 'email_new_time' => 0, 'email_code' => '', 'next_email' => 0, 'last_post' => 0, 'flag' => 'pl');
public static $fields = array('id', 'name', 'password', 'premdays', 'lastday', 'email', 'key', 'create_ip', 'creation', 'premium_points', 'page_access', 'location', 'rlname', 'email_new', 'email_new_time', 'email_code', 'next_email', 'last_post', 'flag');
public $data = array('name' => null, 'password' => null, 'premium_ends_at' => 0, 'email' => '', 'key' => '', 'create_ip' => 0, 'creation' => 0, 'premium_points' => 0, 'page_access' => 0, 'location' => '', 'rlname' => '', 'email_new' => '', 'email_new_time' => 0, 'email_code' => '', 'next_email' => 0, 'last_post' => 0, 'flag' => 'pl');
public static $fields = array('id', 'name', 'password', 'premium_ends_at', 'email', 'key', 'create_ip', 'creation', 'premium_points', 'page_access', 'location', 'rlname', 'email_new', 'email_new_time', 'email_code', 'next_email', 'last_post', 'flag');
public $players;
public $playerRanks;
public $guildAccess;
public $bans;

public function __construct($search_text = null, $search_by = self::LOADTYPE_ID)
Expand Down Expand Up @@ -83,52 +81,7 @@ public function getPlayers($forceReload = false)
}
return $this->players;
}
/*
public function getGuildRanks($forceReload = false)
{
if(!isset($this->playerRanks) || $forceReload)
{
$this->playerRanks = new DatabaseList('AccountGuildRank');
$filterAccount = new SQL_Filter(new SQL_Field('account_id', 'players'), SQL_Filter::EQUAL, $this->getID());
$filterPlayer1 = new SQL_Filter(new SQL_Field('id', 'players'), SQL_Filter::EQUAL, new SQL_Field('player_id', 'guild_membership'));
$filterPlayer2 = new SQL_Filter(new SQL_Field('rank_id', 'guild_membership'), SQL_Filter::EQUAL, new SQL_Field('id', 'guild_ranks'));
$filterGuild = new SQL_Filter(new SQL_Field('guild_id', 'guild_ranks'), SQL_Filter::EQUAL, new SQL_Field('id', 'guilds'));
$filter = new SQL_Filter($filterAccount, SQL_Filter::CRITERIUM_AND, $filterPlayer1);
$filter = new SQL_Filter($filter, SQL_Filter::CRITERIUM_AND, $filterPlayer2);
$filter = new SQL_Filter($filter, SQL_Filter::CRITERIUM_AND, $filterGuild);
$this->playerRanks->setFilter($filter);
}
return $this->playerRanks;
}
public function loadGuildAccess($forceReload = false)
{
if(!isset($this->guildAccess) || $forceReload)
{
$this->guildAccess = array();
foreach($this->getGuildRanks($forceReload) as $rank)
if($rank->getOwnerID() == $rank->getPlayerID())
$this->guildAccess[$rank->getGuildID()] = Guild::LEVEL_OWNER;
elseif(!isset($this->guildAccess[$rank->getGuildID()]) || $rank->getLevel() > $this->guildAccess[$rank->getGuildID()])
$this->guildAccess[$rank->getGuildID()] = $rank->getLevel();
}
}

public function isInGuild($guildId, $forceReload = false)
{
$this->loadGuildAccess($forceReload);
return isset($this->guildAccess[$guildId]);
}
public function getGuildLevel($guildId, $forceReload = false)
{
$this->loadGuildAccess($forceReload);
if(isset($this->guildAccess[$guildId]))
return $this->guildAccess[$guildId];
else
return 0;
}
*/
public function unban()
{
$this->getDatabaseHandler()->query('DELETE FROM ' . $this->getDatabaseHandler()->tableName('account_bans') . ' WHERE ' . $this->getDatabaseHandler()->fieldName('account_id') . ' = ' . $this->getDatabaseHandler()->quote($this->data['id']));
Expand Down Expand Up @@ -156,7 +109,7 @@ public function getBanTime($forceReload = false)
{
$this->loadBans($forceReload);
$lastExpires = 0;
foreach($bans as $ban)
foreach($this->bans as $ban)
{
if($ban->getExpiresAt() <= 0)
{
Expand Down Expand Up @@ -185,10 +138,8 @@ public function setPassword($value)
$this->data['password'] = Website::encryptPassword($value, $this);
}
public function getPassword(){return $this->data['password'];}
public function setPremDays($value){$this->data['premdays'] = $value;}
public function getPremDays(){return $this->data['premdays'] - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $this->data['lastday']))) - date("z", $this->data['lastday']));}
public function setLastDay($value){$this->data['lastday'] = $value;}
public function getLastDay(){return $this->data['lastday'];}
public function setPremiumEndsAt($value){$this->data['premium_ends_at'] = $value;}
public function getPremiumEndsAt(){return $this->data['premium_ends_at'];}
public function setMail($value){$this->data['email'] = $value;}
public function getMail(){return $this->data['email'];}
public function setKey($value){$this->data['key'] = $value;}
Expand Down Expand Up @@ -222,7 +173,6 @@ public function getFlag(){return $this->data['flag'];}
public function getEMail(){return $this->getMail();}
public function setEMail($value){$this->setMail($value);}
public function getPlayersList(){return $this->getPlayers();}
public function getGuildAccess($guildID){return $this->getGuildLevel($guildID);}

public function isValidPassword($password)
{
Expand All @@ -231,6 +181,10 @@ public function isValidPassword($password)

public function find($name){$this->loadByName($name);}
public function findByEmail($email){$this->loadByEmail($email);}
public function isPremium(){return ($this->getPremDays() > 0);}
public function getLastLogin(){return $this->getLastDay();}
public function isPremium(){return ($this->getPremiumEndsAt() > time());}
public function getLastLogin(){return 0;}
public function getPremDays()
{
return max(0, ceil(($this->getPremiumEndsAt() - time()) / 86400));
}
}
18 changes: 12 additions & 6 deletions classes/configlua.php
Expand Up @@ -54,12 +54,18 @@ public function loadFromString($string)
{
foreach($this->config as $tmp_key => $tmp_value) // load values definied by other keys, like: dailyFragsToBlackSkull = dailyFragsToRedSkull
$value = str_replace($tmp_key, $tmp_value, $value);
$ret = @eval("return $value;");
if((string) $ret == '') // = parser error
{
throw new RuntimeException('#C-1 - Line <b>' . ($ln + 1) . '</b> of LUA config file is not valid [key: <b>' . $key . '</b>]');
}
$this->config[ $key ] = $ret;
try {
$ret = @eval("return $value;");
if ((string)$ret == '') // = parser error
{
throw new RuntimeException(
'#C-1 - Line <b>' . ($ln + 1) . '</b> of LUA config file is not valid [key: <b>' . $key . '</b>]'
);
}
$this->config[$key] = $ret;
} catch(ParseError $e) {
// skip LUA table errors
}
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions classes/functions.php
@@ -1,6 +1,6 @@
<?php
if(!defined('INITIALIZED'))
exit;
<?php
if(!defined('INITIALIZED'))
exit;

class Functions
{
Expand All @@ -23,11 +23,6 @@ public static function isValidMail($email)
return (filter_var($email, FILTER_VALIDATE_EMAIL) != false);
}

public static function isPremium($premdays, $lastday)
{
return ($premdays - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $lastday))) - date("z", $lastday)) > 0);
}

public function getBanReasonName($reasonId)
{
switch($reasonId)
Expand Down Expand Up @@ -90,4 +85,4 @@ public function limitTextLength($text, $length_limit)
else
return $text;
}
}
}
6 changes: 3 additions & 3 deletions config/config.php 100644 → 100755
Expand Up @@ -4,10 +4,10 @@
$config['site']['server_name'] = 'Forgotten';
$towns_list = array(2 => 'Thais', 1 => 'Venore', 4 => 'Carlin');

$config['site']['outfit_images_url'] = 'http://outfit-images.ots.me/outfit.php';
$config['site']['item_images_url'] = 'http://item-images.ots.me/960/';
$config['site']['outfit_images_url'] = 'https://outfit-images.ots.me/idleOutfits1092/outfit.php';
$config['site']['item_images_url'] = 'https://item-images.ots.me/1092/';
$config['site']['item_images_extension'] = '.gif';
$config['site']['flag_images_url'] = 'http://flag-images.ots.me/';
$config['site']['flag_images_url'] = 'https://flag-images.ots.me/';
$config['site']['flag_images_extension'] = '.png';

# Create Account Options
Expand Down
37 changes: 23 additions & 14 deletions install.php
Expand Up @@ -304,24 +304,33 @@ function setServerPath($newPath)
if (isset($column[5]) && $column[5]) {
$unsignedSql = ' UNSIGNED';
}
if($column[4] === NULL) {
if($SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . $unsignedSql . ' NULL DEFAULT NULL'))
echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
else
echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
} else {
if($SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . '' . (($column[3] == '') ? '' : '(' . $column[3] . ')') . $unsignedSql . ' NOT NULL DEFAULT \'' . $column[4] . '\'') !== false)
echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
else
echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
try {
if($column[4] === NULL) {
if($SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . $unsignedSql . ' NULL DEFAULT NULL'))
echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
else
echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
} else {
if($SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . '' . (($column[3] == '') ? '' : '(' . $column[3] . ')') . $unsignedSql . ' NOT NULL DEFAULT \'' . $column[4] . '\'') !== false)
echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
else
echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
}
} catch (PDOException $e) {
echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
}
}
foreach($tables[$SQL->getDatabaseDriver()] as $tableName => $tableQuery)
{
if($SQL->query($tableQuery) !== false)
echo "<span style=\"color:green\">Table <b>" . $tableName . "</b> created.</span><br />";
else
echo "Could not create table <b>" . $tableName . "</b>. Already exist?<br />";
try {
if ($SQL->query($tableQuery) !== false) {
echo "<span style=\"color:green\">Table <b>" . $tableName . "</b> created.</span><br />";
} else {
echo "Could not create table <b>" . $tableName . "</b>. Already exist?<br />";
}
} catch (PDOException $e) {
echo "Could not create table <b>" . $tableName . "</b>. Already exist?<br />";
}
}
echo 'Tables and columns added to database.<br>Go to <a href="install.php?page=step&step=4">STEP 4 - Add samples</a>';
}
Expand Down
5 changes: 2 additions & 3 deletions pages/createaccount.php
Expand Up @@ -325,8 +325,7 @@ function validate_form(thisform)
}
if(isset($config['site']['newaccount_premdays']) && $config['site']['newaccount_premdays'] > 0)
{
$reg_account->set("premdays", $config['site']['newaccount_premdays']);
$reg_account->set("lastday", time());
$reg_account->setPremiumEndsAt(time() + 86400 * $config['site']['newaccount_premdays']);
}
$reg_account->save();
//show information about registration
Expand Down Expand Up @@ -450,4 +449,4 @@ function validate_form(thisform)
</TD></TR></FORM></TABLE>
</CENTER>';
}
}
}
5 changes: 0 additions & 5 deletions system/load.compat.php
Expand Up @@ -67,11 +67,6 @@ function microtime_float()
return microtime(true);
}

function isPremium($premdays, $lastday)
{
return Functions::isPremium($premdays, $lastday);
}

function check_name($name)
{
$name = (string) $name;
Expand Down

0 comments on commit 5288b3f

Please sign in to comment.