Дополнительный файл конфигов. Разнесение конфигов на игровые и системные.

This commit is contained in:
lopar
2021-03-10 23:03:59 +02:00
parent 32573f3e8e
commit d78b2eda34
34 changed files with 181 additions and 275 deletions

View File

@@ -52,7 +52,7 @@ class Bank
*/
private function bankCommission(int $amount): int
{
$bankCommission = round($amount * Config::$bank_commission);
$bankCommission = round($amount * GameConfigs::BANK_COMISSION);
if ($bankCommission < 1) {
return 1;
} else {

View File

@@ -2,11 +2,7 @@
namespace Battles\Database;
const DATABASE_HOST = '192.168.20.5';
const DATABASE_NAME = 'battles';
const DATABASE_USER = 'battles';
const DATABASE_PASS = 'bottle-neck-horse';
const DATABASE_PORT = '32101';
use Battles\GameConfigs;
use PDO, PDOException;
class DBPDO
{
@@ -37,9 +33,9 @@ class DBPDO
{
if (!$this->pdo) {
$dsn = 'mysql:dbname=' . DATABASE_NAME . ';host=' . DATABASE_HOST . ';port=' . DATABASE_PORT . ';charset=utf8;';
$user = DATABASE_USER;
$password = DATABASE_PASS;
$dsn = 'mysql:dbname=' . GameConfigs::DATABASE_NAME . ';host=' . GameConfigs::DATABASE_HOST . ';port=' . GameConfigs::DATABASE_PORT . ';charset=utf8;';
$user = GameConfigs::DATABASE_USER;
$password = GameConfigs::DATABASE_PASS;
try {
$this->pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_PERSISTENT => true));
@@ -144,5 +140,4 @@ class DBPDO
{
return $this->pdo->lastInsertId();
}
}

View File

@@ -0,0 +1,21 @@
<?php
# Date: 15.02.2021 (02:33)
namespace Battles;
class GameConfigs
{
const DATABASE_HOST = '192.168.20.5';
const DATABASE_NAME = 'battles';
const DATABASE_USER = 'battles';
const DATABASE_PASS = 'bottle-neck-horse';
const DATABASE_PORT = '32101';
const DATABASE_CHARSET = 'utf8';
const CLAN_REGISTER_COST = 10000;
const CLAN_REGISTER_LOCK = true; // Запрет на регистрацию кланов.
const BANK_COMISSION = 0.05; // 5%
const DB_SQLITE = '/volume2/web/battles/databases/logs.sqlite';
}

View File

@@ -19,7 +19,7 @@ class GameLogs
*/
public static function addBankLog(int $senderId, int $receiverId, int $amount, string $type, string $text)
{
$db = new SQLite3(Config::$db_sqlite);
$db = new SQLite3(GameConfigs::DB_SQLITE);
$row = $db->prepare("INSERT INTO bank_logs (sender_id, receiver_id, amount, type, text) VALUES (?, ?, ?, ?, ?)");
$row->bindParam(1, $senderId, SQLITE3_INTEGER);
$row->bindParam(2, $receiverId, SQLITE3_INTEGER);
@@ -45,7 +45,7 @@ class GameLogs
if (empty($type)) {
$type = "system";
}
$db = new SQLite3(Config::$db_sqlite);
$db = new SQLite3(GameConfigs::DB_SQLITE);
$row = $db->prepare("INSERT INTO users_logs (user_id, author_id, type, text) VALUES (?,?,?,?)");
$row->bindParam(1, $userId, SQLITE3_INTEGER);
$row->bindParam(2, $authorId, SQLITE3_INTEGER);
@@ -57,7 +57,7 @@ class GameLogs
public static function getUserLogs($userId = null, $type = null): SQLite3Result
{
$db = new SQLite3(Config::$db_sqlite);
$db = new SQLite3(GameConfigs::DB_SQLITE);
if ($userId && $type) {
$query = "SELECT * FROM users_logs WHERE user_id = ? AND type = ?";

View File

@@ -55,7 +55,9 @@ class User
protected $maxMana = 5;
protected static $db;
public function __construct(int $user)
public const INFO_CHAR_LIMIT = 1500;
public function __construct($user)
{
self::$db = DBPDO::INIT();
$user_query = self::$db->fetch('SELECT * FROM users WHERE id = ? OR login = ?', [$user, $user]);

View File

@@ -1,6 +1,6 @@
<?php
if (in_array($user->getRoom(), Config::$caverooms)) {
$cavedata = Config::$cavedata ?? [];
if (in_array($user->getRoom(), CAVE_ROOMS)) {
$cavedata = CAVE_DATA ?? [];
$floor = mysql_fetch_row(mysql_query("SELECT `floor` FROM `caveparties` WHERE `user` = '$user[id]' LIMIT 1"));
if (!isset($cavedata[$user->getRoom()]['x' . $floor])) {
$floor = 1;
@@ -11,7 +11,7 @@ $lomka1 = $lomka;
foreach ($lomka1 as $k => $v) {
if ($v < _BOTSEPARATOR_) {
if (in_array($user->getRoom(), Config::$caverooms)) {
if (in_array($user->getRoom(), CAVE_ROOMS)) {
mysql_query("UPDATE `caveparties` SET `floor` = $floor, `x` = '" . $cavedata[$user->getRoom()]['x' . $floor] . "', `y` = '" . $cavedata[$user->getRoom()]['y' . $floor] . "', `dir` = '" . $cavedata[$user->getRoom()]['dir' . $floor] . "', `loses` = (`loses`+1) WHERE `user` = '$v' LIMIT 1");
}
if ($user['laba'] > 0) {

View File

@@ -21,7 +21,7 @@ function cavesys($text)
}
}
if (in_array($user->getRoom(), Config::$caverooms)) {
if (in_array($user->getRoom(), CAVE_ROOMS)) {
include("CaveItems.php");
mysql_query('LOCK TABLES `cavebots` WRITE, `caveitems` WRITE, `shop` WRITE, `caveparties` WRITE');
$location = mysql_fetch_array(mysql_query("SELECT `x`, `y`, `dir`, `floor` FROM `caveparties` WHERE `user` = '$user[id]' LIMIT 1"));

View File

@@ -1,4 +1,7 @@
<?php
use Battles\GameConfigs;
/**
* Created by PhpStorm.
* User: lopiu
@@ -20,11 +23,16 @@ class db
{
if (!self::$_instance)
{
self::$_instance = Krugozor\Database\Mysql\Mysql::create("192.168.20.5", "battles", "bottle-neck-horse", 32101)
self::$_instance = Krugozor\Database\Mysql\Mysql::create(
GameConfigs::DATABASE_HOST,
GameConfigs::DATABASE_USER,
GameConfigs::DATABASE_PASS,
GameConfigs::DATABASE_PORT
)
// Выбор базы данных
->setDatabaseName("battles")
->setDatabaseName(GameConfigs::DATABASE_NAME)
// Выбор кодировки
->setCharset("utf8");
->setCharset(GameConfigs::DATABASE_CHARSET);
}
return self::$_instance;
}

View File

@@ -1700,7 +1700,7 @@ class fbattle
}
if (in_array($user->getRoom(), Config::$caverooms)) {
if (in_array($user->getRoom(), CAVE_ROOMS)) {
$location = mysql_fetch_array(mysql_query("SELECT `x`, `y`, `dir` FROM `caveparties` WHERE `user` = '" . $this->user['id'] . "' LIMIT 1"));
if ($location['dir'] == 0) {
@@ -1805,7 +1805,7 @@ class fbattle
function addAction($time, $vars, $vls, $uid)
{
$ins = mysql_query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`) VALUES ("' . $uid . '", "' . $time . '", "capitalcity", "0", "' . mysql_real_escape_string($vars) . '", "' . mysql_real_escape_string($_SERVER['HTTP_X_REAL_IP']) . '", "' . mysql_real_escape_string($vls) . '")');
$ins = mysql_query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`) VALUES ("' . $uid . '", "' . $time . '", "capitalcity", "0", "' . mysql_real_escape_string($vars) . '", "' . $_SERVER['REMOTE_ADDR'] . '", "' . mysql_real_escape_string($vls) . '")');
if ($ins) {
return true;
} else {