Skip to content

Commit 904e547

Browse files
committed
Assign socket only if it was created
Fixes #149
1 parent cd36247 commit 904e547

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

SourceQuery/Socket.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ public function Open( string $Address, int $Port, int $Timeout, int $Engine ) :
4242
$this->Port = $Port;
4343
$this->Address = $Address;
4444

45-
$this->Socket = @FSockOpen( 'udp://' . $Address, $Port, $ErrNo, $ErrStr, $Timeout );
45+
$Socket = @FSockOpen( 'udp://' . $Address, $Port, $ErrNo, $ErrStr, $Timeout );
4646

47-
if( $ErrNo || $this->Socket === false )
47+
if( $ErrNo || $Socket === false )
4848
{
4949
throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET );
5050
}
5151

52+
$this->Socket = $Socket;
5253
Stream_Set_Timeout( $this->Socket, $Timeout );
5354
Stream_Set_Blocking( $this->Socket, true );
5455
}

SourceQuery/SourceRcon.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ public function Open( ) : void
5757
{
5858
if( !$this->RconSocket )
5959
{
60-
$this->RconSocket = @FSockOpen( $this->Socket->Address, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout );
60+
$RconSocket = @FSockOpen( $this->Socket->Address, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout );
6161

62-
if( $ErrNo || !$this->RconSocket )
62+
if( $ErrNo || !$RconSocket )
6363
{
6464
throw new SocketException( 'Can\'t connect to RCON server: ' . $ErrStr, SocketException::CONNECTION_FAILED );
6565
}
6666

67+
$this->RconSocket = $RconSocket;
6768
Stream_Set_Timeout( $this->RconSocket, $this->Socket->Timeout );
6869
Stream_Set_Blocking( $this->RconSocket, true );
6970
}

0 commit comments

Comments
 (0)