From fe9f512dec5e5da0ddef1f93f7ca703f4553106a Mon Sep 17 00:00:00 2001 From: Wire Date: Tue, 10 Dec 2024 22:52:11 -0500 Subject: [PATCH] get boned octane --- app/Libraries/GameBridge/BridgeConnection.php | 72 ++++++++++--------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/app/Libraries/GameBridge/BridgeConnection.php b/app/Libraries/GameBridge/BridgeConnection.php index a4ca3c8..7d73aa5 100644 --- a/app/Libraries/GameBridge/BridgeConnection.php +++ b/app/Libraries/GameBridge/BridgeConnection.php @@ -98,28 +98,28 @@ public function cacheFor(int $seconds) private function handler($address, $port, $options) { - return function () use ($address, $port, $options) { - $socket = new BridgeConnectionSocket($address, $port, $options); - $response = ''; - $error = false; - - try { - $socket->send(); - if ($socket->wantResponse) { - $response = $socket->read(); - $error = $socket->error; - } - } catch (\Throwable $e) { - if ($socket->wantResponse) { - $response = $e->getMessage(); - $error = true; - } + // return function () use ($address, $port, $options) { + $socket = new BridgeConnectionSocket($address, $port, $options); + $response = ''; + $error = false; + + try { + $socket->send(); + if ($socket->wantResponse) { + $response = $socket->read(); + $error = $socket->error; + } + } catch (\Throwable $e) { + if ($socket->wantResponse) { + $response = $e->getMessage(); + $error = true; } + } - $socket->disconnect(); + $socket->disconnect(); - return new BridgeConnectionResponse($response, $error, $socket->cacheHit); - }; + return new BridgeConnectionResponse($response, $error, $socket->cacheHit); + // }; } public function send(bool $wantResponse = true): BridgeConnectionResponse|Collection @@ -132,26 +132,28 @@ public function send(bool $wantResponse = true): BridgeConnectionResponse|Collec 'wantResponse' => $wantResponse, ]; - $jobs = []; - $timeout = 0; + // $jobs = []; + // $timeout = 0; + $responses = collect(); foreach ($this->targets as $target) { - $jobs[$target->serverId] = $this->handler($target->address, $target->port, $options); - if ($wantResponse) { - $timeout += $this->timeout * 3; // connect, send, read - } else { - $timeout += $this->timeout * 2; // connect, send - } + // $jobs[$target->serverId] = $this->handler($target->address, $target->port, $options); + // if ($wantResponse) { + // $timeout += $this->timeout * 3; // connect, send, read + // } else { + // $timeout += $this->timeout * 2; // connect, send + // } + $responses->add($this->handler($target->address, $target->port, $options)); } - $response = null; - try { - $responses = collect(Octane::concurrently($jobs, $timeout * 1000)); - $response = count($responses) === 1 ? $responses->first() : $responses; - } catch (TaskTimeoutException $e) { - $response = new BridgeConnectionResponse($e->getMessage(), true); - } + // $response = null; + // try { + // $responses = collect(Octane::concurrently($jobs, $timeout * 1000)); + // $response = count($responses) === 1 ? $responses->first() : $responses; + // } catch (TaskTimeoutException $e) { + // $response = new BridgeConnectionResponse($e->getMessage(), true); + // } - return $response; + return count($responses) === 1 ? $responses->first() : $responses; } public function sendAndForget()