[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  Read a file and send it to the world.

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Read a file and send it to the world.
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Foifur   (2 posts)  [Biography] bio
Date Tue 27 Sep 2005 03:27 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,800 posts)  [Biography] bio   Forum Administrator
Date Sun 18 Sep 2005 06:41 AM (UTC)  quote  ]

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
[Go to top] top

Posted by Ekerim   Sweden  (18 posts)  [Biography] bio
Date Thu 15 Sep 2005 06:20 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Foifur   (2 posts)  [Biography] bio
Date Thu 15 Sep 2005 05:49 PM (UTC)  quote  ]
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
[Go to top] 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.


1,955 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]