File tree 2 files changed +16
-9
lines changed
2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ const protocol = Object.freeze({
11
11
SERVERDATA_RESPONSE_VALUE : 0x00 , // Response of SERVERDATA_EXECCOMMAND
12
12
13
13
ID_AUTH : 0x999 ,
14
- ID_REQUEST : 0x123
14
+ ID_REQUEST : 0x123 ,
15
+ ID_TERM :0x777
15
16
} )
16
17
17
18
export default protocol
Original file line number Diff line number Diff line change @@ -161,14 +161,20 @@ class RCON {
161
161
}
162
162
163
163
this . connection . removeListener ( 'data' , onData )
164
- } else if ( id === decodedPacket . id ) {
165
- response = response . concat ( decodedPacket . body . replace ( / \n $ / , '\n' ) ) // remove last line break
166
-
167
- // Check the response if it's defined rather than if it contains 'command ${body}'
168
- // Reason for this is because we no longer need to check if it starts with 'command', testing shows it never will
169
- if ( response ) {
170
- this . connection . removeListener ( 'data' , onData )
171
- resolve ( response )
164
+ } else if ( id === decodedPacket . id || decodedPacket . id === protocol . ID_TERM ) {
165
+ // don't add the termination packet.
166
+ if ( decodedPacket . id != protocol . ID_TERM ) {
167
+ response = response . concat ( decodedPacket . body . replace ( / \n $ / , '\n' ) ) // remove last line break
168
+ }
169
+
170
+ // Hack to cope with multipacket responses.
171
+ // see https://developer.valvesoftware.com/wiki/Talk:Source_RCON_Protocol#How_to_receive_split_response?
172
+ if ( decodedPacket . size > 3700 ) {
173
+ let encodedTerminationPacket = packets . encode ( protocol . SERVERDATA_RESPONSE_VALUE , protocol . ID_TERM , '' ) ;
174
+ this . connection . write ( encodedTerminationPacket ) ;
175
+ } else if ( decodedPacket . size <= 3700 ) { // no need to check for ID_TERM here, since this packet will always be < 3700
176
+ this . connection . removeListener ( 'data' , onData ) ;
177
+ resolve ( response ) ;
172
178
}
173
179
}
174
180
You can’t perform that action at this time.
0 commit comments