[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]  Plugins
. . -> [Subject]  Redirecting Client Output to External Program
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Redirecting Client Output to External Program

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


Posted by Eir   (10 posts)  [Biography] bio
Date Tue 10 Jul 2012 02:53 PM (UTC)  quote  ]

Amended on Tue 10 Jul 2012 02:55 PM (UTC) by Eir

Message
Hi, I'm working on a MOO that I currently connect to using MUSH client. There is a verb command on the MOO that outputs to my MUSH client a large volume of 3D Cartesian coordinates.

I can manually copy the output from my MUSH client window after entering in the verb command to my MOO, and paste it to a flat file where I can run a standalone Windows application, that I wrote myself, that is able to consume the output pasted to the flat file and generate a Direct X 3D visualization.

What I would be very interested in is somehow setting up MUSH client to automatically capture the output generated after entering the verb command and then send it to my standalone application for rendering.

Additionally, I'd like to eliminate the need of a flat-file altogether if possible.

I don't know the capabilities of MUSH client add-ins, or if what I want to do is feasible using MUSCH client. I'm looking for some suggestions or guidance into the correct approach here.

Thanks for reading.
[Go to top] top

Posted by Eir   (10 posts)  [Biography] bio
Date Reply #1 on Tue 10 Jul 2012 04:16 PM (UTC)  quote  ]
Message
After doing some more reading, I think what I really want is a trigger that captures some output (based on regex) and sends it to an external program.

Seems simple enough.

I looked at the edit trigger window and saw under "Send to:" a lot of options:

World
Command
Output
Status
Notepad (new)
Notepad (append)
Log file
Notepad (replace)
World (speedwalk delay)
Variable
Execute
Speedwalk
Script
World (immediate)
Script (after omit)

Are any of these what I need? I found some documentation on triggers, but none that explained the "Send To" parameter pick list.
[Go to top] top

Posted by Eir   (10 posts)  [Biography] bio
Date Reply #2 on Tue 10 Jul 2012 07:13 PM (UTC)  quote  ]

Amended on Tue 10 Jul 2012 08:45 PM (UTC) by Eir

Message
OK, so I came up with what I believe is a reasonable solution.

I setup my visualization program to create a thread which sets up a TCP Listener on my localhost and a port of my choosing.

I then wrote a small utility client that simply accepts some input in a command parameter and sends it to my localhost and port to update the data for the visualization.

So if my client were `client.exe` I'm thinking on using the script function that I found in the LUA docs here:
http://www.gammon.com.au/scripts/doc.php?lua=os.execute

So something like,

io.execute('client.exe data to send to tcp port')

What I'm trying to do now is workout the trigger part to collect the data. Currently it spans multiple lines, but I'm not sure how to go about the regex in this case. I think the regex only matches one line output per trigger?


Er I know the start of the line, so I can trigger the start and call a script to read in all the lines till it matches an empty line?
[Go to top] top

Posted by Nick Gammon   Australia  (19,470 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 10 Jul 2012 10:38 PM (UTC)  quote  ]
Message
Like this:

Template:faq=37 Please read the MUSHclient FAQ - point 37.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Eir   (10 posts)  [Biography] bio
Date Reply #4 on Wed 11 Jul 2012 04:56 PM (UTC)  quote  ]

Amended on Wed 11 Jul 2012 11:16 PM (UTC) by Eir

Message
Awesome Nick! I've been bringing myself quickly up-to-speed with your useful youtube videos and documentation. I'm thoroughly impressed with MUSH client and the sheer amount of effort that must've went in to this program, website, and documentation.

Anyways, I have everything working almost like I want it, just one piece eludes me:

I can use the Lua function:

os.execute

For example, I used / as my script prefix on the MUSH client command window:

/os.execute('E:\"XNA Stuff"\Client\bin\Release\Client.exe "cmd line param"')

I don't work much with Lua, but I found it was necessary to escape all the backslashes in the OS command.

My program executes in the background and does not spawn a command window.

However when I execute the above a "C:\Windows\system32\cmd.exe" appears while my program is executing.

I can instead use:

/os.execute('start /min E:\"XNA Stuff"\Client\bin\Release\Client.exe "cmd line param"')

or

/os.execute('start /B E:\"XNA Stuff"\Client\bin\Release\Client.exe "cmd line param"')

Which causes this command windows to "flash" briefly. I'd like for no flashing window at all... any suggestions?

I did some research on my own and found it's most likely a Lua limitation:

http://stackoverflow.com/questions/6362841/use-lua-os-execute-in-windows-to-launch-a-program-with-out-a-flash-of-cmd

I'm not sure if the other scripting languages can spawn a process without a brief shell command window flashing.

Update:

