Skip to content

Commit

Permalink
Fixed errors for missing value
Browse files Browse the repository at this point in the history
  • Loading branch information
tltneon committed Dec 27, 2024
1 parent 5586089 commit 99f84f7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
27 changes: 27 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function type($var) {
}
$config =
"<?php
namespace tltneon\LGSL;
global \$lgsl_config; \$lgsl_config = [];
/* */
\$lgsl_config['installed'] = true;
Expand Down Expand Up @@ -224,6 +225,32 @@ function type($var) {
\$lgsl_config['select_lang'] = {$conf['select_lang']}; // allow to select language for users
\$lgsl_config['language'] = '{$conf['language']}'; // sets LGSL language
include('languages/{$conf['language']}.php'); // loads LGSL language
class Config implements \ArrayAccess {
private \$config;
public function __construct() {
\$this->loadConfig();
}
private function loadConfig() {
global \$lgsl_config;
\$this->config = \$lgsl_config;
}
public function offsetExists(mixed \$offset): bool {
return isset(\$this->config[\$offset]);
}
public function offsetGet(mixed \$offset): mixed {
return \$this->config[\$offset] ?? null;
}
public function offsetSet(mixed \$offset, mixed \$value): void {
\$this->config[\$offset] = \$value;
}
public function offsetUnset(mixed \$offset): void {
unset(\$this->config[\$offset]);
}
}
?>";
file_put_contents('src/lgsl_config.php', $config);
unlink('install.php');
Expand Down
13 changes: 13 additions & 0 deletions src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,19 @@ function shutdown() {
</style>
<div class='prettyphp'><h2>Fatal PHP error</h2><div>".nl2br($msg)."</div></div>";
}
if ($e['type'] === E_WARNING) {
$msg = isset($e['message']) ? "{$e['message']} in {$e['file']} on line {$e['line']}" : '';
$msg = preg_replace('/[a-z0-9_\-]*\.php/i','$1<u>$0</u>',$msg);
$msg = preg_replace('/[0-9]/i','$1<em>$0</em>',$msg);
$msg = preg_replace('/[\(\)#\[\]\':]/i','$1<ss>$0</ss>',$msg);

echo "<style>
u{color:#ed6;text-decoration:none;} b{color:#ddd;letter-spacing:1px;} em{color:#cfc;font-style:normal;} ss{color:white;}
h2{letter-spacing:1px;font-size:1.5rem;color:#b8b;margin-top:0;} br{margin-bottom:1.8rem;}
.prettyphp{margin:3rem auto;line-height:1.4em;padding:2rem;background:#ffffff1a;font-size:1.1rem;border-radius:0.5rem;max-width:1000px;font-family:monospace;}
</style>
<div class='prettyphp'><h2>PHP warning</h2><div>".nl2br($msg)."</div></div>";
}
}
}
register_shutdown_function('tltneon\LGSL\shutdown');
29 changes: 28 additions & 1 deletion src/lgsl_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace tltneon\LGSL;
//------------------------------------------------------------------------------------------------------------+
//[ PREPARE CONFIG - DO NOT CHANGE OR MOVE THIS ]

Expand Down Expand Up @@ -171,3 +171,30 @@
// Chinese_simplified language: "languages/chinese_simplified.php" // Nanfei

//------------------------------------------------------------------------------------------------------------+

class Config implements \ArrayAccess {
private $config;
public function __construct() {
$this->loadConfig();
}

private function loadConfig() {
global $lgsl_config;
$this->config = $lgsl_config;
}

public function offsetExists(mixed $offset): bool {
return isset($this->config[$offset]);
}

public function offsetGet(mixed $offset): mixed {
return $this->config[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void {
$this->config[$offset] = $value;
}

public function offsetUnset(mixed $offset): void {
unset($this->config[$offset]);
}
}
2 changes: 1 addition & 1 deletion src/lgsl_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

$p = str_replace('src/', '', LGSL::urlPath()) . ($lgsl_config["direct_index"] ? 'index.php' : '');
$framespace = max(0, min(6, $server->getPlayersCount('active'))) * 8.8;
$framespace = max(0, min(6, $server->getPlayersCount('active'))) * 8.85;
$output .= "
<details>
<summary style='margin-bottom: 12px;'>
Expand Down
6 changes: 2 additions & 4 deletions src/lgsl_protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -3219,8 +3219,7 @@ public function close() {
//------------------------------------------------------------------------------------------------------------+
class Helper {
static function lgslHtmlColor($string, $removeColors = false) {
global $lgsl_config;
if ($lgsl_config['remove_colors'] || $removeColors) {
if ((new Config())->offsetGet('remove_colors') || $removeColors) {
return preg_replace('/##([0-9a-fA-F]{6})/', "", $string);
}
$outputText = preg_replace_callback('/##([0-9a-fA-F]{6})([0-9a-zA-Z !@$%&-*+|\/\.]+)?/', function($matches) {
Expand All @@ -3237,8 +3236,7 @@ static function lgslColorParser($string, $pattern, &$colors) {
}, $string);
}
static function lgslParseColor($string, $type, $needRemove = true) {
global $lgsl_config;
$needRemove &= !$lgsl_config['remove_colors'];
$needRemove &= !(new Config())->offsetGet('remove_colors');
switch ($type) {
case "2": return preg_replace("/\^[\x20-\x7E]/", "", $string);
case "doomskulltag": return preg_replace("/\\x1c./", "", $string);
Expand Down

0 comments on commit 99f84f7

Please sign in to comment.