Дополнительный файл конфигов. Разнесение конфигов на игровые и системные.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
@@ -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 = ?";
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user