I got around the issue by switching to VBScript, not as ideal as Lua but at least got the job done:


Function ff(strIn)
ff = Chr(34) & strIn & Chr(34)
End Function

Function sendData(data)
Dim WSHShell
Dim RunIt
Set WSHShell = CreateObject("WScript.Shell")
RunIt = "E:\XNA Stuff\Client\bin\Release\Client.exe"
WSHShell.Run(ff(RunIt) & " " & ff(data))
End Function

sendData("sfsf ff ls sfs")


Another Update:

I'm currently doing some VBScript research, since I know even less about it than Lua to determine if I can cut the Client.exe out of the equation entirely. That is to define a connection to localhost 8012 via VBScript alone and send the string data via VBScript without using an auxiliary application like the above.


Yet another Update:

Since I new JScript far better than VBScript I decided to go that route. I altered my visualization to be an HTTPlistener instead of a generic TCPlistener so I could use some AJAX style stuff:


function send( data ) {
var server = new ActiveXObject("Msxml2.XMLHTTP.3.0");
server.open("POST","http://localhost:8012", true);
server.send(data);
}


With this in my script file I can always call this send function as often as I like to send as many async calls to my visualization http listener as I like. This rids the need of the client.exe and solves all my problems.

Now on to getting the triggers and regex's setup properly and send the correct data for visualizing.


EDIT:

OK my triggers are setup now, I went with the three trigger setup. Seems pretty good. Only thing was I wanted to store new lines in my string but \n or \0A wasn't doing the trick. Got some parse errors with \n stating unterminated string.
[Go to top] top

Posted by Nick Gammon   Australia  (19,470 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 12 Jul 2012 12:46 AM (UTC)  quote  ]
Message
This may possibly work better, not sure:

http://www.gammon.com.au/scripts/doc.php?lua=utils.shellexecute

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Eir   (10 posts)  [Biography] bio
Date Reply #6 on Thu 12 Jul 2012 01:43 AM (UTC)  quote  ]
Message
Interesting, I may take a look at that. Though, at current I finally got everything setup so it's at least working on Windows with JScript.
[Go to top] top

Posted by Eir   (10 posts)  [Biography] bio
Date Reply #7 on Thu 12 Jul 2012 02:36 PM (UTC)  quote  ]
Message
OK, things are working great (except now that I got this going, the world I was playing on went down...heh). I was browsing through your Lua pages, especially the io, os, and utils.

I was trying to find something in Lua to where I can asynchronously pass a string to either a TcpListener or HttpListener in my .NET XNA app. I was able to achieve POSTing to my HttpListener in JScript via the send function I posted above.

Basically, does the Lua with MUSH client support socket connections?
[Go to top] top

Posted by Nick Gammon   Australia  (19,470 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Fri 13 Jul 2012 02:17 AM (UTC)  quote  ]
Message
Well, yes, but ...

Asynchronous sockets are a bit of a problem. It's the problem of "who is the boss?". Already the client deals with incoming (Windows) events and does nothing until it gets one. The normal way you deal with sockets (or indeed any IO) under Unix anyway is to set up the IOs and then do a select() call.

I don't see any major objection to sending synchronous TCP data to some other app. I seem to recall making a UDP sender a while ago, in fact UDP sending is built into the client.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Eir   (10 posts)  [Biography] bio
Date Reply #9 on Fri 13 Jul 2012 04:07 PM (UTC)  quote  ]

Amended on Fri 13 Jul 2012 07:07 PM (UTC) by Eir

Message
Ah, nice.

Is there a quick example somewhere how I can send some data via UDP from within MUSH client using, say Lua?

E.g. I'd plan to:

1. Capture some data via triggers and process it a bit with some script

2. Send some data via UDP to another app based on the results of step 1


I've learned how to do 1 pretty easily now, just not sure what Lua calls to make to initiate the UDP part within MUSH client.

To give a glimpse into what I'm trying to achieve:
http://i.imgur.com/5a7ks.png

The world I'm playing on issues a series of 3D coords from an input command. I capture this data via triggers, and then process it and am currently using an unideal JScript xmlhttp request object to send the data to my http listener built into the program to visualize the data in 3D space.

Right now I'm just using very basic models to ensure I got all the locations correct, etc. But, each time I run the command to the world, the new coordinates automatically send the data to the visualizer and are rendered in their new locations.

I'd like to switch over to Lua from JScript and use UDP if possible.
[Go to top] top

Posted by Nick Gammon   Australia  (19,470 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Sat 14 Jul 2012 02:12 AM (UTC)  quote  ]
Message
Example here:

http://www.gammon.com.au/forum/?id=4951

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


2,974 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

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[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]    [Web site powered by FutureQuest.Net]