You don't need to start a server in lua and interchange data with your application.
Thanks to Clement, it's possible to use Qt directly in DFHack as a C++ plugin.
See https://github.com/cvuchener/dfhack-qt for the framework and
my plugin https://github.com/ragundo/DwarfExplorer as a working Qt dfhack plugin example.
Also, I'm working in something similar, but I started working for the "DF events area" instead of the "sound area".
See https://github.com/ragundo/dwidder.
Anyway, I'd prefer to collaborate in a C++ plugin.
That's awesome. I'll be honest and say that I had no clue such a project existed.
Still, there's a great disadvantage to that, and that's
the reason why I chose not to use C++: you'd have to recompile the plugin whenever you upgrade df/dfhack.
There's plenty of df players out there who don't have the knowledge/time/environment... to build a plugin.
Perhaps they're running old versions, maybe the build environment cannot be reproduced easily.
Luckily, the QtSense's approach allows dfhack to have multiple "clients" or "plugins" that connect to QtSense.
So, one could still develop a dfhack integration with a C++ or a Qt plugin that connects to QtSense simply using a TCP socket to localhost.
If this helps, let me document the protocol down here:
Whenever a client connects, QtSense sends back his version and its status:
QtSense 1.0.0
READY
Any QtSense version 1.0.x uses the same protocol as 1.0.0.
The protocol follows a fixed line-based command protocol;
A command can have multiple distinct arguments.
After each command, a newline ('\n') character needs to be appended in order to run the command.
The only commands that actually do something are MSG and PING.
MSGAll arguments are all distinct phrases that need to be interpreted and played by QtSense.
Arguments are separated by the '|' character.
MSG|It is raining.
PINGSends a PING to the server.
The server will send a PONG back.
Some character substitution needs to happen on the plugin-side as per the following table:
Before | After |
& | &1 |
| | &2 |
\n | &3 |
\r | &4 |
All the arguments have to be joined together using the separator character '|'.
The server will transform the resulting string back into the original command and run it.
The server will never send you any data, unless you use a "PING" command in which case it sends a PONG back.