Skip to content

Commit dc5c130

Browse files
committed
Rename buffer read functions
1 parent 951e2c3 commit dc5c130

File tree

7 files changed

+118
-118
lines changed

7 files changed

+118
-118
lines changed

SourceQuery/BaseSocket.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function ReadInternal( Buffer $Buffer, callable $SherlockFunction ) :
5252
throw new InvalidPacketException( 'Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY );
5353
}
5454

55-
$Header = $Buffer->GetLong( );
55+
$Header = $Buffer->ReadInt32( );
5656

5757
if( $Header === -1 ) // Single packet
5858
{
@@ -67,13 +67,13 @@ protected function ReadInternal( Buffer $Buffer, callable $SherlockFunction ) :
6767

6868
do
6969
{
70-
$RequestID = $Buffer->GetLong( );
70+
$RequestID = $Buffer->ReadInt32( );
7171

7272
switch( $this->Engine )
7373
{
7474
case SourceQuery::GOLDSOURCE:
7575
{
76-
$PacketCountAndNumber = $Buffer->GetByte( );
76+
$PacketCountAndNumber = $Buffer->ReadByte( );
7777
$PacketCount = $PacketCountAndNumber & 0xF;
7878
$PacketNumber = $PacketCountAndNumber >> 4;
7979

@@ -82,18 +82,18 @@ protected function ReadInternal( Buffer $Buffer, callable $SherlockFunction ) :
8282
case SourceQuery::SOURCE:
8383
{
8484
$IsCompressed = ( $RequestID & 0x80000000 ) !== 0;
85-
$PacketCount = $Buffer->GetByte( );
86-
$PacketNumber = $Buffer->GetByte( ) + 1;
85+
$PacketCount = $Buffer->ReadByte( );
86+
$PacketNumber = $Buffer->ReadByte( ) + 1;
8787

8888
if( $IsCompressed )
8989
{
90-
$Buffer->GetLong( ); // Split size
90+
$Buffer->ReadInt32( ); // Split size
9191

92-
$PacketChecksum = $Buffer->GetUnsignedLong( );
92+
$PacketChecksum = $Buffer->ReadUInt32( );
9393
}
9494
else
9595
{
96-
$Buffer->GetShort( ); // Split size
96+
$Buffer->ReadInt16( ); // Split size
9797
}
9898

9999
break;
@@ -104,7 +104,7 @@ protected function ReadInternal( Buffer $Buffer, callable $SherlockFunction ) :
104104
}
105105
}
106106

107-
$Packets[ $PacketNumber ] = $Buffer->Get( );
107+
$Packets[ $PacketNumber ] = $Buffer->Read( );
108108

109109
$ReadMore = $PacketCount > sizeof( $Packets );
110110
}

SourceQuery/Buffer.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public function Remaining( ) : int
6161
}
6262

6363
/**
64-
* Gets data from buffer
64+
* Reads the specified number of bytes.
6565
*
6666
* @param int $Length Bytes to read
6767
*/
68-
public function Get( int $Length = -1 ) : string
68+
public function Read( int $Length = -1 ) : string
6969
{
7070
if( $Length === 0 )
7171
{
@@ -91,97 +91,97 @@ public function Get( int $Length = -1 ) : string
9191
}
9292

9393
/**
94-
* Get byte from buffer
94+
* Reads the next byte.
9595
*/
96-
public function GetByte( ) : int
96+
public function ReadByte( ) : int
9797
{
98-
return ord( $this->Get( 1 ) );
98+
return ord( $this->Read( 1 ) );
9999
}
100100

101101
/**
102-
* Get short from buffer
102+
* Reads a 2-byte signed integer.
103103
*/
104-
public function GetShort( ) : int
104+
public function ReadInt16( ) : int
105105
{
106106
if( $this->Remaining( ) < 2 )
107107
{
108-
throw new InvalidPacketException( 'Not enough data to unpack a short.', InvalidPacketException::BUFFER_EMPTY );
108+
throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
109109
}
110110

111-
$Data = unpack( 'v', $this->Get( 2 ) );
111+
$Data = unpack( 'v', $this->Read( 2 ) );
112112

113113
if( $Data === false )
114114
{
115-
throw new InvalidPacketException( 'Failed to unpack a short.', InvalidPacketException::UNPACK_FAILED );
115+
throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
116116
}
117117

118118
return (int)$Data[ 1 ];
119119
}
120120

121121
/**
122-
* Get long from buffer
122+
* Reads a 4-byte signed integer.
123123
*/
124-
public function GetLong( ) : int
124+
public function ReadInt32( ) : int
125125
{
126126
if( $this->Remaining( ) < 4 )
127127
{
128-
throw new InvalidPacketException( 'Not enough data to unpack a long.', InvalidPacketException::BUFFER_EMPTY );
128+
throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
129129
}
130130

131-
$Data = unpack( 'l', $this->Get( 4 ) );
131+
$Data = unpack( 'l', $this->Read( 4 ) );
132132

133133
if( $Data === false )
134134
{
135-
throw new InvalidPacketException( 'Failed to unpack a long.', InvalidPacketException::UNPACK_FAILED );
135+
throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
136136
}
137137

138138
return (int)$Data[ 1 ];
139139
}
140140

141141
/**
142-
* Get float from buffer
142+
* Reads a 4-byte floating point value.
143143
*/
144-
public function GetFloat( ) : float
144+
public function ReadFloat32( ) : float
145145
{
146146
if( $this->Remaining( ) < 4 )
147147
{
148-
throw new InvalidPacketException( 'Not enough data to unpack a float.', InvalidPacketException::BUFFER_EMPTY );
148+
throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
149149
}
150150

151-
$Data = unpack( 'f', $this->Get( 4 ) );
151+
$Data = unpack( 'f', $this->Read( 4 ) );
152152

153153
if( $Data === false )
154154
{
155-
throw new InvalidPacketException( 'Failed to unpack a float.', InvalidPacketException::UNPACK_FAILED );
155+
throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
156156
}
157157

158158
return (float)$Data[ 1 ];
159159
}
160160

161161
/**
162-
* Get unsigned long from buffer
162+
* Reads a 4-byte unsigned integer.
163163
*/
164-
public function GetUnsignedLong( ) : int
164+
public function ReadUInt32( ) : int
165165
{
166166
if( $this->Remaining( ) < 4 )
167167
{
168-
throw new InvalidPacketException( 'Not enough data to unpack an usigned long.', InvalidPacketException::BUFFER_EMPTY );
168+
throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
169169
}
170170

171-
$Data = unpack( 'V', $this->Get( 4 ) );
171+
$Data = unpack( 'V', $this->Read( 4 ) );
172172

173173
if( $Data === false )
174174
{
175-
throw new InvalidPacketException( 'Failed to unpack a ulong.', InvalidPacketException::UNPACK_FAILED );
175+
throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
176176
}
177177

178178
return (int)$Data[ 1 ];
179179
}
180180

181181
/**
182-
* Read one string from buffer ending with null byte
182+
* Read a null-terminated string.
183183
*/
184-
public function GetString( ) : string
184+
public function ReadNullTermString( ) : string
185185
{
186186
$ZeroBytePosition = strpos( $this->Buffer, "\0", $this->Position );
187187

@@ -190,7 +190,7 @@ public function GetString( ) : string
190190
return '';
191191
}
192192

193-
$String = $this->Get( $ZeroBytePosition - $this->Position );
193+
$String = $this->Read( $ZeroBytePosition - $this->Position );
194194

195195
$this->Position++;
196196

SourceQuery/GoldSourceRcon.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public function Read( ) : Buffer
8383

8484
if( $ReadMore )
8585
{
86-
if( $Buffer->GetByte( ) !== SourceQuery::S2A_RCON )
86+
if( $Buffer->ReadByte( ) !== SourceQuery::S2A_RCON )
8787
{
8888
throw new InvalidPacketException( 'Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH );
8989
}
9090

91-
$Packet = $Buffer->Get( );
91+
$Packet = $Buffer->Read( );
9292
$StringBuffer .= $Packet;
9393
//$StringBuffer .= SubStr( $Packet, 0, -2 );
9494

@@ -129,7 +129,7 @@ public function Command( string $Command ) : string
129129
$this->Write( 0, 'rcon ' . $this->RconChallenge . ' "' . $this->RconPassword . '" ' . $Command . "\0" );
130130
$Buffer = $this->Read( );
131131

132-
return $Buffer->Get( );
132+
return $Buffer->Read( );
133133
}
134134

135135
public function Authorize( string $Password ) : void
@@ -139,11 +139,11 @@ public function Authorize( string $Password ) : void
139139
$this->Write( 0, 'challenge rcon' );
140140
$Buffer = $this->Socket->Read( );
141141

142-
if( $Buffer->Get( 14 ) !== 'challenge rcon' )
142+
if( $Buffer->Read( 14 ) !== 'challenge rcon' )
143143
{
144144
throw new AuthenticationException( 'Failed to get RCON challenge.', AuthenticationException::BAD_PASSWORD );
145145
}
146146

147-
$this->RconChallenge = trim( $Buffer->Get( ) );
147+
$this->RconChallenge = trim( $Buffer->Read( ) );
148148
}
149149
}

SourceQuery/Socket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ public function Sherlock( Buffer $Buffer ) : bool
108108

109109
$Buffer->Set( $Data );
110110

111-
return $Buffer->GetLong( ) === -2;
111+
return $Buffer->ReadInt32( ) === -2;
112112
}
113113
}

0 commit comments

Comments
 (0)