1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php function ExecRCon($socket, string $rcon_pw, string $cmd): string { 	$strbuild = ["\x01\x00\xF2"]; 	$strbuild[] = chr(strlen($rcon_pw)); 	$strbuild[] = $rcon_pw; 	$strbuild[] = pack('v', strlen($cmd)); 	$strbuild[] = $cmd; 	 	$str = implode('', $strbuild); 	$str_length = strlen($str); 	 	socket_write($socket, $str); 	 	if(strcmp(socket_read($socket, 3), "\x01\x00\xF0") == 0) 	{ 		socket_read($socket, 2); 		$command_result_length = unpack('v', socket_read($socket, 2))[1]; 		 		return socket_read($socket, $command_result_length); 	} 	else 		throw new Exception('Failed to execute remote command'); }
I can send RCon command to the server (I can see Parse RCon ext. message), but reading the server message throws warning (and FALSE is returned in socket_read).
1
PHP Warning: socket_read(): unable to read from socket [10040]: A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself.
Attempt to read the socket again simply hangs it.
This is how I call it. I can see ERROR: Unknown command 'Mon' (Mon) in the server.
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php require('rcon.php'); $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_bind($sock, '0.0.0.0', 3662); socket_connect($sock, '192.168.43.54', 25000); echo ExecRCon($sock, 'Password', 'Mon');
Can someone help? I'm relatively new on this thing.