Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
require_once __DIR__ . '/Workerman-master/Autoloader.php';
use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Protocols\Websocket;
use Workerman\Lib\Timer;
$udp1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($udp1, SOL_SOCKET, SO_BROADCAST, 1);
$udp2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($udp2, SOL_SOCKET, SO_BROADCAST, 1);
Timer::add(3, function () use(&$udp1, &$udp2) {
$hostInfoData = hex2bin(
'70B70F0076B70F001500000016000000'.
'73657269616C697A6174696F6E3A3A61'.
'7263686976650A000404040801000000'.
'0000000000'.dechex(ip2long('192.168.195.91')).'01000000000000'
);
$BASE_HOST_DATA =
"\x44\x00\x00\x00" . openssl_encrypt($hostInfoData, 'AES-128-ECB', 'CHUNICHUNICHUNIC', OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING);
socket_sendto($udp1, $BASE_HOST_DATA, strlen($BASE_HOST_DATA), 0, '192.168.195.255', 50001);
$BASE_SERVER_DATA =
"\x44\x00\x00\x00\x95\xa3" .
"\x13\x71\x9b\x9a\x6b\xd4\xf9\xc9\x68\xe3\x88\xe0\xf5\x5a\x5b\x4c" .
"\xfd\xf8\x96\xd4\x38\x75\x42\xd6\x5e\xbc\x3a\x22\x89\x3b\x63\x84" .
"\x8f\x52\x4c\x57\x3a\x36\xc3\x32\xcd\x13\xab\xd1\x5c\x2c\xee\x37" .
"\x9c\xde\x1d\x51\xd4\x25\x78\xc9\xfa\xf4\x68\x2c\x95\x66";
socket_sendto($udp2, $BASE_SERVER_DATA, strlen($BASE_SERVER_DATA), 0, '192.168.195.255', 50003);
//echo "Broadcast ".time()."\n";
});
$worker = new Worker("tcp://0.0.0.0:50001");
$worker->count = 1;
$worker->onConnect = function($conn) {
//echo "Got Connection\n";
$BASE_SERVER_SYNC_DATA =
"\x44\x00\x00\x00\xa1\xeb\x40\x0e\x0a\xa8" .
"\xc5\xd6\xfa\x69\x45\x3d\x41\x85\xc5\x9f\x5b\x4c\xfd\xf8\x96\xd4" .
"\x38\x75\x42\xd6\x5e\xbc\x3a\x22\x89\x3b\x63\x84\x8f\x52\x4c\x57" .
"\x3a\x36\xc3\x32\xcd\x13\xab\xd1\x5c\x2c\xc7\x11\x64\x70\x80\x6e" .
"\x45\x31\x61\x61\x5b\x64\xab\x6d\xe1\xcf";
$conn->send($BASE_SERVER_SYNC_DATA);
};
$worker->onMessage = function($conn, $data) {
if (bin2hex(substr($data, 0, 6)) === '44000000a1eb') {
//echo "heartbeat\n";
$BASE_SERVER_SYNC_DATA =
"\x44\x00\x00\x00\xa1\xeb\x40\x0e\x0a\xa8" .
"\xc5\xd6\xfa\x69\x45\x3d\x41\x85\xc5\x9f\x5b\x4c\xfd\xf8\x96\xd4" .
"\x38\x75\x42\xd6\x5e\xbc\x3a\x22\x89\x3b\x63\x84\x8f\x52\x4c\x57" .
"\x3a\x36\xc3\x32\xcd\x13\xab\xd1\x5c\x2c\xc7\x11\x64\x70\x80\x6e" .
"\x45\x31\x61\x61\x5b\x64\xab\x6d\xe1\xcf";
$conn->send($BASE_SERVER_SYNC_DATA);
} else if (bin2hex(substr($data, 0, 6)) === '44000000377c') {
//echo "get settings\n";
$BASE_SERVER_SYNC_DATA =
"\x54\x00\x00\x00\xb9\xb1\xca\x9f\x66\x0d" .
"\x6f\xed\xaf\xa1\x1c\x63\xb9\x7a\x80\xa4\x5b\x4c\xfd\xf8\x96\xd4" .
"\x38\x75\x42\xd6\x5e\xbc\x3a\x22\x89\x3b\x63\x84\x8f\x52\x4c\x57" .
"\x3a\x36\xc3\x32\xcd\x13\xab\xd1\x5c\x2c\xe7\xcf\x11\x7a\xed\xc8" .
"\xce\x73\xd7\xb6\x34\x85\x90\x4d\x30\x01\xc7\x11\x64\x70\x80\x6e" .
"\x45\x31\x61\x61\x5b\x64\xab\x6d\xe1\xcf";
$conn->send($BASE_SERVER_SYNC_DATA);
}
};
Worker::runAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.