Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Tips and tricks
➜ Read a file and send it to the world.
Read a file and send it to the world.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Foifur
(2 posts) Bio
|
Date
| Thu 15 Sep 2005 05:49 PM (UTC) |
Message
| I'm looking for a way to send the contents of a file to the mud. Is this possible? I would be very useful for uploading edited textfiles without having to send it as one long line.
Example:
I have an alias .plan (displayed in finger information) on the mud that I want to update with new content.
I want to be able to do something like 'alias .plan <command to read file> or something that would accomplish that.
//Foifur | Top |
|
Posted by
| Ekerim
Sweden (18 posts) Bio
|
Date
| Reply #1 on Thu 15 Sep 2005 06:20 PM (UTC) |
Message
| Yes, you can read a file and send the contents (line-by-line) to the MU*.
I would put something like the code below in my script file (Perl):
sub sendFile2PlanEditor( $$$ ) {
# We don't care about the 1st two arguments so we discard them and save the 3rd arg.
my ( undef, undef, $aref_args ) = @_;
my $fileName = @{$aref_args}[0];
# Open the file or show a nice error message.
if ( open( IN, '<' . $fileName ) ) {
# If you need to send some command to initiate the .plan editor you do it like this...
# $world->SendImmediate( 'planeditor' );
# If you need to send a special character at the beginning
# of each line (like a - or a = or something)...
my $preStr = '';
# Send the text...line by line...
while ( <IN> ) {
# Remove the newline.
chomp;
# Send it allready!!
$world->SendImmediate( $preStr . $_ );
}
close( IN );
# If you need to send a command to close the edit you do it here...
# $world->SendImmediate( '.' );
} else {
$world->ColourNote( '#FFFF00', '#FF0000', "#ERROR: Unable to open file - $!" );
}
}
// Fredrik | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 18 Sep 2005 06:41 AM (UTC) Amended on Sun 18 Sep 2005 06:44 AM (UTC) by Nick Gammon
|
Message
| For a start, MUSHclient has that ability built in.
See the Input menu -> Send File.
Assuming you want to do it via scripting, you can do it quickly and shortly using Lua. This alias below assumes you have the Lua language selected as your scripting language. If not, just make a plugin with it in. When you type "sendfile" it will then send the contents of file "test.txt" to the MUD. You may want to add a pathname to it, or maybe put the filename as an argument to the alias.
<aliases>
<alias
match="sendfile"
enabled="y"
send_to="12"
sequence="100"
>
<send>
do
local f = assert (io.open ("test.txt", "r"))
local t = f:read ("*all") -- read file in
f:close ()
Send (t) -- send to MUD
end
</send>
</alias>
</aliases>
This example raises a script assertion if the file cannot be opened. You could make it neater by displaying a message in red, for instance.
You might also use SendNoEcho rather than Send to stop the file from being echoed in the output window.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Foifur
(2 posts) Bio
|
Date
| Reply #3 on Tue 27 Sep 2005 03:27 PM (UTC) |
Message
| Sorry for the late reply, I've been away for a while.
The functionality in input-> Send file was excactly what I was looking for. I obviously didn't look hard enough.
Thank you for the good answer and examples.
//Foifur | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,625 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top