File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class Rcon
2626
2727 const PACKET_AUTHORIZE = 5 ;
2828 const PACKET_COMMAND = 6 ;
29+ const PACKET_COMMAND_ENDING = 7 ;
2930
3031 const SERVERDATA_AUTH = 3 ;
3132 const SERVERDATA_AUTH_RESPONSE = 2 ;
@@ -117,15 +118,21 @@ public function sendCommand($command)
117118 // send command packet
118119 $ this ->writePacket (self ::PACKET_COMMAND , self ::SERVERDATA_EXECCOMMAND , $ command );
119120
121+ // send additional packet to determine last response packet later
122+ $ this ->writePacket (self ::PACKET_COMMAND_ENDING , self ::SERVERDATA_EXECCOMMAND , 'ping ' );
123+
120124 // get response
125+ $ response = '' ;
121126 $ response_packet = $ this ->readPacket ();
122- if ($ response_packet ['id ' ] == self ::PACKET_COMMAND ) {
123- if ($ response_packet ['type ' ] == self ::SERVERDATA_RESPONSE_VALUE ) {
124- $ this ->lastResponse = $ response_packet ['body ' ];
125-
126- return $ response_packet ['body ' ];
127- }
127+ while ($ response_packet ['id ' ] == self ::PACKET_COMMAND && $ response_packet ['type ' ] == self ::SERVERDATA_RESPONSE_VALUE ) {
128+ $ response .= $ response_packet ['body ' ];
129+ $ response_packet = $ this ->readPacket ();
128130 }
131+ $ response = substr ($ response , 0 , -3 );
132+ if ($ response != '' ) {
133+ $ this ->lastResponse = $ response_packet ['body ' ];
134+ return $ response ;
135+ }
129136
130137 return false ;
131138 }
You can’t perform that action at this time.
0 commit comments