Skip to content

Instantly share code, notes, and snippets.

@douglasparker
Last active December 9, 2022 23:56
Show Gist options
  • Save douglasparker/43a5f836f31e1663e7317b361d9c924f to your computer and use it in GitHub Desktop.
Save douglasparker/43a5f836f31e1663e7317b361d9c924f to your computer and use it in GitHub Desktop.
BYOND Export is a PHP Function that creates a socket, connects to a remote DreamDaemon Instance, and sends a message that can be received via world.Import().

BYOND Export

BYOND Export is a PHP Function that creates a socket, connects to a remote DreamDaemon Instance, and sends a message that can be received via world.Import().

Dependencies

  • PHP Versions: 4.1, 5.0, 7.0

Contributors

A special thanks to Mobius Evalon and Crispy for their contributions to the structuring of packet data.

<?
function byond_export($ip_address, $port, $message)
{
if($message{0} != '?') {
$message = ('?' . $message);
}
$packet = '\x00\x83' . pack('n', strlen($message) + 6) . '\x00\x00\x00\x00\x00' . $message . '\x00';
if(!$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) {
echo('Failed to create socket resource: ' . socket_strerror(socket_last_error()));
return false;
}
else if(!socket_connect($socket, $ip_address, $port)) {
echo('Failed to connect to remote endpoint: ' . socket_strerror(socket_last_error()));
return false;
}
else if(!socket_write($socket, $packet, strlen($packet))) {
echo('Failed to send packet to remote endpoint. ' . socket_strerror(socket_last_error()));
return false;
}
socket_close($socket);
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment