diff --git a/src/LonaDB/Actions/eval.php b/src/LonaDB/Actions/eval.php index be855bc..419bc85 100644 --- a/src/LonaDB/Actions/eval.php +++ b/src/LonaDB/Actions/eval.php @@ -1,11 +1,5 @@ Execute($LonaDB); + //$result will be the returned variable from the eval script + $result = $functions[$functionName]->Execute($LonaDB); } catch (Exception $e) { //Catch errors - $answer = $e->getMessage(); + $result = $e->getMessage(); + $success = false; } } catch (Exception $e) { //Catch errors - $answer = $e->getMessage(); + $result = $e->getMessage(); + $success = false; } - //Send response and close socket - $this->sendSuccessResponse($client, $answer, $data['process']); - // Remove the function from the $functions array - unset($functions[$functionName]); //Run plugin event $LonaDB->PluginManager->RunEvent($data['login']['name'], "eval", [ "content" => $data['function'] ]); + // Remove the function from the $functions array + unset($functions[$functionName]); + //Send response + return $this->Send($client, ["success" => $success, "result" => $result, "process" => $process]);; } - private function sendErrorResponse($client, $error, $process): void { - //Create response array - $response = json_encode(["success" => false, "err" => $error, "process" => $process]); - //Send response and close socket - socket_write($client, $response); - socket_close($client); - } - - private function sendSuccessResponse($client, $response, $process): void { - //Create response array - $response = json_encode(["success" => true, "response" => $response, "process" => $process]); + private function Send ($client, $responseArray) : bool { + //Convert response array to JSON object + $response = json_encode($responseArray); //Send response and close socket socket_write($client, $response); socket_close($client); + //Return state + $bool = false; + if($responseArray['success']) $bool = true; + return $bool; } }; \ No newline at end of file diff --git a/src/LonaDB/Actions/execute_function.php b/src/LonaDB/Actions/execute_function.php index 9ed6f4e..e44d0c0 100644 --- a/src/LonaDB/Actions/execute_function.php +++ b/src/LonaDB/Actions/execute_function.php @@ -1,12 +1,26 @@ FunctionManager->GetFunction($data['name']); //Execute function - $function->Execute($LonaDB, $data, $client); + $response = $function->Execute($LonaDB, $data, $client); //Run plugin event $LonaDB->PluginManager->RunEvent($data['login']['name'], "functionExecute", [ "name" => $data['name'] ]); + //Send response + return $this->Send($client, ["success" => true, "result" => $response, "process" => $data["process"]]); + } + + private function Send ($client, $responseArray) : bool { + //Convert response array to JSON object + $response = json_encode($responseArray); + //Send response and close socket + socket_write($client, $response); + socket_close($client); + //Return state + $bool = false; + if($responseArray['success']) $bool = true; + return $bool; } }; diff --git a/src/LonaDB/Functions/LonaFunction.php b/src/LonaDB/Functions/LonaFunction.php index dd997d6..5230bd9 100644 --- a/src/LonaDB/Functions/LonaFunction.php +++ b/src/LonaDB/Functions/LonaFunction.php @@ -35,7 +35,7 @@ class LonaFunction{ //We are using an array because overwriting/defining a function inside eval didn't work for us //Our workaround is creating a class instance with a run function which is our Lona function $function = "\$this->functions['" . $this->Name . "'] = new class {\n"; - $function .= "public function run(\$LonaDB, \$data, \$server, \$fd) {\n"; + $function .= "public function run(\$LonaDB, \$data) {\n"; $function .= $temp; $function .= "\n} \n};"; @@ -45,8 +45,8 @@ class LonaFunction{ $this->LonaDB->Logger->Load("Function '" . $this->Name . "' has been loaded"); } - public function Execute(LonaDB $LonaDB, array $data, $server, $fd) : mixed { + public function Execute(LonaDB $LonaDB, array $data, $client) : mixed { //Run function - return $this->functions[$this->Name]->run($LonaDB, $data, $server, $fd); + return $this->functions[$this->Name]->run($LonaDB, $data); } } \ No newline at end of file diff --git a/src/LonaDB/Users/UserManager.php b/src/LonaDB/Users/UserManager.php index 9319994..e641a78 100644 --- a/src/LonaDB/Users/UserManager.php +++ b/src/LonaDB/Users/UserManager.php @@ -49,7 +49,7 @@ class UserManager{ //If username is root, check for the root password if($name === "root" && $password === $this->LonaDB->config["root"]) return true; //Check if the user exists - if(!$this->CheckUsers($name)) return false; + if(!$this->CheckUser($name)) return false; //Check if the password is correct if($this->Users[$name]["password"] !== $password) return false; //All checks successfull