@@ -69,45 +69,50 @@ public function Read( $Length = 1400 )
6969 // GoldSource RCON has same structure as Query
7070 $ Buffer = $ this ->Socket ->Read ( );
7171
72- if ( $ Buffer ->GetByte ( ) !== SourceQuery::S2A_RCON )
73- {
74- throw new InvalidPacketException ( 'Invalid rcon response. ' , InvalidPacketException::PACKET_HEADER_MISMATCH );
75- }
76-
77- $ Buffer = $ Buffer ->Get ( );
78- $ Trimmed = Trim ( $ Buffer );
79-
80- if ( $ Trimmed === 'Bad rcon_password. ' )
81- {
82- throw new AuthenticationException ( $ Trimmed , AuthenticationException::BAD_PASSWORD );
83- }
84- else if ( $ Trimmed === 'You have been banned from this server. ' )
85- {
86- throw new AuthenticationException ( $ Trimmed , AuthenticationException::BANNED );
87- }
88-
72+ $ StringBuffer = '' ;
8973 $ ReadMore = false ;
9074
9175 // There is no indentifier of the end, so we just need to continue reading
92- // TODO: Needs to be looked again, it causes timeouts
9376 do
9477 {
95- $ this ->Socket ->Read ( );
96-
97- $ ReadMore = $ Buffer ->Remaining ( ) > 0 && $ Buffer ->GetByte ( ) === SourceQuery::S2A_RCON ;
78+ $ ReadMore = $ Buffer ->Remaining ( ) > 0 ;
9879
9980 if ( $ ReadMore )
10081 {
101- $ Packet = $ Buffer ->Get ( );
102- $ Buffer .= SubStr ( $ Packet , 0 , -2 );
82+ if ( $ Buffer ->GetByte ( ) !== SourceQuery::S2A_RCON )
83+ {
84+ throw new InvalidPacketException ( 'Invalid rcon response. ' , InvalidPacketException::PACKET_HEADER_MISMATCH );
85+ }
86+
87+ $ Packet = $ Buffer ->Get ( );
88+ $ StringBuffer .= $ Packet ;
89+ //$StringBuffer .= SubStr( $Packet, 0, -2 );
10390
10491 // Let's assume if this packet is not long enough, there are no more after this one
10592 $ ReadMore = StrLen ( $ Packet ) > 1000 ; // use 1300?
93+
94+ if ( $ ReadMore )
95+ {
96+ $ Buffer = $ this ->Socket ->Read ( );
97+ }
10698 }
10799 }
108100 while ( $ ReadMore );
109101
110- $ Buffer ->Set ( Trim ( $ Buffer ) );
102+ $ Trimmed = trim ( $ StringBuffer );
103+
104+ if ( $ Trimmed === 'Bad rcon_password. ' )
105+ {
106+ throw new AuthenticationException ( $ Trimmed , AuthenticationException::BAD_PASSWORD );
107+ }
108+ else if ( $ Trimmed === 'You have been banned from this server. ' )
109+ {
110+ throw new AuthenticationException ( $ Trimmed , AuthenticationException::BANNED );
111+ }
112+
113+ $ Buffer ->Set ( $ Trimmed );
114+
115+ return $ Buffer ;
111116 }
112117
113118 public function Command ( $ Command )
0 commit comments