2020-09-09 18:32:57 +02:00
|
|
|
#!/usr/bin/env perl
|
2020-09-01 14:03:18 +02:00
|
|
|
|
2020-09-09 18:32:57 +02:00
|
|
|
use IO::Socket;
|
2020-10-06 16:50:31 +02:00
|
|
|
use File::Spec;
|
2020-09-09 18:32:57 +02:00
|
|
|
|
|
|
|
$socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1",
|
|
|
|
PeerPort => 1234,
|
|
|
|
Proto => "tcp",
|
|
|
|
Type => SOCK_STREAM);
|
|
|
|
|
2020-10-06 16:50:31 +02:00
|
|
|
my $absolute_path = File::Spec->rel2abs($ARGV[0]);
|
|
|
|
|
2020-09-13 18:40:44 +02:00
|
|
|
# Send the length of the first argument as a byte.
|
2020-10-26 21:29:11 +01:00
|
|
|
$socket->send(pack("L", length($absolute_path)));
|
2020-09-13 18:40:44 +02:00
|
|
|
# Send the first argument as a string.
|
2020-10-06 16:50:31 +02:00
|
|
|
$socket->send($absolute_path);
|
2020-09-13 18:40:44 +02:00
|
|
|
|
2020-10-26 21:29:11 +01:00
|
|
|
# Get and send the content of the file, prefixed by its length.
|
|
|
|
my $content = do{local(@ARGV,$/)=$absolute_path;<>};
|
|
|
|
$socket->send(pack("L", length($content)));
|
|
|
|
$socket->send($content);
|
|
|
|
|
|
|
|
# Get size of written content. This blocks until the players hits save or close.
|
|
|
|
my $length_str;
|
|
|
|
$socket->recv($length_str, 4);
|
|
|
|
my $length = unpack("L", $length_str);
|
|
|
|
my $new_content = "";
|
|
|
|
$socket->recv($new_content, $length);
|
|
|
|
|
|
|
|
# Write content back into the file.
|
|
|
|
my $handle;
|
|
|
|
open ($handle,'>',$absolute_path) or die("Error opening file");
|
|
|
|
print $handle $new_content;
|
|
|
|
close ($handle) or die ("Error closing file");
|
|
|
|
|
2020-09-13 18:40:44 +02:00
|
|
|
# This call is intended to block, we're waiting for Godot to close the connection.
|
2020-09-09 18:32:57 +02:00
|
|
|
my $reply;
|
|
|
|
$socket->read($reply, 1000);
|